Skip to content

Commit fa28727

Browse files
pszulczewskiPatryk Szulczewski
andauthored
Tests for sw upgrade testing (#37)
* Tests for sw upgrade testing * Fix diff_helpers.py for flat data structures. * Remove xfail from tests passing after fix. * Add bgp prefix tolerance test + improve tolerance check * Update tests * Post-review updates. * Extend sw_upgrade tests with cisco_nxos platform. Co-authored-by: Patryk Szulczewski <[email protected]>
1 parent c00c6f3 commit fa28727

23 files changed

+3653
-3
lines changed

netcompare/check_types.py

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -149,9 +149,17 @@ def evaluate(self, value_to_compare: Any, reference_data: Any, tolerance: int) -
149149
def _remove_within_tolerance(self, diff: Dict, tolerance: int) -> None:
150150
"""Recursively look into diff and apply tolerance check, remove reported difference when within tolerance."""
151151

152-
def _within_tolerance(*, old_value: float, new_value: float) -> bool:
152+
def _make_float(value):
153+
"""Make float, treat non-convertable as 0."""
154+
try:
155+
return float(value)
156+
except ValueError:
157+
return 0
158+
159+
def _within_tolerance(*, old_value: Union[str, int, float], new_value: Union[str, int, float]) -> bool:
153160
"""Return True if new value is within the tolerance range of the previous value."""
154161
tolerance_factor = tolerance / 100
162+
old_value, new_value = _make_float(old_value), _make_float(new_value)
155163
max_diff = old_value * tolerance_factor
156164
return (old_value - max_diff) < new_value < (old_value + max_diff)
157165

netcompare/utils/diff_helpers.py

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -29,13 +29,17 @@ def get_diff_iterables_items(diff_result: Mapping) -> Dict:
2929
items_removed = diff_result.get("iterable_item_removed")
3030
if items_removed:
3131
for key, value in items_removed.items():
32-
key, *_ = get_dict_keys.match(key).groups()
32+
re_key = get_dict_keys.match(key)
33+
if re_key: # Change only if there is a match, otherwise retain the key.
34+
key, *_ = re_key.groups()
3335
result[key]["missing"].append(value)
3436

3537
items_added = diff_result.get("iterable_item_added")
3638
if items_added:
3739
for key, value in items_added.items():
38-
key, *_ = get_dict_keys.match(key).groups()
40+
re_key = get_dict_keys.match(key)
41+
if re_key:
42+
key, *_ = re_key.groups()
3943
result[key]["new"].append(value)
4044

4145
return result
@@ -58,6 +62,8 @@ def fix_deepdiff_key_names(obj: Mapping) -> Dict:
5862
result = {}
5963
for key, value in obj.items():
6064
key_parts = re.findall(REGEX_PATTERN_RELEVANT_KEYS, key)
65+
if not key_parts: # If key parts can't be find, keep original key so data is not lost.
66+
key_parts = [key.replace("root", "index_element")] # replace root from DeepDiff with more meaningful name.
6167
partial_res = group_value(key_parts, value)
6268
dict_merger(result, partial_res)
6369
return result
Lines changed: 72 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,72 @@
1+
[
2+
{
3+
"interface": "Ethernet1",
4+
"link_status": "up",
5+
"protocol_status": "up (connected)",
6+
"hardware_type": "Ethernet",
7+
"address": "0800.27dc.5443",
8+
"bia": "",
9+
"description": "",
10+
"ip_address": "172.16.1.1/24",
11+
"mtu": "1500",
12+
"bandwidth": "10000000 kbit",
13+
"interface_up_time": "14 minutes, 2 seconds",
14+
"link_status_change": "1"
15+
},
16+
{
17+
"interface": "Ethernet49/1",
18+
"link_status": "administratively down",
19+
"protocol_status": "notpresent (disabled)",
20+
"hardware_type": "Ethernet",
21+
"address": "fcbd.67e2.b922",
22+
"bia": "fcbd.67e2.b922",
23+
"description": "Connects to Ethernet1 on localhost",
24+
"ip_address": "172.16.2.1/24",
25+
"mtu": "9214",
26+
"bandwidth": "100000000 kbit",
27+
"interface_up_time": "6 days, 11 hours, 16 minutes, 54 seconds",
28+
"link_status_change": "1"
29+
},
30+
{
31+
"interface": "Loopback0",
32+
"link_status": "up",
33+
"protocol_status": "up (connected)",
34+
"hardware_type": "Loopback",
35+
"address": "",
36+
"bia": "",
37+
"description": "",
38+
"ip_address": "1.1.1.1/32",
39+
"mtu": "65535",
40+
"bandwidth": "",
41+
"interface_up_time": "7 seconds",
42+
"link_status_change": ""
43+
},
44+
{
45+
"interface": "Port-Channel1",
46+
"link_status": "down",
47+
"protocol_status": "lowerlayerdown (notconnect)",
48+
"hardware_type": "Port-Channel",
49+
"address": "0000.0000.0000",
50+
"bia": "",
51+
"description": "",
52+
"ip_address": "",
53+
"mtu": "9214",
54+
"bandwidth": "",
55+
"interface_up_time": "10 minutes, 21 seconds",
56+
"link_status_change": "1"
57+
},
58+
{
59+
"interface": "Management1",
60+
"link_status": "up",
61+
"protocol_status": "up (connected)",
62+
"hardware_type": "Ethernet",
63+
"address": "0800.27a5.02b7",
64+
"bia": "0800.27a5.02b7",
65+
"description": "",
66+
"ip_address": "",
67+
"mtu": "1500",
68+
"bandwidth": "1000000 kbit",
69+
"interface_up_time": "14 minutes, 4 seconds",
70+
"link_status_change": "3"
71+
}
72+
]
Lines changed: 47 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,47 @@
1+
[
2+
{
3+
"router_id": "10.0.65.72",
4+
"local_as": "64911",
5+
"vrf": "default",
6+
"bgp_neigh": "10.10.128.0",
7+
"neigh_as": "65292",
8+
"msg_rcvd": "0",
9+
"msg_sent": "0",
10+
"in_queue": "0",
11+
"out_queue": "0",
12+
"up_down": "79d05h",
13+
"state": "Active",
14+
"state_pfxrcd": "",
15+
"state_pfxacc": ""
16+
},
17+
{
18+
"router_id": "10.0.65.72",
19+
"local_as": "64911",
20+
"vrf": "default",
21+
"bgp_neigh": "10.106.0.153",
22+
"neigh_as": "64832",
23+
"msg_rcvd": "0",
24+
"msg_sent": "0",
25+
"in_queue": "0",
26+
"out_queue": "0",
27+
"up_down": "79d05h",
28+
"state": "Idle(NoIf)",
29+
"state_pfxrcd": "",
30+
"state_pfxacc": ""
31+
},
32+
{
33+
"router_id": "10.0.65.72",
34+
"local_as": "64911",
35+
"vrf": "default",
36+
"bgp_neigh": "10.106.0.157",
37+
"neigh_as": "64833",
38+
"msg_rcvd": "114056",
39+
"msg_sent": "118481",
40+
"in_queue": "0",
41+
"out_queue": "0",
42+
"up_down": "79d05h",
43+
"state": "Estab",
44+
"state_pfxrcd": "1",
45+
"state_pfxacc": "1"
46+
}
47+
]
Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
[
2+
{
3+
"address": "10.3.4.3",
4+
"interface": "Ethernet2",
5+
"state": "FULL/BDR",
6+
"neighbor_id": "3.3.3.3",
7+
"vrf": "default",
8+
"priority": "1",
9+
"dead_time": "00:00:34"
10+
},
11+
{
12+
"address": "10.2.4.2",
13+
"interface": "Ethernet3",
14+
"state": "FULL",
15+
"neighbor_id": "2.2.2.2",
16+
"vrf": "default",
17+
"priority": "1",
18+
"dead_time": "00:00:38"
19+
}
20+
]

0 commit comments

Comments
 (0)