Skip to content

Added logic to get PSU info directly from the state DB#101

Merged
lguohan merged 3 commits intosonic-net:masterfrom
nazariig:master-get-psu-info-from-db
Apr 3, 2019
Merged

Added logic to get PSU info directly from the state DB#101
lguohan merged 3 commits intosonic-net:masterfrom
nazariig:master-get-psu-info-from-db

Conversation

@nazariig
Copy link
Copy Markdown
Collaborator

@nazariig nazariig commented Mar 19, 2019

Signed-off-by: Nazarii Hnydyn nazariig@mellanox.com

Propagating SNMP test fix.

- What I did

  • Added logic to get PSU info directly from the state DB
  • Aligned PSU UTs according to the new flow

- How I did it

  • N/A

- How to verify it

  1. Run SNMP test

- Description for the changelog

  • N/A

Signed-off-by: Nazarii Hnydyn <nazariig@mellanox.com>
@nazariig
Copy link
Copy Markdown
Collaborator Author

Signed-off-by: Nazarii Hnydyn <nazariig@mellanox.com>
@nazariig
Copy link
Copy Markdown
Collaborator Author

@jleveque please review.


try:
num_psus = self.psuutil.get_num_psus()
psu_num = self._getPsuNum()
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Why change variable name (and new related getter function name) to "psu_num"? To me, "psu_num" infers the index of a given PSU. If you prefer to start the variable name with "psu_" (as opposed to "num_psus"), I suggest renaming to "psu_count".

Also, please follow PEP8 style rules for consistency (i.e., function names should not be camelCase, but rather lowercase with words separated by underscores as necessary.

Copy link
Copy Markdown
Collaborator Author

Choose a reason for hiding this comment

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

@jleveque The reason for that is official Spec name convention: https://github.com/Azure/SONiC/blob/master/doc/pmon/pmon-enhancement-design.md

1.5.2 Chassis Table
psu_num = INT ; psu numbers on the chassis

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

I see. Would you consider changing the variable names?

Copy link
Copy Markdown
Collaborator Author

Choose a reason for hiding this comment

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

@jleveque sure. Will do it.

Copy link
Copy Markdown
Collaborator Author

Choose a reason for hiding this comment

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

@jleveque done.

Copy link
Copy Markdown
Collaborator Author

Choose a reason for hiding this comment

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

@jleveque done. The variable names were aligned as well.

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Thanks. You decided on "num_psus" instead of something else like "psu_count"? If you want the variable name to start with "psu" I would recommend psu_count. We didn't need to go back to "num_psus", but I just think "psu_num" is confusing.

Copy link
Copy Markdown
Collaborator Author

Choose a reason for hiding this comment

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

@jleveque NP. I decided to stay with original name. Do you want me to force psu_count? I don't care to much regarding variables naming, but rather the stuff to be working. The idea of these changes to fix SNMP test.

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

I'm fine either way. I just wanted to make it clear that I'm not set on the old name.

Copy link
Copy Markdown
Collaborator Author

Choose a reason for hiding this comment

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

@jleveque ok. Got it. Thanks for the clarifications.

Signed-off-by: Nazarii Hnydyn <nazariig@mellanox.com>
@nazariig nazariig force-pushed the master-get-psu-info-from-db branch from a1c18a6 to 222dc25 Compare March 27, 2019 15:58
@jleveque jleveque requested a review from qiluo-msft March 27, 2019 19:29
self.statedb.connect(self.statedb.STATE_DB)

try:
module = imp.load_source(PSU_PLUGIN_MODULE_NAME, PSU_PLUGIN_MODULE_PATH)
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

load_source [](start = 25, length = 11)

Since we don't need the module 'psutil', can we remove it from setup.py?

Copy link
Copy Markdown
Collaborator Author

Choose a reason for hiding this comment

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

@qiluo-msft Unfortunately we can't remove it from setup.py

Summary:
From psutil:

psutil (process and system utilities) is a cross-platform library for retrieving information on running processes and system utilization (CPU, memory, disks, network, sensors) in Python.

Usage:
From sonic_ax_impl:

# From the psutil documentation https://pythonhosted.org/psutil/#psutil.cpu_percent:
#
#    Warning the first time this function is called
#    with interval = 0.0 or None it will return a
#    meaningless 0.0 value which you are supposed
#    to ignore.
psutil.cpu_percent()
# '...is recommended for accuracy that this function be called with at least 0.1 seconds between calls.'
time.sleep(0.1)
# a sliding window of 60 contiguous 5 sec utilization (up to five minutes)
self.cpuutils = collections.deque([psutil.cpu_percent()], maxlen=60)
self.system_virtual_memory = psutil.virtual_memory()

Copy link
Copy Markdown
Contributor

@qiluo-msft qiluo-msft left a comment

Choose a reason for hiding this comment

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

As comment

Copy link
Copy Markdown
Contributor

@qiluo-msft qiluo-msft left a comment

Choose a reason for hiding this comment

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

Looks good to me

@nazariig
Copy link
Copy Markdown
Collaborator Author

@lguohan please review

@lguohan lguohan merged commit bd41744 into sonic-net:master Apr 3, 2019
stepanblyschak pushed a commit to stepanblyschak/sonic-snmpagent that referenced this pull request Apr 12, 2019
* Added logic to get PSU info directly from the state DB.

Signed-off-by: Nazarii Hnydyn <nazariig@mellanox.com>

* Fixed PSU UTs.

Signed-off-by: Nazarii Hnydyn <nazariig@mellanox.com>

* Aligned method names according to PEP8.

Signed-off-by: Nazarii Hnydyn <nazariig@mellanox.com>
return (1,)

psu_index = self._getPsuIndex(sub_id)
psu_index = self._get_psu_index(sub_id)
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

_get_psu_index [](start = 25, length = 14)

get_next is nothrow function. However, if the StateDB is not as good as you expect, there will be exception.

This is a sample:

  File "/usr/local/lib/python3.6/dist-packages/sonic_ax_impl/mibs/vendor/cisco/ciscoEntityFruControlMIB.py", line 102, in _get_psu_index
    num_psus = self._get_num_psus()
  File "/usr/local/lib/python3.6/dist-packages/sonic_ax_impl/mibs/vendor/cisco/ciscoEntityFruControlMIB.py", line 65, in _get_num_psus
    num_psus = get_chassis_data(chassis_info)
  File "/usr/local/lib/python3.6/dist-packages/sonic_ax_impl/mibs/vendor/cisco/ciscoEntityFruControlMIB.py", line 36, in get_chassis_data
    return tuple(chassis_info.get(chassis_field.value, b"").decode() for chassis_field in CHASSISInfoDB)
  File "/usr/local/lib/python3.6/dist-packages/sonic_ax_impl/mibs/vendor/cisco/ciscoEntityFruControlMIB.py", line 36, in <genexpr>
    return tuple(chassis_info.get(chassis_field.value, b"").decode() for chassis_field in CHASSISInfoDB)
AttributeError: 'NoneType' object has no attribute 'get'

ssithaia-ebay pushed a commit to ssithaia-ebay/sonic-snmpagent that referenced this pull request May 23, 2025
* Added logic to get PSU info directly from the state DB.

Signed-off-by: Nazarii Hnydyn <nazariig@mellanox.com>

* Fixed PSU UTs.

Signed-off-by: Nazarii Hnydyn <nazariig@mellanox.com>

* Aligned method names according to PEP8.

Signed-off-by: Nazarii Hnydyn <nazariig@mellanox.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants