Closed jambofun closed 2 years ago
I cannot reproduce the error without having your YANG library file, but I guess the problem is in the namespace identifier: you have to use openconfig-bgp-types:IPV4_UNICAST
(which you do in two instances) rather than oc-bgp-types:IPV4_UNICAST
.
Thanks IIhotka, but even with that change, i am still getting an error. This time it is:
yangson.exceptions.SchemaError: {/openconfig-bgp:bgp/neighbors/neighbor[neighbor-address="1.1.1.1"]/afi-safis/afi-safi[afi-safi-name="openconfig-bgp-types:IPV4_UNICAST"]} config member-not-allowed: ipv4-unicast
I notice that within the openconfig-bgp-common-multiprotocol.yang model, there is a conditional WHEN statement which is expecting when "../afi-safi-name = 'oc-bgp-types:IPV4_UNICAST'" .. hence looked at using oc-bgp-types: instead.
Any thoughts as to why this new error has persisted?
Please see updated payload below:
{
"openconfig-routing-policy:routing-policy": {
"policy-definitions": {
"policy-definition": [
{
"name": "ipv4-inbound",
"config": {
"name": "ipv4-inbound"
}
}
]
}
},
"openconfig-bgp:bgp": {
"global": {
"config": {
"as": 1234
}
},
"neighbors": {
"neighbor": [
{
"neighbor-address": "1.1.1.1",
"config":
{
"peer-group": "ipv4",
"neighbor-address": "1.1.1.1",
"enabled": true,
"peer-as": 9009,
"auth-password": "secret",
"description": "ExampleISP"
},
"apply-policy":
{
"config":
{
"import-policy": ["ipv4-inbound"]
}
},
"afi-safis": {
"afi-safi": [
{
"afi-safi-name": "openconfig-bgp-types:IPV4_UNICAST",
"config": {
"afi-safi-name": "openconfig-bgp-types:IPV4_UNICAST",
"enabled": true
},
"ipv4-unicast": {
"prefix-limit": {
"config": {
"max-prefixes": 50
}
}
}
}
]
}
}
]
},
"peer-groups": {
"peer-group": [
{
"peer-group-name": "ipv4",
"config": {
"peer-group-name": "ipv4"
}
}
]
}
}
}
when "../afi-safi-name = 'oc-bgp-types:IPV4_UNICAST'"
Yeah, this is a common problem. This XPath expression uses literal string comparison, which cannot work with JSON data unless the namespace prefix is exactly the same as the module name. That's why YANG 1.1 introduced new XPath functions derived-from() and derived-from-or-self().
I am attempting to validate a JSON payload with the openconfig-bgp.yang model with YANGSON. However, even though I believe my payload is formatted as per the openconfig-bgp.yang schema correctly, validation fails. Can someone assist with this?
JSON payload
{ "openconfig-routing-policy:routing-policy": { "policy-definitions": { "policy-definition": [ { "name": "ipv4-inbound", "config": { "name": "ipv4-inbound" } } ] } }, "openconfig-bgp:bgp": { "global": { "config": { "as": 1234 }, "afi-safis": { "afi-safi": [ { "config": { "enabled": true, "afi-safi-name": "openconfig-bgp-types:IPV4_UNICAST" }, "afi-safi-name": "openconfig-bgp-types:IPV4_UNICAST" } ] } }, "neighbors": { "neighbor": [ { "neighbor-address": "1.1.1.1", "config": { "peer-group": "ipv4", "neighbor-address": "1.1.1.1", "peer-as": 2345, "auth-password": "secret", "description": "ExampleISP" }, "apply-policy": { "config": { "import-policy": ["ipv4-inbound"] } }, "afi-safis": { "afi-safi": [ { "afi-safi-name": "oc-bgp-types:IPV4_UNICAST", "config": { "enabled": true, "afi-safi-name": "oc-bgp-types:IPV4_UNICAST" }, "ipv4-unicast": { "config": { "send-default-route": true } } } ]
} } ] }, "peer-groups": { "peer-group": [ { "peer-group-name": "ipv4", "config": { "peer-group-name": "ipv4" }, "afi-safis": { "afi-safi": [ { "config": { "enabled": true, "afi-safi-name": "oc-bgp-types:IPV4_UNICAST" }, "afi-safi-name": "oc-bgp-types:IPV4_UNICAST" } ] } } ] } } }
My Yangson JSON catalogue is set up correctly and working
When performing the .validate() method in Yangson, the following error occurs:
Traceback (most recent call last): File "play.py", line 38, in
inst.validate()
File "/Library/Frameworks/Python.framework/Versions/3.7/lib/python3.7/site-packages/yangson/instance.py", line 366, in validate
self.schema_node._validate(self, scope, ctype)
File "/Library/Frameworks/Python.framework/Versions/3.7/lib/python3.7/site-packages/yangson/schemanode.py", line 612, in _validate
inst._member(m).validate(scope, ctype)
File "/Library/Frameworks/Python.framework/Versions/3.7/lib/python3.7/site-packages/yangson/instance.py", line 366, in validate
self.schema_node._validate(self, scope, ctype)
File "/Library/Frameworks/Python.framework/Versions/3.7/lib/python3.7/site-packages/yangson/schemanode.py", line 944, in _validate
super()._validate(inst, scope, ctype)
File "/Library/Frameworks/Python.framework/Versions/3.7/lib/python3.7/site-packages/yangson/schemanode.py", line 612, in _validate
inst._member(m).validate(scope, ctype)
File "/Library/Frameworks/Python.framework/Versions/3.7/lib/python3.7/site-packages/yangson/instance.py", line 366, in validate
self.schema_node._validate(self, scope, ctype)
File "/Library/Frameworks/Python.framework/Versions/3.7/lib/python3.7/site-packages/yangson/schemanode.py", line 944, in _validate
super()._validate(inst, scope, ctype)
File "/Library/Frameworks/Python.framework/Versions/3.7/lib/python3.7/site-packages/yangson/schemanode.py", line 612, in _validate
inst._member(m).validate(scope, ctype)
File "/Library/Frameworks/Python.framework/Versions/3.7/lib/python3.7/site-packages/yangson/instance.py", line 366, in validate
self.schema_node._validate(self, scope, ctype)
File "/Library/Frameworks/Python.framework/Versions/3.7/lib/python3.7/site-packages/yangson/schemanode.py", line 1143, in _validate
super()._validate(e, scope, ctype)
File "/Library/Frameworks/Python.framework/Versions/3.7/lib/python3.7/site-packages/yangson/schemanode.py", line 944, in _validate
super()._validate(inst, scope, ctype)
File "/Library/Frameworks/Python.framework/Versions/3.7/lib/python3.7/site-packages/yangson/schemanode.py", line 612, in _validate
inst._member(m).validate(scope, ctype)
File "/Library/Frameworks/Python.framework/Versions/3.7/lib/python3.7/site-packages/yangson/instance.py", line 366, in validate
self.schema_node._validate(self, scope, ctype)
File "/Library/Frameworks/Python.framework/Versions/3.7/lib/python3.7/site-packages/yangson/schemanode.py", line 944, in _validate
super()._validate(inst, scope, ctype)
File "/Library/Frameworks/Python.framework/Versions/3.7/lib/python3.7/site-packages/yangson/schemanode.py", line 612, in _validate
inst._member(m).validate(scope, ctype)
File "/Library/Frameworks/Python.framework/Versions/3.7/lib/python3.7/site-packages/yangson/instance.py", line 366, in validate
self.schema_node._validate(self, scope, ctype)
File "/Library/Frameworks/Python.framework/Versions/3.7/lib/python3.7/site-packages/yangson/schemanode.py", line 1143, in _validate
super()._validate(e, scope, ctype)
File "/Library/Frameworks/Python.framework/Versions/3.7/lib/python3.7/site-packages/yangson/schemanode.py", line 944, in _validate
super()._validate(inst, scope, ctype)
File "/Library/Frameworks/Python.framework/Versions/3.7/lib/python3.7/site-packages/yangson/schemanode.py", line 612, in _validate
inst._member(m).validate(scope, ctype)
File "/Library/Frameworks/Python.framework/Versions/3.7/lib/python3.7/site-packages/yangson/instance.py", line 366, in validate
self.schema_node._validate(self, scope, ctype)
File "/Library/Frameworks/Python.framework/Versions/3.7/lib/python3.7/site-packages/yangson/schemanode.py", line 944, in _validate
super()._validate(inst, scope, ctype)
File "/Library/Frameworks/Python.framework/Versions/3.7/lib/python3.7/site-packages/yangson/schemanode.py", line 1045, in _validate
self.type.error_message)
yangson.exceptions.YangTypeError: {/openconfig-bgp:bgp/neighbors/neighbor[neighbor-address="1.1.1.1"]/afi-safis/afi-safi[afi-safi-name="oc-bgp-types:IPV4_UNICAST"]/afi-safi-name} None