From 1874d56e75db816bfc918dac7adf322070b48ce4 Mon Sep 17 00:00:00 2001 From: anamehra <54692434+anamehra@users.noreply.github.com> Date: Sat, 23 Mar 2024 01:03:25 -0700 Subject: [PATCH 1/5] Use asic_id/asic_name for APIs to get port config related data Signed-off-by: Anand Mehra anamehra@cisco.com --- src/sonic-config-engine/sonic-cfggen | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/sonic-config-engine/sonic-cfggen b/src/sonic-config-engine/sonic-cfggen index 215ca3ba5fde..3f21f59c1f53 100755 --- a/src/sonic-config-engine/sonic-cfggen +++ b/src/sonic-config-engine/sonic-cfggen @@ -359,9 +359,9 @@ def main(): }}} deep_update(data, hardware_data) if args.port_config is None: - args.port_config = device_info.get_path_to_port_config_file(hwsku) + args.port_config = device_info.get_path_to_port_config_file(hwsku, asic_id) load_namespace_config(asic_name) - (ports, _, _) = get_port_config(hwsku, platform, args.port_config, asic_id) + (ports, _, _) = get_port_config(hwsku, platform, args.port_config, hwsku_config_file=args.hwsku_config, asic_name=asic_name) if ports is None: print('Failed to get port config', file=sys.stderr) sys.exit(1) From 746c3c847e5946daa9b7c356358311c5d48d842b Mon Sep 17 00:00:00 2001 From: anamehra <54692434+anamehra@users.noreply.github.com> Date: Sat, 11 May 2024 11:31:57 -0700 Subject: [PATCH 2/5] Add test case --- .../tests/test_multinpu_cfggen.py | 15 +++++++++++++++ 1 file changed, 15 insertions(+) diff --git a/src/sonic-config-engine/tests/test_multinpu_cfggen.py b/src/sonic-config-engine/tests/test_multinpu_cfggen.py index bc4227f85d52..22f6a9026896 100644 --- a/src/sonic-config-engine/tests/test_multinpu_cfggen.py +++ b/src/sonic-config-engine/tests/test_multinpu_cfggen.py @@ -3,6 +3,7 @@ import os import shutil import subprocess +import sys import unittest import yaml import tests.common_utils as utils @@ -10,6 +11,10 @@ from unittest import TestCase from sonic_py_common.general import getstatusoutput_noshell +if sys.version_info.major == 3: + from unittest import mock +else: + import mock SKU = 'multi-npu-01' ASIC_SKU = 'multi-npu-asic' @@ -27,6 +32,7 @@ def setUp(self): self.sample_graph = os.path.join(self.test_data_dir, 'sample-minigraph.xml') self.sample_graph1 = os.path.join(self.test_data_dir, 'sample-minigraph-noportchannel.xml') self.sample_port_config = os.path.join(self.test_data_dir, 'sample_port_config.ini') + self.sample_port_config_0 = os.path.join(self.test_data_dir, 'sample_port_config-0.ini') self.port_config = [] for asic in range(NUM_ASIC): self.port_config.append(os.path.join(self.test_data_dir, "sample_port_config-{}.ini".format(asic))) @@ -227,6 +233,15 @@ def test_frontend_asic_ports(self): "Ethernet-BP8": { "admin_status": "up", "alias": "Eth6-ASIC0", "asic_port_name": "Eth6-ASIC0", "description": "ASIC3:Eth0-ASIC3", "index": "2", "lanes": "21,22,23,24", "mtu": "9100", "tpid": "0x8100", "pfc_asym": "off", "role": "Int", "speed": "40000" }, "Ethernet-BP12": { "admin_status": "up", "alias": "Eth7-ASIC0", "asic_port_name": "Eth7-ASIC0", "description": "ASIC3:Eth1-ASIC3", "index": "3", "lanes": "25,26,27,28", "mtu": "9100", "tpid": "0x8100", "pfc_asym": "off", "role": "Int", "speed": "40000" }}) + def test_backend_asic_intf(self): + mock.patch('device_info.get_path_to_port_config_file', mock.MagicMock(return_value=self.sample_port_config_0)) + argument = ["-k", ASIC_SKU, "-n", "asic0", "-v", "PORT.keys()|list"] + output = self.run_script(argument) + self.assertEqual( + utils.liststr_to_dict(output.strip()), + utils.liststr_to_dict("['Ethernet0','Ethernet4','Ethernet8','Ethernet12','Ethernet-BP0','Ethernet-BP4','Ethernet-BP8','Ethernet-BP12']") + ) + def test_frontend_asic_ports_config_db(self): argument = ["-m", self.sample_graph, "-p", self.port_config[0], "-n", "asic0", "--var-json", "PORT"] output = json.loads(self.run_script(argument)) From 44ff2a01feac201834f71a80d75dfac5dca2defd Mon Sep 17 00:00:00 2001 From: anamehra <54692434+anamehra@users.noreply.github.com> Date: Sat, 11 May 2024 11:35:53 -0700 Subject: [PATCH 3/5] Update test_multinpu_cfggen.py --- src/sonic-config-engine/tests/test_multinpu_cfggen.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/sonic-config-engine/tests/test_multinpu_cfggen.py b/src/sonic-config-engine/tests/test_multinpu_cfggen.py index 22f6a9026896..cbe0c95d4a9d 100644 --- a/src/sonic-config-engine/tests/test_multinpu_cfggen.py +++ b/src/sonic-config-engine/tests/test_multinpu_cfggen.py @@ -233,7 +233,7 @@ def test_frontend_asic_ports(self): "Ethernet-BP8": { "admin_status": "up", "alias": "Eth6-ASIC0", "asic_port_name": "Eth6-ASIC0", "description": "ASIC3:Eth0-ASIC3", "index": "2", "lanes": "21,22,23,24", "mtu": "9100", "tpid": "0x8100", "pfc_asym": "off", "role": "Int", "speed": "40000" }, "Ethernet-BP12": { "admin_status": "up", "alias": "Eth7-ASIC0", "asic_port_name": "Eth7-ASIC0", "description": "ASIC3:Eth1-ASIC3", "index": "3", "lanes": "25,26,27,28", "mtu": "9100", "tpid": "0x8100", "pfc_asym": "off", "role": "Int", "speed": "40000" }}) - def test_backend_asic_intf(self): + def test_hwsku_option_port_list(self): mock.patch('device_info.get_path_to_port_config_file', mock.MagicMock(return_value=self.sample_port_config_0)) argument = ["-k", ASIC_SKU, "-n", "asic0", "-v", "PORT.keys()|list"] output = self.run_script(argument) From 4fba8ca244b3e914444a75f87906619ea809d4ae Mon Sep 17 00:00:00 2001 From: anamehra <54692434+anamehra@users.noreply.github.com> Date: Mon, 13 May 2024 14:14:17 -0700 Subject: [PATCH 4/5] Added test for configdb data validation --- src/sonic-config-engine/tests/test_multinpu_cfggen.py | 11 ++++++++++- 1 file changed, 10 insertions(+), 1 deletion(-) diff --git a/src/sonic-config-engine/tests/test_multinpu_cfggen.py b/src/sonic-config-engine/tests/test_multinpu_cfggen.py index cbe0c95d4a9d..665f2b9719a9 100644 --- a/src/sonic-config-engine/tests/test_multinpu_cfggen.py +++ b/src/sonic-config-engine/tests/test_multinpu_cfggen.py @@ -233,7 +233,7 @@ def test_frontend_asic_ports(self): "Ethernet-BP8": { "admin_status": "up", "alias": "Eth6-ASIC0", "asic_port_name": "Eth6-ASIC0", "description": "ASIC3:Eth0-ASIC3", "index": "2", "lanes": "21,22,23,24", "mtu": "9100", "tpid": "0x8100", "pfc_asym": "off", "role": "Int", "speed": "40000" }, "Ethernet-BP12": { "admin_status": "up", "alias": "Eth7-ASIC0", "asic_port_name": "Eth7-ASIC0", "description": "ASIC3:Eth1-ASIC3", "index": "3", "lanes": "25,26,27,28", "mtu": "9100", "tpid": "0x8100", "pfc_asym": "off", "role": "Int", "speed": "40000" }}) - def test_hwsku_option_port_list(self): + def test_hwsku_option_port_list_port_config_ini(self): mock.patch('device_info.get_path_to_port_config_file', mock.MagicMock(return_value=self.sample_port_config_0)) argument = ["-k", ASIC_SKU, "-n", "asic0", "-v", "PORT.keys()|list"] output = self.run_script(argument) @@ -242,6 +242,15 @@ def test_hwsku_option_port_list(self): utils.liststr_to_dict("['Ethernet0','Ethernet4','Ethernet8','Ethernet12','Ethernet-BP0','Ethernet-BP4','Ethernet-BP8','Ethernet-BP12']") ) + def test_hwsku_option_port_list_configdb(self): + mock.patch('device_info.get_path_to_port_config_file', mock.MagicMock(return_value=None)) + argument = ["-k", ASIC_SKU, "-n", "asic0", "-v", "PORT.keys()|list"] + output = self.run_script(argument) + self.assertEqual( + utils.liststr_to_dict(output.strip()), + utils.liststr_to_dict("['Ethernet0','Ethernet4','Ethernet8','Ethernet12','Ethernet-BP0','Ethernet-BP4','Ethernet-BP8','Ethernet-BP12']") + ) + def test_frontend_asic_ports_config_db(self): argument = ["-m", self.sample_graph, "-p", self.port_config[0], "-n", "asic0", "--var-json", "PORT"] output = json.loads(self.run_script(argument)) From b468674206bf4dba3a03badf994b1e6288b6a072 Mon Sep 17 00:00:00 2001 From: anamehra <54692434+anamehra@users.noreply.github.com> Date: Sun, 19 May 2024 10:24:44 -0700 Subject: [PATCH 5/5] Update sonic-cfggen --- src/sonic-config-engine/sonic-cfggen | 2 -- 1 file changed, 2 deletions(-) diff --git a/src/sonic-config-engine/sonic-cfggen b/src/sonic-config-engine/sonic-cfggen index ca98cc33256f..e3314d34fa42 100755 --- a/src/sonic-config-engine/sonic-cfggen +++ b/src/sonic-config-engine/sonic-cfggen @@ -359,11 +359,9 @@ def main(): }}} deep_update(data, hardware_data) if args.port_config is None: - args.port_config = device_info.get_path_to_port_config_file(hwsku, asic_id) load_namespace_config() (ports, _, _) = get_port_config(hwsku, platform, args.port_config, hwsku_config_file=args.hwsku_config, asic_name=asic_name) - if ports is None: print('Failed to get port config', file=sys.stderr) sys.exit(1)