Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion simplyblock_core/controllers/lvol_controller.py
Original file line number Diff line number Diff line change
Expand Up @@ -416,7 +416,7 @@ def add_lvol_ha(name, size, host_id_or_name, ha_type, pool_id_or_name, use_comp=
if len(nodes) > 0:
host_node = nodes[0]
else:
return False, f"Can not find storage node: {host_id_or_name}"
raise KeyError(f"Can not find storage node: {host_id_or_name}")
if host_node.lvol_sync_del():
logger.info(f"LVol sync delete task on node: {host_node.get_id()}, proceeding anyway")

Expand Down
55 changes: 29 additions & 26 deletions simplyblock_web/api/v2/cluster/storage_pool/volume/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -75,31 +75,34 @@ def add(
pass

if isinstance(data, _CreateParams):
volume_id_or_false, error = lvol_controller.add_lvol_ha(
name=data.name,
size=data.size,
pool_id_or_name=pool.get_id(),
use_crypto=data.encrypt,
max_size=0,
max_rw_iops=data.max_rw_iops,
max_rw_mbytes=data.max_rw_mbytes,
max_r_mbytes=data.max_r_mbytes,
max_w_mbytes=data.max_w_mbytes,
host_id_or_name=data.host_id,
ha_type=data.ha_type if data.ha_type is not None else 'default',
use_comp=False,
distr_vuid=0,
lvol_priority_class=data.priority_class,
namespaced=data.namespaced,
pvc_name=data.pvc_name,
ndcs=data.ndcs,
npcs=data.npcs,
allowed_hosts=data.allowed_hosts,
fabric=data.fabric,
max_namespace_per_subsys=data.max_namespace_per_subsys,
do_replicate=data.do_replicate,
replication_cluster_id=data.replication_cluster_id,
)
try:
volume_id_or_false, error = lvol_controller.add_lvol_ha(
name=data.name,
size=data.size,
pool_id_or_name=pool.get_id(),
use_crypto=data.encrypt,
max_size=0,
max_rw_iops=data.max_rw_iops,
max_rw_mbytes=data.max_rw_mbytes,
max_r_mbytes=data.max_r_mbytes,
max_w_mbytes=data.max_w_mbytes,
host_id_or_name=data.host_id,
ha_type=data.ha_type if data.ha_type is not None else 'default',
use_comp=False,
distr_vuid=0,
lvol_priority_class=data.priority_class,
namespaced=data.namespaced,
pvc_name=data.pvc_name,
ndcs=data.ndcs,
npcs=data.npcs,
allowed_hosts=data.allowed_hosts,
fabric=data.fabric,
max_namespace_per_subsys=data.max_namespace_per_subsys,
do_replicate=data.do_replicate,
replication_cluster_id=data.replication_cluster_id,
)
except KeyError as e:
raise HTTPException(404, str(e))
Comment on lines +104 to +105
elif isinstance(data, _CloneParams):
volume_id_or_false, error = snapshot_controller.clone(
data.snapshot_id,
Expand All @@ -113,7 +116,7 @@ def add(
raise AssertionError('unreachable')

if volume_id_or_false == False: # noqa
raise ValueError(error)
raise HTTPException(422, error)

return util.creation_response(
request, response_format,
Expand Down
10 changes: 10 additions & 0 deletions tests/unit/web/api/v2/test_volume_endpoints.py
Original file line number Diff line number Diff line change
Expand Up @@ -78,6 +78,16 @@ def test_clone_parameters_call_snapshot_clone(self, client, db, pool, lvol_contr
)
lvol_controller.add_lvol_ha.assert_not_called()

def test_missing_host_node_returns_404(self, client, db, pool, lvol_controller):
db.get_lvol_by_name.side_effect = KeyError('LVol not found')
lvol_controller.add_lvol_ha.side_effect = KeyError('Can not find storage node: bogus-id')

response = client.post(
f'{BASE}/', json={'name': 'volume-1', 'size': '10G', 'host_id': 'bogus-id'},
)

assert response.status_code == 404

def test_existing_name_returns_409(self, client, db, pool, volume, lvol_controller):
db.get_lvol_by_name.return_value = volume

Expand Down
Loading