Skip to content

Commit

Permalink
Merge pull request #1079 from gbregman/devel
Browse files Browse the repository at this point in the history
Ignore dashes when comparing UUID values for namespace
  • Loading branch information
gbregman authored Feb 3, 2025
2 parents db6ab07 + 7b6180c commit 9ce6540
Show file tree
Hide file tree
Showing 2 changed files with 94 additions and 5 deletions.
21 changes: 16 additions & 5 deletions control/grpc.py
Original file line number Diff line number Diff line change
Expand Up @@ -404,6 +404,16 @@ def host_count(self):
def set_ana_group_id(self, anagrpid):
self.anagrpid = anagrpid

@staticmethod
def are_uuids_equal(uuid1: str, uuid2: str) -> bool:
assert uuid1 and uuid2, "UUID can't be empty"
try:
if uuid.UUID(uuid1) == uuid.UUID(uuid2):
return True
except Exception:
pass
return False


class NamespacesLocalList:
EMPTY_NAMESPACE = NamespaceInfo(None, None, None, 0, False, None, None, False)
Expand Down Expand Up @@ -440,7 +450,7 @@ def find_namespace(self, nqn, nsid, uuid=None) -> NamespaceInfo:

if uuid:
for ns in self.namespace_list[nqn]:
if uuid == self.namespace_list[nqn][ns].uuid:
if NamespaceInfo.are_uuids_equal(uuid, self.namespace_list[nqn][ns].uuid):
return self.namespace_list[nqn][ns]

return NamespacesLocalList.EMPTY_NAMESPACE
Expand Down Expand Up @@ -2532,10 +2542,11 @@ def list_namespaces(self, request, context=None):
self.logger.debug(f'Filter out namespace {n["nsid"]} which is '
f'different than requested nsid {request.nsid}')
continue
if request.uuid and request.uuid != n["uuid"]:
self.logger.debug(f'Filter out namespace with UUID {n["uuid"]} which is '
f'different than requested UUID {request.uuid}')
continue
if request.uuid:
if not NamespaceInfo.are_uuids_equal(request.uuid, n["uuid"]):
self.logger.debug(f'Filter out namespace with UUID {n["uuid"]} which '
f'is different than requested UUID {request.uuid}')
continue
lb_group = 0
try:
lb_group = n["anagrpid"]
Expand Down
78 changes: 78 additions & 0 deletions tests/test_cli.py
Original file line number Diff line number Diff line change
Expand Up @@ -529,6 +529,20 @@ def test_add_namespace(self, caplog, gateway):
cli(["--format", "json", "namespace", "list", "--subsystem", subsystem, "--uuid", uuid])
assert f'"uuid": "{uuid}"' in caplog.text
caplog.clear()
cli(["--format", "json", "namespace", "list", "--subsystem", subsystem,
"--uuid", uuid.upper()])
assert f'"uuid": "{uuid}"' in caplog.text
caplog.clear()
uuid_no_dashes = uuid.replace("-", "")
cli(["--format", "json", "namespace", "list", "--subsystem", subsystem,
"--uuid", uuid_no_dashes])
assert f'"uuid": "{uuid}"' in caplog.text
caplog.clear()
uuid_no_dashes = uuid.replace("-", "").upper()
cli(["--format", "json", "namespace", "list", "--subsystem", subsystem,
"--uuid", uuid_no_dashes])
assert f'"uuid": "{uuid}"' in caplog.text
caplog.clear()
cli(["namespace", "change_load_balancing_group", "--subsystem", subsystem,
"--nsid", nsid, "--load-balancing-group", "10"])
assert f"Failure changing load balancing group for namespace with ID {nsid} " \
Expand Down Expand Up @@ -1018,6 +1032,70 @@ def test_resize_namespace(self, caplog, gateway):
assert '"nsid": 4' not in caplog.text
assert '"nsid": 5' not in caplog.text
caplog.clear()
cli(["--format", "json", "namespace", "list", "--subsystem", subsystem,
"--uuid", uuid2.upper()])
assert '"nsid": 6' in caplog.text
assert '"block_size": 512' in caplog.text
assert '"rbd_image_size": "67108864"' in caplog.text
assert f'"uuid": "{uuid2}"' in caplog.text
assert '"nsid": 1' not in caplog.text
assert '"nsid": 2' not in caplog.text
assert '"nsid": 3' not in caplog.text
assert '"nsid": 4' not in caplog.text
assert '"nsid": 5' not in caplog.text
caplog.clear()
uuid2_no_dashes = uuid2.replace("-", "")
cli(["--format", "json", "namespace", "list", "--subsystem", subsystem,
"--uuid", uuid2_no_dashes])
assert '"nsid": 6' in caplog.text
assert '"block_size": 512' in caplog.text
assert '"rbd_image_size": "67108864"' in caplog.text
assert f'"uuid": "{uuid2}"' in caplog.text
assert '"nsid": 1' not in caplog.text
assert '"nsid": 2' not in caplog.text
assert '"nsid": 3' not in caplog.text
assert '"nsid": 4' not in caplog.text
assert '"nsid": 5' not in caplog.text
caplog.clear()
uuid2_no_dashes = uuid2.replace("-", "").upper()
cli(["--format", "json", "namespace", "list", "--subsystem", subsystem,
"--uuid", uuid2_no_dashes])
assert '"nsid": 6' in caplog.text
assert '"block_size": 512' in caplog.text
assert '"rbd_image_size": "67108864"' in caplog.text
assert f'"uuid": "{uuid2}"' in caplog.text
assert '"nsid": 1' not in caplog.text
assert '"nsid": 2' not in caplog.text
assert '"nsid": 3' not in caplog.text
assert '"nsid": 4' not in caplog.text
assert '"nsid": 5' not in caplog.text
caplog.clear()
uuid2_some_dashes = uuid2.replace("-", "", 2)
cli(["--format", "json", "namespace", "list", "--subsystem", subsystem,
"--uuid", uuid2_some_dashes])
assert '"nsid": 6' in caplog.text
assert '"block_size": 512' in caplog.text
assert '"rbd_image_size": "67108864"' in caplog.text
assert f'"uuid": "{uuid2}"' in caplog.text
assert '"nsid": 1' not in caplog.text
assert '"nsid": 2' not in caplog.text
assert '"nsid": 3' not in caplog.text
assert '"nsid": 4' not in caplog.text
assert '"nsid": 5' not in caplog.text
caplog.clear()
uuid2_some_dashes = uuid2.replace("-", "", 2).upper()
cli(["--format", "json", "namespace", "list", "--subsystem", subsystem,
"--uuid", uuid2_some_dashes])
assert '"nsid": 6' in caplog.text
assert '"block_size": 512' in caplog.text
assert '"rbd_image_size": "67108864"' in caplog.text
assert f'"uuid": "{uuid2}"' in caplog.text
assert '"nsid": 1' not in caplog.text
assert '"nsid": 2' not in caplog.text
assert '"nsid": 3' not in caplog.text
assert '"nsid": 4' not in caplog.text
assert '"nsid": 5' not in caplog.text
caplog.clear()
cli(["namespace", "resize", "--subsystem", subsystem, "--nsid", "22", "--size", "128MB"])
assert f"Failure resizing namespace 22 on {subsystem}: Can't find namespace" in caplog.text
caplog.clear()
Expand Down

0 comments on commit 9ce6540

Please sign in to comment.