napalm-automation / napalm

Network Automation and Programmability Abstraction Layer with Multivendor support
Apache License 2.0
2.25k stars 554 forks source link

get_environment fails on Cisco 3850 switch #468

Open mirceaulinic opened 7 years ago

mirceaulinic commented 7 years ago

Description of Issue/Question

When it tries to get the memory, it executes show memory statistics which is not implemented on Cisco 3850 switches. it fails to find the Processor line and fails to set proc_used_mem variable Cisco 3850s (and I believe 3650s) use

show memory switch 1
System memory   : 3931592K total, 1645124K used, 2286468K free, 221424K kernel reserved
Lowest(b)       : 1693808812

                Total(K)     Used(K)      Free(K)
Process         3931592      1645124      2286468
Config          0            0            0

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

Setup

napalm-ios version

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

napalm-ios==0.7.0

IOS version

(Paste verbatim output from show version between quotes below)

Cisco IOS Software, IOS-XE Software, Catalyst L3 Switch Software (CAT3K_CAA-UNIVERSALK9-M), Version 03.06.06E RELEASE SOFTWARE (fc1)
Technical Support: http://www.cisco.com/techsupport
Copyright (c) 1986-2016 by Cisco Systems, Inc.
Compiled Sat 17-Dec-16 00:22 by prod_rel_team

Cisco IOS-XE software, Copyright (c) 2005-2015 by cisco Systems, Inc.
All rights reserved.  Certain components of Cisco IOS-XE software are
licensed under the GNU General Public License ("GPL") Version 2.0.  The
software code licensed under GPL Version 2.0 is free software that comes
with ABSOLUTELY NO WARRANTY.  You can redistribute and/or modify such
GPL code under the terms of GPL Version 2.0.
(http://www.gnu.org/licenses/gpl-2.0.html) For more details, see the
documentation or "License Notice" file accompanying the IOS-XE software,
or the applicable URL provided on the flyer accompanying the IOS-XE
software.

ROM: IOS-XE ROMMON
BOOTLDR: CAT3K_CAA Boot Loader (CAT3K_CAA-HBOOT-M) Version 1.2, RELEASE SOFTWARE (P)

s-edge10-mpoe uptime is 14 weeks, 2 days, 14 hours, 24 minutes
Uptime for this control processor is 14 weeks, 2 days, 14 hours, 31 minutes
System returned to ROM by reload at 10:30:30 PDT Mon Apr 17 2017
System restarted at 18:22:53 PDT Mon Apr 17 2017
System image file is "flash:packages.conf"
Last reload reason: Reload command

This product contains cryptographic features and is subject to United
States and local country laws governing import, export, transfer and
use. Delivery of Cisco cryptographic products does not imply
third-party authority to import, export, distribute or use encryption.
Importers, exporters, distributors and users are responsible for
compliance with U.S. and local country laws. By using this product you
agree to comply with applicable laws and regulations. If you are unable
to comply with U.S. and local laws, return this product immediately.

A summary of U.S. laws governing Cisco cryptographic products may be found at:
http://www.cisco.com/wwl/export/crypto/tool/stqrg.html

If you require further assistance please contact us by sending email to
export@cisco.com.

License Level: Ipbase
License Type: Permanent
Next reload license Level: Ipbase

cisco WS-C3850-48P (MIPS) processor with 4194304K bytes of physical memory.
Processor board ID XXXXXXXX
4 Virtual Ethernet interfaces
104 Gigabit Ethernet interfaces
8 Ten Gigabit Ethernet interfaces
2048K bytes of non-volatile configuration memory.
4194304K bytes of physical memory.
250456K bytes of Crash Files at crashinfo:.
257008K bytes of Crash Files at crashinfo-2:.
1609272K bytes of Flash at flash:.
1550272K bytes of Flash at flash-2:.
0K bytes of Dummy USB Flash at usbflash0:.
0K bytes of Dummy USB Flash at usbflash0-2:.
0K bytes of  at webui:.

Base Ethernet MAC Address          : 28:34:a2:06:80:00
Motherboard Assembly Number        : 73-14442-09
Motherboard Serial Number          : XXXXXXXX
Model Revision Number              : M0
Motherboard Revision Number        : A0
Model Number                       : WS-C3850-48P
System Serial Number               : XXXXXXXX

Switch Ports Model              SW Version        SW Image              Mode
------ ----- -----              ----------        ----------            ----
*    1 56    WS-C3850-48P       03.06.06E         cat3k_caa-universalk9 INSTALL
     2 56    WS-C3850-48P       03.06.06E         cat3k_caa-universalk9 INSTALL

Switch 02
---------
Switch uptime                      : 14 weeks, 2 days, 14 hours, 32 minutes
Base Ethernet MAC Address          : 2c:3e:cf:a9:a1:00
Motherboard Assembly Number        : 73-14442-09
Motherboard Serial Number          : XXXXXXXX
Model Revision Number              : M0
Motherboard Revision Number        : A0
Model Number                       : WS-C3850-48P
System Serial Number               : XXXXXXX

Configuration register is 0x102

Steps to Reproduce the Issue

trying to run from net box, but it runs get_environment and fails to collect memory, stating proc_used_mem referenced before assignment. The variable is not set since the call would fail.

Error Traceback

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

Not available

I don't see any way to get memory for the entire stack. it seems to be on a per member basis. It would be show memory switch where n is each stack members number, but then you have to worry about getting the number of stack members. Or you could just get it for the active stack member, but have to get that using show switch detailed.

show process memory also shows the memory usage on the first line of output. It can take a parameter switch , so am not sure if when not supplying a switch number if it defaults to the master or to switch 1, as In my stack, switch 1 is the active member.

3850-sw#show process memory | i System
System memory  : 3931592K total, 1689244K used, 2242348K free, 221424K kernel reserved

3850-sw#show memory switch 1
System memory   : 3931592K total, 1689244K used, 2242348K free, 221424K kernel reserved
Lowest(b)       : 1514225016

                Total(K)     Used(K)      Free(K)
Process         3931592      1689284      2242308
Config          0            0            0

Issue moved from https://github.com/napalm-automation/napalm-ios/issues/181

ghost commented 6 years ago

What info is needed? I am experiencing the same issue and am willing to provide what info I can. The switch I'm working with currently is not stacked, but I do have a stacked switch I can try if needed.

Here is the show version on the switch

Cisco IOS Software, IOS-XE Software, Catalyst L3 Switch Software (CAT3K_CAA-UNIVERSALK9-M), Version 03.02.03.SE RELEASE SOFTWARE (fc2)
Technical Support: http://www.cisco.com/techsupport
Copyright (c) 1986-2013 by Cisco Systems, Inc.
Compiled Mon 23-Sep-13 18:24 by prod_rel_team

Cisco IOS-XE software, Copyright (c) 2005-2013 by cisco Systems, Inc.
All rights reserved.  Certain components of Cisco IOS-XE software are
licensed under the GNU General Public License ("GPL") Version 2.0.  The
software code licensed under GPL Version 2.0 is free software that comes
with ABSOLUTELY NO WARRANTY.  You can redistribute and/or modify such
GPL code under the terms of GPL Version 2.0.
(http://www.gnu.org/licenses/gpl-2.0.html) For more details, see the
documentation or "License Notice" file accompanying the IOS-XE software,
or the applicable URL provided on the flyer accompanying the IOS-XE
software.

ROM: IOS-XE ROMMON
BOOTLDR: CAT3K_CAA Boot Loader (CAT3K_CAA-HBOOT-M) Version 1.18, RELEASE SOFTWARE (P)

NAME uptime is 23 weeks, 5 days, 21 hours, 18 minutes
Uptime for this control processor is 23 weeks, 5 days, 21 hours, 21 minutes
System returned to ROM by reload
System restarted at 13:06:11 EDT Sat Sep 9 2017
System image file is "flash:packages.conf"
Last reload reason: Reload command

This product contains cryptographic features and is subject to United
States and local country laws governing import, export, transfer and
use. Delivery of Cisco cryptographic products does not imply
third-party authority to import, export, distribute or use encryption.
Importers, exporters, distributors and users are responsible for
compliance with U.S. and local country laws. By using this product you
agree to comply with applicable laws and regulations. If you are unable
to comply with U.S. and local laws, return this product immediately.

A summary of U.S. laws governing Cisco cryptographic products may be found at:
http://www.cisco.com/wwl/export/crypto/tool/stqrg.html

If you require further assistance please contact us by sending email to
export@cisco.com.

License Level: Ipservices
License Type: Permanent
Next reload license Level: Ipservices

cisco WS-C3850-48P (MIPS) processor with 4194304K bytes of physical memory.
Processor board ID FOC1919U1DJ
1 Virtual Ethernet interface
52 Gigabit Ethernet interfaces
4 Ten Gigabit Ethernet interfaces
2048K bytes of non-volatile configuration memory.
4194304K bytes of physical memory.
250456K bytes of Crash Files at crashinfo:.
1609272K bytes of Flash at flash:.
0K bytes of Dummy USB Flash at usbflash0:.
0K bytes of  at webui:.

Base Ethernet MAC Address          : MAC
Motherboard Assembly Number        : 73-15800-07
Motherboard Serial Number          : SERIAL
Model Revision Number              : T0
Motherboard Revision Number        : A0
Model Number                       : WS-C3850-48P
System Serial Number               : SERIAL

Switch Ports Model              SW Version        SW Image              Mode
------ ----- -----              ----------        ----------            ----
     1 56    WS-C3850-48P       03.02.03.SE       cat3k_caa-universalk9 INSTALL

Configuration register is 0x102

Here is the traceback

  File "/usr/local/bin/napalm", line 9, in <module>
    load_entry_point('napalm==2.3.0', 'console_scripts', 'napalm')()
  File "/usr/local/lib/python3.5/dist-packages/napalm/base/clitools/cl_napalm.py", line 285, in main
    run_tests(args)
  File "/usr/local/lib/python3.5/dist-packages/napalm/base/clitools/cl_napalm.py", line 268, in run_tests
    call_getter(device, args.method, **method_kwargs)
  File "/usr/local/lib/python3.5/dist-packages/napalm/base/clitools/cl_napalm.py", line 27, in wrapper
    r = func(*args, **kwargs)
  File "/usr/local/lib/python3.5/dist-packages/napalm/base/clitools/cl_napalm.py", line 238, in call_getter
    r = func(**kwargs)
  File "/usr/local/lib/python3.5/dist-packages/napalm/ios/ios.py", line 1632, in get_environment
    total_mem = int(proc_total_mem) + int(io_total_mem)
UnboundLocalError: local variable 'proc_total_mem' referenced before assignment

show memory on switch

System memory   : 4004464K total, 1742352K used, 2262112K free, 150332K kernel reserved
Lowest(b)       : 1816808472

                Total(K)     Used(K)      Free(K)
Process         4004464      1742352      2262112
Config          0            0            0
michaelgibson commented 6 years ago

Would this not at least prevent the command from failing? https://github.com/michaelgibson/napalm/commit/112d4a5a543528d89683c7adbf72b4a046c6f01d

ktbyers commented 6 years ago

@dbarrosop @mirceaulinic So what do we want to do here (i.e. in the switch stack case).

Options

  1. Just set it to 0
  2. Set it to the value of the primary/master switch stack master
  3. Parse all stack members and return a list (though causes compatibility/migration issues in napalm).
  4. Aggregate values (which doesn't sound like a good idea to me).

If we go with 3, then that brings up questions about other data structure elements (like power, fans, temperature).

Item 2 is probably the easy solution...I am a bit worried we are opening a big can of worms if we try to do 3.

dbarrosop commented 6 years ago

Can't we just query individual stack members somehow?

explody commented 6 years ago

I'm hitting this as well. Option 1 makes sense from a purely code perspective, in that there's a variable that only gets set inside a conditional that may never test true, and it makes sense to ensure that it exists. Plus it is easy to implement.

I would much rather get a '0' return than a complete failure.

Lukiko commented 6 years ago

I'm receiving this same error on several Cisco 3650 switches not stacked (WS-C3650-24TS).

Has there been any resolution or workaround? Thanks!

explody commented 6 years ago

I should add, our issues are appearing on 3650's as well. Our 3850s seem ok, which I presume is due new/different OS versions.

Noname2244 commented 6 years ago

ios vs. ios xe issue?

ktbyers commented 6 years ago

@Lukiko @explody @Noname2244 Can you open a separate issue if you are not on a switch stack.

Include the output from this command on the failing device.

show memory statistics
mrfroggg commented 5 years ago

I'm having the same issue on a Nexus 3500 switch using nxos_ssh driver.

There is no "show memory" command available on it. Using NAPALM 2.2.0.

airblag commented 5 years ago

Hi,

I'm having a similar problem on a 3750X stack (get_environment() fails) with napalm 2.3.3

# show version
Cisco IOS Software, C3750E Software (C3750E-UNIVERSALK9-M), Version 12.2(55)SE3, RELEASE SOFTWARE (fc1)
[...]
#!/usr/bin/python3

import napalm
from config import *

cisco = napalm.get_network_driver('ios')
c3750 = cisco(hostname,login,password)

c3750.open()
print(c3750.get_environment())
$ ./napalm-test.py 
Traceback (most recent call last):
  File "./napalm-test.py", line 10, in <module>
    print(c3750.get_environment())
  File "/home/user/.local/lib/python3.5/site-packages/napalm/ios/ios.py", line 1620, in get_environment
    if temp_value > system_temp_alert:
UnboundLocalError: local variable 'temp_value' referenced before assignment

so temp_value should be also initialized as in https://github.com/napalm-automation/napalm/issues/468#issuecomment-368975678

but on my switch stack, the output of show env temperature status looks like this :

Temperature Value: 30 Degree Celsius
Temperature State: GREEN
Yellow Threshold : 46 Degree Celsius
Red Threshold    : 60 Degree Celsius

So the regexp is wrong. Changing it like this make my get_environment() call works.

 --- /home/user/.local/lib/python3.5/site-packages/napalm/ios/ios.py.orig   2019-01-25 17:11:02.048000000 +0100
+++ /home/user/.local/lib/python3.5/site-packages/napalm/ios/ios.py 2019-01-25 17:11:21.962000000 +0100
@@ -1602,7 +1602,7 @@
         environment['memory']['used_ram'] = used_mem
         environment['memory']['available_ram'] = total_mem
         environment.setdefault('temperature', {})
-        re_temp_value = re.compile('(.*) Temperature Value')
+        re_temp_value = re.compile('Temperature Value(.*)')
         # The 'show env temperature status' is not ubiquitous in Cisco IOS
         output = self._send_command(temp_cmd)
         if '% Invalid' not in output: