From c7a9f2fd87f443c595a645156fe2d2ace8ec5788 Mon Sep 17 00:00:00 2001 From: vaibhav-dahiya Date: Thu, 27 Aug 2020 20:17:35 +0000 Subject: [PATCH 01/18] [sonic-utilities]update submodule with fix Fix pfcwd stats crash with invalid queue name (#1077) [show][bgp]Display the Total number of neighbors in the show ip bgp(v6) summary. (#1079) [config] Update SONiC Environment Vars When Loading Minigraph (#1073) Multi asic platform changes for interface, portchannel commands (#878) Update Command-Reference.md (#1075) [filter-fdb] Fix Filter FDB With IPv6 Present in Config DB (#1059) [config] Remove _get_breakout_cfg_file_name helper function (#1069) [SHOW][BGP] support show ip(v6) bgp summary for multi asic platform (#1064) [fanshow] Display other fan status, such as Updating (#1014) Add ip_prefix len based on proxy_arp status (#1046) Enable the platform specific ssd firmware upgrade during reboot (#954) [show][cli[show interface portchannel support for Multi ASIC (#1005) support show interface commands for multi ASIC platforms (#1006) Signed-off-by: vaibhav-dahiya --- .../sonic_py_common/device_info.py | 37 ++++++++++++------- src/sonic-utilities | 2 +- 2 files changed, 24 insertions(+), 15 deletions(-) diff --git a/src/sonic-py-common/sonic_py_common/device_info.py b/src/sonic-py-common/sonic_py_common/device_info.py index b5aefc397fe8..ddc6e3ac01d6 100644 --- a/src/sonic-py-common/sonic_py_common/device_info.py +++ b/src/sonic-py-common/sonic_py_common/device_info.py @@ -181,27 +181,36 @@ def get_paths_to_platform_and_hwsku_dirs(): return (platform_path, hwsku_path) - -def get_path_to_port_config_file(): +def get_path_to_port_config_file(asic=None): """ Retrieves the path to the device's port configuration file Returns: A string containing the path the the device's port configuration file """ - # Get platform and hwsku path - (platform_path, hwsku_path) = get_paths_to_platform_and_hwsku_dirs() - - # First check for the presence of the new 'platform.json' file - port_config_file_path = os.path.join(platform_path, PLATFORM_JSON_FILE) - if not os.path.isfile(port_config_file_path): - # platform.json doesn't exist. Try loading the legacy 'port_config.ini' file - port_config_file_path = os.path.join(hwsku_path, PORT_CONFIG_FILE) - if not os.path.isfile(port_config_file_path): - raise OSError("Failed to detect port config file: {}".format(port_config_file_path)) - - return port_config_file_path + (platform, hwsku) = get_platform_and_hwsku() + # check 'platform.json' file presence + port_config_candidates_json = [] + port_config_candidates_json.append(os.path.join(PLATFORM_ROOT_PATH_DOCKER, PLATFORM_JSON)) + port_config_candidates_json.append(os.path.join(PLATFORM_ROOT_PATH, platform, PLATFORM_JSON)) + + # check 'portconfig.ini' file presence + port_config_candidates = [] + port_config_candidates.append(os.path.join(HWSKU_ROOT_PATH, PORT_CONFIG_INI)) + if asic: + port_config_candidates.append(os.path.join(PLATFORM_ROOT_PATH, platform, hwsku, asic, PORT_CONFIG_INI)) + port_config_candidates.append(os.path.join(PLATFORM_ROOT_PATH, platform, hwsku, PORT_CONFIG_INI)) + port_config_candidates.append(os.path.join(PLATFORM_ROOT_PATH_DOCKER, hwsku, PORT_CONFIG_INI)) + port_config_candidates.append(os.path.join(SONIC_ROOT_PATH, hwsku, PORT_CONFIG_INI)) + + if platform and not hwsku: + port_config_candidates.append(os.path.join(PLATFORM_ROOT_PATH, platform, PORT_CONFIG_INI)) + + for candidate in port_config_candidates_json + port_config_candidates: + if os.path.isfile(candidate): + return candidate + return None def get_sonic_version_info(): if not os.path.isfile(SONIC_VERSION_YAML_PATH): diff --git a/src/sonic-utilities b/src/sonic-utilities index 17fb3781b2cb..58c29616f510 160000 --- a/src/sonic-utilities +++ b/src/sonic-utilities @@ -1 +1 @@ -Subproject commit 17fb3781b2cb7dfb845faa9f16bc17ccd0069649 +Subproject commit 58c29616f510ebd94122db4490523174e1256943 From 9bf9aed014db060546243e90ad6d4b96c836c8e9 Mon Sep 17 00:00:00 2001 From: vaibhav-dahiya Date: Thu, 27 Aug 2020 21:41:39 +0000 Subject: [PATCH 02/18] [sonic-utilities] Update submodule fix the build Signed-off-by: vaibhav-dahiya --- .../sonic_py_common/device_info.py | 19 +++++++++++-------- 1 file changed, 11 insertions(+), 8 deletions(-) diff --git a/src/sonic-py-common/sonic_py_common/device_info.py b/src/sonic-py-common/sonic_py_common/device_info.py index ddc6e3ac01d6..533cc3309cdb 100644 --- a/src/sonic-py-common/sonic_py_common/device_info.py +++ b/src/sonic-py-common/sonic_py_common/device_info.py @@ -193,18 +193,21 @@ def get_path_to_port_config_file(asic=None): # check 'platform.json' file presence port_config_candidates_json = [] port_config_candidates_json.append(os.path.join(PLATFORM_ROOT_PATH_DOCKER, PLATFORM_JSON)) - port_config_candidates_json.append(os.path.join(PLATFORM_ROOT_PATH, platform, PLATFORM_JSON)) + if platform: + port_config_candidates_Json.append(os.path.join(PLATFORM_ROOT_PATH, platform, PLATFORM_JSON)) # check 'portconfig.ini' file presence port_config_candidates = [] port_config_candidates.append(os.path.join(HWSKU_ROOT_PATH, PORT_CONFIG_INI)) - if asic: - port_config_candidates.append(os.path.join(PLATFORM_ROOT_PATH, platform, hwsku, asic, PORT_CONFIG_INI)) - port_config_candidates.append(os.path.join(PLATFORM_ROOT_PATH, platform, hwsku, PORT_CONFIG_INI)) - port_config_candidates.append(os.path.join(PLATFORM_ROOT_PATH_DOCKER, hwsku, PORT_CONFIG_INI)) - port_config_candidates.append(os.path.join(SONIC_ROOT_PATH, hwsku, PORT_CONFIG_INI)) - - if platform and not hwsku: + if hwsku: + if platform: + if asic: + port_config_candidates.append(os.path.join(PLATFORM_ROOT_PATH, platform, hwsku, asic, PORT_CONFIG_INI)) + port_config_candidates.append(os.path.join(PLATFORM_ROOT_PATH, platform, hwsku, PORT_CONFIG_INI)) + port_config_candidates.append(os.path.join(PLATFORM_ROOT_PATH_DOCKER, hwsku, PORT_CONFIG_INI)) + port_config_candidates.append(os.path.join(SONIC_ROOT_PATH, hwsku, PORT_CONFIG_INI)) + + elif platform and not hwsku: port_config_candidates.append(os.path.join(PLATFORM_ROOT_PATH, platform, PORT_CONFIG_INI)) for candidate in port_config_candidates_json + port_config_candidates: From 9b0ae79f466faa63d38d9292c0a2dcb322cda7f0 Mon Sep 17 00:00:00 2001 From: vaibhav-dahiya Date: Thu, 27 Aug 2020 22:08:37 +0000 Subject: [PATCH 03/18] [sonic-py-common] address comments Signed-off-by: vaibhav-dahiya --- .../sonic_py_common/device_info.py | 35 ++++++++----------- 1 file changed, 14 insertions(+), 21 deletions(-) diff --git a/src/sonic-py-common/sonic_py_common/device_info.py b/src/sonic-py-common/sonic_py_common/device_info.py index 533cc3309cdb..e95bfabd1bed 100644 --- a/src/sonic-py-common/sonic_py_common/device_info.py +++ b/src/sonic-py-common/sonic_py_common/device_info.py @@ -188,31 +188,24 @@ def get_path_to_port_config_file(asic=None): Returns: A string containing the path the the device's port configuration file """ - (platform, hwsku) = get_platform_and_hwsku() - - # check 'platform.json' file presence - port_config_candidates_json = [] - port_config_candidates_json.append(os.path.join(PLATFORM_ROOT_PATH_DOCKER, PLATFORM_JSON)) - if platform: - port_config_candidates_Json.append(os.path.join(PLATFORM_ROOT_PATH, platform, PLATFORM_JSON)) + (platform_path, hwsku_path) = get_paths_to_platform_and_hwsku_dirs() - # check 'portconfig.ini' file presence port_config_candidates = [] - port_config_candidates.append(os.path.join(HWSKU_ROOT_PATH, PORT_CONFIG_INI)) - if hwsku: - if platform: - if asic: - port_config_candidates.append(os.path.join(PLATFORM_ROOT_PATH, platform, hwsku, asic, PORT_CONFIG_INI)) - port_config_candidates.append(os.path.join(PLATFORM_ROOT_PATH, platform, hwsku, PORT_CONFIG_INI)) - port_config_candidates.append(os.path.join(PLATFORM_ROOT_PATH_DOCKER, hwsku, PORT_CONFIG_INI)) - port_config_candidates.append(os.path.join(SONIC_ROOT_PATH, hwsku, PORT_CONFIG_INI)) - - elif platform and not hwsku: - port_config_candidates.append(os.path.join(PLATFORM_ROOT_PATH, platform, PORT_CONFIG_INI)) - - for candidate in port_config_candidates_json + port_config_candidates: + + # Check for 'platform.json' file presence first + port_config_candidates_json.append(os.path.join(platform_path, PLATFORM_JSON)) + + # Check for 'portconfig.ini' file presence in a few locations + port_config_candidates.append(os.path.join(hwsku_path, PORT_CONFIG_INI)) + if asic: + port_config_candidates.append(os.path.join(hwsku_path, asic, PORT_CONFIG_INI)) + port_config_candidates.append(os.path.join(hwsku_path, PORT_CONFIG_INI)) + port_config_candidates.append(os.path.join(platform_path, PORT_CONFIG_INI)) + + for candidate in port_config_candidates: if os.path.isfile(candidate): return candidate + return None def get_sonic_version_info(): From ab2f8a3c63e2969d0508c1ea6ecebcf81c0d6f62 Mon Sep 17 00:00:00 2001 From: vaibhav-dahiya Date: Fri, 28 Aug 2020 01:34:52 +0000 Subject: [PATCH 04/18] [sonic-py-common] address comments fix builds Signed-off-by: vaibhav-dahiya --- .../sonic_py_common/device_info.py | 15 +++++++++------ 1 file changed, 9 insertions(+), 6 deletions(-) diff --git a/src/sonic-py-common/sonic_py_common/device_info.py b/src/sonic-py-common/sonic_py_common/device_info.py index e95bfabd1bed..6f745f45b9ac 100644 --- a/src/sonic-py-common/sonic_py_common/device_info.py +++ b/src/sonic-py-common/sonic_py_common/device_info.py @@ -167,17 +167,21 @@ def get_paths_to_platform_and_hwsku_dirs(): # Get platform and hwsku (platform, hwsku) = get_platform_and_hwsku() + platform_path = None + hwsku_path = None # Determine whether we're running in a container or on the host - platform_path_host = os.path.join(HOST_DEVICE_PATH, platform) + if platform: + platform_path_host = os.path.join(HOST_DEVICE_PATH, platform) - if os.path.isdir(CONTAINER_PLATFORM_PATH): + if os.path.isdir(CONTAINER_PLATFORM_PATH): platform_path = CONTAINER_PLATFORM_PATH - elif os.path.isdir(platform_path_host): + elif platform_path_host and os.path.isdir(platform_path_host): platform_path = platform_path_host else: raise OSError("Failed to locate platform directory") - hwsku_path = os.path.join(platform_path, hwsku) + if hwsku: + hwsku_path = os.path.join(platform_path, hwsku) return (platform_path, hwsku_path) @@ -195,11 +199,10 @@ def get_path_to_port_config_file(asic=None): # Check for 'platform.json' file presence first port_config_candidates_json.append(os.path.join(platform_path, PLATFORM_JSON)) - # Check for 'portconfig.ini' file presence in a few locations + # Check for 'port_config.ini' file presence in a few locations port_config_candidates.append(os.path.join(hwsku_path, PORT_CONFIG_INI)) if asic: port_config_candidates.append(os.path.join(hwsku_path, asic, PORT_CONFIG_INI)) - port_config_candidates.append(os.path.join(hwsku_path, PORT_CONFIG_INI)) port_config_candidates.append(os.path.join(platform_path, PORT_CONFIG_INI)) for candidate in port_config_candidates: From d9c7acc3ad41011e832f8938ffce60f1df8f9bf4 Mon Sep 17 00:00:00 2001 From: vaibhav-dahiya Date: Fri, 28 Aug 2020 04:25:21 +0000 Subject: [PATCH 05/18] [sonic-py-common] address comments Signed-off-by: vaibhav-dahiya --- src/sonic-config-engine/portconfig.py | 32 ++----------------- src/sonic-config-engine/sonic-cfggen | 5 +-- .../sonic_py_common/device_info.py | 14 +++----- 3 files changed, 11 insertions(+), 40 deletions(-) diff --git a/src/sonic-config-engine/portconfig.py b/src/sonic-config-engine/portconfig.py index 714ddd37f5f9..7206f1f84835 100644 --- a/src/sonic-config-engine/portconfig.py +++ b/src/sonic-config-engine/portconfig.py @@ -7,6 +7,7 @@ import re from collections import OrderedDict from swsssdk import ConfigDBConnector + from sonic_py_common import device_info except ImportError as e: raise ImportError("%s - required module not found" % str(e)) @@ -64,33 +65,6 @@ def db_connect_configdb(): config_db = None return config_db -def get_port_config_file_name(hwsku=None, platform=None, asic=None): - - # check 'platform.json' file presence - port_config_candidates_Json = [] - port_config_candidates_Json.append(os.path.join(PLATFORM_ROOT_PATH_DOCKER, PLATFORM_JSON)) - if platform: - port_config_candidates_Json.append(os.path.join(PLATFORM_ROOT_PATH, platform, PLATFORM_JSON)) - - # check 'portconfig.ini' file presence - port_config_candidates = [] - port_config_candidates.append(os.path.join(HWSKU_ROOT_PATH, PORT_CONFIG_INI)) - if hwsku: - if platform: - if asic: - port_config_candidates.append(os.path.join(PLATFORM_ROOT_PATH, platform, hwsku, asic, PORT_CONFIG_INI)) - port_config_candidates.append(os.path.join(PLATFORM_ROOT_PATH, platform, hwsku, PORT_CONFIG_INI)) - port_config_candidates.append(os.path.join(PLATFORM_ROOT_PATH_DOCKER, hwsku, PORT_CONFIG_INI)) - port_config_candidates.append(os.path.join(SONIC_ROOT_PATH, hwsku, PORT_CONFIG_INI)) - - elif platform and not hwsku: - port_config_candidates.append(os.path.join(PLATFORM_ROOT_PATH, platform, PORT_CONFIG_INI)) - - for candidate in port_config_candidates_Json + port_config_candidates: - if os.path.isfile(candidate): - return candidate - return None - def get_hwsku_file_name(hwsku=None, platform=None): hwsku_candidates_Json = [] hwsku_candidates_Json.append(os.path.join(HWSKU_ROOT_PATH, HWSKU_JSON)) @@ -119,7 +93,7 @@ def get_port_config(hwsku=None, platform=None, port_config_file=None, hwsku_conf return (ports, port_alias_map, port_alias_asic_map) if not port_config_file: - port_config_file = get_port_config_file_name(hwsku, platform, asic) + port_config_file = device_info.get_path_to_port_config_file(asic) if not port_config_file: return ({}, {}, {}) @@ -289,7 +263,7 @@ def parse_platform_json_file(hwsku_json_file, platform_json_file): def get_breakout_mode(hwsku=None, platform=None, port_config_file=None): if not port_config_file: - port_config_file = get_port_config_file_name(hwsku, platform) + port_config_file = device_info.get_path_to_port_config_file() if not port_config_file: return None if port_config_file.endswith('.json'): diff --git a/src/sonic-config-engine/sonic-cfggen b/src/sonic-config-engine/sonic-cfggen index 6897e383d8c6..b74ffb588142 100755 --- a/src/sonic-config-engine/sonic-cfggen +++ b/src/sonic-config-engine/sonic-cfggen @@ -41,9 +41,10 @@ from minigraph import minigraph_encoder from minigraph import parse_xml from minigraph import parse_device_desc_xml from minigraph import parse_asic_sub_role -from portconfig import get_port_config, get_port_config_file_name, get_breakout_mode +from portconfig import get_port_config, get_breakout_mode from sonic_py_common.device_info import get_platform, get_system_mac from sonic_py_common.multi_asic import get_asic_id_from_name, is_multi_asic +from sonic_py_common import device_info from config_samples import generate_sample_config from config_samples import get_available_config from swsssdk import SonicV2Connector, ConfigDBConnector, SonicDBConfig, ConfigDBPipeConnector @@ -301,7 +302,7 @@ def main(): }}} deep_update(data, hardware_data) if args.port_config is None: - args.port_config = get_port_config_file_name(hwsku, platform) + args.port_config = device_info.get_path_to_port_config_file() (ports, _, _) = get_port_config(hwsku, platform, args.port_config, asic_id) if not ports: print('Failed to get port config', file=sys.stderr) diff --git a/src/sonic-py-common/sonic_py_common/device_info.py b/src/sonic-py-common/sonic_py_common/device_info.py index 6f745f45b9ac..150bd431a11d 100644 --- a/src/sonic-py-common/sonic_py_common/device_info.py +++ b/src/sonic-py-common/sonic_py_common/device_info.py @@ -167,21 +167,17 @@ def get_paths_to_platform_and_hwsku_dirs(): # Get platform and hwsku (platform, hwsku) = get_platform_and_hwsku() - platform_path = None - hwsku_path = None # Determine whether we're running in a container or on the host - if platform: - platform_path_host = os.path.join(HOST_DEVICE_PATH, platform) + platform_path_host = os.path.join(HOST_DEVICE_PATH, platform) - if os.path.isdir(CONTAINER_PLATFORM_PATH): + if os.path.isdir(CONTAINER_PLATFORM_PATH): platform_path = CONTAINER_PLATFORM_PATH - elif platform_path_host and os.path.isdir(platform_path_host): + elif os.path.isdir(platform_path_host): platform_path = platform_path_host else: raise OSError("Failed to locate platform directory") - if hwsku: - hwsku_path = os.path.join(platform_path, hwsku) + hwsku_path = os.path.join(platform_path, hwsku) return (platform_path, hwsku_path) @@ -197,7 +193,7 @@ def get_path_to_port_config_file(asic=None): port_config_candidates = [] # Check for 'platform.json' file presence first - port_config_candidates_json.append(os.path.join(platform_path, PLATFORM_JSON)) + port_config_candidates.append(os.path.join(platform_path, PLATFORM_JSON)) # Check for 'port_config.ini' file presence in a few locations port_config_candidates.append(os.path.join(hwsku_path, PORT_CONFIG_INI)) From bd27d97b63751e90d5aa2394609bc857b19b8af9 Mon Sep 17 00:00:00 2001 From: vaibhav-dahiya Date: Sun, 30 Aug 2020 21:17:47 +0000 Subject: [PATCH 06/18] [sonic-config-engine] address comments Signed-off-by: vaibhav-dahiya --- src/sonic-config-engine/sonic-cfggen | 9 ++++----- 1 file changed, 4 insertions(+), 5 deletions(-) diff --git a/src/sonic-config-engine/sonic-cfggen b/src/sonic-config-engine/sonic-cfggen index b74ffb588142..0aa95d3cefb5 100755 --- a/src/sonic-config-engine/sonic-cfggen +++ b/src/sonic-config-engine/sonic-cfggen @@ -42,7 +42,6 @@ from minigraph import parse_xml from minigraph import parse_device_desc_xml from minigraph import parse_asic_sub_role from portconfig import get_port_config, get_breakout_mode -from sonic_py_common.device_info import get_platform, get_system_mac from sonic_py_common.multi_asic import get_asic_id_from_name, is_multi_asic from sonic_py_common import device_info from config_samples import generate_sample_config @@ -278,7 +277,7 @@ def main(): group.add_argument("-K", "--key", help="Lookup for a specific key") args = parser.parse_args() - platform = get_platform() + platform = device_info.get_platform() db_kwargs = {} if args.redis_unix_sock_file != None: @@ -357,11 +356,11 @@ def main(): asic_role = parse_asic_sub_role(args.minigraph, asic_name) if asic_role is not None and asic_role.lower() == "backend": - mac = get_system_mac(namespace=asic_name) + mac = device_info.get_system_mac(namespace=asic_name) else: - mac = get_system_mac() + mac = device_info.get_system_mac() else: - mac = get_system_mac() + mac = device_info.get_system_mac() hardware_data = {'DEVICE_METADATA': {'localhost': { 'platform': platform, From 98417020e84944ecd84517e0f93cf50b13b1cd87 Mon Sep 17 00:00:00 2001 From: vaibhav-dahiya Date: Wed, 2 Sep 2020 05:46:57 +0000 Subject: [PATCH 07/18] [sonic-py-common] fixing the build Signed-off-by: vaibhav-dahiya --- src/sonic-py-common/sonic_py_common/device_info.py | 13 +++++++++++++ 1 file changed, 13 insertions(+) diff --git a/src/sonic-py-common/sonic_py_common/device_info.py b/src/sonic-py-common/sonic_py_common/device_info.py index 150bd431a11d..f0f407e2a6c2 100644 --- a/src/sonic-py-common/sonic_py_common/device_info.py +++ b/src/sonic-py-common/sonic_py_common/device_info.py @@ -188,6 +188,19 @@ def get_path_to_port_config_file(asic=None): Returns: A string containing the path the the device's port configuration file """ + + ''' + This platform check is performed to make sure we return a None + in case of unit-tests within sonic-cfggen where platform is not expected to be + present because tests are not run on actual Hardware/Container. + This check should however be ommitted once Sonic-cfggen does not use + port_config file for unit-tests. + ''' + + platform = get_platform() + if not platform: + return None + (platform_path, hwsku_path) = get_paths_to_platform_and_hwsku_dirs() port_config_candidates = [] From 1a1c126741ab770ab6702e634dcee3aadd5d812d Mon Sep 17 00:00:00 2001 From: vaibhav-dahiya Date: Wed, 2 Sep 2020 08:37:15 +0000 Subject: [PATCH 08/18] [sonic-py-common] fix build errors Signed-off-by: vaibhav-dahiya --- src/sonic-py-common/sonic_py_common/device_info.py | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/src/sonic-py-common/sonic_py_common/device_info.py b/src/sonic-py-common/sonic_py_common/device_info.py index f0f407e2a6c2..d7ea312439be 100644 --- a/src/sonic-py-common/sonic_py_common/device_info.py +++ b/src/sonic-py-common/sonic_py_common/device_info.py @@ -206,13 +206,13 @@ def get_path_to_port_config_file(asic=None): port_config_candidates = [] # Check for 'platform.json' file presence first - port_config_candidates.append(os.path.join(platform_path, PLATFORM_JSON)) + port_config_candidates.append(os.path.join(platform_path, PLATFORM_JSON_FILE)) # Check for 'port_config.ini' file presence in a few locations - port_config_candidates.append(os.path.join(hwsku_path, PORT_CONFIG_INI)) + port_config_candidates.append(os.path.join(hwsku_path, PORT_CONFIG_FILE)) if asic: - port_config_candidates.append(os.path.join(hwsku_path, asic, PORT_CONFIG_INI)) - port_config_candidates.append(os.path.join(platform_path, PORT_CONFIG_INI)) + port_config_candidates.append(os.path.join(hwsku_path, asic, PORT_CONFIG_FILE)) + port_config_candidates.append(os.path.join(platform_path, PORT_CONFIG_FILE)) for candidate in port_config_candidates: if os.path.isfile(candidate): From 1b67ff876fbd00de4bca37b49252a0d73584e857 Mon Sep 17 00:00:00 2001 From: vaibhav-dahiya Date: Wed, 2 Sep 2020 19:36:35 +0000 Subject: [PATCH 09/18] [sonic-py-common] changes to make code simpler Signed-off-by: vaibhav-dahiya --- src/sonic-py-common/sonic_py_common/device_info.py | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/sonic-py-common/sonic_py_common/device_info.py b/src/sonic-py-common/sonic_py_common/device_info.py index d7ea312439be..cb8bb4a4de88 100644 --- a/src/sonic-py-common/sonic_py_common/device_info.py +++ b/src/sonic-py-common/sonic_py_common/device_info.py @@ -209,10 +209,10 @@ def get_path_to_port_config_file(asic=None): port_config_candidates.append(os.path.join(platform_path, PLATFORM_JSON_FILE)) # Check for 'port_config.ini' file presence in a few locations - port_config_candidates.append(os.path.join(hwsku_path, PORT_CONFIG_FILE)) if asic: port_config_candidates.append(os.path.join(hwsku_path, asic, PORT_CONFIG_FILE)) - port_config_candidates.append(os.path.join(platform_path, PORT_CONFIG_FILE)) + else: + port_config_candidates.append(os.path.join(hwsku_path, PORT_CONFIG_FILE)) for candidate in port_config_candidates: if os.path.isfile(candidate): From e131eadbaebed5427a0c8ac4e824616a65e6d893 Mon Sep 17 00:00:00 2001 From: vaibhav-dahiya Date: Wed, 2 Sep 2020 19:50:12 +0000 Subject: [PATCH 10/18] [sonic-py-common] fix the coments Signed-off-by: vaibhav-dahiya --- src/sonic-py-common/sonic_py_common/device_info.py | 7 +++---- 1 file changed, 3 insertions(+), 4 deletions(-) diff --git a/src/sonic-py-common/sonic_py_common/device_info.py b/src/sonic-py-common/sonic_py_common/device_info.py index cb8bb4a4de88..221faf153729 100644 --- a/src/sonic-py-common/sonic_py_common/device_info.py +++ b/src/sonic-py-common/sonic_py_common/device_info.py @@ -189,13 +189,12 @@ def get_path_to_port_config_file(asic=None): A string containing the path the the device's port configuration file """ - ''' + """ This platform check is performed to make sure we return a None in case of unit-tests within sonic-cfggen where platform is not expected to be present because tests are not run on actual Hardware/Container. - This check should however be ommitted once Sonic-cfggen does not use - port_config file for unit-tests. - ''' + TODO: refactor sonic-cfggen such that we can remove this check + """ platform = get_platform() if not platform: From e18a0c7461858619f2c04ed76f9253c7d17454d5 Mon Sep 17 00:00:00 2001 From: vaibhav-dahiya Date: Fri, 4 Sep 2020 00:40:58 +0000 Subject: [PATCH 11/18] [sonic-py-common] fix the build/add more logic Signed-off-by: vaibhav-dahiya --- src/sonic-config-engine/portconfig.py | 4 +- src/sonic-config-engine/sonic-cfggen | 2 +- .../sonic_py_common/device_info.py | 54 ++++++++++++++++++- 3 files changed, 55 insertions(+), 5 deletions(-) diff --git a/src/sonic-config-engine/portconfig.py b/src/sonic-config-engine/portconfig.py index 7206f1f84835..6e867955a2c7 100644 --- a/src/sonic-config-engine/portconfig.py +++ b/src/sonic-config-engine/portconfig.py @@ -93,7 +93,7 @@ def get_port_config(hwsku=None, platform=None, port_config_file=None, hwsku_conf return (ports, port_alias_map, port_alias_asic_map) if not port_config_file: - port_config_file = device_info.get_path_to_port_config_file(asic) + port_config_file = device_info.get_path_to_port_config_file(asic, hwsku) if not port_config_file: return ({}, {}, {}) @@ -263,7 +263,7 @@ def parse_platform_json_file(hwsku_json_file, platform_json_file): def get_breakout_mode(hwsku=None, platform=None, port_config_file=None): if not port_config_file: - port_config_file = device_info.get_path_to_port_config_file() + port_config_file = device_info.get_path_to_port_config_file(hwsku) if not port_config_file: return None if port_config_file.endswith('.json'): diff --git a/src/sonic-config-engine/sonic-cfggen b/src/sonic-config-engine/sonic-cfggen index 0aa95d3cefb5..3e4e661f6adc 100755 --- a/src/sonic-config-engine/sonic-cfggen +++ b/src/sonic-config-engine/sonic-cfggen @@ -301,7 +301,7 @@ def main(): }}} deep_update(data, hardware_data) if args.port_config is None: - args.port_config = device_info.get_path_to_port_config_file() + args.port_config = device_info.get_path_to_port_config_file(hwsku) (ports, _, _) = get_port_config(hwsku, platform, args.port_config, asic_id) if not ports: print('Failed to get port config', file=sys.stderr) diff --git a/src/sonic-py-common/sonic_py_common/device_info.py b/src/sonic-py-common/sonic_py_common/device_info.py index 221faf153729..bb4bccd6db79 100644 --- a/src/sonic-py-common/sonic_py_common/device_info.py +++ b/src/sonic-py-common/sonic_py_common/device_info.py @@ -154,6 +154,52 @@ def get_asic_conf_file_path(): return None +def get_path_to_platform_dir(): + """ + Retreives the paths to the device's platform directory + + Returns: + A string containing the path to the platform directory of the device + """ + # Get platform + platform = get_platform() + + # Determine whether we're running in a container or on the host + platform_path_host = os.path.join(HOST_DEVICE_PATH, platform) + + if os.path.isdir(CONTAINER_PLATFORM_PATH): + platform_path = CONTAINER_PLATFORM_PATH + elif os.path.isdir(platform_path_host): + platform_path = platform_path_host + else: + raise OSError("Failed to locate platform directory") + + return platform_path + +def get_path_to_hwsku_dir(): + """ + Retreives the path to the device's hardware SKU data directory + + Returns: + A string, containing the path to the hardware SKU directory of the device + """ + # Get hwsku + hwsku = get_hwsku() + + # Determine whether we're running in a container or on the host + platform_path_host = os.path.join(HOST_DEVICE_PATH, platform) + + if os.path.isdir(CONTAINER_PLATFORM_PATH): + platform_path = CONTAINER_PLATFORM_PATH + elif os.path.isdir(platform_path_host): + platform_path = platform_path_host + else: + raise OSError("Failed to locate platform directory") + + hwsku_path = os.path.join(platform_path, hwsku) + + return hwsku_path + def get_paths_to_platform_and_hwsku_dirs(): """ Retreives the paths to the device's platform and hardware SKU data @@ -181,7 +227,7 @@ def get_paths_to_platform_and_hwsku_dirs(): return (platform_path, hwsku_path) -def get_path_to_port_config_file(asic=None): +def get_path_to_port_config_file(asic=None, hwsku=None): """ Retrieves the path to the device's port configuration file @@ -200,7 +246,11 @@ def get_path_to_port_config_file(asic=None): if not platform: return None - (platform_path, hwsku_path) = get_paths_to_platform_and_hwsku_dirs() + if hwsku: + platform_path = get_path_to_platform_dir() + hwsku_path = hwsku + else: + (platform_path, hwsku_path) = get_paths_to_platform_and_hwsku_dirs() port_config_candidates = [] From e1d34d88262e15d4280d51b7a41ca2e9bf66c9b6 Mon Sep 17 00:00:00 2001 From: vaibhav-dahiya Date: Fri, 4 Sep 2020 00:50:46 +0000 Subject: [PATCH 12/18] [sonic-py-common] fix the args passing Signed-off-by: vaibhav-dahiya --- src/sonic-config-engine/portconfig.py | 2 +- src/sonic-py-common/sonic_py_common/device_info.py | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/src/sonic-config-engine/portconfig.py b/src/sonic-config-engine/portconfig.py index 6e867955a2c7..df1decece763 100644 --- a/src/sonic-config-engine/portconfig.py +++ b/src/sonic-config-engine/portconfig.py @@ -93,7 +93,7 @@ def get_port_config(hwsku=None, platform=None, port_config_file=None, hwsku_conf return (ports, port_alias_map, port_alias_asic_map) if not port_config_file: - port_config_file = device_info.get_path_to_port_config_file(asic, hwsku) + port_config_file = device_info.get_path_to_port_config_file(hwsku, asic) if not port_config_file: return ({}, {}, {}) diff --git a/src/sonic-py-common/sonic_py_common/device_info.py b/src/sonic-py-common/sonic_py_common/device_info.py index bb4bccd6db79..7ebdd63532a9 100644 --- a/src/sonic-py-common/sonic_py_common/device_info.py +++ b/src/sonic-py-common/sonic_py_common/device_info.py @@ -227,7 +227,7 @@ def get_paths_to_platform_and_hwsku_dirs(): return (platform_path, hwsku_path) -def get_path_to_port_config_file(asic=None, hwsku=None): +def get_path_to_port_config_file(hwsku=None, asic=None): """ Retrieves the path to the device's port configuration file From 38a0bb815c2436e19c7976b1ab9a8a059a39658c Mon Sep 17 00:00:00 2001 From: vaibhav-dahiya Date: Fri, 4 Sep 2020 00:55:32 +0000 Subject: [PATCH 13/18] [sonic-py-common] fixing the logic Signed-off-by: vaibhav-dahiya --- src/sonic-py-common/sonic_py_common/device_info.py | 8 +++----- 1 file changed, 3 insertions(+), 5 deletions(-) diff --git a/src/sonic-py-common/sonic_py_common/device_info.py b/src/sonic-py-common/sonic_py_common/device_info.py index 7ebdd63532a9..33759b3f07e6 100644 --- a/src/sonic-py-common/sonic_py_common/device_info.py +++ b/src/sonic-py-common/sonic_py_common/device_info.py @@ -246,11 +246,9 @@ def get_path_to_port_config_file(hwsku=None, asic=None): if not platform: return None - if hwsku: - platform_path = get_path_to_platform_dir() - hwsku_path = hwsku - else: - (platform_path, hwsku_path) = get_paths_to_platform_and_hwsku_dirs() + platform_path = get_path_to_platform_dir() + + hwsku_path = os.path.join(platform_path, hwsku) if hwsku else get_path_to_hwsku_dir() port_config_candidates = [] From 2607b9f230cbcaf80b2f4757bb70efdb4eecb9bb Mon Sep 17 00:00:00 2001 From: vaibhav-dahiya Date: Fri, 4 Sep 2020 01:00:01 +0000 Subject: [PATCH 14/18] [sonic-py-common] fixing the logic Signed-off-by: vaibhav-dahiya --- src/sonic-py-common/sonic_py_common/device_info.py | 8 +++++--- 1 file changed, 5 insertions(+), 3 deletions(-) diff --git a/src/sonic-py-common/sonic_py_common/device_info.py b/src/sonic-py-common/sonic_py_common/device_info.py index 33759b3f07e6..23a89a2224b0 100644 --- a/src/sonic-py-common/sonic_py_common/device_info.py +++ b/src/sonic-py-common/sonic_py_common/device_info.py @@ -246,9 +246,11 @@ def get_path_to_port_config_file(hwsku=None, asic=None): if not platform: return None - platform_path = get_path_to_platform_dir() - - hwsku_path = os.path.join(platform_path, hwsku) if hwsku else get_path_to_hwsku_dir() + if hwsku: + platform_path = get_path_to_platform_dir() + hwsku_path = os.path.join(platform_path, hwsku) + else: + (platform_path, hwsku_path) = get_paths_to_platform_and_hwsku_dirs() port_config_candidates = [] From db4149e1ce510edf91bc0c315da708411997ef8a Mon Sep 17 00:00:00 2001 From: vaibhav-dahiya Date: Fri, 4 Sep 2020 01:03:47 +0000 Subject: [PATCH 15/18] [sonic-py-common] fixed the logic Signed-off-by: vaibhav-dahiya --- .../sonic_py_common/device_info.py | 24 ------------------- 1 file changed, 24 deletions(-) diff --git a/src/sonic-py-common/sonic_py_common/device_info.py b/src/sonic-py-common/sonic_py_common/device_info.py index 23a89a2224b0..f4d6a5a252ff 100644 --- a/src/sonic-py-common/sonic_py_common/device_info.py +++ b/src/sonic-py-common/sonic_py_common/device_info.py @@ -176,30 +176,6 @@ def get_path_to_platform_dir(): return platform_path -def get_path_to_hwsku_dir(): - """ - Retreives the path to the device's hardware SKU data directory - - Returns: - A string, containing the path to the hardware SKU directory of the device - """ - # Get hwsku - hwsku = get_hwsku() - - # Determine whether we're running in a container or on the host - platform_path_host = os.path.join(HOST_DEVICE_PATH, platform) - - if os.path.isdir(CONTAINER_PLATFORM_PATH): - platform_path = CONTAINER_PLATFORM_PATH - elif os.path.isdir(platform_path_host): - platform_path = platform_path_host - else: - raise OSError("Failed to locate platform directory") - - hwsku_path = os.path.join(platform_path, hwsku) - - return hwsku_path - def get_paths_to_platform_and_hwsku_dirs(): """ Retreives the paths to the device's platform and hardware SKU data From de5fda726b1faa5d377a103637debc1dc3b98168 Mon Sep 17 00:00:00 2001 From: vaibhav-dahiya Date: Fri, 4 Sep 2020 01:13:21 +0000 Subject: [PATCH 16/18] [sonic-py-common] adding the function back Signed-off-by: vaibhav-dahiya --- .../sonic_py_common/device_info.py | 24 +++++++++++++++++++ 1 file changed, 24 insertions(+) diff --git a/src/sonic-py-common/sonic_py_common/device_info.py b/src/sonic-py-common/sonic_py_common/device_info.py index f4d6a5a252ff..301a44fba13d 100644 --- a/src/sonic-py-common/sonic_py_common/device_info.py +++ b/src/sonic-py-common/sonic_py_common/device_info.py @@ -176,6 +176,30 @@ def get_path_to_platform_dir(): return platform_path +def get_path_to_hwsku_dir(): + """ + Retreives the path to the device's hardware SKU data directory + + Returns: + A string, containing the path to the hardware SKU directory of the device + """ + # Get platform and hwsku + (platform, hwsku) = get_platform_and_hwsku() + + # Determine whether we're running in a container or on the host + platform_path_host = os.path.join(HOST_DEVICE_PATH, platform) + + if os.path.isdir(CONTAINER_PLATFORM_PATH): + platform_path = CONTAINER_PLATFORM_PATH + elif os.path.isdir(platform_path_host): + platform_path = platform_path_host + else: + raise OSError("Failed to locate platform directory") + + hwsku_path = os.path.join(platform_path, hwsku) + + return hwsku_path + def get_paths_to_platform_and_hwsku_dirs(): """ Retreives the paths to the device's platform and hardware SKU data From 8988996320b768fca9c2fba8206507c0b3c99e20 Mon Sep 17 00:00:00 2001 From: vaibhav-dahiya Date: Fri, 4 Sep 2020 01:34:06 +0000 Subject: [PATCH 17/18] [sonic_py_common] refactoring the code Signed-off-by: vaibhav-dahiya --- .../sonic_py_common/device_info.py | 33 ++++++++----------- 1 file changed, 13 insertions(+), 20 deletions(-) diff --git a/src/sonic-py-common/sonic_py_common/device_info.py b/src/sonic-py-common/sonic_py_common/device_info.py index 301a44fba13d..2117b48edbb7 100644 --- a/src/sonic-py-common/sonic_py_common/device_info.py +++ b/src/sonic-py-common/sonic_py_common/device_info.py @@ -183,18 +183,12 @@ def get_path_to_hwsku_dir(): Returns: A string, containing the path to the hardware SKU directory of the device """ - # Get platform and hwsku - (platform, hwsku) = get_platform_and_hwsku() - # Determine whether we're running in a container or on the host - platform_path_host = os.path.join(HOST_DEVICE_PATH, platform) + # Get Platform path first + platform_path = get_path_to_platform_dir() - if os.path.isdir(CONTAINER_PLATFORM_PATH): - platform_path = CONTAINER_PLATFORM_PATH - elif os.path.isdir(platform_path_host): - platform_path = platform_path_host - else: - raise OSError("Failed to locate platform directory") + # Get hwsku + hwsku = get_hwsku() hwsku_path = os.path.join(platform_path, hwsku) @@ -210,18 +204,12 @@ def get_paths_to_platform_and_hwsku_dirs(): directory of the device, the second containing the path to the hardware SKU directory of the device """ - # Get platform and hwsku - (platform, hwsku) = get_platform_and_hwsku() - # Determine whether we're running in a container or on the host - platform_path_host = os.path.join(HOST_DEVICE_PATH, platform) + # Get Platform path first + platform_path = get_path_to_platform_dir() - if os.path.isdir(CONTAINER_PLATFORM_PATH): - platform_path = CONTAINER_PLATFORM_PATH - elif os.path.isdir(platform_path_host): - platform_path = platform_path_host - else: - raise OSError("Failed to locate platform directory") + # Get hwsku + hwsku = get_hwsku() hwsku_path = os.path.join(platform_path, hwsku) @@ -231,6 +219,11 @@ def get_path_to_port_config_file(hwsku=None, asic=None): """ Retrieves the path to the device's port configuration file + the hwsku argument is allowed to be passed in args because when loading the + initial configuration on the device, the HwSKU is not yet present in ConfigDB. + asic argument should be passed on multi-ASIC devices only, + it should be omitted on single-ASIC platforms. + Returns: A string containing the path the the device's port configuration file """ From 8047e8a9acc3c8bfd6e01da13105d048ee15a3b2 Mon Sep 17 00:00:00 2001 From: vaibhav-dahiya Date: Fri, 4 Sep 2020 01:52:10 +0000 Subject: [PATCH 18/18] [sonic-py-common] fixing the comment format Signed-off-by: vaibhav-dahiya --- src/sonic-py-common/sonic_py_common/device_info.py | 9 +++++---- 1 file changed, 5 insertions(+), 4 deletions(-) diff --git a/src/sonic-py-common/sonic_py_common/device_info.py b/src/sonic-py-common/sonic_py_common/device_info.py index 2117b48edbb7..fb76174b548f 100644 --- a/src/sonic-py-common/sonic_py_common/device_info.py +++ b/src/sonic-py-common/sonic_py_common/device_info.py @@ -219,10 +219,11 @@ def get_path_to_port_config_file(hwsku=None, asic=None): """ Retrieves the path to the device's port configuration file - the hwsku argument is allowed to be passed in args because when loading the - initial configuration on the device, the HwSKU is not yet present in ConfigDB. - asic argument should be passed on multi-ASIC devices only, - it should be omitted on single-ASIC platforms. + Args: + hwsku: a string, it is allowed to be passed in args because when loading the + initial configuration on the device, the HwSKU is not yet present in ConfigDB. + asic: a string , asic argument should be passed on multi-ASIC devices only, + it should be omitted on single-ASIC platforms. Returns: A string containing the path the the device's port configuration file