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 and chassis info methods to device_info #7652

Merged
merged 6 commits into from
Jun 1, 2021

Conversation

alexrallen
Copy link
Contributor

Why I did it

These methods were added to make some convenient platform and chassis information methods accessible through sonic-py-common. These methods were refactored from sonic-utilities and are used in the show platform summary and show version commands.

How I did it

There are two methods, one is get_platform_info() which simply calls local methods to collect useful platform information into a dictionary format, this came directly from sonic-utilities.

The other method is get_chassis_info() which retrieves the chassis model, serial number, and hardware revision from the STATE_DB directly.

How to verify it

Open a python3 interpreter and enter the following lines

Python 3.7.3 (default, Jan 22 2021, 20:04:44)
[GCC 8.3.0] on linux
Type "help", "copyright", "credits" or "license" for more information.
>>> from sonic_py_common import device_info
>>> device_info.get_platform_info()
{'platform': 'x86_64-mlnx_msn2700-r0', 'hwsku': 'ACS-MSN2700', 'asic_type': 'mellanox', 'asic_count': 1}
>>> device_info.get_chassis_info()
{'model':'MSN2700-CS2FO', 'serial':'MT1623X09522', 'revision': 'A1'}

For different platforms these values will be different, simply check if they are successfully populated (Not empty or N/A). If it says "Not Provided" this means that the requested information is not encoded into the DMI of the switch.

Description for the changelog

[sonic-py-common] Add platform and chassis info methods to device_info

A picture of a cute animal (not mandatory but encouraged)

Highland-Cow-Lavena-and-calf-Star

@lgtm-com
Copy link

lgtm-com bot commented May 19, 2021

This pull request introduces 1 alert when merging a305336 into c646257 - view on LGTM.com

new alerts:

  • 1 for Except block handles 'BaseException'

@alexrallen

This comment has been minimized.

@alexrallen
Copy link
Contributor Author

This pull request introduces 1 alert when merging a305336 into c646257 - view on LGTM.com

new alerts:

* 1 for Except block handles 'BaseException'

This is expected. The block of code calling this makes a redis db call which from my experience right now can return a plethora of errors (if the whole service is down, timeout etc.), I want this to nicely handle that situation and simply return the dictionary with as many values as it was able to successfully retrieve. Handling of not having this information is done by the caller.

@liat-grozovik
Copy link
Collaborator

/azp run

@azure-pipelines
Copy link

Azure Pipelines successfully started running 1 pipeline(s).

@alexrallen alexrallen requested a review from jleveque May 25, 2021 14:14
@lgtm-com
Copy link

lgtm-com bot commented May 25, 2021

This pull request introduces 1 alert when merging 9f92c74 into 9930e73 - view on LGTM.com

new alerts:

  • 1 for Except block handles 'BaseException'

@jleveque
Copy link
Contributor

Please fix LGTM alert.

@alexrallen
Copy link
Contributor Author

Did you see my earlier comment about the LGTM alert?

@jleveque
Copy link
Contributor

Did you see my earlier comment about the LGTM alert?

If you need to catch all exceptions, please use except Exception rather than simply except. This is the preferred method, and it will resolve the LGTM alert.

@jleveque
Copy link
Contributor

Here's a little bit more about the difference: https://stackoverflow.com/a/18982754

@alexrallen
Copy link
Contributor Author

Thats very interesting, I was not aware of that distinction. Thanks!

@jleveque
Copy link
Contributor

Thats very interesting, I was not aware of that distinction. Thanks!

I wasn't either until we began using the LGTM plugin. :)

@dgsudharsan
Copy link
Collaborator

/azpw run

@jleveque
Copy link
Contributor

/azp run

@azure-pipelines
Copy link

Azure Pipelines successfully started running 1 pipeline(s).

@alexrallen alexrallen requested a review from jleveque May 29, 2021 06:06
@liat-grozovik
Copy link
Collaborator

/azp run

@azure-pipelines
Copy link

Azure Pipelines successfully started running 1 pipeline(s).

@jleveque jleveque merged commit 020daa9 into sonic-net:master Jun 1, 2021
jleveque pushed a commit to sonic-net/sonic-utilities that referenced this pull request Jun 4, 2021
… and version (#1624)

#### What I did
I added chassis model number, serial number, and hardware revision to the commands `show platform summary` and `show version`

#### How I did it
I refactored and modified the existing `get_hw_info_dict()` function to make calls to STATE_DB and get the chassis information populated by sonic-net/sonic-platform-daemons#183 script. 

The new refactored versions of `get_hw_info_dict()` are added here sonic-net/sonic-buildimage#7652
gitsabari pushed a commit to gitsabari/sonic-utilities that referenced this pull request Jun 15, 2021
… and version (sonic-net#1624)

#### What I did
I added chassis model number, serial number, and hardware revision to the commands `show platform summary` and `show version`

#### How I did it
I refactored and modified the existing `get_hw_info_dict()` function to make calls to STATE_DB and get the chassis information populated by sonic-net/sonic-platform-daemons#183 script. 

The new refactored versions of `get_hw_info_dict()` are added here sonic-net/sonic-buildimage#7652
carl-nokia pushed a commit to carl-nokia/sonic-buildimage that referenced this pull request Aug 7, 2021
sonic-net#7652)

#### Why I did it
These methods were added to make some convenient platform and chassis information methods accessible through sonic-py-common. These methods were refactored from sonic-utilities and are used in the `show platform summary` and `show version` commands. 

#### How I did it
There are two methods, one is `get_platform_info()` which simply calls local methods to collect useful platform information into a dictionary format, this came directly from sonic-utilities.
raphaelt-nvidia pushed a commit to raphaelt-nvidia/sonic-utilities that referenced this pull request Aug 10, 2021
… and version (sonic-net#1624)

#### What I did
I added chassis model number, serial number, and hardware revision to the commands `show platform summary` and `show version`

#### How I did it
I refactored and modified the existing `get_hw_info_dict()` function to make calls to STATE_DB and get the chassis information populated by sonic-net/sonic-platform-daemons#183 script. 

The new refactored versions of `get_hw_info_dict()` are added here sonic-net/sonic-buildimage#7652
alexrallen added a commit to alexrallen/sonic-utilities that referenced this pull request Jul 6, 2022
… and version (sonic-net#1624)

I added chassis model number, serial number, and hardware revision to the commands `show platform summary` and `show version`

I refactored and modified the existing `get_hw_info_dict()` function to make calls to STATE_DB and get the chassis information populated by sonic-net/sonic-platform-daemons#183 script.

The new refactored versions of `get_hw_info_dict()` are added here sonic-net/sonic-buildimage#7652
qiluo-msft pushed a commit that referenced this pull request Jul 8, 2022
#7652)

#### Why I did it
These methods were added to make some convenient platform and chassis information methods accessible through sonic-py-common. These methods were refactored from sonic-utilities and are used in the `show platform summary` and `show version` commands. 

#### How I did it
There are two methods, one is `get_platform_info()` which simply calls local methods to collect useful platform information into a dictionary format, this came directly from sonic-utilities.
malletvapid23 added a commit to malletvapid23/Sonic-Utility that referenced this pull request Aug 3, 2023
… and version (#1624)

#### What I did
I added chassis model number, serial number, and hardware revision to the commands `show platform summary` and `show version`

#### How I did it
I refactored and modified the existing `get_hw_info_dict()` function to make calls to STATE_DB and get the chassis information populated by sonic-net/sonic-platform-daemons#183 script. 

The new refactored versions of `get_hw_info_dict()` are added here sonic-net/sonic-buildimage#7652
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.

6 participants