Skip to content

Commit

Permalink
Release 0.0.6 (#113)
Browse files Browse the repository at this point in the history
* Release 0.0.6

---------

Signed-off-by: dependabot[bot] <[email protected]>
Co-authored-by: Patryk Szulczewski <[email protected]>
  • Loading branch information
pszulczewski and Patryk Szulczewski authored Jan 24, 2024
1 parent af07aa7 commit 59488b7
Show file tree
Hide file tree
Showing 7 changed files with 221 additions and 230 deletions.
3 changes: 3 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,8 @@
# Changelog

## v0.0.6
- Sort the data when data normalization is used with key anchoring

## v0.0.5
- Update jmespath dependency
- Drop python 3.7 support
Expand Down
4 changes: 3 additions & 1 deletion jdiff/extract_data.py
Original file line number Diff line number Diff line change
Expand Up @@ -87,6 +87,8 @@ def extract_data_from_json(data: Union[Mapping, List], path: str = "*", exclude:
else:
raise ValueError("Reference Key normalization failure. Please verify data type returned.")

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

return values
366 changes: 163 additions & 203 deletions poetry.lock

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion pyproject.toml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
[tool.poetry]
name = "jdiff"
version = "0.0.5"
version = "0.0.6"
description = "A light-weight library to compare structured output from network devices show commands."
authors = ["Network to Code, LLC <[email protected]>"]
license = "Apache-2.0"
Expand Down
20 changes: 10 additions & 10 deletions tests/mock/napalm_get_lldp_neighbors/pre.json
Original file line number Diff line number Diff line change
@@ -1,24 +1,24 @@
{
"Ethernet2": [
"Ethernet1": [
{
"hostname": "junos-unittest",
"port": "520"
"port": "519"
},
{
"hostname": "ios-xrv-unittest",
"port": "Gi0/0/0/0"
}
],
"Ethernet3": [
"Ethernet2": [
{
"hostname": "junos-unittest",
"port": "522"
"port": "520"
}
],
"Ethernet1": [
"Ethernet3": [
{
"hostname": "junos-unittest",
"port": "519"
},
{
"hostname": "ios-xrv-unittest",
"port": "Gi0/0/0/0"
"port": "522"
}
],
"Management1": [
Expand Down
26 changes: 13 additions & 13 deletions tests/test_operators.py
Original file line number Diff line number Diff line change
Expand Up @@ -10,13 +10,6 @@
"result[0].vrfs.default.peerList[*].[$peerAddress$,peerGroup,vrf,state]",
(
[
{
"7.7.7.7": {
"peerGroup": "EVPN-OVERLAY-SPINE",
"state": "Idle",
"vrf": "default",
}
},
{
"10.1.0.0": {
"peerGroup": "IPv4-UNDERLAY-SPINE",
Expand All @@ -38,6 +31,13 @@
"vrf": "default",
}
},
{
"7.7.7.7": {
"peerGroup": "EVPN-OVERLAY-SPINE",
"state": "Idle",
"vrf": "default",
}
},
],
False,
),
Expand Down Expand Up @@ -124,10 +124,10 @@
"result[0].vrfs.default.peerList[*].[$peerAddress$,prefixesSent]",
(
[
{"7.7.7.7": {"prefixesSent": 50}},
{"10.1.0.0": {"prefixesSent": 50}},
{"10.2.0.0": {"prefixesSent": 50}},
{"10.64.207.255": {"prefixesSent": 50}},
{"7.7.7.7": {"prefixesSent": 50}},
],
False,
),
Expand All @@ -146,10 +146,10 @@
"result[0].vrfs.default.peerList[*].[$peerAddress$,prefixesSent]",
(
[
{"7.7.7.7": {"prefixesSent": 50}},
{"10.1.0.0": {"prefixesSent": 50}},
{"10.2.0.0": {"prefixesSent": 50}},
{"10.64.207.255": {"prefixesSent": 50}},
{"7.7.7.7": {"prefixesSent": 50}},
],
False,
),
Expand Down Expand Up @@ -191,22 +191,22 @@ def test_operator(filename, check_type_str, evaluate_args, path, expected_result
[
(
[
{"7.7.7.7": {"peerGroup": "EVPN-OVERLAY-SPINE", "vrf": "default", "state": "Connected"}},
{"10.1.0.0": {"peerGroup": "EVPN-OVERLAY-SPINE", "vrf": "default", "state": "Connected"}},
{"7.7.7.7": {"peerGroup": "EVPN-OVERLAY-SPINE", "vrf": "default", "state": "Connected"}},
],
True,
([], True),
),
(
[
{"7.7.7.7": {"peerGroup": "EVPN-OVERLAY-SPINE", "vrf": "default", "state": "Connected"}},
{"10.1.0.0": {"peerGroup": "IPv4-UNDERLAY-SPINE", "vrf": "default", "state": "Connected"}},
{"7.7.7.7": {"peerGroup": "EVPN-OVERLAY-SPINE", "vrf": "default", "state": "Connected"}},
],
True,
(
[
{"7.7.7.7": {"peerGroup": "EVPN-OVERLAY-SPINE", "vrf": "default", "state": "Connected"}},
{"10.1.0.0": {"peerGroup": "IPv4-UNDERLAY-SPINE", "vrf": "default", "state": "Connected"}},
{"7.7.7.7": {"peerGroup": "EVPN-OVERLAY-SPINE", "vrf": "default", "state": "Connected"}},
],
False,
),
Expand All @@ -227,8 +227,8 @@ def test_operator(filename, check_type_str, evaluate_args, path, expected_result
),
(
[
{"7.7.7.7": {"peerGroup": "EVPN-OVERLAY-SPINE", "vrf": "default", "state": "Connected"}},
{"10.1.0.0": {"peerGroup": "IPv4-UNDERLAY-SPINE", "vrf": "default", "state": "Connected"}},
{"7.7.7.7": {"peerGroup": "EVPN-OVERLAY-SPINE", "vrf": "default", "state": "Connected"}},
],
False,
([], True),
Expand Down
30 changes: 28 additions & 2 deletions tests/test_sw_upgrade_device_state.py
Original file line number Diff line number Diff line change
Expand Up @@ -192,10 +192,36 @@ def test_lldp_neighbor_state(platform, command, check_should_pass):
"""Test LLDP neighbors with exact match."""
command_pre = load_json_file("sw_upgrade", f"{platform}_{command}.json")
command_post = deepcopy(command_pre)
jpath = "[*].[neighbor,capabilities,$local_interface$,neighbor_interface]"
command_pre_normalized = extract_data_from_json(command_pre, jpath)
command_post_normalized = extract_data_from_json(command_post, jpath)

if check_should_pass is False:
command_post = command_post[:2]
command_post_normalized = command_post_normalized[:2]

check = CheckType.create("exact_match")
eval_results, passed = check.evaluate(command_post, command_pre)
eval_results, passed = check.evaluate(command_pre_normalized, command_post_normalized)
assert passed is check_should_pass, f"FAILED, eval_result: {eval_results}"


@pytest.mark.parametrize(
"platform, command",
[
("arista_eos", "show_lldp_neighbors"),
("cisco_ios", "show_lldp_neighbors"),
("cisco_nxos", "show_lldp_neighbors"),
],
)
def test_lldp_neighbor_state_changed_order(platform, command):
"""Test LLDP neighbors with exact match, when post-check is in reversed order."""
command_pre = load_json_file("sw_upgrade", f"{platform}_{command}.json")
command_post = deepcopy(command_pre)
command_post.reverse() # reverse data for the test

jpath = "[*].[neighbor,capabilities,$local_interface$,neighbor_interface]"
command_pre_normalized = extract_data_from_json(command_pre, jpath)
command_post_normalized = extract_data_from_json(command_post, jpath)

check = CheckType.create("exact_match")
eval_results, passed = check.evaluate(command_pre_normalized, command_post_normalized)
assert passed is True, f"FAILED, eval_result: {eval_results}"

0 comments on commit 59488b7

Please sign in to comment.