From 018770ef6c8af8531f6ef823220701ce8d19bbf2 Mon Sep 17 00:00:00 2001 From: Jie Feng Date: Sun, 30 Jul 2023 22:22:23 -0700 Subject: [PATCH] Add "state" field in CONFIG_DB fabric_monitor table as a toggle of the fabric port monitoring feature. The command to set this is "config fabric port monitor state " Signed-off-by: Jie Feng --- config/fabric.py | 7 +------ tests/config_fabric_test.py | 29 +++++++++++++++++++++++++++++ 2 files changed, 30 insertions(+), 6 deletions(-) diff --git a/config/fabric.py b/config/fabric.py index 513a0df3464..966b9a838ad 100644 --- a/config/fabric.py +++ b/config/fabric.py @@ -163,10 +163,6 @@ def setFabricPortMonitorState(state, namespace ): config_db = ConfigDBConnector(use_unix_socket_path=True, namespace=namespace) config_db.connect() - # Connect to state database - state_db = SonicV2Connector(use_unix_socket_path=True, namespace=namespace) - state_db.connect(state_db.STATE_DB, False) - # Make sure configuration data exists monitorData = config_db.get_all(config_db.CONFIG_DB, "FABRIC_MONITOR|FABRIC_MONITOR_DATA") if not bool(monitorData): @@ -188,8 +184,7 @@ def state(state, namespace): n_asics = multi_asic.get_num_asics() if n_asics > 1 and namespace is None: - ns = multi_asic.get_all_namespaces() - ns_list = ns['front_ns'] + ns['back_ns'] + ns['fabric_ns'] + ns_list = multi_asic.get_namespace_list() for namespace in ns_list: setFabricPortMonitorState(state, namespace) else: diff --git a/tests/config_fabric_test.py b/tests/config_fabric_test.py index 5b1b54049a2..534e1e35f47 100644 --- a/tests/config_fabric_test.py +++ b/tests/config_fabric_test.py @@ -103,3 +103,32 @@ def test_config_fabric_monitor_state(self, ctx): result = self.basic_check("port", ["monitor", "state", "disable"], ctx) expect_result = 0 assert operator.eq(result.exit_code, expect_result) + +class TestMultiAsicConfigFabric(object): + @classmethod + def setup_class(cls): + print("SETUP") + os.environ["PATH"] += os.pathsep + scripts_path + os.environ["UTILITIES_UNIT_TESTING"] = "2" + os.environ["UTILITIES_UNIT_TESTING_TOPOLOGY"] = "multi_asic" + + def basic_check(self, command_name, para_list, ctx): + # This function issues command of "config fabric xxxx", + # and returns the result of the command. + runner = CliRunner() + result = runner.invoke(config.config.commands["fabric"].commands[command_name], para_list, obj = ctx) + print(result.output) + return result + + def test_multi_config_fabric_monitor_state(self, ctx): + result = self.basic_check("port", ["monitor", "state", "disable"], ctx) + expect_result = 0 + assert operator.eq(result.exit_code, expect_result) + + @classmethod + def teardown_class(cls): + print("TEARDOWN_TEST") + os.environ["PATH"] = os.pathsep.join( + os.environ["PATH"].split(os.pathsep)[:-1]) + os.environ["UTILITIES_UNIT_TESTING"] = "0" + os.environ["UTILITIES_UNIT_TESTING_TOPOLOGY"] = ""