Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Error string from leafref assignment can be unhelpful #174

Open
tarkatronic opened this issue Apr 12, 2018 · 1 comment
Open

Error string from leafref assignment can be unhelpful #174

tarkatronic opened this issue Apr 12, 2018 · 1 comment

Comments

@tarkatronic
Copy link
Collaborator

This was discovered while converting xpath tests to use unittest. Specifically in tests.xpath.01-list_leaflist.XPathListLeaflistTests.test_standalone_ref.

Given this section of the YANG model:

    container standalone {
        list l {
            key x;
            leaf x {
                type int8;
            }
        }

        leaf ref {
            type leafref {
                path "../l/x";
            }
        }
    }

This test would fail:

  def test_standalone_ref(self):
    self.instance.standalone.ref = 1
    self.assertEqual(self.instance.standalone.ref._referenced_object, 1)

With this error message:

ValueError: {'error-string': 'ref must be of a type compatible with leafref', 'generated-type': 'YANGDynClass(base=ReferenceType(referenced_path=\'../l/x\', caller=self._path() + [\'ref\'], path_helper=self._path_helper, require_instance=True), is_leaf=True, yang_name="ref", parent=self, path_helper=self._path_helper, extmethods=self._extmethods, register_paths=True, namespace=\'http://rob.sh/yang/xpathelper/tc01\', defining_module=\'list-tc01\', yang_type=\'leafref\', is_config=True)', 'defined-type': 'leafref'}

This is due to the absence of a line calling self.instance.standalone.l.add(1).

While this is a valid error, the message could be a little more helpful. I don't have a solid suggestion on how to change it, but mentioning that the value assigned must be in the list of values added to the referred leaf would be much more helpful.

@qiaoboyqb
Copy link

qiaoboyqb commented Apr 9, 2019

The same error occurs when i serialise data into obj like bellow:
KeyError: u'key value must be valid, {'error-string': 'vlan_name must be of a type compatible with leafref', 'generated-type': 'YANGDynClass(base=ReferenceType(referenced_path=\'/VLAN/name__\', caller=self._path() + [\'vlan_name\'], path_helper=self._path_helper, require_instance=True), is_leaf=True, yang_name="vlan_name", parent=self, path_helper=self._path_helper, extmethods=self._extmethods, register_paths=True, is_keyval=True, namespace=\'http://north-api.aliababa.com/schema/vlan\\\', defining_module=\'vlan_schema\', yang_type=\'leafref\', is_config=True)', 'defined-type': 'leafref'}'
do you have any suggestion about this ? here is my yang model and json data, thank you:

import ietf-inet-types {
    prefix "inet";
}
import common-types {
    prefix "common";
}

typedef mtu {
    type uint16 {
        range "64 .. 9216";
    }
}
grouping vlan-config {
    list VLAN {
        key name__;
        leaf name__ {
            type string;
            description
              "VLAN name";
        }

        container ipAddress {
            leaf-list ipv4Address {
                type inet:ipv4-prefix;
            }

            leaf-list ipv6Address {
                type inet:ipv6-prefix;
            }

            leaf ipv6Auto {
                type common:enable-status;
            }
        }

        leaf vrf {
            type string;
        }

        leaf adminStatus {
            type common:status;
        }
        leaf aclIn {
            type string;
        }
        leaf aclOut {
            type string;
        }
        leaf mtu {
            type mtu;
        }
        leaf arpProxy {
            type common:status;
        }
        leaf description {
            type string;
        }
        leaf dhcpRelaySrcIP {
            type inet:ip-address;
        }
        leaf-list dhcpSever {
            type inet:ip-address;
        }
        leaf ndpProxy {
            type common:enable-status;
        }
    }
}

grouping vlan_ip {
    list VLAN_IP {
        key vlan_name;

        leaf vlan_name {
            type leafref{
                path "/VLAN/name__";
            }
        }

        container ipAddress {
            leaf-list ipv4Address {
                type inet:ipv4-prefix;
            }

            leaf-list ipv6Address {
                type inet:ipv6-prefix;
            }
        }
    }
}

uses vlan_ip;

uses vlan-config;

}`

{ "VLAN_IP":{ "VLAN10":{ "ipAddress":{ "ipv6Address":[ "fe00::1/64", "fe00::2/64" ] }, "vlan_name":"VLAN10" } }, "VLAN":{ "VLAN10":{ "adminStatus":"down", "description":"default gateway", "ndpProxy":"enable", "aclIn":"AL01", "name__":"VLAN10", "aclOut":"AL02", "mtu":9100, "vrf":"golbal", "arpProxy":"up", "ipAddress":{ "ipv4Address":[ "11.210.88.1/30", "192.168.0.1/30" ], "ipv6Auto":"enable", "ipv6Address":[ "fe00::1/64", "fe00::2/64" ] }, "dhcpSever":[ "100.0.0.2" ], "dhcpRelaySrcIP":"12.162.231.2" } } }

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

2 participants