* Augment target node check strict, instead of printing a warning, it will terminate with error.

* Fixed: [Augment that reference a submodule as target node fails #178](https://github.com/clicon/clixon/issues/178)
* Fixed a memory error that was reported in slack by Pawel Maslanka
  * The crash printout was: `realloc(): invalid next size Aborted`
This commit is contained in:
Olof hagsand 2021-02-19 15:46:55 +01:00
parent 108f94cfad
commit 9840e248c6
12 changed files with 227 additions and 130 deletions

View file

@ -86,6 +86,7 @@ Developers may need to change their code
### Minor changes ### Minor changes
* Augment target node check strict, instead of printing a warning, it will terminate with error.
* Implemented: [Simplifying error messages for regex validations. #174](https://github.com/clicon/clixon/issues/174) * Implemented: [Simplifying error messages for regex validations. #174](https://github.com/clicon/clixon/issues/174)
* Add ca_reset plugin also when backend starts as `-s none` * Add ca_reset plugin also when backend starts as `-s none`
* Corrected client session handling to make internal IPC socket persistent * Corrected client session handling to make internal IPC socket persistent
@ -113,6 +114,9 @@ Developers may need to change their code
### Corrected Bugs ### Corrected Bugs
* Fixed: [Augment that reference a submodule as target node fails #178](https://github.com/clicon/clixon/issues/178)
* Fixed a memory error that was reported in slack by Pawel Maslanka
* The crash printout was: `realloc(): invalid next size Aborted`
* Fixed: [Irregular ordering of cli command + help text when integer is a part of command #176](https://github.com/clicon/clixon/issues/176) * Fixed: [Irregular ordering of cli command + help text when integer is a part of command #176](https://github.com/clicon/clixon/issues/176)
* Enabled by default `cligen_lexicalorder_set()` using strversmp instead of strcmp * Enabled by default `cligen_lexicalorder_set()` using strversmp instead of strcmp
* Fixed: [xml bind yang error in xml_bind_yang_rpc_reply #175](https://github.com/clicon/clixon/issues/175) * Fixed: [xml bind yang error in xml_bind_yang_rpc_reply #175](https://github.com/clicon/clixon/issues/175)

View file

@ -1011,7 +1011,8 @@ main(int argc,
/* Start session-id for clients */ /* Start session-id for clients */
clicon_session_id_set(h, 0); clicon_session_id_set(h, 0);
if (clicon_debug_get() && /* Enable this to get prints of datastore and session status */
if (0 && clicon_debug_get() &&
backend_timer_setup(0, h) < 0) backend_timer_setup(0, h) < 0)
goto done; goto done;
if (stream_timer_setup(0, h) < 0) if (stream_timer_setup(0, h) < 0)

View file

@ -695,7 +695,7 @@ usage(clicon_handle h,
fprintf(stderr, "usage:%s [options]\n" fprintf(stderr, "usage:%s [options]\n"
"where options are\n" "where options are\n"
"\t-h \t\t Help\n" "\t-h \t\t Help\n"
"\t-D <level>\t Debug level\n" "\t-D <level>\t Debug level _ overrides any config debug setting\n"
"\t-f <file>\t Configuration file (mandatory)\n" "\t-f <file>\t Configuration file (mandatory)\n"
"\t-E <dir> \t Extra configuration file directory\n" "\t-E <dir> \t Extra configuration file directory\n"
"\t-l <s|f<file>> \t Log on (s)yslog, (f)ile (syslog is default)\n" "\t-l <s|f<file>> \t Log on (s)yslog, (f)ile (syslog is default)\n"
@ -923,6 +923,7 @@ cx_evhtp_socket(clicon_handle h,
* @param[in] xconfig XML config * @param[in] xconfig XML config
* @param[in] nsc Namespace context * @param[in] nsc Namespace context
* @param[in] eh Evhtp handle * @param[in] eh Evhtp handle
* @param[in] dbg0 Manually set debug flag, if set overrides configuration setting
* @retval -1 Error * @retval -1 Error
* @retval 0 OK, but restconf disabled, proceed with other if possible * @retval 0 OK, but restconf disabled, proceed with other if possible
* @retval 1 OK * @retval 1 OK
@ -931,7 +932,8 @@ static int
cx_evhtp_init(clicon_handle h, cx_evhtp_init(clicon_handle h,
cxobj *xrestconf, cxobj *xrestconf,
cvec *nsc, cvec *nsc,
cx_evhtp_handle *eh) cx_evhtp_handle *eh,
int dbg0)
{ {
int retval = -1; int retval = -1;
int ssl_enable = 0; int ssl_enable = 0;
@ -962,7 +964,9 @@ cx_evhtp_init(clicon_handle h,
server_key_path = xml_body(x); server_key_path = xml_body(x);
if ((x = xpath_first(xrestconf, nsc, "server-ca-cert-path")) != NULL) if ((x = xpath_first(xrestconf, nsc, "server-ca-cert-path")) != NULL)
server_ca_cert_path = xml_body(x); server_ca_cert_path = xml_body(x);
if ((x = xpath_first(xrestconf, nsc, "debug")) != NULL && /* Only set debug from config if not set manually */
if (dbg0 == 0 &&
(x = xpath_first(xrestconf, nsc, "debug")) != NULL &&
(bstr = xml_body(x)) != NULL){ (bstr = xml_body(x)) != NULL){
dbg = atoi(bstr); dbg = atoi(bstr);
clicon_debug_init(dbg, NULL); clicon_debug_init(dbg, NULL);
@ -1022,12 +1026,14 @@ cx_evhtp_init(clicon_handle h,
* That is, EITHER local config OR read config from backend once * That is, EITHER local config OR read config from backend once
* @param[in] h Clicon handle * @param[in] h Clicon handle
* @param[in] eh Clixon's evhtp handle * @param[in] eh Clixon's evhtp handle
* @param[in] dbg0 Manually set debug flag, if set overrides configuration setting
* @retval 0 OK * @retval 0 OK
* @retval -1 Error * @retval -1 Error
*/ */
int int
restconf_config(clicon_handle h, restconf_config(clicon_handle h,
cx_evhtp_handle *eh) cx_evhtp_handle *eh,
int dbg)
{ {
int retval = -1; int retval = -1;
char *dir; char *dir;
@ -1139,7 +1145,7 @@ restconf_config(clicon_handle h,
/* First try to get restconf config from local config-file */ /* First try to get restconf config from local config-file */
if ((xrestconf1 = clicon_conf_restconf(h)) != NULL){ if ((xrestconf1 = clicon_conf_restconf(h)) != NULL){
/* Initialize evhtp with local config: ret 0 means disabled -> need to query remote */ /* Initialize evhtp with local config: ret 0 means disabled -> need to query remote */
if ((ret = cx_evhtp_init(h, xrestconf1, NULL, eh)) < 0) if ((ret = cx_evhtp_init(h, xrestconf1, NULL, eh, dbg)) < 0)
goto done; goto done;
if (ret == 1) if (ret == 1)
configure_done = 1; configure_done = 1;
@ -1175,7 +1181,7 @@ restconf_config(clicon_handle h,
/* Extract restconf configuration */ /* Extract restconf configuration */
if ((xrestconf2 = xpath_first(xconfig2, nsc, "restconf")) != NULL){ if ((xrestconf2 = xpath_first(xconfig2, nsc, "restconf")) != NULL){
/* Initialize evhtp with config from backend */ /* Initialize evhtp with config from backend */
if ((ret = cx_evhtp_init(h, xrestconf2, nsc, eh)) < 0) if ((ret = cx_evhtp_init(h, xrestconf2, nsc, eh, dbg)) < 0)
goto done; goto done;
if (ret == 1) if (ret == 1)
configure_done = 1; configure_done = 1;
@ -1221,7 +1227,7 @@ main(int argc,
case 'h': case 'h':
usage(h, argv0); usage(h, argv0);
break; break;
case 'D' : /* debug */ case 'D' : /* debug. Note this overrides any setting in the config */
if (sscanf(optarg, "%d", &dbg) != 1) if (sscanf(optarg, "%d", &dbg) != 1)
usage(h, argv0); usage(h, argv0);
break; break;
@ -1339,7 +1345,7 @@ main(int argc,
_EVHTP_HANDLE = eh; /* global */ _EVHTP_HANDLE = eh; /* global */
/* Read config */ /* Read config */
if (restconf_config(h, eh) < 0) if (restconf_config(h, eh, dbg) < 0)
goto done; goto done;
/* Drop privileges after evhtp and server key/cert read */ /* Drop privileges after evhtp and server key/cert read */
if (drop_privileges){ if (drop_privileges){

View file

@ -181,7 +181,7 @@ typedef int (yang_applyfn_t)(yang_stmt *ys, void *arg);
* leaf, leaf-list, list, choice, case, rpc, input, output, * leaf, leaf-list, list, choice, case, rpc, input, output,
* notification, anydata, and anyxml. * notification, anydata, and anyxml.
*/ */
#define yang_schemanode(y) (yang_datanode(y) || yang_keyword_get(y) == Y_RPC || yang_keyword_get(y) == Y_CHOICE || yang_keyword_get(y) == Y_CASE || yang_keyword_get(y) == Y_INPUT || yang_keyword_get(y) == Y_OUTPUT || yang_keyword_get(y) == Y_NOTIFICATION) #define yang_schemanode(y) (yang_datanode(y) || yang_keyword_get(y) == Y_RPC || yang_keyword_get(y) == Y_CHOICE || yang_keyword_get(y) == Y_CASE || yang_keyword_get(y) == Y_INPUT || yang_keyword_get(y) == Y_OUTPUT || yang_keyword_get(y) == Y_NOTIFICATION || yang_keyword_get(y) == Y_ACTION)
/* /*
* Prototypes * Prototypes

View file

@ -97,6 +97,7 @@ static int yang_search_index_extension(clicon_handle h, yang_stmt *yext, yang_st
* Here is also the place where doc on some types store variables (cv) * Here is also the place where doc on some types store variables (cv)
*/ */
static const map_str2int ykmap[] = { static const map_str2int ykmap[] = {
{"action", Y_ACTION},
{"anydata", Y_ANYDATA}, {"anydata", Y_ANYDATA},
{"anyxml", Y_ANYXML}, {"anyxml", Y_ANYXML},
{"argument", Y_ARGUMENT}, {"argument", Y_ARGUMENT},
@ -497,12 +498,15 @@ ys_prune(yang_stmt *yp,
if (i >= yp->ys_len) if (i >= yp->ys_len)
goto done; goto done;
size = (yp->ys_len - i - 1)*sizeof(struct yang_stmt *);
yc = yp->ys_stmt[i]; yc = yp->ys_stmt[i];
if (i < yp->ys_len - 1){
size = (yp->ys_len - i - 1)*sizeof(struct yang_stmt *);
memmove(&yp->ys_stmt[i], memmove(&yp->ys_stmt[i],
&yp->ys_stmt[i+1], &yp->ys_stmt[i+1],
size); size);
yp->ys_stmt[yp->ys_len--] = NULL; }
yp->ys_len--;
yp->ys_stmt[yp->ys_len] = NULL;
done: done:
return yc; return yc;
} }
@ -931,10 +935,16 @@ yang_find_schemanode(yang_stmt *yn,
for (i=0; i<yn->ys_len; i++){ for (i=0; i<yn->ys_len; i++){
ys = yn->ys_stmt[i]; ys = yn->ys_stmt[i];
if (ys->ys_keyword == Y_CHOICE){ /* Look for its children */ if (yang_keyword_get(ys) == Y_CHOICE){
/* First check choice itself */
if (ys->ys_argument && strcmp(argument, ys->ys_argument) == 0){
ysmatch = ys;
goto match;
}
/* Then look for its children (case) */
for (j=0; j<ys->ys_len; j++){ for (j=0; j<ys->ys_len; j++){
yc = ys->ys_stmt[j]; yc = ys->ys_stmt[j];
if (yc->ys_keyword == Y_CASE) /* Look for its children */ if (yang_keyword_get(yc) == Y_CASE) /* Look for its children */
ysmatch = yang_find_schemanode(yc, argument); ysmatch = yang_find_schemanode(yc, argument);
else else
if (yang_schemanode(yc)){ if (yang_schemanode(yc)){
@ -950,7 +960,9 @@ yang_find_schemanode(yang_stmt *yn,
} /* Y_CHOICE */ } /* Y_CHOICE */
else else
if (yang_schemanode(ys)){ if (yang_schemanode(ys)){
if (argument == NULL) if (yang_keyword_get(ys) == Y_INPUT || yang_keyword_get(ys) == Y_OUTPUT)
ysmatch = ys;
else if (argument == NULL)
ysmatch = ys; ysmatch = ys;
else else
if (ys->ys_argument && strcmp(argument, ys->ys_argument) == 0) if (ys->ys_argument && strcmp(argument, ys->ys_argument) == 0)
@ -1070,7 +1082,7 @@ yang_find_prefix_by_namespace(yang_stmt *ys,
yang_stmt *yimport; yang_stmt *yimport;
yang_stmt *yprefix; yang_stmt *yprefix;
clicon_debug(1, "%s", __FUNCTION__); clicon_debug(2, "%s", __FUNCTION__);
/* First check if namespace is my own module */ /* First check if namespace is my own module */
myns = yang_find_mynamespace(ys); myns = yang_find_mynamespace(ys);
if (strcmp(myns, ns) == 0){ if (strcmp(myns, ns) == 0){
@ -2559,7 +2571,6 @@ schema_nodeid_iterate(yang_stmt *yn,
char *prefix; /* node-identifier = [prefix ":"] identifier */ char *prefix; /* node-identifier = [prefix ":"] identifier */
char *id; char *id;
yang_stmt *ys; yang_stmt *ys;
yang_stmt *ym2;
yang_stmt *yp; yang_stmt *yp;
cg_var *cv; cg_var *cv;
char *ns; char *ns;
@ -2586,34 +2597,28 @@ schema_nodeid_iterate(yang_stmt *yn,
clicon_err(OE_YANG, EFAULT, "No module for namespace: %s", ns); clicon_err(OE_YANG, EFAULT, "No module for namespace: %s", ns);
goto done; goto done;
} }
/* Iterate over children of current node to get a match ys = yang_find_schemanode(yp, id);
* XXX namespace????? /* Special case: if rpc/action, an empty input/output may need to be created, it is optional but may
* still be referenced.
* XXX: maybe input/output should always be created when rpc/action is created?
*/ */
ys = NULL; if (ys == NULL &&
while ((ys = yn_each(yp, ys)) != NULL) { (yang_keyword_get(yp) == Y_RPC || yang_keyword_get(yp) == Y_ACTION) &&
if (!yang_schemanode(ys)) (strcmp(id, "input") == 0 || strcmp(id, "output") == 0)){
continue; enum rfc_6020 kw;
kw = clicon_str2int(ykmap, id);
/* some keys dont have arguments, match on key */ /* Add ys as id to yp */
if (ys->ys_keyword == Y_INPUT || ys->ys_keyword == Y_OUTPUT){ if ((ys = ys_new(kw)) == NULL)
if (strcmp(id, yang_key2str(ys->ys_keyword)) == 0){ goto done;
break; if (yn_insert(yp, ys) < 0) /* Insert into hierarchy */
goto done;
} }
}
else {
if (ys->ys_argument && strcmp(id, ys->ys_argument) == 0){
/* Also check for right prefix/module */
ym2 = ys->ys_mymodule?ys->ys_mymodule:ys_module(ys);
if (ym2 == ymod)
break;
}
}
} /* while ys */
if (ys == NULL){ if (ys == NULL){
clicon_debug(1, "%s: %s not found", __FUNCTION__, id); clicon_debug(1, "%s: %s not found", __FUNCTION__, id);
goto ok; goto ok;
} }
yp = ys; yp = ys; /* ys is matched */
} /* while cv */ } /* while cv */
assert(yp && yang_schemanode((yang_stmt*)yp)); assert(yp && yang_schemanode((yang_stmt*)yp));
*yres = (yang_stmt*)yp; *yres = (yang_stmt*)yp;

View file

@ -238,12 +238,18 @@ yang_augment_node(yang_stmt *ys)
goto done; goto done;
if (ytarget == NULL){ if (ytarget == NULL){
#if 0 /* Lots of yang models fail here */ #if 1
/* Fail with fatal error if augment target not found
* This is "correct"
*/
clicon_err(OE_YANG, 0, "Augment failed in module %s: target node %s not found", clicon_err(OE_YANG, 0, "Augment failed in module %s: target node %s not found",
yang_argument_get(ys_module(ys)), yang_argument_get(ys_module(ys)),
schema_nodeid); schema_nodeid);
goto done; goto done;
#else #else
/* Log a warning and proceed if augment target not found
* This may be necessary with some broken models
*/
clicon_log(LOG_WARNING, "Warning: Augment failed in module %s: target node %s not found", clicon_log(LOG_WARNING, "Warning: Augment failed in module %s: target node %s not found",
yang_argument_get(ys_module(ys)), yang_argument_get(ys_module(ys)),
schema_nodeid); schema_nodeid);
@ -276,7 +282,7 @@ yang_augment_node(yang_stmt *ys)
if (childkey != Y_ACTION && childkey != Y_NOTIFICATION && childkey != Y_UNKNOWN && if (childkey != Y_ACTION && childkey != Y_NOTIFICATION && childkey != Y_UNKNOWN &&
childkey != Y_CONTAINER && childkey != Y_LEAF && childkey != Y_LIST && childkey != Y_CONTAINER && childkey != Y_LEAF && childkey != Y_LIST &&
childkey != Y_LEAF_LIST && childkey != Y_USES && childkey != Y_CHOICE){ childkey != Y_LEAF_LIST && childkey != Y_USES && childkey != Y_CHOICE){
clicon_log(LOG_WARNING, "Warning: A Augment failed in module %s: node %s %d cannot be added to target node %s", clicon_log(LOG_WARNING, "Warning: Augment failed in module %s: node %s %d cannot be added to target node %s",
yang_argument_get(ys_module(ys)), yang_argument_get(ys_module(ys)),
yang_key2str(childkey), yang_key2str(childkey),
childkey, childkey,
@ -295,7 +301,7 @@ yang_augment_node(yang_stmt *ys)
if (childkey != Y_CONTAINER && childkey != Y_LEAF && childkey != Y_LIST && if (childkey != Y_CONTAINER && childkey != Y_LEAF && childkey != Y_LIST &&
childkey != Y_LEAF_LIST && childkey != Y_USES && childkey != Y_CHOICE && childkey != Y_LEAF_LIST && childkey != Y_USES && childkey != Y_CHOICE &&
childkey != Y_UNKNOWN){ childkey != Y_UNKNOWN){
clicon_log(LOG_WARNING, "Warning: B Augment failed in module %s: node %s %d cannot be added to target node %s", clicon_log(LOG_WARNING, "Warning: Augment failed in module %s: node %s %d cannot be added to target node %s",
yang_argument_get(ys_module(ys)), yang_argument_get(ys_module(ys)),
yang_key2str(childkey), yang_key2str(childkey),
childkey, childkey,
@ -316,7 +322,7 @@ yang_augment_node(yang_stmt *ys)
childkey != Y_CHOICE && childkey != Y_CONTAINER && childkey != Y_LEAF && childkey != Y_CHOICE && childkey != Y_CONTAINER && childkey != Y_LEAF &&
childkey != Y_LIST && childkey != Y_LEAF_LIST){ childkey != Y_LIST && childkey != Y_LEAF_LIST){
clicon_log(LOG_WARNING, "Warning: C Augment failed in module %s: node %s %d cannot be added to target node %s", clicon_log(LOG_WARNING, "Warning: Augment failed in module %s: node %s %d cannot be added to target node %s",
yang_argument_get(ys_module(ys)), yang_argument_get(ys_module(ys)),
yang_key2str(childkey), yang_key2str(childkey),
childkey, childkey,

View file

@ -259,10 +259,7 @@ if [ $RC -ne 0 ]; then
stop_restconf stop_restconf
fi fi
if [ $BE -eq 0 ]; then if [ $BE -ne 0 ]; then
exit # BE
fi
new "Kill backend" new "Kill backend"
# Check if premature kill # Check if premature kill
pid=`pgrep -u root -f clixon_backend` pid=`pgrep -u root -f clixon_backend`
@ -271,6 +268,7 @@ if [ -z "$pid" ]; then
fi fi
# kill backend # kill backend
stop_backend -f $cfg stop_backend -f $cfg
fi
# unset conditional parameters # unset conditional parameters
unset format unset format

View file

@ -85,6 +85,20 @@ module ietf-interfaces {
type uint16; type uint16;
} }
} }
/* Original choice that gets augmented */
choice target {
case stream {
leaf one{
type string;
}
}
}
notification started {
leaf id{
type string;
}
}
} }
EOF EOF
@ -145,6 +159,9 @@ module example-augment {
refine port { refine port {
default 80; default 80;
} }
refine ip {
description "double refine triggered mem error";
}
} }
uses localgroup { uses localgroup {
description "Use a local grouping defining lip and lport"; description "Use a local grouping defining lip and lport";
@ -153,7 +170,22 @@ module example-augment {
} }
} }
} }
/* augment choice */
augment "/if:target" {
case datastore {
leaf two{
type uint32;
} }
}
}
/* augment notification */
augment "/if:started" {
leaf argument{
type string;
}
}
}
EOF EOF
new "test params: -f $cfg" new "test params: -f $cfg"

View file

@ -66,6 +66,12 @@ module main{
type string; type string;
} }
} }
/* Augment something in sub module */
augment /ex:sub2 {
leaf aug0{
type string;
}
}
} }
EOF EOF
@ -87,6 +93,18 @@ submodule sub1 {
type string; type string;
} }
} }
/* Augment something in module */
augment /ex:main {
leaf aug1{
type string;
}
}
/* Augment something in another submodule */
augment /ex:sub2 {
leaf aug2{
type string;
}
}
} }
EOF EOF
@ -221,6 +239,15 @@ expectpart "$(curl $CURLOPTS -X POST -H "Content-Type: application/yang-data+jso
new "restconf check main/sub1/sub2 contents" new "restconf check main/sub1/sub2 contents"
expectpart "$(curl $CURLOPTS -X GET $RCPROTO://localhost/restconf/data?content=config)" 0 'HTTP/1.1 200 OK' '{"data":{"main:main":{"ext":"foo","x":"foo"},"main:sub1":{"ext1":"foo","x":"foo"},"main:sub2":{"ext2":"foo","x":"foo"}' expectpart "$(curl $CURLOPTS -X GET $RCPROTO://localhost/restconf/data?content=config)" 0 'HTTP/1.1 200 OK' '{"data":{"main:main":{"ext":"foo","x":"foo"},"main:sub1":{"ext1":"foo","x":"foo"},"main:sub2":{"ext2":"foo","x":"foo"}'
new "restconf edit augment 0"
expectpart "$(curl $CURLOPTS -X POST -H "Content-Type: application/yang-data+json" $RCPROTO://localhost/restconf/data/main:sub2 -d '{"main:aug0":"foo"}')" 0 'HTTP/1.1 201 Created'
new "restconf edit augment 1"
expectpart "$(curl $CURLOPTS -X POST -H "Content-Type: application/yang-data+json" $RCPROTO://localhost/restconf/data/main:main -d '{"main:aug1":"foo"}')" 0 'HTTP/1.1 201 Created'
new "restconf edit augment 2"
expectpart "$(curl $CURLOPTS -X POST -H "Content-Type: application/yang-data+json" $RCPROTO://localhost/restconf/data/main:sub2 -d '{"main:aug2":"foo"}')" 0 'HTTP/1.1 201 Created'
if [ $RC -ne 0 ]; then if [ $RC -ne 0 ]; then
new "Kill restconf daemon" new "Kill restconf daemon"
stop_restconf stop_restconf

View file

@ -1,20 +1,10 @@
#!/usr/bin/env bash #!/usr/bin/env bash
# Parse yangmodels from https://github.com/YangModels/yang # Parse "all" IEEE yangmodels from https://github.com/YangModels/yang/standard/ietf/RFC
# Notes: # Notes:
# - Only a simple smoketest (CLI check) is made, A full system may not work
# - Env variable YANGMODELS should point to checkout place. (define it in site.sh for example) # - Env variable YANGMODELS should point to checkout place. (define it in site.sh for example)
# - Only cisco/nx/9.2-2 # Many other versions # - Some FEATURES are set to make it work
# - Only cisco/xe/1631 # Many other versions # - Some DIFFs are necessary in yangmodels (see end of script)
# - Only cisco/xr/530 # Many other versions
# - Only juniper/18.2/18.2R/junos # Many other versions and platoforms
# These are the test scripts:
#./experimental/ieee/check.sh
#./standard/ieee/check.sh
#./standard/ietf/check.sh
#./vendor/cisco/xr/check.sh
#./vendor/cisco/check.sh
#./vendor/cisco/xe/check.sh
#./vendor/cisco/nx/check.sh
# 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
@ -35,27 +25,24 @@ cat <<EOF > $cfg
<clixon-config xmlns="http://clicon.org/config"> <clixon-config xmlns="http://clicon.org/config">
<CLICON_CONFIGFILE>$cfg</CLICON_CONFIGFILE> <CLICON_CONFIGFILE>$cfg</CLICON_CONFIGFILE>
<CLICON_FEATURE>ni-ieee1588-ptp:cmlds</CLICON_FEATURE> <CLICON_FEATURE>ni-ieee1588-ptp:cmlds</CLICON_FEATURE>
<CLICON_FEATURE>ietf-alarms:alarm-shelving</CLICON_FEATURE> <CLICON_YANG_DIR>/usr/local/share/clixon</CLICON_YANG_DIR>
<CLICON_YANG_DIR>$YANGMODELS/standard/ietf/RFC</CLICON_YANG_DIR> <CLICON_YANG_DIR>$YANGMODELS/standard/ietf/RFC</CLICON_YANG_DIR>
<CLICON_YANG_DIR>$YANGMODELS/standard/ieee/draft/802.1/Qcr</CLICON_YANG_DIR> <CLICON_YANG_DIR>$YANGMODELS/standard/ieee/draft/802.1/Qcr</CLICON_YANG_DIR>
<CLICON_YANG_DIR>$YANGMODELS/standard/ieee/draft/802</CLICON_YANG_DIR> <CLICON_YANG_DIR>$YANGMODELS/standard/ieee/draft/802</CLICON_YANG_DIR>
<CLICON_YANG_DIR>$YANGMODELS/standard/ieee/draft/802</CLICON_YANG_DIR>
<CLICON_YANG_DIR>$YANGMODELS/standard/ieee/published/802.1</CLICON_YANG_DIR> <CLICON_YANG_DIR>$YANGMODELS/standard/ieee/published/802.1</CLICON_YANG_DIR>
<CLICON_YANG_DIR>$YANGMODELS/standard/ieee/published/802</CLICON_YANG_DIR> <CLICON_YANG_DIR>$YANGMODELS/standard/ieee/published/802</CLICON_YANG_DIR>
<CLICON_YANG_DIR>/usr/local/share/clixon</CLICON_YANG_DIR>
<CLICON_YANG_LIST_CHECK>false</CLICON_YANG_LIST_CHECK>
<CLICON_CLISPEC_DIR>/usr/local/lib/$APPNAME/clispec</CLICON_CLISPEC_DIR> <CLICON_CLISPEC_DIR>/usr/local/lib/$APPNAME/clispec</CLICON_CLISPEC_DIR>
<CLICON_CLI_DIR>/usr/local/lib/$APPNAME/cli</CLICON_CLI_DIR> <CLICON_CLI_DIR>/usr/local/lib/$APPNAME/cli</CLICON_CLI_DIR>
<CLICON_CLI_MODE>$APPNAME</CLICON_CLI_MODE> <CLICON_CLI_MODE>$APPNAME</CLICON_CLI_MODE>
<CLICON_SOCK>/usr/local/var/$APPNAME/$APPNAME.sock</CLICON_SOCK> <CLICON_SOCK>/usr/local/var/$APPNAME/$APPNAME.sock</CLICON_SOCK>
<CLICON_BACKEND_PIDFILE>/usr/local/var/$APPNAME/$APPNAME.pidfile</CLICON_BACKEND_PIDFILE> <CLICON_BACKEND_PIDFILE>/usr/local/var/$APPNAME/$APPNAME.pidfile</CLICON_BACKEND_PIDFILE>
<CLICON_XMLDB_DIR>/usr/local/var/$APPNAME</CLICON_XMLDB_DIR> <CLICON_XMLDB_DIR>/usr/local/var/$APPNAME</CLICON_XMLDB_DIR>
<CLICON_MODULE_LIBRARY_RFC7895>true</CLICON_MODULE_LIBRARY_RFC7895>
</clixon-config> </clixon-config>
EOF EOF
new "yangmodels parse: -f $cfg" new "yangmodels parse: -f $cfg"
new "yangmodel Experimental IEEE 802.1: $YANGMODELS/experimental/ieee/802.1" new "yangmodel Experimental IEEE 802.1: $YANGMODELS/experimental/ieee/802.1"
expectpart "$($clixon_cli -D $DBG -1f $cfg -o CLICON_YANG_MAIN_DIR=$YANGMODELS/experimental/ieee/802.1 -p $YANGMODELS/experimental/ieee/1588 show version)" 0 "$version." expectpart "$($clixon_cli -D $DBG -1f $cfg -o CLICON_YANG_MAIN_DIR=$YANGMODELS/experimental/ieee/802.1 -p $YANGMODELS/experimental/ieee/1588 show version)" 0 "$version."
@ -85,56 +72,22 @@ expectpart "$($clixon_cli -D $DBG -1f $cfg -o CLICON_YANG_MAIN_DIR=$YANGMODELS/s
new "yangmodel Standard IEEE 802.1: $YANGMODELS/standard/ieee/published/802.3" new "yangmodel Standard IEEE 802.1: $YANGMODELS/standard/ieee/published/802.3"
expectpart "$($clixon_cli -D $DBG -1f $cfg -o CLICON_YANG_MAIN_DIR=$YANGMODELS/standard/ieee/published/802.3 show version)" 0 "$version." expectpart "$($clixon_cli -D $DBG -1f $cfg -o CLICON_YANG_MAIN_DIR=$YANGMODELS/standard/ieee/published/802.3 show version)" 0 "$version."
# Standard IETF
# XXX fails on augmenting "action"
new "yangmodel Standard IETF: $YANGMODELS/standard/ietf/RFC"
expectpart "$($clixon_cli -D $DBG -1f $cfg -o CLICON_YANG_MAIN_DIR=$YANGMODELS/standard/ietf/RFC show version)" 0 "$version."
# vendor/junos
#junos : M/MX, T/TX, Some EX platforms, ACX
#junos-es : SRX, Jseries, LN-*
#junos-ex : EX series
#junos-qfx : QFX series
#junos-nfx : NFX series
# Juniper JunOS. Junos files have 4 lines copyright, then "<space>module" on
# line 5. No sub-modules.
# NOTE: We DISABLE CLI generation, because some juniper are very large.
# and cli generation consumes memory.
# For example (100K lines):
#wc /usr/local/share/yangmodels/vendor/juniper/18.2/18.2R1/junos/conf/junos-conf-system@2018-01-01.yang
# 92853 274279 3228229 /usr/local/share/yangmodels/vendor/juniper/18.2/18.2R1/junos/conf/junos-conf-system@2018-01-01.yan
# But junos-conf-logical-systems@2018-01-01.yang takes longest time
files=$(find $YANGMODELS/vendor/juniper/18.2/18.2R1/junos/conf -name "*.yang")
let i=0;
for f in $files; do
if [ -n "$(head -5 $f|grep '^ module')" ]; then
new "$clixon_cli -1f $cfg -o CLICON_YANG_MAIN_FILE=$f -p $YANGMODELS/vendor/juniper/18.2/18.2R1/common -p $YANGMODELS/vendor/juniper/18.2/18.2R1/junos/conf show version"
expectpart "$($clixon_cli -D $DBG -1f $cfg -o CLICON_YANG_MAIN_FILE=$f -p $YANGMODELS/vendor/juniper/18.2/18.2R1/common -p $YANGMODELS/vendor/juniper/18.2/18.2R1/junos/conf -o CLICON_CLI_GENMODEL=0 show version)" 0 "$version."
let i++;
sleep 1
fi
done
# We skip CISCO because we have errors that vilates the RFC (I think)
# eg: Test 7(7) [yangmodel vendor cisco xr 623: /usr/local/share/yangmodels/vendor/cisco/xr/623]
# yang_abs_schema_nodeid: Absolute schema nodeid /bgp-rib/afi-safis/afi-safi/ipv4-unicast/loc-rib must have prefix
if false; then
# vendor/cisco/xr
new "yangmodel vendor cisco xr 623: $YANGMODELS/vendor/cisco/xr/623"
expectpart "$($clixon_cli -D $DBG -1f $cfg -o CLICON_YANG_MAIN_DIR=$YANGMODELS/vendor/cisco/xr/623 show version)" 0 "$version."
new "yangmodel vendor cisco xr 632: $YANGMODELS/vendor/cisco/xr/632"
expectpart "$($clixon_cli -D $DBG -1f $cfg -o CLICON_YANG_MAIN_DIR=$YANGMODELS/vendor/cisco/xr/632 show version)" 0 "$version."
new "yangmodel vendor cisco xr 623: $YANGMODELS/vendor/cisco/xr/642"
expectpart "$($clixon_cli -D $DBG -1f $cfg -o CLICON_YANG_MAIN_DIR=$YANGMODELS/vendor/cisco/xr/642 show version)" 0 "$version."
new "yangmodel vendor cisco xr 651: $YANGMODELS/vendor/cisco/xr/651"
expectpart "$($clixon_cli -D $DBG -1f $cfg -o CLICON_YANG_MAIN_DIR=$YANGMODELS/vendor/cisco/xr/651 show version)" 0 "$version."
fi ### cisco
rm -rf $dir rm -rf $dir
exit 0
# Diff to make it work
diff --git a/standard/ieee/published/802.3/ieee802-ethernet-pon.yang b/standard/ieee/published/802.3/ieee802-ethernet-pon.yang
index 37c54c2a..a56b5f50 100755
--- a/standard/ieee/published/802.3/ieee802-ethernet-pon.yang
+++ b/standard/ieee/published/802.3/ieee802-ethernet-pon.yang
@@ -2421,7 +2421,7 @@ module ieee802-ethernet-pon {
}
leaf mpcp-maximum-queue-count-per-report {
- when "../ompe-mode = olt'";
+ when "../ompe-mode = 'olt'";^M
type mpcp-maximum-queue-count-per-report;
config false;

65
test/test_yang_models_ietf.sh Executable file
View file

@ -0,0 +1,65 @@
#!/usr/bin/env bash
# Parse "all" IETF yangmodels from https://github.com/YangModels/yang/standard/ieee and experimental/ieee
# Notes:
# - Only a simple smoketest (CLI check) is made, A full system may not work
# - Env variable YANGMODELS should point to checkout place. (define it in site.sh for example)
# - Some FEATURES are set to make it work
# - Some DIFFs are necessary in yangmodels (see end of script)
# Magic line must be first in script (see README.md)
s="$_" ; . ./lib.sh || if [ "$s" = $0 ]; then exit 0; else return 0; fi
# Yang specifics: multi-keys and empty type
APPNAME=example
cfg=$dir/conf_yang.xml
fyang=$dir/test.yang
YANGMODELS=/home/olof/tmp/yang
if [ ! -d "$YANGMODELS" ]; then
# err "Hmm Yangmodels dir does not seem to exist, try git clone https://github.com/YangModels/yang?"
if [ "$s" = $0 ]; then exit 0; else return 0; fi
fi
cat <<EOF > $cfg
<clixon-config xmlns="http://clicon.org/config">
<CLICON_CONFIGFILE>$cfg</CLICON_CONFIGFILE>
<CLICON_FEATURE>ietf-alarms:alarm-shelving</CLICON_FEATURE>
<CLICON_FEATURE>ietf-subscribed-notifications:configured</CLICON_FEATURE>
<CLICON_FEATURE>ietf-subscribed-notifications:replay</CLICON_FEATURE>
<CLICON_FEATURE>ietf-access-control-list:match-on-tcp</CLICON_FEATURE>
<CLICON_YANG_DIR>/usr/local/share/clixon</CLICON_YANG_DIR>
<CLICON_YANG_DIR>$YANGMODELS/standard/ieee/published/802.1</CLICON_YANG_DIR>
<CLICON_CLISPEC_DIR>/usr/local/lib/$APPNAME/clispec</CLICON_CLISPEC_DIR>
<CLICON_CLI_DIR>/usr/local/lib/$APPNAME/cli</CLICON_CLI_DIR>
<CLICON_CLI_MODE>$APPNAME</CLICON_CLI_MODE>
<CLICON_SOCK>/usr/local/var/$APPNAME/$APPNAME.sock</CLICON_SOCK>
<CLICON_BACKEND_PIDFILE>/usr/local/var/$APPNAME/$APPNAME.pidfile</CLICON_BACKEND_PIDFILE>
<CLICON_XMLDB_DIR>/usr/local/var/$APPNAME</CLICON_XMLDB_DIR>
</clixon-config>
EOF
# Standard IETF
new "yangmodel Standard IETF: $YANGMODELS/standard/ietf/RFC"
echo "$clixon_cli -D $DBG -1f $cfg -o CLICON_YANG_MAIN_DIR=$YANGMODELS/standard/ietf/RFC show version"
expectpart "$($clixon_cli -D $DBG -1f $cfg -o CLICON_YANG_MAIN_DIR=$YANGMODELS/standard/ietf/RFC show version)" 0 "$version."
rm -rf $dir
exit 0
# Diff to make it work
diff --git a/standard/ietf/RFC/ietf-mud@2019-01-28.yang b/standard/ietf/RFC/ietf-mud@2019-01-28.yang
index 1842284e..4197ad46 100644
--- a/standard/ietf/RFC/ietf-mud@2019-01-28.yang
+++ b/standard/ietf/RFC/ietf-mud@2019-01-28.yang
@@ -297,7 +297,7 @@ module ietf-mud {
}
}
augment "/acl:acls/acl:acl/acl:aces/acl:ace/acl:matches"
- + "/acl:l4/acl:tcp/acl:tcp" {
+ + "/acl:l4/acl:tcp" { /* Olof: rm extra /acl:tcp */
description
"add direction-initiated";
leaf direction-initiated {