Skip to content
This repository has been archived by the owner on Sep 17, 2019. It is now read-only.

Commit

Permalink
Merge pull request #224 from napalm-automation/develop
Browse files Browse the repository at this point in the history
Release 0.23.1
  • Loading branch information
mirceaulinic authored Mar 17, 2017
2 parents 0d769be + 8505e67 commit c8f078c
Show file tree
Hide file tree
Showing 13 changed files with 273 additions and 205 deletions.
8 changes: 8 additions & 0 deletions napalm_base/base.py
Original file line number Diff line number Diff line change
Expand Up @@ -59,6 +59,14 @@ def __exit__(self, exc_type, exc_value, exc_traceback):
if exc_type is not None:
self.__raise_clean_exception(exc_type, exc_value, exc_traceback)

def __del__(self):
"""
This method is used to cleanup when the program is terminated suddenly.
We need to make sure the connection is closed properly and the configuration DB
is released (unlocked).
"""
self.close()

@staticmethod
def __raise_clean_exception(exc_type, exc_value, exc_traceback):
"""
Expand Down
41 changes: 28 additions & 13 deletions napalm_base/validate.py
Original file line number Diff line number Diff line change
Expand Up @@ -123,27 +123,42 @@ def _compare_getter(src, dst):
if isinstance(src, py23_compat.string_types):
m = re.search(src, py23_compat.text_type(dst))
return m is not None
elif(type(src) == type(dst) == list):
pairs = zip(src, dst)
diff_lists = [[(k, x[k], y[k])
for k in x if not re.search(x[k], y[k])]
for x, y in pairs if x != y]
return empty_tree(diff_lists)
else:
return src == dst


def empty_tree(input_list):
"""Recursively iterate through values in nested lists."""
for item in input_list:
if not isinstance(item, list) or not empty_tree(item):
return False
return True


def compliance_report(cls, validation_file=None):
report = {}
validation_source = _get_validation_file(validation_file)

for getter, expected_results in validation_source.items():
if getter == "get_config":
# TBD
pass
else:
key = expected_results.pop("_name", "") or getter

try:
kwargs = expected_results.pop('_kwargs', {})
actual_results = getattr(cls, getter)(**kwargs)
report[key] = _compare_getter(expected_results, actual_results)
except NotImplementedError:
report[key] = {"skipped": True, "reason": "NotImplemented"}
for validation_check in validation_source:
for getter, expected_results in validation_check.items():
if getter == "get_config":
# TBD
pass
else:
key = expected_results.pop("_name", "") or getter

try:
kwargs = expected_results.pop('_kwargs', {})
actual_results = getattr(cls, getter)(**kwargs)
report[key] = _compare_getter(expected_results, actual_results)
except NotImplementedError:
report[key] = {"skipped": True, "reason": "NotImplemented"}

complies = all([e.get("complies", True) for e in report.values()])
report["skipped"] = [k for k, v in report.items() if v.get("skipped", False)]
Expand Down
2 changes: 1 addition & 1 deletion setup.py
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@

setup(
name="napalm-base",
version='0.23.0',
version='0.23.1',
packages=find_packages(),
author="David Barroso",
author_email="[email protected]",
Expand Down
2 changes: 1 addition & 1 deletion test/unit/TestGetNetworkDriver.py
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ class TestGetNetworkDriver(unittest.TestCase):

drivers_common = ('eos', 'ios', 'iosxr', 'IOS-XR', 'junos', 'ros', 'nxos',
'pluribus', 'panos', 'vyos')
drivers_py2_only = ('fortios', 'ibm')
drivers_py2_only = ('fortios', )
if PY2:
# All drivers support python2
network_drivers = drivers_common + drivers_py2_only
Expand Down
1 change: 0 additions & 1 deletion test/unit/requirements.txt
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
ddt
napalm-eos
napalm-fortios
napalm-ibm
napalm-ios
napalm-iosxr
napalm-junos
Expand Down
70 changes: 35 additions & 35 deletions test/unit/validate/mocked_data/non_strict_fail/validate.yml
Original file line number Diff line number Diff line change
@@ -1,39 +1,39 @@
---
get_facts:
os_version: 7.0\(3\)I2\(2d\)
interface_list:
list:
- Vlan5
- Vlan666
hostname: n9k2
- get_facts:
os_version: 7.0\(3\)I2\(2d\)
interface_list:
list:
- Vlan5
- Vlan666
hostname: n9k2

get_bgp_neighbors:
default:
router_id: 192.6.6.6
peers:
192.6.7.8:
is_enabled: false
192.0.2.3:
is_enabled: false
192.0.2.2:
is_enabled: true
address_family:
ipv4:
sent_prefixes: 5
ipv6:
sent_prefixes: 6
- get_bgp_neighbors:
default:
router_id: 192.6.6.6
peers:
192.6.7.8:
is_enabled: false
192.0.2.3:
is_enabled: false
192.0.2.2:
is_enabled: true
address_family:
ipv4:
sent_prefixes: 5
ipv6:
sent_prefixes: 6

get_interfaces_ip:
Ethernet2/1:
ipv4:
192.0.2.1:
prefix_length: 30
- get_interfaces_ip:
Ethernet2/1:
ipv4:
192.0.2.1:
prefix_length: 30

get_route_to:
_kwargs:
destination: 185.155.180.192/26
"10.155.180.192/26":
list:
- next_hop: 10.155.180.22
outgoing_interface: "irb.0"
protocol: "OSPF"
- get_route_to:
_kwargs:
destination: 185.155.180.192/26
"10.155.180.192/26":
list:
- next_hop: 10.155.180.22
outgoing_interface: "irb.0"
protocol: "OSPF"
66 changes: 33 additions & 33 deletions test/unit/validate/mocked_data/non_strict_pass/validate.yml
Original file line number Diff line number Diff line change
@@ -1,37 +1,37 @@
---
get_facts:
os_version: 7.0\(3\)I2\(2d\)
interface_list:
list:
- Vlan5
- Vlan100
hostname: n9k2
- get_facts:
os_version: 7.0\(3\)I2\(2d\)
interface_list:
list:
- Vlan5
- Vlan100
hostname: n9k2

get_bgp_neighbors:
default:
router_id: 192.0.2.2
peers:
192.0.2.3:
is_enabled: false
192.0.2.2:
is_enabled: true
address_family:
ipv4:
sent_prefixes: 5
ipv6:
sent_prefixes: 2
- get_bgp_neighbors:
default:
router_id: 192.0.2.2
peers:
192.0.2.3:
is_enabled: false
192.0.2.2:
is_enabled: true
address_family:
ipv4:
sent_prefixes: 5
ipv6:
sent_prefixes: 2

get_interfaces_ip:
Ethernet2/1:
ipv4:
192.0.2.1:
prefix_length: 30
- get_interfaces_ip:
Ethernet2/1:
ipv4:
192.0.2.1:
prefix_length: 30

get_route_to:
_kwargs:
destination: 185.155.180.192/26
"10.155.180.192/26":
list:
- next_hop: 10.155.180.22
outgoing_interface: "irb.0"
protocol: "BGP"
- get_route_to:
_kwargs:
destination: 185.155.180.192/26
"10.155.180.192/26":
list:
- next_hop: 10.155.180.22
outgoing_interface: "irb.0"
protocol: "BGP"
82 changes: 41 additions & 41 deletions test/unit/validate/mocked_data/strict_fail/validate.yml
Original file line number Diff line number Diff line change
@@ -1,46 +1,46 @@
---
get_facts:
os_version: 7.0\(3\)I2\(2d\)
interface_list:
_mode: strict
list:
- Vlan5
- Vlan100
hostname: n9k2
- get_facts:
os_version: 7.0\(3\)I2\(2d\)
interface_list:
_mode: strict
list:
- Vlan5
- Vlan100
hostname: n9k2

get_bgp_neighbors:
default:
router_id: 192.0.2.2
peers:
_mode: strict
192.0.2.2:
is_enabled: true
address_family:
ipv4:
sent_prefixes: ^[1-9]
ipv6:
sent_prefixes: ^[1-9]
- get_bgp_neighbors:
default:
router_id: 192.0.2.2
peers:
_mode: strict
192.0.2.2:
is_enabled: true
address_family:
ipv4:
sent_prefixes: ^[1-9]
ipv6:
sent_prefixes: ^[1-9]

get_route_to:
_kwargs:
destination: 185.155.180.192/26
"10.155.180.192/26":
list:
- next_hop: 10.155.180.22
outgoing_interface: "irb.0"
protocol: "BGP"
_mode: strict
- get_route_to:
_kwargs:
destination: 185.155.180.192/26
"10.155.180.192/26":
list:
- next_hop: 10.155.180.22
outgoing_interface: "irb.0"
protocol: "BGP"
_mode: strict

get_interfaces_ip:
Ethernet2/1:
ipv4:
192.0.2.1:
prefix_length: 30
- get_interfaces_ip:
Ethernet2/1:
ipv4:
192.0.2.1:
prefix_length: 30

ping:
_kwargs:
destination: 8.8.8.8
source: 192.168.1.1
success:
packet_loss: 0
_mode: strict
- ping:
_kwargs:
destination: 8.8.8.8
source: 192.168.1.1
success:
packet_loss: 0
_mode: strict
10 changes: 10 additions & 0 deletions test/unit/validate/mocked_data/strict_pass/get_lldp_neighbors.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
{
"ge-1/0/2": [{
"hostname": "fw1b.private.lon2",
"port": "ethernet1/13"
}],
"ge-1/0/3": [{
"hostname": "border2.private.lon2",
"port": "519"
}]
}
16 changes: 15 additions & 1 deletion test/unit/validate/mocked_data/strict_pass/report.yml
Original file line number Diff line number Diff line change
Expand Up @@ -27,9 +27,23 @@ get_interfaces_ip:
missing: []
present:
Ethernet2/1: {complies: true, nested: true}
ping:
ping1:
complies: true
extra: []
missing: []
present:
success: {complies: true, nested: true}
ping2:
complies: true
extra: []
missing: []
present:
success: {complies: true, nested: true}

get_lldp_neighbors:
complies: true
extra: []
missing: []
present:
ge-1/0/2: {complies: true, nested: false}
ge-1/0/3: {complies: true, nested: False}
Loading

0 comments on commit c8f078c

Please sign in to comment.