From ca23b63a4e71da43964ef025a80d832432ea33b3 Mon Sep 17 00:00:00 2001 From: Olof hagsand Date: Tue, 27 Dec 2022 11:29:22 +0100 Subject: [PATCH] Fixed: [leafref in new type no work in union type](https://github.com/clicon/clixon/issues/388) --- CHANGELOG.md | 3 ++- lib/src/clixon_validate.c | 28 ++++++++++++++++++---------- test/test_leafref_union.sh | 19 +++++++++++++++++++ 3 files changed, 39 insertions(+), 11 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index dde0cba5..9c6c6da5 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -82,7 +82,8 @@ Developers may need to change their code ### Corrected Bugs -* [must statement check int value failed](https://github.com/clicon/clixon/issues/386) +* Fixed: [leafref in new type no work in union type](https://github.com/clicon/clixon/issues/388) +* Fixed: [must statement check int value failed](https://github.com/clicon/clixon/issues/386) * Fixed: [Defaults in choice does not work properly](https://github.com/clicon/clixon/issues/390) * Fixed: [Netconf monitoring](https://github.com/clicon/clixon/issues/370) - Announce module capability diff --git a/lib/src/clixon_validate.c b/lib/src/clixon_validate.c index e56d21c3..5ff366c9 100644 --- a/lib/src/clixon_validate.c +++ b/lib/src/clixon_validate.c @@ -1109,24 +1109,32 @@ xml_yang_validate_leaf_union(clicon_handle h, { int retval = -1; int ret; - yang_stmt *yc = NULL; + yang_stmt *ytsub = NULL; cxobj *xret1 = NULL; + yang_stmt *ytype; /* resolved type */ + char *restype; /* Enough that one is valid, eg returns 1,otherwise fail */ - while ((yc = yn_each(yrestype, yc)) != NULL){ - if (yang_keyword_get(yc) != Y_TYPE) + while ((ytsub = yn_each(yrestype, ytsub)) != NULL){ + if (yang_keyword_get(ytsub) != Y_TYPE) continue; + /* Resolve the sub-union type to a resolved type */ + if (yang_type_resolve(yt, yt, ytsub, /* in */ + &ytype, NULL, /* resolved type */ + NULL, NULL, NULL, NULL) < 0) + goto done; + restype = ytype?yang_argument_get(ytype):NULL; ret = 1; /* If not leafref/identityref it is valid on this level */ - if (strcmp(yang_argument_get(yc), "leafref") == 0){ - if ((ret = validate_leafref(xt, yt, yc, &xret1)) < 0) + if (strcmp(restype, "leafref") == 0){ + if ((ret = validate_leafref(xt, yt, ytype, &xret1)) < 0) // XXX goto done; } - else if (strcmp(yang_argument_get(yc), "identityref") == 0){ - if ((ret = validate_identityref(xt, yt, yc, &xret1)) < 0) + else if (strcmp(restype, "identityref") == 0){ + if ((ret = validate_identityref(xt, yt, ytype, &xret1)) < 0) goto done; } - else if (strcmp("union", yang_argument_get(yc)) == 0){ - if ((ret = xml_yang_validate_leaf_union(h, xt, yt, yc, &xret1)) < 0) + else if (strcmp("union", yang_argument_get(ytsub)) == 0){ + if ((ret = xml_yang_validate_leaf_union(h, xt, yt, ytype, &xret1)) < 0) goto done; } if (ret == 1) @@ -1141,7 +1149,7 @@ xml_yang_validate_leaf_union(clicon_handle h, xret1 = NULL; } } - if (yc == NULL) + if (ytsub == NULL) goto fail; retval = 1; done: diff --git a/test/test_leafref_union.sh b/test/test_leafref_union.sh index 22325e30..90950979 100755 --- a/test/test_leafref_union.sh +++ b/test/test_leafref_union.sh @@ -50,6 +50,18 @@ module example{ identity saab { base "airplane"; } + typedef ref1 { + type leafref { + path "../x"; + require-instance true; + } + } + typedef ref2 { + type leafref { + path "../y"; + require-instance true; + } + } container c { leaf x { type string; @@ -70,6 +82,13 @@ module example{ } } } + leaf zdecl { + description "leafref union using declared types"; + type union { + type ref1; + type ref2; + } + } leaf w { description "idref union"; type union {