You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Copy file name to clipboardExpand all lines: README.md
+78-57Lines changed: 78 additions & 57 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -1,19 +1,39 @@
1
1
# netcompare
2
2
3
-
This library is meant to be a light-weight way to compare structured output from network devices `show` commands. `netcompare` is a python library targeted at intelligently deep diffing structured data objects of json type. In addition, `netcompare` can also provide some basic testing of key/values within a data structure.
3
+
This library is meant to be a light-weight way to compare structured output. `netcompare` is a python library targeted at intelligently deep diffing structured data objects of json type.
4
+
5
+
`netcompare` also provides some basic testing of key/values within data structures.
4
6
5
7
The library heavily relies on [jmespath](https://jmespath.org/) for traversing the json object and finding the value(s) to be evaluated. More on that later.
6
8
9
+
## Use Cases
10
+
11
+
`netcompare` is meant to be a building block used within testing frameworks. Originally devised specifically to test structured data returned from network device show commands, `netcompare` is designed to deeply and intelligently diff data structures while also providing tests for specific values in the data structure. `netcompare` evolved to be agnostic from the collection of that data and can compare and test and type of data structure.
12
+
13
+
With that said, it is perfectly suited to diff data gathered from network devices via show commands, Ansible playbooks, in Django based applications such as Nautobot or Netbox, and is targeted at being the 'plumbing' behind a full network automation validation solution.
14
+
15
+
`netcompare` was developed for checking the state of the network before and after a change; however, `netcompare` is also well suited for comparing intended state derived from a Source-of-Truth or other source of intended state.
16
+
17
+
The intended usage is to collect structured `show` command output before and after a change window. Prior to closing the change window, the results are compared to help determine if the change was successful as intended and if the network is in an acceptable state. The output can be stored with the change's documentation for easy reference and proof of completion.
18
+
19
+
With `netcompare` we've left the collection of the data up to you, to easily fit within your preferred method.
20
+
21
+
### Testing data structures
22
+
23
+
Briefly, these tests are provided to test the objects, to aide in determining the status of the data.
24
+
25
+
-`exact_match`: the keys and values much match between the two objects
26
+
-`tolerance`: the keys must match and the values can differ according to the 'tolerance' value provided
27
+
-`parameter_match`: provide a known good key/value 'parameter' and check for it's presence or absence in the provided objects
28
+
-`regex`: provide a regex and check for the presence or absence of a match in the provided object
29
+
-`operator`: evaluate or compare values with a number of different operators: 'in', 'bool', 'string', and numerical comparison with 'int' and 'float'
7
30
8
-
## Use Case
9
31
10
-
`netcompare` enables an easy and direct way to see the outcome of network configuration or operational status change. The intended usage is to collect structured `show` command output before and after a change window. Prior to closing the change window, the results are compared to help determine if the change was successful as intended and if the network is in an acceptable state. The output can be stored with the change's documentation for easy reference and proof of completion.
@@ -22,7 +42,7 @@ An instance of `CheckType` object must be created first before passing one of th
22
42
23
43
-`exact_match`
24
44
-`tolerance`
25
-
-`parameters`
45
+
-`parameter_match`
26
46
-`regex`
27
47
-`operator`
28
48
@@ -228,58 +248,6 @@ Targeting only the `interfaceStatus` key, we would need to define a reference ke
228
248
The anchor logic for the reference key applies to all check-types available in `netcompare`
229
249
230
250
231
-
### parameter_match
232
-
233
-
parameter_match provides a way to match keys and values in the output with known good values.
234
-
235
-
The test defines key/value pairs known to be the good value - type `dict()` - as well as a mode - `match`, `no-match` - to match or not against the parsed output. The test fails if any status has changed based on what is defined in pre/post. If there are new values not contained in the input/test value, that will not count as a failure.
In network data, this could be a state of bgp neighbors being Established or the connectedness of certain interfaces being up.
282
-
283
251
### Tolerance
284
252
285
253
The `tolerance` test defines a percentage of differing `float()` between pre and post checks numeric value. The threshold is defined as a percentage that can be different either from the value stated in pre and post fields.
@@ -364,6 +332,59 @@ Lets have a look to a couple of examples:
364
332
This test can test the tolerance for changing quantities of certain things such as routes, or L2 or L3 neighbors. It could also test actual outputted values such as transmitted light levels for optics.
365
333
366
334
335
+
### Parameter_match
336
+
337
+
parameter_match provides a way to match keys and values in the output with known good values.
338
+
339
+
The test defines key/value pairs known to be the good value - type `dict()` - as well as a mode - `match`, `no-match` - to match or not against the parsed output. The test fails if any status has changed based on what is defined in pre/post. If there are new values not contained in the input/test value, that will not count as a failure.
In network data, this could be a state of bgp neighbors being Established or the connectedness of certain interfaces being up.
386
+
387
+
367
388
### Regex
368
389
369
390
The `regex` check type evaluates data against a python regular expression defined as check-type argument. As per `parameter_match` the option `match`, `no-match`is also supported.
0 commit comments