Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
18 changes: 17 additions & 1 deletion lib/src/clixon_datastore_write.c
Original file line number Diff line number Diff line change
Expand Up @@ -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 &&
Expand Down Expand Up @@ -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;
Expand Down
69 changes: 69 additions & 0 deletions test/test_openconfig_spanning_tree_enabled_protocol.sh
Original file line number Diff line number Diff line change
@@ -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 <<EOF >$cfg
<clixon-config xmlns="http://clicon.org/config">
<CLICON_CONFIGFILE>$cfg</CLICON_CONFIGFILE>
<CLICON_YANG_DIR>${OPENCONFIG}</CLICON_YANG_DIR>
<CLICON_YANG_DIR>${YANG_INSTALLDIR}</CLICON_YANG_DIR>
<CLICON_YANG_MAIN_FILE>$OCSTP</CLICON_YANG_MAIN_FILE>
<CLICON_YANG_AUGMENT_ACCEPT_BROKEN>true</CLICON_YANG_AUGMENT_ACCEPT_BROKEN>
<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/run/$APPNAME.sock</CLICON_SOCK>
<CLICON_BACKEND_PIDFILE>/usr/local/var/run/$APPNAME.pidfile</CLICON_BACKEND_PIDFILE>
<CLICON_XMLDB_DIR>$dir</CLICON_XMLDB_DIR>
$AUTOCLI
</clixon-config>
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" "<rpc $DEFAULTNS><discard-changes/></rpc>" "" "<rpc-reply $DEFAULTNS><ok/></rpc-reply>"

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