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-py-common] Add platform.json to port_config files candidates only if interfaces are present within platform.json #5538

Merged
Merged
Changes from 7 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
17 changes: 16 additions & 1 deletion src/sonic-py-common/sonic_py_common/device_info.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
import glob
import json
import os
import re
import subprocess
Expand Down Expand Up @@ -255,8 +256,22 @@ def get_path_to_port_config_file(hwsku=None, asic=None):

# if 'hwsku.json' file is available, Check for 'platform.json' file presence,
# if 'platform.json' is available, APPEND it. Otherwise, SKIP it.

"""
This length check for interfaces in platform.json is performed to make sure
the cfggen does not fail if port configuration information is not present
TODO: once platform.json has all the necessary port config information
remove this check
"""

if os.path.isfile(hwsku_json_file):
port_config_candidates.append(os.path.join(platform_path, PLATFORM_JSON_FILE))
if os.path.isfile(os.path.join(platform_path, PLATFORM_JSON_FILE)):
json_file = os.path.join(platform_path, PLATFORM_JSON_FILE)
platform_data = json.loads(open(json_file).read())
interfaces = platform_data.get('interfaces', None)
if interfaces:
if len(interfaces) > 0:
Copy link
Contributor

Choose a reason for hiding this comment

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

I believe if interfaces: should be enough, as it will return false if either interfaces is None or its length is 0. If you want to be more explicit, I recommend if interfaces is not None and len(interfaces) > 0:

Copy link
Contributor Author

Choose a reason for hiding this comment

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

fixed

port_config_candidates.append(os.path.join(platform_path, PLATFORM_JSON_FILE))

# Check for 'port_config.ini' file presence in a few locations
if asic:
Expand Down