Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[sonic-utilities][sonic-py-common] Move logic to get port config file path to sonic-py-common and update sonic-utilities to comply #5264

Merged
merged 18 commits into from
Sep 4, 2020
Merged
Show file tree
Hide file tree
Changes from 1 commit
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
4 changes: 2 additions & 2 deletions src/sonic-config-engine/portconfig.py
Original file line number Diff line number Diff line change
Expand Up @@ -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 ({}, {}, {})

Expand Down Expand Up @@ -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)
jleveque marked this conversation as resolved.
Show resolved Hide resolved
if not port_config_file:
return None
if port_config_file.endswith('.json'):
Expand Down
2 changes: 1 addition & 1 deletion src/sonic-config-engine/sonic-cfggen
Original file line number Diff line number Diff line change
Expand Up @@ -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)
jleveque marked this conversation as resolved.
Show resolved Hide resolved
(ports, _, _) = get_port_config(hwsku, platform, args.port_config, asic_id)
if not ports:
print('Failed to get port config', file=sys.stderr)
Expand Down
54 changes: 52 additions & 2 deletions src/sonic-py-common/sonic_py_common/device_info.py
Original file line number Diff line number Diff line change
Expand Up @@ -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)
jleveque marked this conversation as resolved.
Show resolved Hide resolved

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
Expand Down Expand Up @@ -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
jleveque marked this conversation as resolved.
Show resolved Hide resolved

Expand All @@ -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()
jleveque marked this conversation as resolved.
Show resolved Hide resolved

port_config_candidates = []

Expand Down