Skip to content
Merged
Show file tree
Hide file tree
Changes from 3 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
27 changes: 16 additions & 11 deletions src/sonic-py-common/sonic_py_common/device_info.py
Original file line number Diff line number Diff line change
Expand Up @@ -181,27 +181,32 @@ 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))
port_config_candidates = []

# Check for 'platform.json' file presence first
port_config_candidates_json.append(os.path.join(platform_path, PLATFORM_JSON))

return port_config_file_path
# 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))
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

line 199 and 202 are appending the same file. The list from the sonic-config-engine is:

    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))

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yes. the second is no longer needed.

Copy link
Copy Markdown
Contributor

@jleveque jleveque Aug 27, 2020

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Question is, why were we checking for port_config.ini in this order?

  1. /usr/share/sonic/hwsku/
  2. /usr/share/sonic/device/<platform>/<hwsku>/<ASIC>/
  3. /usr/share/sonic/device/<platform>/<hwsku>/
  4. /usr/share/sonic/<platform>/

@samaity, @SuvarnaMeenakshi: Can you help answer this? Determining whether we are running inside a container versus in the host OS should now be handled by get_paths_to_platform_and_hwsku_dirs(). What is the new proper order with which to look for the port_config.ini file?

Before the addition of multi-ASIC functionality, the port_config.ini file was always located under the HwSKU directory, which, in the host OS was at /usr/share/sonic/device/<platform>/<hwsku>/ and in the containers was mounted at /usr/share/sonic/hwsku/. Why did we start checking the <platform> directory? Is there now a case where port_config.ini will reside directly under the platform directory? That has never been the case as far as I'm aware.

I believe the proper method for finding the port_config.ini file now that we have multi-ASIC functionality should be as simple as this:

# This function will return `/usr/share/sonic/hwsku/` as hwsku_path if run inside a container
# or `/usr/share/sonic/device/<platform>/<hwsku>/` if run in the host OS
(platform_path, hwsku_path) = get_paths_to_platform_and_hwsku_dirs()

if asic:
    port_config_candidates.append(os.path.join(hwsku_path, asic, PORT_CONFIG_INI))
else:
    port_config_candidates.append(os.path.join(hwsku_path, PORT_CONFIG_INI))

Please correct me if I am wrong.

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():
if not os.path.isfile(SONIC_VERSION_YAML_PATH):
Expand Down
2 changes: 1 addition & 1 deletion src/sonic-utilities