From c8facf75cc5635645412114a0dbb7cd70a2bcd41 Mon Sep 17 00:00:00 2001 From: Gil Bregman Date: Thu, 14 Nov 2024 12:50:25 +0200 Subject: [PATCH] Give an explicit error message in case of creating too many namespaces on a subsystem Fixes bz#2282295 Signed-off-by: Gil Bregman --- control/grpc.py | 13 ++++++++++++- tests/test_cli.py | 24 +++++++++++++++++++++++- 2 files changed, 35 insertions(+), 2 deletions(-) diff --git a/control/grpc.py b/control/grpc.py index 929083f2..81bf52c4 100644 --- a/control/grpc.py +++ b/control/grpc.py @@ -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) diff --git a/tests/test_cli.py b/tests/test_cli.py index 7222812e..951a25f8 100644 --- a/tests/test_cli.py +++ b/tests/test_cli.py @@ -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" @@ -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 {subsystem5}: 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]) @@ -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