diff --git a/src/sonic-config-engine/sonic-cfggen b/src/sonic-config-engine/sonic-cfggen index a3b54c756425..e3314d34fa42 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() - (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) diff --git a/src/sonic-config-engine/tests/test_multinpu_cfggen.py b/src/sonic-config-engine/tests/test_multinpu_cfggen.py index bc4227f85d52..665f2b9719a9 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,24 @@ 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_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) + 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_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))