napalm-automation / napalm-ios

Apache License 2.0
31 stars 40 forks source link

Exception (Socket.error) when connecting to cisco device #135

Closed jorgenbl closed 7 years ago

jorgenbl commented 7 years ago

Description of Issue/Question

I get a "Socket error" each time I connect to a cisco device. The get_facts() function seem to work as it should. It seems to be related to handling the connection. See below for example. (tested with Python2.7) Problem similar when testing on Python3.6.

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)

pip freeze | grep napalm-ios
You are using pip version 8.1.1, however version 9.0.1 is available.
You should consider upgrading via the 'pip install --upgrade pip' command.
napalm-ios==0.6.1
napalm-iosxr==0.4.8

IOS version

(Paste verbatim output from show version between quotes below)

router#show version
Cisco IOS Software, 7200 Software (C7200-ADVENTERPRISEK9-M), Version 15.1(4)M, RELEASE SOFTWARE (fc1)
Technical Support: http://www.cisco.com/techsupport
Copyright (c) 1986-2011 by Cisco Systems, Inc.
Compiled Thu 24-Mar-11 19:26 by prod_rel_team

ROM: ROMMON Emulation Microcode
BOOTLDR: 7200 Software (C7200-ADVENTERPRISEK9-M), Version 15.1(4)M, RELEASE SOFTWARE (fc1)

router uptime is 1 hour, 54 minutes
System returned to ROM by unknown reload cause - suspect boot_data[BOOT_COUNT] 0x0, BOOT_COUNT 0, BOOTDATA 19
System image file is "tftp://255.255.255.255/unknown"

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.

Cisco 7206VXR (NPE400) processor (revision A) with 491520K/32768K bytes of memory.
Processor board ID 4279256517
R7000 CPU at 150MHz, Implementation 39, Rev 2.1, 256KB L2 Cache
6 slot VXR midplane, Version 2.1

Last reset from power-on

PCI bus mb0_mb1 (Slots 0, 1, 3 and 5) has a capacity of 600 bandwidth points.
Current configuration on bus mb0_mb1 has a total of 1400 bandwidth points.
The set of PA-2FE, PA-POS-2OC3, and I/O-2FE qualify for "half
bandwidth points" consideration, when full bandwidth point counting
results in oversubscription, under the condition that only one of the
two ports is used. With this adjustment, current configuration on bus
mb0_mb1 has a total of 1200 bandwidth points.
This configuration has oversubscripted the PCI bus and is not a
supported configuration.

PCI bus mb2 (Slots 2, 4, 6) has a capacity of 600 bandwidth points.
Current configuration on bus mb2 has a total of 1200 bandwidth points
The set of PA-2FE, PA-POS-2OC3, and I/O-2FE qualify for "half
bandwidth points" consideration, when full bandwidth point counting
results in oversubscription, under the condition that only one of the
two ports is used. With this adjustment, current configuration on bus
mb2 has a total of 1000 bandwidth points.
This configuration has oversubscripted the PCI bus and is not a
supported configuration.

Please refer to the following document "Cisco 7200 Series Port Adaptor
Hardware Configuration Guidelines" on Cisco.com <http://www.cisco.com>
for c7200 bandwidth points oversubscription and usage guidelines.

WARNING: PCI bus mb0_mb1 Exceeds 600 bandwidth points
WARNING: PCI bus mb2 Exceeds 600 bandwidth points

5 FastEthernet interfaces
4 Gigabit Ethernet interfaces
509K bytes of NVRAM.

8192K bytes of Flash internal SIMM (Sector size 256K).

Configuration register is 0x2102

Steps to Reproduce the Issue

Error Traceback

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

Script:
import napalm

driver = napalm.get_network_driver("ios")
oargs = "{'dest_file_system': 'flash:'}"
deviceCon = driver(hostname="192.168.41.202", username="cisco", password="cisco", optional_args=eval(oargs))
deviceCon.open()
print(deviceCon.get_facts())
print(deviceCon.is_alive())
deviceCon.close()
print(deviceCon.is_alive())

Output:
{u'os_version': u'7200 Software (C7200-ADVENTERPRISEK9-M), Version 15.1(4)M, RELEASE SOFTWARE (fc1)', u'uptime': 6900, u'interface_list': [u'FastEthernet0/0', u'FastEthernet1/0', u'FastEthernet1/1', u'FastEthernet2/0', u'FastEthernet2/1', u'GigabitEthernet3/0', u'GigabitEthernet4/0', u'GigabitEthernet5/0', u'GigabitEthernet6/0', u'Loopback0'], u'vendor': u'Cisco', u'serial_number': u'4279256517', u'model': u'7206VXR', u'hostname': u'router', u'fqdn': u'router.test.net'}
{u'is_alive': True}
{u'is_alive': False}
Exception socket.error: error('Socket is closed',) in <bound method IOSDriver.__del__ of <napalm_ios.ios.IOSDriver object at 0x7f240e10f190>> ignored
ktbyers commented 7 years ago

I have been a bit out of the loop on the del method work. I think @mirceaulinic is working on this.

It shouldn't hurt anything so in the interim until we fix this, you can gracefully handle it using a try/except statement.

jorgenbl commented 7 years ago

OK, thanks for the quick response.

dbarrosop commented 7 years ago

@jorgenbl are you getting that error using the latest napalm-base? Could you try to upgrade with pip install -U napalm-base and let us know if it still happens?

jorgenbl commented 7 years ago

root@90e9d99176d9:/# pip install -U napalm-base Requirement already up-to-date: napalm-base in /usr/local/lib/python2.7/dist-packages Requirement already up-to-date: pyYAML in /usr/local/lib/python2.7/dist-packages (from napalm-base) Requirement already up-to-date: jinja2 in /usr/local/lib/python2.7/dist-packages (from napalm-base) Requirement already up-to-date: jtextfsm in /usr/local/lib/python2.7/dist-packages (from napalm-base) Requirement already up-to-date: netaddr in /usr/local/lib/python2.7/dist-packages (from napalm-base) Requirement already up-to-date: MarkupSafe>=0.23 in /usr/local/lib/python2.7/dist-packages (from jinja2->napalm-base) root@90e9d99176d9:/# python testNapalm.py {u'os_version': u'7200 Software (C7200-ADVENTERPRISEK9-M), Version 15.1(4)M, RELEASE SOFTWARE (fc1)', u'uptime': 7800, u'interface_list': [u'FastEthernet0/0', u'FastEthernet1/0', u'FastEthernet1/1', u'FastEthernet2/0', u'FastEthernet2/1', u'GigabitEthernet3/0', u'GigabitEthernet4/0', u'GigabitEthernet5/0', u'GigabitEthernet6/0', u'Loopback0'], u'vendor': u'Cisco', u'serial_number': u'4279256517', u'model': u'7206VXR', u'hostname': u'router', u'fqdn': u'router.test.net'} {u'is_alive': True} {u'is_alive': False} Exception socket.error: error('Socket is closed',) in <bound method IOSDriver.del of <napalm_ios.ios.IOSDriver object at 0x7f63ef977190>> ignored

dbarrosop commented 7 years ago

Ok, I will take a look during that weekend. Thanks for reporting.

dbarrosop commented 7 years ago

I proposed a fix for this here: https://github.com/napalm-automation/napalm-base/pull/235