akarneliuk / pygnmi

The pure Python implementation of the gNMI client.
https://training.karneliuk.com
BSD 3-Clause "New" or "Revised" License
126 stars 44 forks source link

Diff action not showing add related changes #124

Open XioNoX opened 1 year ago

XioNoX commented 1 year ago

Trying to make my way through the diff feature after https://github.com/akarneliuk/pygnmi/pull/122 and https://github.com/akarneliuk/pygnmi/pull/123.

I noticed 2 issues when adding configuration options to a gNMI peer.

For example, sending this replace message (which works fine): [('openconfig-interfaces:interfaces/interface[name=Ethernet1]/openconfig-if-ethernet:ethernet/openconfig-vlan:switched-vlan', {'openconfig-vlan:switched-vlan': {'config': {'interface-mode': 'TRUNK', 'access-vlan': 1038, 'trunk-vlans': [1031]}}})]

I added some debug print messages under elif entry_tuple[0] == "add": (in https://github.com/akarneliuk/pygnmi/blob/master/pygnmi/tools.py#L128)

entry tuple: ('add', [], [('openconfig-vlan:switched-vlan', {'config': {'access-vlan': 1038, 'interface-mode': 'TRUNK', 'trunk-vlans': [1031]}})])

But the diff only shows:

+ /openconfig-interfaces:interfaces/interface[name=Ethernet1]/openconfig-if-ethernet:ethernet/openconfig-vlan:switched-vlan/config/access-vlan 1038
+ /openconfig-interfaces:interfaces/interface[name=Ethernet1]/openconfig-if-ethernet:ethernet/openconfig-vlan:switched-vlan/config/interface-mode TRUNK

While it should also show the change related to 'trunk-vlans': [1031]

The same issue happen with the "delete" action. For example sending: ['openconfig-interfaces:interfaces/interface[name=Ethernet1]/openconfig-if-ethernet:ethernet/openconfig-vlan:switched-vlan'] Only returns:

- /openconfig-interfaces:interfaces/interface[name=Ethernet1]/openconfig-if-ethernet:ethernet/openconfig-vlan:switched-vlan/config/access-vlan 1038
- /openconfig-interfaces:interfaces/interface[name=Ethernet1]/openconfig-if-ethernet:ethernet/openconfig-vlan:switched-vlan/config/interface-mode TRUNK

While it's also present in diff_list (at the beginning of def diff_openconfig()) [('change', ['notification', 0, 'timestamp'], (1686224822858689646, 1686224823572389369)), ('remove', ['notification', 0, 'update', 0, 'val'], [('openconfig-vlan:switched-vlan', {'config': {'access-vlan': 1038, 'interface-mode': 'TRUNK', 'trunk-vlans': [1031]}})])]


Next, sending this update message: [('openconfig-interfaces:interfaces/interface[name=Ethernet1]', {'openconfig-interfaces:interface': [{'config': {'enabled': True, 'description': 'sretest1003', 'mtu': 9192}, 'name': 'Ethernet1'}]})]

have this entry tuple: entry tuple: ('add', ['openconfig-interfaces:interface', 0, 'config'], [('description', 'sretest1003'), ('enabled', True), ('mtu', 9192)]) Which doesn't work out with _dict_to_xpath as elem_list[-1] is a string (Eg. sretest1003) and not the expected dict.

And doesn't return any diff.

Let me know if I can be of any help.

Thanks,