diff --git a/apps/backend/backend_client.c b/apps/backend/backend_client.c index 8e89e848..939511b1 100644 --- a/apps/backend/backend_client.c +++ b/apps/backend/backend_client.c @@ -403,7 +403,11 @@ from_client_edit_config(clicon_handle h, ""); goto ok; } - + /* Cant do this earlier since we dont have a yang spec to + * the upper part of the tree, until we get the "config" tree. + */ + if (xml_child_sort && xml_apply0(xc, CX_ELMNT, xml_sort, NULL) < 0) + goto done; if (xmldb_put(h, target, operation, xc) < 0){ cprintf(cbret, "" "operation-failed" diff --git a/datastore/text/clixon_xmldb_text.c b/datastore/text/clixon_xmldb_text.c index cdf7aea8..da40df1d 100644 --- a/datastore/text/clixon_xmldb_text.c +++ b/datastore/text/clixon_xmldb_text.c @@ -474,9 +474,6 @@ text_get(xmldb_handle xh, if (singleconfigroot(xt, &xt) < 0) goto done; } - /* Sort XML children according to YANG */ - if (xml_child_sort && xml_apply0(xt, CX_ELMNT, xml_sort, NULL) < 0) - goto done; } /* xt == NULL */ /* Here xt looks like: ... */ @@ -540,11 +537,10 @@ text_get(xmldb_handle xh, /* Order XML children according to YANG */ if (!xml_child_sort && xml_apply(xt, CX_ELMNT, xml_order, NULL) < 0) goto done; - /* Again just so default values are placed correctly */ - if (xml_child_sort && xml_apply0(xt, CX_ELMNT, xml_sort, NULL) < 0) - goto done; +#if 0 /* debug */ if (xml_child_sort && xml_apply0(xt, -1, xml_sort_verify, NULL) < 0) clicon_log(LOG_NOTICE, "%s: verify failed #2", __FUNCTION__); +#endif if (debug>1) clicon_xml2file(stderr, xt, 0, 1); *xtop = xt; @@ -730,6 +726,7 @@ text_modify(cxobj *x0, } /* CONTAINER switch op */ } /* else Y_CONTAINER */ // ok: + xml_sort(x0p, NULL); retval = 0; done: if (x0vec) @@ -916,8 +913,10 @@ text_put(xmldb_handle xh, /* XXX: where is this created? Add yspec */ if (xml_apply(x1, CX_ELMNT, xml_spec_populate, yspec) < 0) goto done; - if (xml_child_sort && xml_apply0(x1, CX_ELMNT, xml_sort, NULL) < 0) - goto done; +#if 0 /* debug */ + if (xml_child_sort && xml_apply0(x1, -1, xml_sort_verify, NULL) < 0) + clicon_log(LOG_NOTICE, "%s: verify failed #1", __FUNCTION__); +#endif /* * Modify base tree x with modification x1. This is where the * new tree is made. @@ -937,9 +936,10 @@ text_put(xmldb_handle xh, /* Remove (prune) nodes that are marked (non-presence containers w/o children) */ if (xml_tree_prune_flagged(x0, XML_FLAG_MARK, 1) < 0) goto done; - if (xml_child_sort && xml_apply0(x0, CX_ELMNT, xml_sort, NULL) < 0) - goto done; - +#if 0 /* debug */ + if (xml_child_sort && xml_apply0(x0, -1, xml_sort_verify, NULL) < 0) + clicon_log(LOG_NOTICE, "%s: verify failed #3", __FUNCTION__); +#endif /* Write back to datastore cache if first time */ if (xmltree_cache){ struct db_element de0 = {0,}; diff --git a/lib/src/clixon_xml.c b/lib/src/clixon_xml.c index ae63e306..eefad00f 100644 --- a/lib/src/clixon_xml.c +++ b/lib/src/clixon_xml.c @@ -534,10 +534,10 @@ xml_childvec_get(cxobj *x) cxobj * xml_new(char *name, cxobj *xp, - yang_stmt *spec) + yang_stmt *yspec) { cxobj *x; - + if ((x = malloc(sizeof(cxobj))) == NULL){ clicon_err(OE_XML, errno, "%s: malloc", __FUNCTION__); return NULL; @@ -545,11 +545,12 @@ xml_new(char *name, memset(x, 0, sizeof(cxobj)); if ((xml_name_set(x, name)) < 0) return NULL; - - xml_parent_set(x, xp); - if (xp && xml_child_append(xp, x) < 0) - return NULL; - x->x_spec = spec; /* Can be NULL */ + if (xp){ + xml_parent_set(x, xp); + if (xml_child_append(xp, x) < 0) + return NULL; + } + x->x_spec = yspec; /* Can be NULL */ return x; } @@ -1212,8 +1213,8 @@ xmltree2cbuf(cbuf *cb, */ static int _xml_parse(const char *str, - yang_spec *yspec, - cxobj *xt) + yang_spec *yspec, + cxobj *xt) { int retval = -1; struct xml_parse_yacc_arg ya = {0,}; @@ -1233,6 +1234,13 @@ _xml_parse(const char *str, goto done; if (clixon_xml_parseparse(&ya) != 0) /* yacc returns 1 on error */ goto done; + /* Sort the complete tree after parsing */ + if (yspec){ + if (xml_apply0(xt, CX_ELMNT, xml_sort, NULL) < 0) + goto done; + if (xml_apply0(xt, -1, xml_sort_verify, NULL) < 0) + goto done; + } retval = 0; done: clixon_xml_parsel_exit(&ya); diff --git a/lib/src/clixon_xml_map.c b/lib/src/clixon_xml_map.c index 0cfdda27..bb910066 100644 --- a/lib/src/clixon_xml_map.c +++ b/lib/src/clixon_xml_map.c @@ -1206,6 +1206,7 @@ xml_default(cxobj *xt, } } } + xml_sort(xt, NULL); retval = 0; done: return retval; diff --git a/test/test_perf.sh b/test/test_perf.sh index a6a9087d..580b2d16 100755 --- a/test/test_perf.sh +++ b/test/test_perf.sh @@ -18,7 +18,6 @@ cfg=/tmp/scaling-conf.xml fyang=/tmp/scaling.yang fconfig=/tmp/config - # include err() and new() functions . ./lib.sh @@ -67,7 +66,7 @@ if [ $? -ne 0 ]; then err fi -new "start backend" +new "start backend -s init -f $cfg -y $fyang" # start new backend sudo clixon_backend -s init -f $cfg -y $fyang if [ $? -ne 0 ]; then