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

KeyError in get_environment() on Juniper MX10k3 with Junos 19.2R1.8 #1247

Closed
1 of 2 tasks
steffann opened this issue Jun 30, 2020 · 2 comments · Fixed by #1248
Closed
1 of 2 tasks

KeyError in get_environment() on Juniper MX10k3 with Junos 19.2R1.8 #1247

steffann opened this issue Jun 30, 2020 · 2 comments · Fixed by #1248
Milestone

Comments

@steffann
Copy link
Contributor

Description of Issue/Question

Calling get_environment() on our Juniper MX10003 throws a KeyError.

The error has been traced back to pem_name = pem[0].replace("PEM", "Power Supply"). I assume this was done because Junos returned "Power Suppply" in junos_environment_table and "PEM" in junos_pem_table. However, my box returns "PEM" in both, so replacing it causes the lookup error later.

Suggested fix is to also replace "PEM" with "Power Supply" on the name from the environment. This makes the lookup work and keeps the output consistent by always using the "Power Supply" naming:

for sensor_object, object_data in environment.items():
    ...
    if structured_object_data["class"] == "Power":
        sensor_object = sensor_object.replace("PEM", "Power Supply")
        ....

Did you follow the steps from https://github.com/napalm-automation/napalm#faq

(Place an x between the square brackets where applicable)

  • Yes
  • No

Setup

napalm version

(Paste verbatim output from pip freeze | grep napalm between quotes below)

napalm==3.0.1

Network operating system version

(Paste verbatim output from show version - or equivalent - between quotes below)

Model: mx10003
Junos: 19.2R1.8

Steps to Reproduce the Issue

In [1]: import napalm                                                                                                                                                                                                           
In [2]: driver = napalm.get_network_driver('junos')                                                                                                                                                                             
In [3]: rtr = driver('10.x.y.z', 'sander', 'wouldntyouliketoknow')                                                                                                                                                                      
In [4]: rtr.open()
In [5]: rtr.get_environment()                                                                                                                                                                                                   

Error Traceback

(Paste the complete traceback of the exception between quotes below)

/opt/netbox-dev/venv/lib/python3.6/site-packages/napalm/junos/junos.py in get_environment(self)
    527                     environment_data["power"][pem_name]["capacity"] = pem_table[
    528                         pem_name
--> 529                     ]["capacity"]
    530                 if pem_table[pem_name]["output"] is not None:
    531                     environment_data["power"][pem_name]["output"] = pem_table[pem_name][

KeyError: 'Power Supply 0'
@mirceaulinic
Copy link
Member

Hi @steffann. Thanks for reporting. I think the fix you suggested sounds good.

@mirceaulinic mirceaulinic added this to the 3.0.2 milestone Jun 30, 2020
@steffann
Copy link
Contributor Author

steffann commented Jun 30, 2020

PR incoming!

steffann added a commit to steffann/napalm that referenced this issue Jun 30, 2020
mirceaulinic added a commit that referenced this issue Jul 1, 2020
* Fix #1247 by making PEM naming consistent

* Add tests and fix indentation

Co-authored-by: Mircea Ulinic <mirceaulinic@users.noreply.github.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 a pull request may close this issue.

2 participants