napalm-automation / napalm-junos

Apache License 2.0
22 stars 42 forks source link

get_environment not working against MX240 #66

Closed dhoutz closed 8 years ago

dhoutz commented 8 years ago

Description of Issue/Question

Running get_environment against MX240 failed with the following error:

Traceback (most recent call last): File "", line 1, in File "/usr/local/lib/python2.7/dist-packages/napalm_junos/junos.py", line 288, in get_environment float(structured_object_data['temperature']) TypeError: float() argument must be a string or a number

Other NAPALM function do work correctly with the device

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

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

napalm-junos==0.4.1

JunOS version

(Paste verbatim output from show version and haiku between quotes below)

Hostname: MX240_1
Model: mx240
Junos: 14.1R7.4
JUNOS Base OS boot [14.1R7.4]
JUNOS Base OS Software Suite [14.1R7.4]
JUNOS Packet Forwarding Engine Support (M/T/EX Common) [14.1R7.4]
JUNOS Packet Forwarding Engine Support (MX Common) [14.1R7.4]
JUNOS platform Software Suite [14.1R7.4]
JUNOS Runtime Software Suite [14.1R7.4]
JUNOS Online Documentation [14.1R7.4]
JUNOS Services AACL Container package [14.1R7.4]
JUNOS Services Application Level Gateways [14.1R7.4]
JUNOS AppId Services [14.1R7.4]
JUNOS Border Gateway Function package [14.1R7.4]
JUNOS Services Captive Portal and Content Delivery Container package [14.1R7.4]
JUNOS Services HTTP Content Management package [14.1R7.4]
JUNOS Services Jflow Container package [14.1R7.4]
JUNOS IDP Services [14.1R7.4]
JUNOS Services LL-PDF Container package [14.1R7.4]
JUNOS Services MobileNext Software package [14.1R7.4]
JUNOS Services Mobile Subscriber Service Container package [14.1R7.4]
JUNOS Services NAT [14.1R7.4]
JUNOS Services PTSP Container package [14.1R7.4]
JUNOS Services RPM [14.1R7.4]
JUNOS Services Stateful Firewall [14.1R7.4]
JUNOS Voice Services Container package [14.1R7.4]
JUNOS Services Crypto [14.1R7.4]
JUNOS Services SSL [14.1R7.4]
JUNOS Services IPSec [14.1R7.4]
JUNOS py-base-i386 [14.1R7.4]
JUNOS Kernel Software Suite [14.1R7.4]
JUNOS Crypto Software Suite [14.1R7.4]
JUNOS JAM Plugin Software Suite (MPC2E/3E) [14.1R7.4-C1.1]
JUNOS Routing Software Suite [14.1R7.4]

        No icons; no mouse
        No drop down menus or fonts
        CLIs are cool

Steps to Reproduce the Issue

Error Traceback

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

>>> import napalm
>>> driver = napalm.get_network_driver('junos')
>>> mx = driver(hostname='mx240_1', username='root', password='XXXXXXXX')
>>> mx.open()
>>> mx.get_environment()
Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
  File "/usr/local/lib/python2.7/dist-packages/napalm_junos/junos.py", line 288, in get_environment
    float(structured_object_data['temperature'])
TypeError: float() argument must be a string or a number

Confirmed function works fine against QFX:

>>> qfx = driver(hostname='qfx5100_1', username='root', password='XXXXXXXXXXX')
>>> qfx.get_environment()
>>> qfx.open()
>>> qfx.get_environment()
{'fans': {'FPC 0 Fan Tray 0': {'status': True}}, 'memory': {'available_ram': 1953, 'used_ram': 741}, 'temperature': {'FPC 0 Sensor CPULeft E': {'is_alert': False, 'temperature': 28.0, 'is_critical': False}, 'FPC 0 Sensor TopMiddle C': {'is_alert': False, 'temperature': 29.0, 'is_critical': False}, 'FPC 0 Sensor CPURight C': {'is_alert': False, 'temperature': 32.0, 'is_critical': False}, 'FPC 0 Sensor TopRight C': {'is_alert': False, 'temperature': 25.0, 'is_critical': False}, 'FPC 0 Sensor CPU Die Temp': {'is_alert': False, 'temperature': 44.0, 'is_critical': False}, 'FPC 0 Sensor TopRight I': {'is_alert': False, 'temperature': 32.0, 'is_critical': False}, 'FPC 0 Sensor TopLeft I': {'is_alert': False, 'temperature': 29.0, 'is_critical': False}}, 'power': {'FPC 0 Power Supply 0': {'status': True, 'output': -1.0, 'capacity': -1.0}}, 'cpu': {'0': {'%usage': 7.0}}}
dfex commented 8 years ago

Verified this bug on an MX80 as well:

>>> import napalm
>>> driver = napalm.get_network_driver('junos') 
>>> mx = driver(hostname='10.0.0.66', username='root', password='juniper1')
>>> mx.open() 
>>> mx.get_environment()
Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
  File "/Library/Python/2.7/site-packages/napalm_junos/junos.py", line 288, in get_environment
    float(structured_object_data['temperature'])
TypeError: float() argument must be a string or a number
dfex commented 8 years ago

I believe this issue is primarily being caused because on the MX, Junos is erroneously reporting the PEMs as being of Class "Temp" (but providing no Temperature) instead of Class "Power" like it does on other platforms. Examples below:

bdale@lab-mx80a> show chassis environment | display xml 
<rpc-reply xmlns:junos="http://xml.juniper.net/junos/15.1F4/junos">
    <environment-information xmlns="http://xml.juniper.net/junos/15.1F4/junos-chassis">
        <environment-item>
            <name>PEM 0</name>
            <class>Temp</class>     <-------
            <status>OK</status>
        </environment-item>
        <environment-item>
            <name>PEM 1</name>
            <class>Temp</class>      <-------
            <status>Absent</status>
        </environment-item>
        <environment-item>
            <name>RE 0 Intake</name>
            <class>Temp</class>
            <status>OK</status>
            <temperature junos:celsius="35">35 degrees C / 95 degrees F</temperature>
        </environment-item>

bdale@ex42vc# run show chassis environment | display xml 
<rpc-reply xmlns:junos="http://xml.juniper.net/junos/15.1R4/junos">
    <environment-information xmlns="http://xml.juniper.net/junos/15.1R4/junos-chassis">
        <environment-item>
            <name>FPC 0 Power Supply 0</name>
            <class>Power</class>      <-------
            <status>OK</status>
        </environment-item>
        <environment-item>
            <name>FPC 0 Power Supply 1</name>
            <class>Power</class>      <-------
            <status>Absent</status>
        </environment-item>
        <environment-item>
            <name>FPC 1 Power Supply 0</name>
            <class>Power</class>
            <status>OK</status>
        </environment-item>
        <environment-item>
            <name>FPC 1 Power Supply 1</name>
            <class>Power</class>
            <status>OK</status>
        </environment-item>
        <environment-item>              
            <name>FPC 0 CPU</name>
            <class>Temp</class>
            <status>OK</status>
            <temperature junos:celsius="38">38 degrees C / 100 degrees F</temperature>
        </environment-item>
mirceaulinic commented 8 years ago

Closed via https://github.com/napalm-automation/napalm-junos/pull/68