Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Release 0.0.6 #113

Merged
merged 33 commits into from
Jan 24, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
33 commits
Select commit Hold shift + click to select a range
43467af
Merge pull request #83 from networktocode/main
chadell Sep 1, 2022
e9676bc
Update readme to start with use cases (#84)
itdependsnetworks Sep 22, 2022
0510ebb
Doc update (#87)
itdependsnetworks Sep 23, 2022
7d47d7c
Fix operator checks to follow other check_type logic. (#85)
pszulczewski Sep 23, 2022
afa094d
Implement `ge` and `le` operator type (#89)
lvrfrc87 Sep 27, 2022
21428e8
Fix parameter_match check, to support non-normalized data (#90)
pszulczewski Nov 15, 2022
4a423a7
Update mypy
Apr 11, 2023
c759c33
Bugfix to data normalization
pszulczewski Apr 13, 2023
d30d359
Merge pull request #96 from networktocode/bugfix
pszulczewski Apr 18, 2023
05faf70
Fix ref_key parsing
pszulczewski Apr 18, 2023
b969d0f
Update docs
pszulczewski Apr 18, 2023
e8280c7
Merge pull request #97 from networktocode/fix_ref_key
pszulczewski Apr 19, 2023
b1af665
Issue 92 (#98)
pszulczewski Apr 20, 2023
3f52fd2
Bump certifi from 2022.9.24 to 2022.12.7 (#95)
dependabot[bot] Apr 20, 2023
b5b1daf
Merge branch 'main' into develop
lvrfrc87 Apr 20, 2023
4c981c3
Update version and changelog
lvrfrc87 Apr 20, 2023
7fbefb1
update poetry lock
lvrfrc87 Apr 20, 2023
2ef92b1
Update changelog
lvrfrc87 Apr 20, 2023
f18a9c3
Issue 94 & 91 (#100)
pszulczewski Apr 20, 2023
e09a2ab
Relax deepdiff dependency.
Kircheneer May 12, 2023
b11f4cd
Update pyproject.toml
Kircheneer May 12, 2023
a1ff40c
Update poetry.lock
Kircheneer May 12, 2023
82ba480
Merge pull request #101 from Kircheneer/lk-relax-deepdiff-dependency
pszulczewski May 12, 2023
9081e12
Relase v0.0.4
pszulczewski May 12, 2023
a2844f1
Merge pull request #103 from networktocode/release-0.0.4
pszulczewski May 12, 2023
3b1b3c1
Release v0.0.4 (#105)
pszulczewski May 12, 2023
1540227
Merge branch 'test-main' into develop
pszulczewski May 12, 2023
c3761d9
Bump up jamespath, remove py3.7 (#110)
pszulczewski Nov 17, 2023
a4da579
Add ordering after data normalization.
pszulczewski Jan 22, 2024
d332aee
Update outdated dependencies.
pszulczewski Jan 24, 2024
821760d
Merge pull request #112 from networktocode/add_sorting
pszulczewski Jan 24, 2024
5bad286
Merge remote-tracking branch 'origin/develop' into release-0.0.6
pszulczewski Jan 24, 2024
d1e9dee
Release 0.0.6
pszulczewski Jan 24, 2024
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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}"
Loading