From d200e459c248a07fef494a8e83d10895f84f94d1 Mon Sep 17 00:00:00 2001 From: Gil Bregman Date: Sun, 22 Oct 2023 16:49:01 +0300 Subject: [PATCH] Get local state and not OMAP's for ANA processing. Fixes #276 Signed-off-by: Gil Bregman --- control/cli.py | 5 ++--- control/grpc.py | 24 +++++++++++++++--------- tests/test_cli.py | 2 +- 3 files changed, 18 insertions(+), 13 deletions(-) diff --git a/control/cli.py b/control/cli.py index b61e5f93..b7e41b72 100644 --- a/control/cli.py +++ b/control/cli.py @@ -187,9 +187,8 @@ def delete_bdev(self, args): argument("-n", "--subnqn", help="Subsystem NQN", required=True), argument("-s", "--serial", help="Serial number", required=False), argument("-m", "--max-namespaces", help="Maximum number of namespaces", type=int, default=0, required=False), - argument("-a", "--ana-reporting", help="Enable ANA reporting", type=bool, default=False, required=False), - argument("-t", "--enable-ha", help="Enable automatic HA" , type=bool, default=False, required=False), - + argument("-a", "--ana-reporting", help="Enable ANA reporting", action='store_true', required=False), + argument("-t", "--enable-ha", help="Enable automatic HA", action='store_true', required=False), ]) def create_subsystem(self, args): """Creates a subsystem.""" diff --git a/control/grpc.py b/control/grpc.py index 0f452d62..cc782de2 100644 --- a/control/grpc.py +++ b/control/grpc.py @@ -533,15 +533,21 @@ def create_listener_safe(self, request, context=None): context.set_details(f"{ex}") return pb2.req_status() - state = self.gateway_state.omap.get_state() - for key,val in state.items(): - if (key.startswith(self.gateway_state.omap.SUBSYSTEM_PREFIX + request.nqn)): - self.logger.debug(f"values of key: {key} val: {val} \n") - req = json_format.Parse(val, pb2.create_subsystem_req()) - self.logger.info(f" enable_ha :{req.enable_ha} \n") - break - - if req.enable_ha: + state = self.gateway_state.local.get_state() + req = None + subsys = state.get(self.gateway_state.local.SUBSYSTEM_PREFIX + request.nqn) + if subsys: + self.logger.debug(f"value of sub-system: {subsys}") + try: + req = json_format.Parse(subsys, pb2.create_subsystem_req()) + self.logger.info(f"enable_ha: {req.enable_ha}") + except Exception: + self.logger.error(f"Got exception trying to parse subsystem: {ex}") + pass + else: + self.logger.info(f"No sub-system for {request.nqn}") + + if req and req.enable_ha: for x in range (MAX_ANA_GROUPS): try: ret = rpc_nvmf.nvmf_subsystem_listener_set_ana_state( diff --git a/tests/test_cli.py b/tests/test_cli.py index a8753b07..d883277c 100644 --- a/tests/test_cli.py +++ b/tests/test_cli.py @@ -108,7 +108,7 @@ def test_create_bdev_ana(self, caplog, gateway): def test_create_subsystem_ana(self, caplog, gateway): - cli(["create_subsystem", "-n", subsystem, "-a", "true", "-t", "true"]) + cli(["create_subsystem", "-n", subsystem, "-a", "-t"]) assert "Failed to create" not in caplog.text cli(["get_subsystems"]) assert serial not in caplog.text