11-26-2018 04:36 PM
Hello,
While trying to encode the openconfig-network-instance, seeing a weird validation error where it fails for system-id, area-address and basically all net-ids.
network_instances = openconfig_network_instance.NetworkInstances() network_instance = network_instances.NetworkInstance() network_instance.name = "default" protocol = network_instance.protocols.Protocol() protocol.identifier = openconfig_policy_types.ISIS() protocol.name = "65444" isis = protocol.Isis() interface = isis.interfaces.Interface() interface.interface_id = "HundredGigE0/0/0/0" level = interface.levels.Level() level.level_number = 2 adjacency = level.adjacencies.Adjacency() adjacency.system_id = "0143.0438.AeF0" adjacency.state.neighbor_ipv4_address = "2.1.1.1" adjacency.state.neighbor_ipv6_address = "2001::1" adjacency.state.up_time = YFilter.read adjacency.state.multi_topology = False adjacency.state.neighbor_snpa = "00:01:02:03:04:05" level.adjacencies.adjacency.append(adjacency) interface.levels.level.append(level) protocol.isis.interfaces.interface.append(interface) network_instance.protocols.protocol.append(protocol) network_instances.network_instance.append(network_instance) output = codec_service.encode(codec_service_provider,network_instances) print(output)
Error
YModelError: Value "0143.0438.AeF0" does not satisfy the constraint "^[0-9A-Fa-f]{4}\.[0-9A-Fa-f]{4}\.[0-9A-Fa-f]{4}$" (range, length, or pattern). Path: /openconfig-network-instance:network-instances/network-instance[name='default']/protocols/protocol[identifier='openconfig-policy-types:ISIS'][name='65444']/isis/interfaces/interface[interface-id='HundredGigE0/0/0/0']/levels/level[level-number='2']/adjacencies/adjacency[system-id='0143.0438.AeF0']/system-id
The above system-id value does match the regex given in the openconfig model but fails while doing an encoding to json and raises a model error.
Thanks
11-29-2018 04:21 PM
11-30-2018 03:25 AM
Thank you for answering the question, will follow up there.
I realized there is a regex problem but couldn't pin point where exactly things are going wrong.
If its not too much to ask, let me bother you with one more query.
Looking at the model classes, there are no files with types for validation, so how does ydk-py does the validation ? Does it pick up the types,patterns directly from the yang file while validating the leaf values ? I tried going through the code but lost track after going through the below function:
def _validate_value(leaf_tuple, name, value, logger): if not isinstance(leaf_tuple, tuple): return if isinstance(value, _YFilter): return typs = leaf_tuple[1] for typ in typs: if _is_identity(typ): if _validate_identity_value_object(typ, value): return elif _is_enum(typ): if _validate_enum_value_object(typ, value): return else: if _validate_other_type_value_object(typ, value): return err_msg = "Invalid value {0} for '{1}'. Got type: '{2}'. Expected types: {3}".format(value, name, type(value).__name__, _get_types_string(typs))
def _validate_identity_value_object(typ, value):
if not _is_identity(typ):
return False
mod = importlib.import_module(typ[0])
base_identity_class = getattr(mod, typ[1])
return isinstance(value, base_identity_class)
def _validate_other_type_value_object(typ, value):
if typ == 'Empty':
return isinstance(value, Empty)
if typ == 'str' and (isinstance(value, bytes) or isinstance(value, unicode)):
return True
if typ == 'int' and (isinstance(value, int) or isinstance(value, long)):
return True
typ = eval(typ)
return isinstance(value, typ)
01-17-2019 11:43 AM
This is known issue in openconfig Yang models, which uses non-standard string pattern regular expression. See https://github.com/openconfig/public/issues/175 for details. It is not clear for how long it is going to take for Google to fix the models, it might not happen at all. Therefore, please use Cisco native models in your application. Another option would be download openconfig models, manually fix all the pattern definitions and generate YDK bundle.
Discover and save your favorite ideas. Come back to expert answers, step-by-step guides, recent topics, and more.
New here? Get started with these tips. How to use Community New member guide