Skip to content

Commit

Permalink
Add CLI for `gnmidiff set-to-notifs <setrequest> <subscribe responses…
Browse files Browse the repository at this point in the history
…>` (#786)

* Add utility `flattenOCJSON` in package `gnmidiff`

This is useful for comparing between two SetRequests whose contents are
in JSON_IETF format.

* improve coverage by a bit

* WIP for SetRequestDiff

* Add flag in flattenOCJSON to remove namespace from path

* Complete DiffSetRequest

* improve style & comments

* address comments

* SetRequestDiff -> SetRequestIntentDiff

* Add Format function for SetRequestIntentDiff

* `minimalSetRequestIntent(req *gpb.SetRequest)`

* make output more compact

* Schema-aware SetRequest Diff

* fix corner case

* Fix bug with prefix matching

* add comment explaining why don't simply just pass in a ytypes.Schema

* Basic `DiffSetRequestToNotifications`

* Doesn't support Subscribe/STREAM since no deletes allowed.
* Format function not yet added.

Will fix these in follow-up PRs.

* Improve style

* Change parameter newSchemaFn -> schema for performance

* fix for leaf-lists

* fix leaf-lists

* remove stale comment

* Support non-conflicting deletes in DiffSetRequestIntent

* Add test cases for handling deletes in SetRequest

* Handle prefix paths in gnmidiff utilities

* improve style

* Add Format function for `SetToNotifsDiff`

* Add test for DiffSetRequestToNotifications delete

Not supported, so throws error.

* CLI for diffing between two SetRequests

* add copyright

* Add CLI for `gnmidiff set-to-notifs <setrequest> <subscribe responses>`

* add unmarshalling test

* Add GetResponse support and a sample SetRequest file

* Update README

* add output to README

* move Exit(1) to main.go

* update comment

* remove TODO

* Improve struct sharing between diff objects

* Add missing file

* export setrequest parsing

* export notifs parsing

* move textprotos to own folder

* add test

* add doc-comments

* update version supported
  • Loading branch information
wenovus authored Mar 4, 2023
1 parent 2dc8e40 commit 7dd3342
Show file tree
Hide file tree
Showing 12 changed files with 1,570 additions and 3 deletions.
2 changes: 1 addition & 1 deletion .github/workflows/go.yml
Original file line number Diff line number Diff line change
Expand Up @@ -141,7 +141,7 @@ jobs:
- name: Run coverage
run: |
pkgs="$(go list ./... | grep -v 'github.com/openconfig/ygot/exampleoc' | grep -v 'github.com/openconfig/ygot/uexampleoc' | grep -v 'github.com/openconfig/ygot/proto/' | grep -v 'github.com/openconfig/ygot/demo/' | grep -v 'github.com/openconfig/ygot/integration_tests' | grep -v 'github.com/openconfig/ygot/generator' | tr '\n' ' ')"
pkgs="$(go list ./... | grep -v 'github.com/openconfig/ygot/exampleoc' | grep -v 'github.com/openconfig/ygot/uexampleoc' | grep -v 'github.com/openconfig/ygot/proto/' | grep -v 'github.com/openconfig/ygot/demo/' | grep -v 'github.com/openconfig/ygot/integration_tests' | grep -v 'github.com/openconfig/ygot/generator' | grep -v 'github.com/openconfig/ygot/gnmidiff/cmd' | tr '\n' ' ')"
for p in $pkgs; do
dir=$(echo $p | sed -e 's/^github\.com\/openconfig\/ygot\///')
go test -covermode count -coverprofile profile.coverprofile -outputdir $dir $p
Expand Down
38 changes: 36 additions & 2 deletions gnmidiff/README.md
Original file line number Diff line number Diff line change
@@ -1,7 +1,41 @@
## Usage

```bash
go install ./gnmidiff
$ go install ./gnmidiff

gnmidiff setrequest setrequest_a.textproto setrequest_b.textproto
$ gnmidiff setrequest cmd/demo/setrequest.textproto cmd/demo/setrequest2.textproto

SetRequestIntentDiff(-A, +B):
-------- deletes --------
+ /network-instances/network-instance[name=VrfBlue]: deleted
-------- updates --------
m /system/config/hostname:
- "violetsareblue"
+ "rosesarered"

$ gnmidiff set-to-notifs cmd/demo/setrequest.textproto cmd/demo/notifs.textproto

SetToNotifsDiff(-want/SetRequest, +got/Notifications):
- /lacp/interfaces/interface[name=Port-Channel9]/config/interval: "FAST"
- /lacp/interfaces/interface[name=Port-Channel9]/config/name: "Port-Channel9"
- /lacp/interfaces/interface[name=Port-Channel9]/name: "Port-Channel9"
- /network-instances/network-instance[name=VrfBlue]/config/name: "VrfBlue"
- /network-instances/network-instance[name=VrfBlue]/config/type: "openconfig-network-instance-types:L3VRF"
- /network-instances/network-instance[name=VrfBlue]/name: "VrfBlue"
m /system/config/hostname:
- "violetsareblue"
+ "rosesarered"

$ gnmidiff set-to-notifs cmd/demo/setrequest.textproto cmd/demo/getresponse.textproto

SetToNotifsDiff(-want/SetRequest, +got/Notifications):
- /lacp/interfaces/interface[name=Port-Channel9]/config/interval: "FAST"
- /lacp/interfaces/interface[name=Port-Channel9]/config/name: "Port-Channel9"
- /lacp/interfaces/interface[name=Port-Channel9]/name: "Port-Channel9"
- /network-instances/network-instance[name=VrfBlue]/config/name: "VrfBlue"
- /network-instances/network-instance[name=VrfBlue]/config/type: "openconfig-network-instance-types:L3VRF"
- /network-instances/network-instance[name=VrfBlue]/name: "VrfBlue"
m /system/config/hostname:
- "violetsareblue"
+ "rosesarered"
```
291 changes: 291 additions & 0 deletions gnmidiff/cmd/demo/getresponse.textproto
Original file line number Diff line number Diff line change
@@ -0,0 +1,291 @@
notification: {
timestamp: 1676419100456944135
prefix: {
origin: "openconfig"
target: "fakedut"
}
update: {
path: {
elem: {
name: "system"
}
elem: {
name: "ssh-server"
}
elem: {
name: "state"
}
elem: {
name: "protocol-version"
}
}
val: {
string_val: "V2"
}
}
}
notification: {
timestamp: 1676420328291197426
prefix: {
origin: "openconfig"
target: "fakedut"
}
update: {
path: {
elem: {
name: "system"
}
elem: {
name: "config"
}
elem: {
name: "hostname"
}
}
val: {
string_val: "rosesarered"
}
}
}
notification: {
timestamp: 1676419100456944135
prefix: {
origin: "openconfig"
target: "fakedut"
}
update: {
path: {
elem: {
name: "system"
}
elem: {
name: "ntp"
}
elem: {
name: "state"
}
elem: {
name: "enabled"
}
}
val: {
bool_val: false
}
}
}
notification: {
timestamp: 1676419100456944135
prefix: {
origin: "openconfig"
target: "fakedut"
}
update: {
path: {
elem: {
name: "system"
}
elem: {
name: "ntp"
}
elem: {
name: "state"
}
elem: {
name: "enable-ntp-auth"
}
}
val: {
bool_val: false
}
}
}
notification: {
timestamp: 1676419100456944135
prefix: {
origin: "openconfig"
target: "fakedut"
}
update: {
path: {
elem: {
name: "system"
}
elem: {
name: "ssh-server"
}
elem: {
name: "state"
}
elem: {
name: "enable"
}
}
val: {
bool_val: true
}
}
}
notification: {
timestamp: 1676420328448197153
prefix: {
origin: "openconfig"
target: "fakedut"
}
update: {
path: {
elem: {
name: "system"
}
elem: {
name: "state"
}
elem: {
name: "hostname"
}
}
val: {
string_val: "rosesarered"
}
}
}
notification: {
timestamp: 1676419100459254468
prefix: {
origin: "openconfig"
target: "fakedut"
}
update: {
path: {
elem: {
name: "system"
}
elem: {
name: "state"
}
elem: {
name: "boot-time"
}
}
val: {
uint_val: 1676419100459308639
}
}
}
notification: {
timestamp: 1676419100456944135
prefix: {
origin: "openconfig"
target: "fakedut"
}
update: {
path: {
elem: {
name: "system"
}
elem: {
name: "telnet-server"
}
elem: {
name: "state"
}
elem: {
name: "enable"
}
}
val: {
bool_val: false
}
}
}
notification: {
timestamp: 1676422427135895887
prefix: {
origin: "openconfig"
target: "fakedut"
}
update: {
path: {
elem: {
name: "system"
}
elem: {
name: "config"
}
elem: {
name: "hostname"
}
}
val: {
string_val: "rosesareredd"
}
}
}
notification: {
timestamp: 1676422427269965151
prefix: {
origin: "openconfig"
target: "fakedut"
}
update: {
path: {
elem: {
name: "system"
}
elem: {
name: "state"
}
elem: {
name: "hostname"
}
}
val: {
string_val: "rosesareredd"
}
}
}
notification: {
timestamp: 1676422434342310772
prefix: {
origin: "openconfig"
target: "fakedut"
}
update: {
path: {
elem: {
name: "system"
}
elem: {
name: "config"
}
elem: {
name: "hostname"
}
}
val: {
string_val: "rosesarered"
}
}
}
notification: {
timestamp: 1676422434479082363
prefix: {
origin: "openconfig"
target: "fakedut"
}
update: {
path: {
elem: {
name: "system"
}
elem: {
name: "state"
}
elem: {
name: "hostname"
}
}
val: {
string_val: "rosesarered"
}
}
}
Loading

0 comments on commit 7dd3342

Please sign in to comment.