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

Conversation

vdahiya12
Copy link
Contributor

@vdahiya12 vdahiya12 commented Oct 5, 2020

Summary:

For this PR the motivation is to add logic so that platform.json is considered for port configuration candidates only if platform.json has an interfaces key
and the length of the key is greater than zero. This happened with new platform.json file utilized to test platform_api's infrastructure which in turn had interfaces key without any port configs.

Type of change

  • Bug fix
  • Testbed and Framework(new/improvement)
  • Test case(new/improvement)

Approach

What is the motivation for this PR?

To make sure platform.json is not used for sonic-cfggen if it does not have "interfaces" key populated

How did you do it?

added logic to check if platform.json is present, check if "interfaces" key size is greater than zero

How did you verify/test it?

Run it on a mellanox-acs2700 platform and verify cfggen does not cause errors

Any platform specific information?

platform.json should be present without "interfaces" key populated

Signed-off-by: vaibhav-dahiya vdahiya@microsoft.com

Signed-off-by: vaibhav-dahiya <vdahiya@microsoft.com>
@jleveque jleveque changed the title [sonic-py-common] add logic to add platform.json to port_config files candidates only if interfaces are present within platform.json [sonic-py-common] Add platform.json to port_config files candidates only if interfaces are present within platform.json Oct 6, 2020
Signed-off-by: vaibhav-dahiya <vdahiya@microsoft.com>
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())
if len(platform_data.get("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.

Maybe you should also first check for the presence of the "interfaces" key. That way, if either the key is not present OR it is empty, we don't consider platform.json a candidate.

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

Signed-off-by: vaibhav-dahiya <vdahiya@microsoft.com>
Signed-off-by: vaibhav-dahiya <vdahiya@microsoft.com>
Signed-off-by: vaibhav-dahiya <vdahiya@microsoft.com>
@vdahiya12
Copy link
Contributor Author

Retest this please

@vdahiya12
Copy link
Contributor Author

Retest mellanox please

Signed-off-by: vaibhav-dahiya <vdahiya@microsoft.com>
Comment on lines 272 to 273
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

Signed-off-by: vaibhav-dahiya <vdahiya@microsoft.com>
@vdahiya12
Copy link
Contributor Author

Retest this please

@vdahiya12
Copy link
Contributor Author

Retest vsimage please

1 similar comment
@vdahiya12
Copy link
Contributor Author

Retest vsimage please

@vdahiya12 vdahiya12 merged commit 3cd1d8e into sonic-net:master Oct 13, 2020
santhosh-kt pushed a commit to santhosh-kt/sonic-buildimage that referenced this pull request Feb 25, 2021
…nly if interfaces are present within platform.json (sonic-net#5538)

* [sonic-py-common] add platform.json to port_config

Signed-off-by: vaibhav-dahiya <vdahiya@microsoft.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

New platform.json file cause Mellanox ACS-2700 failed to get port information
2 participants