diff --git a/lib/src/clixon_datastore_write.c b/lib/src/clixon_datastore_write.c index 12879c6d..2875b40a 100644 --- a/lib/src/clixon_datastore_write.c +++ b/lib/src/clixon_datastore_write.c @@ -191,6 +191,8 @@ check_body_namespace(cxobj *x0, cxobj *x; int isroot; cbuf *cberr = NULL; + yang_stmt *yspec = NULL; + yang_stmt *yns = NULL; /* XXX: need to identify root better than hiereustics and strcmp,... */ isroot = xml_parent(x0p)==NULL && @@ -240,7 +242,21 @@ check_body_namespace(cxobj *x0, else if (ns0 == NULL && ns1 != NULL){ /* namespace exists in x1 but not in x0: OK (but request is realy invalid */ } #endif - else{ /* Namespace does not exist in x0: error */ + else{ /* Namespace does not exist in x0 or x1: try YANG, else error */ + if (y && (yspec = ys_spec(y)) != NULL && + (yns = yang_find_module_by_prefix_yspec(yspec, prefix)) != NULL && + (ns0 = yang_find_mynamespace(yns)) != NULL){ + if (isroot) + x = x0; + else + x = x0p; + if (nscache_set(x, prefix, ns0) < 0) + goto done; + if (xml_add_attr(x, prefix, ns0, "xmlns", NULL) == NULL) + goto done; + xml_sort(x); + goto ok; + } if ((cberr = cbuf_new()) == NULL){ clixon_err(OE_UNIX, errno, "cbuf_new"); goto done; diff --git a/test/test_openconfig_spanning_tree_enabled_protocol.sh b/test/test_openconfig_spanning_tree_enabled_protocol.sh new file mode 100644 index 00000000..0a73ff8b --- /dev/null +++ b/test/test_openconfig_spanning_tree_enabled_protocol.sh @@ -0,0 +1,69 @@ +#!/usr/bin/env bash +# Verify openconfig-spanning-tree enabled-protocol identityref resolves oc-stp-types prefix. +# Reproduces CLI error: "prefix \"oc-stp-types\" has no associated namespace" + +# Magic line must be first in script (see README.md) +s="$_" +. ./lib.sh || if [ "$s" = $0 ]; then exit 0; else return 0; fi + +APPNAME=example + +new "openconfig" +if [ ! -d "$OPENCONFIG" ]; then + # err "Hmm Openconfig dir does not seem to exist, try git clone https://github.com/openconfig/public?" + echo "...skipped: OPENCONFIG not set" + rm -rf $dir + if [ "$s" = $0 ]; then exit 0; else return 0; fi +fi + +OCSTP=$OPENCONFIG/release/models/stp/openconfig-spanning-tree.yang +cfg=$dir/openconfig_spanning_tree_enabled_protocol.xml + +AUTOCLI=$(autocli_config "*" kw-nokey false) + +cat <$cfg + + $cfg + ${OPENCONFIG} + ${YANG_INSTALLDIR} + $OCSTP + true + /usr/local/lib/$APPNAME/clispec + /usr/local/lib/$APPNAME/cli + $APPNAME + /usr/local/var/run/$APPNAME.sock + /usr/local/var/run/$APPNAME.pidfile + $dir + $AUTOCLI + +EOF + +if [ $BE -ne 0 ]; then + new "kill old backend" + sudo clixon_backend -zf $cfg + new "start backend -s init -f $cfg" + start_backend -s init -f $cfg +fi + +new "wait backend" +wait_backend + +new "cli set stp global enabled-protocol identityref" +expectpart "$($clixon_cli -1 -f $cfg set stp global config enabled-protocol oc-stp-types:MSTP 2>&1)" 0 "^$" + +new "discard-changes" +expecteof_netconf "$clixon_netconf -qf $cfg" 0 "$DEFAULTHELLO" "" "" "" + +if [ $BE -ne 0 ]; then + new "Kill backend" + pid=$(pgrep -u root -f clixon_backend) + if [ -z "$pid" ]; then + err "backend already dead" + fi + stop_backend -f $cfg +fi + +rm -rf $dir + +new "endtest" +endtest