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

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

Merged
merged 3 commits into from
Apr 3, 2019

Conversation

nazariig
Copy link
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
Collaborator Author

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

@jleveque please review.

return None

psu_index = int(sub_id[0])

try:
num_psus = self.psuutil.get_num_psus()
psu_num = self._getPsuNum()
Copy link
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
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
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
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
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
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
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
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
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
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

try:
module = imp.load_source(PSU_PLUGIN_MODULE_NAME, PSU_PLUGIN_MODULE_PATH)
Copy link
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
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
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
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
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>
if not sub_id:
return (1,)

psu_index = self._getPsuIndex(sub_id)
psu_index = self._get_psu_index(sub_id)
Copy link
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'

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