Skip to content

Commit

Permalink
[sonic-py-common] fix the build/add more logic
Browse files Browse the repository at this point in the history
Signed-off-by: vaibhav-dahiya <vdahiya@microsoft.com>
  • Loading branch information
vdahiya12 committed Sep 4, 2020
1 parent e131ead commit e18a0c7
Show file tree
Hide file tree
Showing 3 changed files with 55 additions and 5 deletions.
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)
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)
(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)

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

port_config_candidates = []

Expand Down

0 comments on commit e18a0c7

Please sign in to comment.