* Error-type changed from protocol to application for data-not-unique netconf/restconf errors

* Added new revision of main example yang: `clixon-example@2020-12-01.yang`
* Fixed [YANG: key statement in rpc/notification list #148](https://github.com/clicon/clixon/issues/148)
  * Do not check uniqueness among lists without keys
This commit is contained in:
Olof hagsand 2020-12-01 18:56:38 +01:00
parent 1cd6d37fa1
commit e46f6f4a36
11 changed files with 275 additions and 26 deletions

View file

@ -1184,7 +1184,7 @@ netconf_data_not_unique_xml(cxobj **xret,
if ((xerr = xml_new("rpc-error", *xret, CX_ELMNT)) == NULL)
goto done;
if (clixon_xml_parse_va(YB_NONE, NULL, &xerr, NULL,
"<error-type>protocol</error-type>"
"<error-type>application</error-type>"
"<error-tag>operation-failed</error-tag>"
"<error-app-tag>data-not-unique</error-app-tag>"
"<error-severity>error</error-severity>") < 0)

View file

@ -654,11 +654,15 @@ check_insert_duplicate(char **vec,
* @param[in] xt The parent of x
* @param[in] y Its yang spec (Y_LIST)
* @param[in] yu A yang unique spec (Y_UNIQUE) for unique keyword or (Y_LIST) for list keys
* @param[out] xret Error XML tree. Free with xml_free after use
* @param[out] xret Error XML tree. Free with xml_free after use
* @retval 1 Validation OK
* @retval 0 Validation failed (cbret set)
* @retval -1 Error
* @note It would be possible to cache the vector built below
* All key leafs MUST be present for all list entries.
* The combined values of all the leafs specified in the key are used to
* uniquely identify a list entry. All key leafs MUST be given values
* when a list entry is created.
*/
static int
check_unique_list(cxobj *x,
@ -666,7 +670,6 @@ check_unique_list(cxobj *x,
yang_stmt *y,
yang_stmt *yu,
cxobj **xret)
{
int retval = -1;
cvec *cvk; /* unique vector */
@ -686,7 +689,11 @@ check_unique_list(cxobj *x,
sorted = (yang_keyword_get(yu) == Y_LIST &&
yang_find(y, Y_ORDERED_BY, "user") == NULL);
cvk = yang_cvec_get(yu);
vlen = cvec_len(cvk); /* nr of unique elements to check */
/* nr of unique elements to check */
if ((vlen = cvec_len(cvk)) == 0){
/* No keys: no checks necessary */
goto ok;
}
if ((vec = calloc(vlen*xml_child_nr(xt), sizeof(char*))) == NULL){
clicon_err(OE_UNIX, errno, "calloc");
goto done;
@ -718,6 +725,7 @@ check_unique_list(cxobj *x,
x = xml_child_each(xt, x, CX_ELMNT);
i++;
} while (x && y == xml_spec(x)); /* stop if list ends, others may follow */
ok:
/* It would be possible to cache vec here as an optimization */
retval = 1;
done:

View file

@ -2853,7 +2853,7 @@ yang_config(yang_stmt *ys)
*
* config statement is default true.
* @param[in] ys Yang statement
* @retval 0 Node or one of its ancestor has config false
* @retval 0 Node or one of its ancestor has config false or is RPC or notification
* @retval 1 Neither node nor any of its ancestors has config false
*/
int
@ -2865,6 +2865,8 @@ yang_config_ancestor(yang_stmt *ys)
do {
if (yang_config(yp) == 0)
return 0;
if (yang_keyword_get(yp) == Y_INPUT || yang_keyword_get(yp) == Y_OUTPUT || yang_keyword_get(yp) == Y_NOTIFICATION)
return 0;
} while((yp = yang_parent_get(yp)) != NULL);
return 1;
}

View file

@ -1091,7 +1091,7 @@ ys_schemanode_check(yang_stmt *ys,
return retval;
}
/*! Check lists: non-config lists MUST have keys
/*! Check lists: config lists MUST have keys
* @param[in] h Clicon handle
* @param[in] ys Yang statement
* Verify the following rule: