From fb246a5618f8cd80cd30e552660a2d580a7bc8d2 Mon Sep 17 00:00:00 2001 From: Jie Feng Date: Sun, 30 Jul 2023 22:22:23 -0700 Subject: [PATCH 1/3] 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 " --- config/fabric.py | 38 +++++++++++++++++++++++++++++++++++++ tests/config_fabric_test.py | 10 ++++++++++ 2 files changed, 48 insertions(+) diff --git a/config/fabric.py b/config/fabric.py index a3870589ae..513a0df346 100644 --- a/config/fabric.py +++ b/config/fabric.py @@ -157,6 +157,44 @@ def error_threshold(crccells, rxcells, namespace): config_db.mod_entry("FABRIC_MONITOR", "FABRIC_MONITOR_DATA", {'monErrThreshCrcCells': crccells, 'monErrThreshRxCells': rxcells}) +def setFabricPortMonitorState(state, namespace ): + """ set the fabric port monitor state""" + # Connect to config database + 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): + ctx.fail("Fabric monitor configuration data not present") + + # Update entry + config_db.mod_entry("FABRIC_MONITOR", "FABRIC_MONITOR_DATA", + {'monState': state}) + +# +# 'config fabric port montior state ' +# +@monitor.command() +@click.argument('state', metavar='', required=True) +@multi_asic_util.multi_asic_click_option_namespace +def state(state, namespace): + """FABRIC PORT MONITOR STATE configuration tasks""" + ctx = click.get_current_context() + + 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'] + for namespace in ns_list: + setFabricPortMonitorState(state, namespace) + else: + setFabricPortMonitorState(state, namespace) + # # 'config fabric port monitor poll ...' # diff --git a/tests/config_fabric_test.py b/tests/config_fabric_test.py index 1f56ea416a..5b1b54049a 100644 --- a/tests/config_fabric_test.py +++ b/tests/config_fabric_test.py @@ -93,3 +93,13 @@ def test_config_fabric_monitor_threshold(self, ctx): result = self.basic_check("port", ["monitor", "poll", "threshold", "recovery", "8"], ctx) expect_result = 0 assert operator.eq(result.exit_code, expect_result) + + def test_config_fabric_monitor_state(self, ctx): + # Issue command "config fabric port monitor state " + result = self.basic_check("port", ["monitor", "state", "enable"], ctx) + expect_result = 0 + assert operator.eq(result.exit_code, expect_result) + + result = self.basic_check("port", ["monitor", "state", "disable"], ctx) + expect_result = 0 + assert operator.eq(result.exit_code, expect_result) From 3b7cc1fd55101443fbad5b3676ad5956b6c127f3 Mon Sep 17 00:00:00 2001 From: Jie Feng Date: Sun, 30 Jul 2023 22:22:23 -0700 Subject: [PATCH 2/3] 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 --- doc/Command-Reference.md | 15 +++++++++++++++ 1 file changed, 15 insertions(+) diff --git a/doc/Command-Reference.md b/doc/Command-Reference.md index c4a28a5460..9503c0cdc0 100644 --- a/doc/Command-Reference.md +++ b/doc/Command-Reference.md @@ -3700,6 +3700,21 @@ This command sets the number of consecutive polls in which no error is detected admin@sonic:~$ config fabric port monitor poll threshold recovery 5 -n asic0 ``` +**config fabric port monitor state ** + +This command sets the monitor state in CONFIG_DB to enable/disable the fabric monitor feature. + +- Usage: + ``` + config fabric port monitor state [OPTIONS] + ``` + +- Example: + ``` + admin@sonic:~$ config fabric port monitor state enable + admin@sonic:~$ config fabric port monitor state disable + ``` + ## Feature SONiC includes a capability in which Feature state can be enabled/disabled From cac9fefc73292e64baae94ad6944bf5611c377e0 Mon Sep 17 00:00:00 2001 From: Jie Feng Date: Sun, 30 Jul 2023 22:22:23 -0700 Subject: [PATCH 3/3] 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 | 13 +++---- tests/config_fabric_test.py | 48 ++++++++++++++++++++++++++ tests/mock_tables/asic0/config_db.json | 7 ++++ tests/mock_tables/asic1/config_db.json | 7 ++++ 4 files changed, 66 insertions(+), 9 deletions(-) diff --git a/config/fabric.py b/config/fabric.py index 513a0df346..16ce35f733 100644 --- a/config/fabric.py +++ b/config/fabric.py @@ -157,16 +157,12 @@ def error_threshold(crccells, rxcells, namespace): config_db.mod_entry("FABRIC_MONITOR", "FABRIC_MONITOR_DATA", {'monErrThreshCrcCells': crccells, 'monErrThreshRxCells': rxcells}) -def setFabricPortMonitorState(state, namespace ): +def setFabricPortMonitorState(state, namespace, ctx): """ set the fabric port monitor state""" # Connect to config database 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,12 +184,11 @@ 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) + setFabricPortMonitorState(state, namespace, ctx) else: - setFabricPortMonitorState(state, namespace) + setFabricPortMonitorState(state, namespace, ctx) # # 'config fabric port monitor poll ...' diff --git a/tests/config_fabric_test.py b/tests/config_fabric_test.py index 5b1b54049a..ca8a8b8a09 100644 --- a/tests/config_fabric_test.py +++ b/tests/config_fabric_test.py @@ -4,6 +4,7 @@ import os import pytest import sys +import importlib from click.testing import CliRunner from utilities_common.db import Db @@ -103,3 +104,50 @@ 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) + + @classmethod + def teardown_class(cls): + print("TEARDOWN") + 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"] = "" + +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" + # change to multi asic config + from .mock_tables import dbconnector + from .mock_tables import mock_multi_asic + importlib.reload(mock_multi_asic) + dbconnector.load_namespace_config() + + 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"] = "" + # change back to single asic config + from .mock_tables import dbconnector + from .mock_tables import mock_single_asic + importlib.reload(mock_single_asic) + dbconnector.load_namespace_config() diff --git a/tests/mock_tables/asic0/config_db.json b/tests/mock_tables/asic0/config_db.json index de20194a64..b3dab0fbe0 100644 --- a/tests/mock_tables/asic0/config_db.json +++ b/tests/mock_tables/asic0/config_db.json @@ -257,5 +257,12 @@ "ports@": "Ethernet124", "type": "L3", "stage": "ingress" + }, + "FABRIC_MONITOR|FABRIC_MONITOR_DATA": { + "monCapacityThreshWarn": "100", + "monErrThreshCrcCells": "1", + "monErrThreshRxCells": "61035156", + "monPollThreshIsolation": "1", + "monPollThreshRecovery": "8" } } diff --git a/tests/mock_tables/asic1/config_db.json b/tests/mock_tables/asic1/config_db.json index f9fa66a048..65267a2415 100644 --- a/tests/mock_tables/asic1/config_db.json +++ b/tests/mock_tables/asic1/config_db.json @@ -197,5 +197,12 @@ "holdtime": "0", "asn": "65100", "keepalive": "0" + }, + "FABRIC_MONITOR|FABRIC_MONITOR_DATA": { + "monCapacityThreshWarn": "100", + "monErrThreshCrcCells": "1", + "monErrThreshRxCells": "61035156", + "monPollThreshIsolation": "1", + "monPollThreshRecovery": "8" } }