Skip to content

Commit 4ceea69

Browse files
authored
Merge pull request #90 from verda-cloud/refactor/volume-dataclass
refactor Volume class to use dataclass and dataclass_json
2 parents c89ea32 + 25d46aa commit 4ceea69

File tree

3 files changed

+77
-347
lines changed

3 files changed

+77
-347
lines changed

CHANGELOG.md

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,10 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
1111

1212
- Added missing fields to the `Volume` class: `pseudo_path`, `mount_command`, `create_directory_command`, `filesystem_to_fstab_command`, `instances`, `contract`, `base_hourly_cost`, `monthly_price`, `currency`, `long_term`
1313

14+
### Changed
15+
16+
- Refactored `Volume` class to use `@dataclass` and `@dataclass_json` for consistency with `Instance` class. `Volume.create_from_dict()` is replaced by `Volume.from_dict()`; unknown API fields are now silently ignored via `Undefined.EXCLUDE`
17+
1418
## [1.23.1] - 2026-03-25
1519

1620
### Fixed

tests/unit_tests/volumes/test_volumes.py

Lines changed: 12 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -49,7 +49,7 @@
4949
'is_os_volume': True,
5050
'created_at': NVME_VOL_CREATED_AT,
5151
'target': TARGET_VDA,
52-
'ssh_key_ids': SSH_KEY_ID,
52+
'ssh_key_ids': [SSH_KEY_ID],
5353
'pseudo_path': 'volume-nxC2tf9F',
5454
'mount_command': 'mount -t nfs -o nconnect=16 nfs.fin-01.datacrunch.io:volume-nxC2tf9F /mnt/volume',
5555
'create_directory_command': 'mkdir -p /mnt/volume',
@@ -108,13 +108,13 @@ def endpoint(self, http_client):
108108

109109
def test_initialize_a_volume(self):
110110
volume = Volume(
111-
RANDOM_VOL_ID,
112-
VolumeStatus.DETACHED,
113-
HDD_VOL_NAME,
114-
HDD_VOL_SIZE,
115-
HDD,
116-
False,
117-
HDD_VOL_CREATED_AT,
111+
id=RANDOM_VOL_ID,
112+
status=VolumeStatus.DETACHED,
113+
name=HDD_VOL_NAME,
114+
size=HDD_VOL_SIZE,
115+
type=HDD,
116+
is_os_volume=False,
117+
created_at=HDD_VOL_CREATED_AT,
118118
)
119119

120120
assert volume.id == RANDOM_VOL_ID
@@ -129,8 +129,8 @@ def test_initialize_a_volume(self):
129129
assert volume.target is None
130130
assert volume.ssh_key_ids == []
131131

132-
def test_create_from_dict_without_new_fields(self):
133-
"""Test that create_from_dict handles API responses missing the new fields."""
132+
def test_from_dict_without_optional_fields(self):
133+
"""Test that from_dict handles API responses missing optional fields."""
134134
minimal_dict = {
135135
'id': RANDOM_VOL_ID,
136136
'status': VolumeStatus.DETACHED,
@@ -144,7 +144,7 @@ def test_create_from_dict_without_new_fields(self):
144144
'instance_id': None,
145145
'ssh_key_ids': [],
146146
}
147-
volume = Volume.create_from_dict(minimal_dict)
147+
volume = Volume.from_dict(minimal_dict)
148148
assert volume.id == RANDOM_VOL_ID
149149
assert volume.pseudo_path is None
150150
assert volume.mount_command is None
@@ -181,7 +181,7 @@ def test_get_volumes(self, volumes_service, endpoint):
181181
assert volume_nvme.is_os_volume
182182
assert volume_nvme.created_at == NVME_VOL_CREATED_AT
183183
assert volume_nvme.target == TARGET_VDA
184-
assert volume_nvme.ssh_key_ids == SSH_KEY_ID
184+
assert volume_nvme.ssh_key_ids == [SSH_KEY_ID]
185185
assert volume_nvme.pseudo_path == NVME_VOLUME['pseudo_path']
186186
assert volume_nvme.mount_command == NVME_VOLUME['mount_command']
187187
assert volume_nvme.create_directory_command == NVME_VOLUME['create_directory_command']

0 commit comments

Comments
 (0)