- Moved deviation actions to include grouped/uses statements. See https://github.com/clicon/clixon/issues/211

This commit is contained in:
Olof hagsand 2021-05-06 16:23:50 +02:00
parent 1c5c5a71f2
commit 0225488c39
4 changed files with 28 additions and 16 deletions

View file

@ -207,7 +207,13 @@ restconf_reply_send(void *req0,
clicon_err(OE_DAEMON, EFAULT, "evhtp_request_get_connection"); clicon_err(OE_DAEMON, EFAULT, "evhtp_request_get_connection");
goto done; goto done;
} }
/* If body, add a content-length header */ /* If body, add a content-length header
* A server MUST NOT send a Content-Length header field in any response
* with a status code of 1xx (Informational) or 204 (No Content). A
* server MUST NOT send a Content-Length header field in any 2xx
* (Successful) response to a CONNECT request (Section 4.3.6 of
* [RFC7231]).
*/
if (cb != NULL && cbuf_len(cb)){ if (cb != NULL && cbuf_len(cb)){
cprintf(cb, "\r\n"); cprintf(cb, "\r\n");
if (restconf_reply_header(req, "Content-Length", "%d", cbuf_len(cb)) < 0) if (restconf_reply_header(req, "Content-Length", "%d", cbuf_len(cb)) < 0)

View file

@ -1627,6 +1627,7 @@ yang_deviation(yang_stmt *ys,
if (yang_abs_schema_nodeid(ys, nodeid, &ytarget) < 0) if (yang_abs_schema_nodeid(ys, nodeid, &ytarget) < 0)
goto done; goto done;
if (ytarget == NULL){ if (ytarget == NULL){
clicon_log(LOG_WARNING, "deviation %s: target not found", nodeid);
goto ok; goto ok;
/* The RFC does not explicitly say the target node MUST exist /* The RFC does not explicitly say the target node MUST exist
clicon_err(OE_YANG, 0, "schemanode sanity check of %s", nodeid); clicon_err(OE_YANG, 0, "schemanode sanity check of %s", nodeid);

View file

@ -1323,21 +1323,13 @@ yang_parse_post(clicon_handle h,
if (yang_features(h, yang_child_i(yspec, i)) < 0) if (yang_features(h, yang_child_i(yspec, i)) < 0)
goto done; goto done;
/* 4: Check deviations: not-supported add/delete/replace statements /* 4: Go through parse tree and populate it with cv types */
* done after if-features since they may affect deviations but before populate since target yang statements
* may be removed or changed
*/
for (i=modmin; i<modmax; i++) /* Really only under (sub)modules no need to traverse whole tree */
if (yang_apply(yang_child_i(yspec, i), -1, yang_deviation, 1, (void*)h) < 0)
goto done;
/* 5: Go through parse tree and populate it with cv types */
for (i=modmin; i<modmax; i++){ for (i=modmin; i<modmax; i++){
if (yang_apply(yang_child_i(yspec, i), -1, ys_populate, 0, (void*)h) < 0) if (yang_apply(yang_child_i(yspec, i), -1, ys_populate, 0, (void*)h) < 0)
goto done; goto done;
} }
/* 6: Resolve all types: populate type caches. Requires eg length/range cvecs /* 5: Resolve all types: populate type caches. Requires eg length/range cvecs
* from ys_populate step. * from ys_populate step.
* Must be done using static binding. * Must be done using static binding.
*/ */
@ -1352,14 +1344,14 @@ yang_parse_post(clicon_handle h,
* single tree as they are used. * single tree as they are used.
*/ */
/* 7: Macro expansion of all grouping/uses pairs. Expansion needs marking */ /* 6: Macro expansion of all grouping/uses pairs. Expansion needs marking */
for (i=0; i<ylen; i++){ for (i=0; i<ylen; i++){
if (yang_expand_grouping(ylist[i]) < 0) if (yang_expand_grouping(ylist[i]) < 0)
goto done; goto done;
yang_apply(ylist[i], -1, (yang_applyfn_t*)yang_flag_reset, 1, (void*)YANG_FLAG_MARK); yang_apply(ylist[i], -1, (yang_applyfn_t*)yang_flag_reset, 1, (void*)YANG_FLAG_MARK);
} }
/* 8: Top-level augmentation of all modules. /* 7: Top-level augmentation of all modules.
* Note: Clixon does not implement augment in USES * Note: Clixon does not implement augment in USES
* Note: There is an ordering problem, where an augment in one module depends on an augment in * Note: There is an ordering problem, where an augment in one module depends on an augment in
* another module not yet augmented. * another module not yet augmented.
@ -1368,6 +1360,13 @@ yang_parse_post(clicon_handle h,
if (yang_augment_module(ylist[i]) < 0) if (yang_augment_module(ylist[i]) < 0)
goto done; goto done;
/* 8: Check deviations: not-supported add/delete/replace statements
* done late since eg groups must be expanded
*/
for (i=modmin; i<modmax; i++) /* Really only under (sub)modules no need to traverse whole tree */
if (yang_apply(yang_child_i(yspec, i), -1, yang_deviation, 1, (void*)h) < 0)
goto done;
/* 9: Go through parse tree and do 2nd step populate (eg default) */ /* 9: Go through parse tree and do 2nd step populate (eg default) */
for (i=0; i<ylen; i++) for (i=0; i<ylen; i++)
if (yang_apply(ylist[i], -1, ys_populate2, 1, (void*)h) < 0) if (yang_apply(ylist[i], -1, ys_populate2, 1, (void*)h) < 0)

View file

@ -2,6 +2,9 @@
# Yang deviate tests # Yang deviate tests
# See RFC 7950 5.6.3 and 7.20.3 # See RFC 7950 5.6.3 and 7.20.3
# Four examples: not supported, add, replace, delete # Four examples: not supported, add, replace, delete
# Also:
# - keyword with/without string
# - use grouping
# Magic line must be first in script (see README.md) # Magic line must be first in script (see README.md)
s="$_" ; . ./lib.sh || if [ "$s" = "$0" ]; then exit 0; else return 0; fi s="$_" ; . ./lib.sh || if [ "$s" = "$0" ]; then exit 0; else return 0; fi
@ -34,6 +37,7 @@ module example-base{
yang-version 1.1; yang-version 1.1;
prefix base; prefix base;
namespace "urn:example:base"; namespace "urn:example:base";
grouping system-top {
container system { container system {
must "daytime or time"; /* deviate delete removes this */ must "daytime or time"; /* deviate delete removes this */
leaf daytime{ /* deviate not-supported removes this */ leaf daytime{ /* deviate not-supported removes this */
@ -61,6 +65,8 @@ module example-base{
} }
} }
} }
uses system-top;
}
EOF EOF
# Args: # Args:
@ -162,7 +168,7 @@ module example-deviations{
} }
} }
EOF EOF
new "1. daytime supported" new "1. Baseline: no deviations"
testrun true false true true testrun true false true true
# Example from RFC 7950 Sec 7.20.3.3 # Example from RFC 7950 Sec 7.20.3.3
@ -193,7 +199,7 @@ module example-deviations{
} }
deviation /base:system/base:user/base:type { deviation /base:system/base:user/base:type {
deviate add { deviate add {
default "admin"; // new users are 'admin' by default default "admin";
} }
} }
} }