- 
                Notifications
    
You must be signed in to change notification settings  - Fork 316
 
Description
While porting SONiC from libyang 1.0.73 to 3.7.8, I ran across a peculiar issue. Unless I'm evaluating it wrong, it looks like a bug in libyang's handling of default values but simply reordering the leaf nodes in the container magically fixes it. I've only found a single instance of this in all of SONiC's schema.
If I reorder the leaf nodes in the schema, then the default value shows up and works.
I have a commit here showing the schema reorder I made to make the tests pass:
sonic-net/sonic-buildimage@dd1dddb
The schema leafs impacted are:
leaf default_bgp_status {
    type enumeration {
        enum up;
        enum down;
    }
    default up;
}
leaf docker_routing_config_mode {
    description "This leaf allows different configuration modes for FRR:
                - separated: FRR config generated from ConfigDB, each FRR daemon has its own config file
                - unified: FRR config generated from ConfigDB, single FRR config file
                - split: FRR config not generated from ConfigDB, each FRR daemon has its own config file
                - split-unified: FRR config not generated from ConfigDB, single FRR config file";
    type string {
        pattern "separated|unified|split|split-unified";
    }
    default "unified";
}
both tests do an xpath query for /sonic-device_metadata:sonic-device_metadata/DEVICE_METADATA/localhost/hostname  then load the child nodes into a dictionary, and validate the keys of sonic-device_metadata:default_bgp_status and sonic-device_metadata:docker_routing_config_mode exist and are of the expected values.
This is happening in libyang-python with code similar to this:
nodes = node.find_all("/sonic-device_metadata:sonic-device_metadata/DEVICE_METADATA/localhost/hostname")
for dnode in nodes:
  if (xpath == dnode.path()):
    data = dnode.print_mem("json", with_siblings=True, pretty=True, include_implicit_defaults=True)
    data = json.loads(data)
    assert ("sonic-device_metadata:default_bgp_status" in data)
    assert (data["sonic-device_metadata:default_bgp_status"] == "up")I'm not sure what the underlying cause is so I don't know how to submit a reduced test case.