From bad08646c3d1dfe23b810b0fa856415f608c343c Mon Sep 17 00:00:00 2001 From: Kirk Byers Date: Tue, 1 Nov 2016 10:02:20 -0700 Subject: [PATCH 1/8] Updating gitignore --- .gitignore | 2 ++ 1 file changed, 2 insertions(+) diff --git a/.gitignore b/.gitignore index a92fbbf..1bc81f8 100644 --- a/.gitignore +++ b/.gitignore @@ -62,3 +62,5 @@ test/unit/test_devices.py test/unit/TestIOSDriverKB.py #test/unit/ios/*.conf #test/unit/ios/*.diff +test/unit/ios/cleanup.sh +test/unit/ios/prep_test.sh From d8565573e7fa551835fd848fecea5c3580d5ab95 Mon Sep 17 00:00:00 2001 From: Kirk Byers Date: Thu, 3 Nov 2016 09:40:24 -0700 Subject: [PATCH 2/8] Adding secret support for napalm-getters --- napalm_ios/ios.py | 2 ++ 1 file changed, 2 insertions(+) diff --git a/napalm_ios/ios.py b/napalm_ios/ios.py index 620814f..3e49f73 100644 --- a/napalm_ios/ios.py +++ b/napalm_ios/ios.py @@ -94,6 +94,8 @@ def open(self): username=self.username, password=self.password, **self.netmiko_optional_args) + # ensure in enable mode + self.device.enable() if not self.dest_file_system: try: self.dest_file_system = self.device._autodetect_fs() From 734acd88cbb41c0d11f65e602ec76b21cbf75816 Mon Sep 17 00:00:00 2001 From: Kirk Byers Date: Sun, 13 Nov 2016 09:40:02 -0800 Subject: [PATCH 3/8] Python3 fixes to support unicode/str typecasting --- napalm_ios/ios.py | 26 ++++++++++++++------------ test/unit/TestIOSDriver.py | 3 ++- 2 files changed, 16 insertions(+), 13 deletions(-) diff --git a/napalm_ios/ios.py b/napalm_ios/ios.py index 3e49f73..916b482 100644 --- a/napalm_ios/ios.py +++ b/napalm_ios/ios.py @@ -14,6 +14,7 @@ # the License. from __future__ import print_function +from __future__ import unicode_literals import re @@ -21,6 +22,7 @@ from netmiko import __version__ as netmiko_version from napalm_base.base import NetworkDriver from napalm_base.exceptions import ReplaceConfigException, MergeConfigException +from napalm_base.utils import py23_compat # Easier to store these as constants HOUR_SECONDS = 3600 @@ -584,10 +586,10 @@ def get_facts(self): return { 'uptime': uptime, 'vendor': vendor, - 'os_version': unicode(os_version), - 'serial_number': unicode(serial_number), - 'model': unicode(model), - 'hostname': unicode(hostname), + 'os_version': py23_compat.text_type(os_version), + 'serial_number': py23_compat.text_type(serial_number), + 'model': py23_compat.text_type(model), + 'hostname': py23_compat.text_type(hostname), 'fqdn': fqdn, 'interface_list': interface_list } @@ -688,7 +690,7 @@ def get_interfaces(self): match_mac = re.match(mac_regex, interface_output, flags=re.DOTALL) group_mac = match_mac.groupdict() mac_address = group_mac["mac_address"] - interface_list[interface]['mac_address'] = unicode(mac_address) + interface_list[interface]['mac_address'] = py23_compat.text_type(mac_address) except AttributeError: interface_list[interface]['mac_address'] = u'N/A' try: @@ -901,7 +903,7 @@ def get_bgp_neighbors(self): router_id = match.group(1) local_as = int(match.group(2)) break - bgp_neighbor_data['global']['router_id'] = unicode(router_id) + bgp_neighbor_data['global']['router_id'] = py23_compat.text_type(router_id) bgp_neighbor_data['global']['peers'] = {} cmd_neighbor_table = 'show ip bgp summary | begin Neighbor' @@ -944,7 +946,7 @@ def get_bgp_neighbors(self): peer_dict['local_as'] = local_as peer_dict['is_enabled'] = is_enabled peer_dict['is_up'] = is_up - peer_dict['remote_id'] = unicode(remote_rid) + peer_dict['remote_id'] = py23_compat.text_type(remote_rid) cmd_current_prefixes = 'show ip bgp neighbors {} | inc Prefixes Current'.format(peer_id) # output: Prefixes Current: 0 0 @@ -1223,12 +1225,12 @@ def get_ntp_stats(self): address_regex = re.match('(\W*)([0-9.*]*)', address) try: ntp_stats.append({ - 'remote': unicode(address_regex.group(2)), + 'remote': py23_compat.text_type(address_regex.group(2)), 'synchronized': ('*' in address_regex.group(1)), - 'referenceid': unicode(ref_clock), + 'referenceid': py23_compat.text_type(ref_clock), 'stratum': int(st), 'type': u'-', - 'when': unicode(when), + 'when': py23_compat.text_type(when), 'hostpoll': int(poll), 'reachability': int(reach), 'delay': float(delay), @@ -1404,8 +1406,8 @@ def ping(self, destination, source='', ttl=255, timeout=2, size=100, count=5): }) results_array = [] for i in range(probes_received): - results_array.append({'ip_address': unicode(destination), 'rtt': 0.0}) - + results_array.append({'ip_address': py23_compat.text_type(destination), + 'rtt': 0.0}) ping_dict['success'].update({'results': results_array}) return ping_dict diff --git a/test/unit/TestIOSDriver.py b/test/unit/TestIOSDriver.py index 6a270ba..e9f326a 100644 --- a/test/unit/TestIOSDriver.py +++ b/test/unit/TestIOSDriver.py @@ -16,6 +16,7 @@ import unittest from napalm_ios import ios +from napalm_base.utils import py23_compat from napalm_base.test.base import TestConfigNetworkDriver, TestGettersNetworkDriver import re @@ -176,7 +177,7 @@ def send_command_expect(self, command): """Fake execute a command in the device by just returning the content of a file.""" cmd = re.sub(r'[\[\]\*\^\+\s\|]', '_', command) output = self.read_txt_file('ios/mock_data/{}.txt'.format(cmd)) - return unicode(output) + return py23_compat.text_type(output) def send_command(self, command): """Fake execute a command in the device by just returning the content of a file.""" From c4277d0514a086d4bd77173cb22e6061b8271b49 Mon Sep 17 00:00:00 2001 From: Kirk Byers Date: Sun, 13 Nov 2016 09:43:30 -0800 Subject: [PATCH 4/8] Fixing issue with dictionary keys being removed while iterating over dict --- napalm_ios/ios.py | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) diff --git a/napalm_ios/ios.py b/napalm_ios/ios.py index 916b482..c70b808 100644 --- a/napalm_ios/ios.py +++ b/napalm_ios/ios.py @@ -807,11 +807,11 @@ def get_interfaces_ip(self): raise ValueError(u"Unexpected Response from the device") # remove keys with no data - for key in interfaces.keys(): - if not bool(interfaces[key]): - del interfaces[key] - - return interfaces + new_interfaces = {} + for k, v in interfaces.items(): + if bool(interfaces[k]): + new_interfaces[k] = v + return new_interfaces @staticmethod def bgp_time_conversion(bgp_uptime): From 20ba0c416cef70d79f687c537d0a279b4f6fecc2 Mon Sep 17 00:00:00 2001 From: Kirk Byers Date: Sun, 13 Nov 2016 10:27:14 -0800 Subject: [PATCH 5/8] Roll version; change author to me --- setup.py | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/setup.py b/setup.py index 0840267..716be0a 100644 --- a/setup.py +++ b/setup.py @@ -4,17 +4,17 @@ from setuptools import setup, find_packages from pip.req import parse_requirements -__author__ = 'David Barroso ' +__author__ = 'Kirk Byers ' install_reqs = parse_requirements('requirements.txt', session=uuid.uuid1()) reqs = [str(ir.req) for ir in install_reqs] setup( name="napalm-ios", - version="0.3.1", + version="0.4.0", packages=find_packages(), - author="David Barroso", - author_email="dbarrosop@dravetech.com", + author="Kirk Byers", + author_email="ktbyers@twb-tech.com", description="Network Automation and Programmability Abstraction Layer with Multivendor support", classifiers=[ 'Topic :: Utilities', From e55e6bd5ed4e1900cbfca5e887048464bccb9318 Mon Sep 17 00:00:00 2001 From: Kirk Byers Date: Sun, 13 Nov 2016 10:28:02 -0800 Subject: [PATCH 6/8] Add py3 to travis test --- .travis.yml | 2 ++ 1 file changed, 2 insertions(+) diff --git a/.travis.yml b/.travis.yml index bd77900..32d0ab4 100644 --- a/.travis.yml +++ b/.travis.yml @@ -1,6 +1,8 @@ language: python python: - 2.7 +- 3.4 +- 3.5 install: - pip install -r requirements-dev.txt - pip install . From 3d7c710d55facc5269a9fea215d94f30252d0c02 Mon Sep 17 00:00:00 2001 From: Kirk Byers Date: Sun, 13 Nov 2016 10:33:27 -0800 Subject: [PATCH 7/8] Fixing iteritems issue in tests --- test/unit/TestIOSDriver.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/test/unit/TestIOSDriver.py b/test/unit/TestIOSDriver.py index e9f326a..d95898c 100644 --- a/test/unit/TestIOSDriver.py +++ b/test/unit/TestIOSDriver.py @@ -160,7 +160,7 @@ def test_ios_only_bgp_time_conversion(self): "never": -1, } - for bgp_time, result in test_cases.iteritems(): + for bgp_time, result in test_cases.items(): self.assertEqual(self.device.bgp_time_conversion(bgp_time), result) From 37581e080d2f215909800c106b33b97d812864d1 Mon Sep 17 00:00:00 2001 From: Kirk Byers Date: Sun, 13 Nov 2016 10:35:26 -0800 Subject: [PATCH 8/8] Better solution for deleting interfaces with no data --- napalm_ios/ios.py | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/napalm_ios/ios.py b/napalm_ios/ios.py index c70b808..bc97484 100644 --- a/napalm_ios/ios.py +++ b/napalm_ios/ios.py @@ -808,9 +808,9 @@ def get_interfaces_ip(self): # remove keys with no data new_interfaces = {} - for k, v in interfaces.items(): - if bool(interfaces[k]): - new_interfaces[k] = v + for k, val in interfaces.items(): + if val: + new_interfaces[k] = val return new_interfaces @staticmethod