Skip to content

Commit 59488b7

Browse files
pszulczewskiPatryk Szulczewski
and
Patryk Szulczewski
authored
Release 0.0.6 (#113)
* Release 0.0.6 --------- Signed-off-by: dependabot[bot] <[email protected]> Co-authored-by: Patryk Szulczewski <[email protected]>
1 parent af07aa7 commit 59488b7

File tree

7 files changed

+221
-230
lines changed

7 files changed

+221
-230
lines changed

CHANGELOG.md

+3
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,8 @@
11
# Changelog
22

3+
## v0.0.6
4+
- Sort the data when data normalization is used with key anchoring
5+
36
## v0.0.5
47
- Update jmespath dependency
58
- Drop python 3.7 support

jdiff/extract_data.py

+3-1
Original file line numberDiff line numberDiff line change
@@ -87,6 +87,8 @@ def extract_data_from_json(data: Union[Mapping, List], path: str = "*", exclude:
8787
else:
8888
raise ValueError("Reference Key normalization failure. Please verify data type returned.")
8989

90-
return keys_values_zipper(list_of_reference_keys, paired_key_value)
90+
normalized = keys_values_zipper(list_of_reference_keys, paired_key_value)
91+
# Data between pre and post may come in different order, so it needs to be sorted.
92+
return sorted(normalized, key=lambda arg: list(arg.keys()))
9193

9294
return values

poetry.lock

+163-203
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

pyproject.toml

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
[tool.poetry]
22
name = "jdiff"
3-
version = "0.0.5"
3+
version = "0.0.6"
44
description = "A light-weight library to compare structured output from network devices show commands."
55
authors = ["Network to Code, LLC <[email protected]>"]
66
license = "Apache-2.0"

tests/mock/napalm_get_lldp_neighbors/pre.json

+10-10
Original file line numberDiff line numberDiff line change
@@ -1,24 +1,24 @@
11
{
2-
"Ethernet2": [
2+
"Ethernet1": [
33
{
44
"hostname": "junos-unittest",
5-
"port": "520"
5+
"port": "519"
6+
},
7+
{
8+
"hostname": "ios-xrv-unittest",
9+
"port": "Gi0/0/0/0"
610
}
711
],
8-
"Ethernet3": [
12+
"Ethernet2": [
913
{
1014
"hostname": "junos-unittest",
11-
"port": "522"
15+
"port": "520"
1216
}
1317
],
14-
"Ethernet1": [
18+
"Ethernet3": [
1519
{
1620
"hostname": "junos-unittest",
17-
"port": "519"
18-
},
19-
{
20-
"hostname": "ios-xrv-unittest",
21-
"port": "Gi0/0/0/0"
21+
"port": "522"
2222
}
2323
],
2424
"Management1": [

tests/test_operators.py

+13-13
Original file line numberDiff line numberDiff line change
@@ -10,13 +10,6 @@
1010
"result[0].vrfs.default.peerList[*].[$peerAddress$,peerGroup,vrf,state]",
1111
(
1212
[
13-
{
14-
"7.7.7.7": {
15-
"peerGroup": "EVPN-OVERLAY-SPINE",
16-
"state": "Idle",
17-
"vrf": "default",
18-
}
19-
},
2013
{
2114
"10.1.0.0": {
2215
"peerGroup": "IPv4-UNDERLAY-SPINE",
@@ -38,6 +31,13 @@
3831
"vrf": "default",
3932
}
4033
},
34+
{
35+
"7.7.7.7": {
36+
"peerGroup": "EVPN-OVERLAY-SPINE",
37+
"state": "Idle",
38+
"vrf": "default",
39+
}
40+
},
4141
],
4242
False,
4343
),
@@ -124,10 +124,10 @@
124124
"result[0].vrfs.default.peerList[*].[$peerAddress$,prefixesSent]",
125125
(
126126
[
127-
{"7.7.7.7": {"prefixesSent": 50}},
128127
{"10.1.0.0": {"prefixesSent": 50}},
129128
{"10.2.0.0": {"prefixesSent": 50}},
130129
{"10.64.207.255": {"prefixesSent": 50}},
130+
{"7.7.7.7": {"prefixesSent": 50}},
131131
],
132132
False,
133133
),
@@ -146,10 +146,10 @@
146146
"result[0].vrfs.default.peerList[*].[$peerAddress$,prefixesSent]",
147147
(
148148
[
149-
{"7.7.7.7": {"prefixesSent": 50}},
150149
{"10.1.0.0": {"prefixesSent": 50}},
151150
{"10.2.0.0": {"prefixesSent": 50}},
152151
{"10.64.207.255": {"prefixesSent": 50}},
152+
{"7.7.7.7": {"prefixesSent": 50}},
153153
],
154154
False,
155155
),
@@ -191,22 +191,22 @@ def test_operator(filename, check_type_str, evaluate_args, path, expected_result
191191
[
192192
(
193193
[
194-
{"7.7.7.7": {"peerGroup": "EVPN-OVERLAY-SPINE", "vrf": "default", "state": "Connected"}},
195194
{"10.1.0.0": {"peerGroup": "EVPN-OVERLAY-SPINE", "vrf": "default", "state": "Connected"}},
195+
{"7.7.7.7": {"peerGroup": "EVPN-OVERLAY-SPINE", "vrf": "default", "state": "Connected"}},
196196
],
197197
True,
198198
([], True),
199199
),
200200
(
201201
[
202-
{"7.7.7.7": {"peerGroup": "EVPN-OVERLAY-SPINE", "vrf": "default", "state": "Connected"}},
203202
{"10.1.0.0": {"peerGroup": "IPv4-UNDERLAY-SPINE", "vrf": "default", "state": "Connected"}},
203+
{"7.7.7.7": {"peerGroup": "EVPN-OVERLAY-SPINE", "vrf": "default", "state": "Connected"}},
204204
],
205205
True,
206206
(
207207
[
208-
{"7.7.7.7": {"peerGroup": "EVPN-OVERLAY-SPINE", "vrf": "default", "state": "Connected"}},
209208
{"10.1.0.0": {"peerGroup": "IPv4-UNDERLAY-SPINE", "vrf": "default", "state": "Connected"}},
209+
{"7.7.7.7": {"peerGroup": "EVPN-OVERLAY-SPINE", "vrf": "default", "state": "Connected"}},
210210
],
211211
False,
212212
),
@@ -227,8 +227,8 @@ def test_operator(filename, check_type_str, evaluate_args, path, expected_result
227227
),
228228
(
229229
[
230-
{"7.7.7.7": {"peerGroup": "EVPN-OVERLAY-SPINE", "vrf": "default", "state": "Connected"}},
231230
{"10.1.0.0": {"peerGroup": "IPv4-UNDERLAY-SPINE", "vrf": "default", "state": "Connected"}},
231+
{"7.7.7.7": {"peerGroup": "EVPN-OVERLAY-SPINE", "vrf": "default", "state": "Connected"}},
232232
],
233233
False,
234234
([], True),

tests/test_sw_upgrade_device_state.py

+28-2
Original file line numberDiff line numberDiff line change
@@ -192,10 +192,36 @@ def test_lldp_neighbor_state(platform, command, check_should_pass):
192192
"""Test LLDP neighbors with exact match."""
193193
command_pre = load_json_file("sw_upgrade", f"{platform}_{command}.json")
194194
command_post = deepcopy(command_pre)
195+
jpath = "[*].[neighbor,capabilities,$local_interface$,neighbor_interface]"
196+
command_pre_normalized = extract_data_from_json(command_pre, jpath)
197+
command_post_normalized = extract_data_from_json(command_post, jpath)
195198

196199
if check_should_pass is False:
197-
command_post = command_post[:2]
200+
command_post_normalized = command_post_normalized[:2]
198201

199202
check = CheckType.create("exact_match")
200-
eval_results, passed = check.evaluate(command_post, command_pre)
203+
eval_results, passed = check.evaluate(command_pre_normalized, command_post_normalized)
201204
assert passed is check_should_pass, f"FAILED, eval_result: {eval_results}"
205+
206+
207+
@pytest.mark.parametrize(
208+
"platform, command",
209+
[
210+
("arista_eos", "show_lldp_neighbors"),
211+
("cisco_ios", "show_lldp_neighbors"),
212+
("cisco_nxos", "show_lldp_neighbors"),
213+
],
214+
)
215+
def test_lldp_neighbor_state_changed_order(platform, command):
216+
"""Test LLDP neighbors with exact match, when post-check is in reversed order."""
217+
command_pre = load_json_file("sw_upgrade", f"{platform}_{command}.json")
218+
command_post = deepcopy(command_pre)
219+
command_post.reverse() # reverse data for the test
220+
221+
jpath = "[*].[neighbor,capabilities,$local_interface$,neighbor_interface]"
222+
command_pre_normalized = extract_data_from_json(command_pre, jpath)
223+
command_post_normalized = extract_data_from_json(command_post, jpath)
224+
225+
check = CheckType.create("exact_match")
226+
eval_results, passed = check.evaluate(command_pre_normalized, command_post_normalized)
227+
assert passed is True, f"FAILED, eval_result: {eval_results}"

0 commit comments

Comments
 (0)