robshakir / pyangbind

A plugin for pyang that creates Python bindings for a YANG model.
Other
204 stars 121 forks source link

The "--set-presence" flag seems to vanish some class methods #226

Closed ymitsos closed 8 months ago

ymitsos commented 6 years ago

Compiling some YANG models, where each of them augments its "predecessor" and using the "--set-presece" switch seems to result into vanishing some class methods.

The use case I am working on, and have stumbled across this behavior, relates to an endeavor to represent our network topology using YANG.

Namely, RFC8346 defines how to represent L3 Topologies using a YANG model. This YANG module augments the general network topology model defined in RFC8345 which augments the base network state data model.

According to section 5 of the RFC, the network-types is augmented as follows:

module: ietf-l3-unicast-topology      
    augment /nw:networks/nw:network/nw:network-types:
      +--rw l3-unicast-topology!      

Provided that the aforementioned is a container with presence, I assume that I need to include the "--set-presence" flag when compiling:

pyang --plugindir $PYBINDPLUGIN -f pybind -p $SDIR/yang/ -o $SDIR/binding_l3_unicast_topology.py $SDIR/yang/ietf-network@2018-02-26.yang $SDIR/yang/ietf-network-topology@2018-02-26.yang $SDIR/yang/ietf-l3-unicast-topology@2018-02-26.yang --set-presence

IETF's YANG models are available in [2].

Using the resulted classes, I am able to set it using container._set_present(); however, some other methods seems not to be included when compared to the resulted file if the --set-presence is omitted. For instance the _set_unnumbered_id method of the yc_l3_termination_point_attributes_ietf_network__networks_network_node_termination_point_l3_termination_point_attributes class is missing. Again, the method is available if the "--set-presence" flag is not set during compilation.

[1] https://tools.ietf.org/html/rfc8346 [2] https://github.com/YangModels/yang/tree/master/standard/ietf/RFC

ymitsos commented 6 years ago

to further illustrate the behaviour, and always referring to RFC8346, I provide two snippets. The first one uses the bindings as build without the "--presence" flag, while the second one with it.

from binding_l3_unicast_topology import *
networks = yc_networks_ietf_network__networks()
net1 = networks.network.add('net1')
node1 = net1.node.add('node1')
tp1 = node1.termination_point.add('1-0-1')

tp1.get()

Out[7]: 
{'l3-termination-point-attributes': {'interface-name': u'',
  'ip-address': [],
  'unnumbered-id': 0L},
 'supporting-termination-point': OrderedDict(),
 'tp-id': u'1-0-1'}

With "--presence"

from binding_l3_unicast_topology_presence import *
networks = yc_networks_ietf_network__networks()
net1 = networks.network.add('net1')
node1 = net1.node.add('node1')
tp1 = node1.termination_point.add('1-0-1')
tp1.get()

Out[7]: 
{'l3-termination-point-attributes': {},
 'supporting-termination-point': OrderedDict(),
 'tp-id': u'1-0-1'}

The attributes "interface-name", "ip-address" and "unnumbered-id" are missing in the latter and of course their corresponding class methods.

JoseIgnacioTamayo commented 9 months ago

Could you please try with the latest code? We did some fixes related to --set-presence in https://github.com/robshakir/pyangbind/pull/339

JoseIgnacioTamayo commented 8 months ago

With pyangbind release 0.8.5, at least, this issue is not present.

I created similar binds with: pyang --plugindir <> -f pybind -p <> -o binding_l3_unicast_topology.py $SDIR/ietf-network.yang $SDIR/ietf-network-topology.yang $SDIR/ietf-l3-unicast-topology.yang and pyang --plugindir <> -f pybind -p <> --presence -o binding_l3_unicast_topology_presence.py $SDIR/ietf-network.yang $SDIR/ietf-network-topology.yang $SDIR/ietf-l3-unicast-topology.yang

Then I imported these 2 bindings and used them to produce the same snipets

`

import binding_l3_unicast_topology import binding_l3_unicast_topology_presence nets = ietfnet.networks.network.add("net1") nets_p = ietfnet_p.networks.network.add("net1") node1 = nets.node.add("node1") node1_p = nets_p.node.add("node1") tp1 = node1.termination_point.add("0/1") tp1_p = node1_p.termination_point.add("0/1") tp1.get() {'tp-id': '0/1', 'supporting-termination-point': OrderedDict(), 'l3-termination-point-attributes': {'ip-address': [], 'unnumbered-id': 0, 'interface-name': ''}} tp1_p.get() {'tp-id': '0/1', 'supporting-termination-point': OrderedDict(), 'l3-termination-point-attributes': {'ip-address': [], 'unnumbered-id': 0, 'interface-name': ''}} `

When diffing the generated Python files, the changes are as expected.