Skip to content

Commit

Permalink
Give an explicit error message in case of creating too many namespace…
Browse files Browse the repository at this point in the history
…s on a subsystem

Fixes bz#2282295

Signed-off-by: Gil Bregman <[email protected]>
  • Loading branch information
gbregman committed Nov 14, 2024
1 parent 3f0fbd7 commit 4c8110b
Show file tree
Hide file tree
Showing 2 changed files with 35 additions and 2 deletions.
13 changes: 12 additions & 1 deletion control/grpc.py
Original file line number Diff line number Diff line change
Expand Up @@ -1172,7 +1172,18 @@ def create_namespace(self, subsystem_nqn, bdev_name, nsid, anagrpid, uuid, no_au

if no_auto_visible and self.subsystem_nsid_bdev_and_uuid.get_namespace_count(subsystem_nqn,
True, 0) >= self.max_namespaces_with_netmask:
errmsg = f"Failure adding namespace{nsid_msg} to {subsystem_nqn}, maximal number of namespaces which are not auto visible ({self.max_namespaces_with_netmask}) was already reached"
errmsg = f"Failure adding namespace{nsid_msg} to {subsystem_nqn}: maximal number of namespaces which are not auto visible ({self.max_namespaces_with_netmask}) has already been reached"
self.logger.error(f"{errmsg}")
return pb2.req_status(status=errno.E2BIG, error_message=errmsg)

if nsid and nsid > self.subsys_max_ns[subsystem_nqn]:
errmsg = f"Failure adding namespace to {subsystem_nqn}: requested NSID {nsid} is bigger than the maximal one ({self.subsys_max_ns[subsystem_nqn]})"
self.logger.error(f"{errmsg}")
return pb2.req_status(status=errno.E2BIG, error_message=errmsg)

if not nsid and self.subsystem_nsid_bdev_and_uuid.get_namespace_count(subsystem_nqn,
False, 0) > self.subsys_max_ns[subsystem_nqn]:
errmsg = f"Failure adding namespace to {subsystem_nqn}: maximal number of namespaces ({self.subsys_max_ns[subsystem_nqn]}) has already been reached"
self.logger.error(f"{errmsg}")
return pb2.req_status(status=errno.E2BIG, error_message=errmsg)

Expand Down
24 changes: 23 additions & 1 deletion tests/test_cli.py
Original file line number Diff line number Diff line change
Expand Up @@ -19,11 +19,14 @@
image6 = "mytestdevimage6"
image7 = "mytestdevimage7"
image8 = "mytestdevimage8"
image9 = "mytestdevimage9"
image10 = "mytestdevimage10"
pool = "rbd"
subsystem = "nqn.2016-06.io.spdk:cnode1"
subsystem2 = "nqn.2016-06.io.spdk:cnode2"
subsystem3 = "nqn.2016-06.io.spdk:cnode3"
subsystem4 = "nqn.2016-06.io.spdk:cnode4"
subsystem5 = "nqn.2016-06.io.spdk:cnode5"
discovery_nqn = "nqn.2014-08.org.nvmexpress.discovery"
serial = "Ceph00000000000001"
uuid = "948878ee-c3b2-4d58-a29b-2cff713fc02d"
Expand Down Expand Up @@ -470,6 +473,25 @@ def test_add_all_hosts_to_namespace(self, caplog, gateway):
cli(["namespace", "add_host", "--subsystem", subsystem, "--nsid", "8", "--host-nqn", "*"])
assert f"Failure adding host to namespace 8 on {subsystem}, host can't be \"*\"" in caplog.text

def test_add_too_many_namespaces_to_a_subsystem(self, caplog, gateway):
caplog.clear()
cli(["namespace", "add", "--subsystem", subsystem, "--rbd-pool", pool, "--rbd-image", image9, "--nsid", "3000", "--size", "16MB", "--rbd-create-image"])
assert f"Failure adding namespace to {subsystem}: requested NSID 3000 is bigger than the maximal one" in caplog.text
assert f"Received request to delete bdev" in caplog.text
caplog.clear()
cli(["subsystem", "add", "--subsystem", subsystem5, "--no-group-append", "--max-namespaces", "1"])
assert f"Adding subsystem {subsystem5}: Successful" in caplog.text
caplog.clear()
cli(["namespace", "add", "--subsystem", subsystem5, "--rbd-pool", pool, "--rbd-image", image9, "--size", "16MB", "--rbd-create-image"])
assert f"Adding namespace 1 to {subsystem5}: Successful" in caplog.text
caplog.clear()
cli(["namespace", "add", "--subsystem", subsystem5, "--rbd-pool", pool, "--rbd-image", image10, "--size", "16MB", "--rbd-create-image"])
assert f"Failure adding namespace to {subsystem}: maximal number of namespaces (1) has already been reached" in caplog.text
assert f"Received request to delete bdev" in caplog.text
caplog.clear()
cli(["subsystem", "del", "--subsystem", subsystem5, "--force"])
assert f"Deleting subsystem {subsystem5}: Successful" in caplog.text

def test_add_discovery_to_namespace(self, caplog, gateway):
caplog.clear()
cli(["namespace", "add_host", "--subsystem", subsystem, "--nsid", "8", "--host-nqn", discovery_nqn])
Expand All @@ -493,7 +515,7 @@ def test_add_host_to_wrong_namespace(self, caplog, gateway):
def test_add_too_many_namespaces_with_hosts(self, caplog, gateway):
caplog.clear()
cli(["namespace", "add", "--subsystem", subsystem, "--rbd-pool", pool, "--rbd-image", image8, "--size", "16MB", "--rbd-create-image", "--no-auto-visible"])
assert f"Failure adding namespace to {subsystem}, maximal number of namespaces which are not auto visible (3) was already reached" in caplog.text
assert f"Failure adding namespace to {subsystem}: maximal number of namespaces which are not auto visible (3) has already been reached" in caplog.text
caplog.clear()
cli(["namespace", "add", "--subsystem", subsystem, "--rbd-pool", pool, "--rbd-image", image8, "--size", "16MB", "--rbd-create-image"])
assert f"Adding namespace 11 to {subsystem}: Successful" in caplog.text
Expand Down

0 comments on commit 4c8110b

Please sign in to comment.