Fixed: [default state data returned with get-config](https://github.com/clicon/clixon/issues/140)
* Generalized default code for both config and state
This commit is contained in:
parent
da54dae396
commit
9984cfa1c8
15 changed files with 344 additions and 39 deletions
263
test/test_augment_state.sh
Executable file
263
test/test_augment_state.sh
Executable file
|
|
@ -0,0 +1,263 @@
|
|||
#!/usr/bin/env bash
|
||||
# Test augmented state
|
||||
# Use main example -- -sS option to add state via a file
|
||||
#
|
||||
# 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
|
||||
|
||||
cfg=$dir/conf_yang.xml
|
||||
fyang=$dir/example-augment.yang
|
||||
fyang2=$dir/example-lib.yang
|
||||
fstate=$dir/state.xml
|
||||
|
||||
cat <<EOF > $cfg
|
||||
<clixon-config xmlns="http://clicon.org/config">
|
||||
<CLICON_CONFIGFILE>$cfg</CLICON_CONFIGFILE>
|
||||
<CLICON_FEATURE>a:test</CLICON_FEATURE>
|
||||
<CLICON_YANG_DIR>$dir</CLICON_YANG_DIR>
|
||||
<CLICON_YANG_DIR>/usr/local/share/clixon</CLICON_YANG_DIR>
|
||||
<CLICON_YANG_MAIN_FILE>$fyang</CLICON_YANG_MAIN_FILE>
|
||||
<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_BACKEND_DIR>/usr/local/lib/$APPNAME/backend</CLICON_BACKEND_DIR>
|
||||
<CLICON_RESTCONF_PRETTY>false</CLICON_RESTCONF_PRETTY>
|
||||
<CLICON_XMLDB_DIR>/usr/local/var/$APPNAME</CLICON_XMLDB_DIR>
|
||||
<CLICON_MODULE_LIBRARY_RFC7895>false</CLICON_MODULE_LIBRARY_RFC7895>
|
||||
</clixon-config>
|
||||
EOF
|
||||
|
||||
# This is the lib function with the base container
|
||||
cat <<EOF > $fyang2
|
||||
module example-lib {
|
||||
yang-version 1.1;
|
||||
namespace "urn:example:lib";
|
||||
revision "2019-03-04";
|
||||
prefix lib;
|
||||
container global-state {
|
||||
config false;
|
||||
leaf gbds{
|
||||
description "Global base default state";
|
||||
type string;
|
||||
default "gbds";
|
||||
}
|
||||
leaf gbos{
|
||||
description "Global base optional state";
|
||||
type string;
|
||||
}
|
||||
container nopres{
|
||||
description "This should be removed";
|
||||
}
|
||||
}
|
||||
container base-config {
|
||||
list parameter{
|
||||
key name;
|
||||
leaf name{
|
||||
type string;
|
||||
}
|
||||
container param-state {
|
||||
config false;
|
||||
leaf lbds{
|
||||
description "Local base default state";
|
||||
type string;
|
||||
default "lbds";
|
||||
}
|
||||
leaf lbos{
|
||||
description "Local base optional state";
|
||||
type string;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
EOF
|
||||
|
||||
# This is the main module where the augment exists
|
||||
cat <<EOF > $fyang
|
||||
module example-augment {
|
||||
yang-version 1.1;
|
||||
namespace "urn:example:augment";
|
||||
prefix aug;
|
||||
revision "2020-09-25";
|
||||
import example-lib {
|
||||
prefix lib;
|
||||
}
|
||||
/* Augments global state */
|
||||
augment "/lib:global-state" {
|
||||
leaf gads{
|
||||
description "Global augmented default state";
|
||||
type string;
|
||||
default "gads";
|
||||
}
|
||||
leaf gaos{
|
||||
description "Global augmented optional state";
|
||||
type string;
|
||||
}
|
||||
}
|
||||
/* Augments state in config in-line */
|
||||
augment "/lib:base-config/lib:parameter/lib:param-state" {
|
||||
leaf lads{
|
||||
description "Local augmented default state";
|
||||
type string;
|
||||
default "lads";
|
||||
}
|
||||
leaf laos{
|
||||
description "Local augmented optional state";
|
||||
type string;
|
||||
}
|
||||
}
|
||||
}
|
||||
EOF
|
||||
|
||||
# Get config and state
|
||||
# Arguments
|
||||
# - expected config
|
||||
# - expected state
|
||||
testrun()
|
||||
{
|
||||
config=$1
|
||||
state=$2
|
||||
|
||||
new "get config"
|
||||
if [ -z "$config" ]; then
|
||||
expecteof "$clixon_netconf -qf $cfg" 0 "<rpc $DEFAULTNS><get-config><source><running/></source></get-config></rpc>]]>]]>" "^<rpc-reply $DEFAULTNS><data/></rpc-reply>]]>]]>$"
|
||||
else
|
||||
expecteof "$clixon_netconf -qf $cfg" 0 "<rpc $DEFAULTNS><get-config><source><running/></source></get-config></rpc>]]>]]>" "^<rpc-reply $DEFAULTNS><data>$config</data></rpc-reply>]]>]]>$"
|
||||
fi
|
||||
|
||||
new "get state"
|
||||
expecteof "$clixon_netconf -qf $cfg" 0 "<rpc $DEFAULTNS><get/></rpc>]]>]]>" "^<rpc-reply $DEFAULTNS><data>$state</data></rpc-reply>]]>]]>$"
|
||||
}
|
||||
|
||||
new "test params: -f $cfg"
|
||||
|
||||
if [ $BE -ne 0 ]; then
|
||||
new "kill old backend"
|
||||
sudo clixon_backend -zf $cfg
|
||||
if [ $? -ne 0 ]; then
|
||||
err
|
||||
fi
|
||||
new "start backend -s init -f $cfg -- -sS $fstate"
|
||||
start_backend -s init -f $cfg -- -sS $fstate
|
||||
fi
|
||||
new "waiting"
|
||||
wait_backend
|
||||
|
||||
|
||||
#-----------------------------
|
||||
new "1. Empty config/state, expect global default state"
|
||||
|
||||
CONFIG=""
|
||||
|
||||
cat <<EOF > $fstate
|
||||
EOF
|
||||
|
||||
EXPSTATE=$(cat <<EOF
|
||||
<global-state xmlns="urn:example:lib"><gbds>gbds</gbds><aug:gads xmlns:aug="urn:example:augment">gads</aug:gads></global-state>
|
||||
EOF
|
||||
)
|
||||
|
||||
testrun "$CONFIG" "$EXPSTATE"
|
||||
|
||||
#-----------------------------
|
||||
new "2. Empty config/top-level state, expect global default state"
|
||||
cat <<EOF > $fstate
|
||||
<global-state xmlns="urn:example:lib"/>
|
||||
EOF
|
||||
|
||||
testrun "$CONFIG" "$EXPSTATE"
|
||||
|
||||
#-----------------------------
|
||||
new "3. Empty config/top-level w non-presence state, expect global default state"
|
||||
cat <<EOF > $fstate
|
||||
<global-state xmlns="urn:example:lib">
|
||||
<nopres/>
|
||||
</global-state>
|
||||
EOF
|
||||
|
||||
testrun "$CONFIG" "$EXPSTATE"
|
||||
|
||||
#-----------------------------
|
||||
new "4. Empty config + optional state, expect global default + optional state"
|
||||
cat <<EOF > $fstate
|
||||
<global-state xmlns="urn:example:lib">
|
||||
<gbos>gbos</gbos>
|
||||
<aug:gaos xmlns:aug="urn:example:augment">gaos</aug:gaos>
|
||||
</global-state>
|
||||
EOF
|
||||
|
||||
EXPSTATE=$(cat <<EOF
|
||||
<global-state xmlns="urn:example:lib"><gbds>gbds</gbds><gbos>gbos</gbos><aug:gads xmlns:aug="urn:example:augment">gads</aug:gads><aug:gaos xmlns:aug="urn:example:augment">gaos</aug:gaos></global-state>
|
||||
EOF
|
||||
)
|
||||
|
||||
testrun "$CONFIG" "$EXPSTATE"
|
||||
|
||||
#-----------------------------
|
||||
# From here, add a config tree
|
||||
new "5. Config tree, empty top state, expect default top state and default local state"
|
||||
|
||||
CONFIG=$(cat <<EOF
|
||||
<base-config xmlns="urn:example:lib"><parameter><name>a</name></parameter></base-config>
|
||||
EOF
|
||||
)
|
||||
|
||||
cat <<EOF > $fstate
|
||||
EOF
|
||||
|
||||
EXPSTATE=$(cat <<EOF
|
||||
<global-state xmlns="urn:example:lib"><gbds>gbds</gbds><aug:gads xmlns:aug="urn:example:augment">gads</aug:gads></global-state><base-config xmlns="urn:example:lib"><parameter><name>a</name><param-state><lbds>lbds</lbds><aug:lads xmlns:aug="urn:example:augment">lads</aug:lads></param-state></parameter></base-config>
|
||||
EOF
|
||||
)
|
||||
|
||||
new "Add config"
|
||||
expecteof "$clixon_netconf -qf $cfg" 0 "<rpc $DEFAULTNS><edit-config><target><candidate/></target><config>$CONFIG</config></edit-config></rpc>]]>]]>" "^<rpc-reply $DEFAULTNS><ok/></rpc-reply>]]>]]>"
|
||||
|
||||
new "netconf commit"
|
||||
expecteof "$clixon_netconf -qf $cfg" 0 "<rpc $DEFAULTNS><commit/></rpc>]]>]]>" "^<rpc-reply $DEFAULTNS><ok/></rpc-reply>]]>]]>$"
|
||||
|
||||
testrun "$CONFIG" "$EXPSTATE"
|
||||
|
||||
#-----------------------------
|
||||
|
||||
new "6. Config tree and optional tree state, empty top state, expect default top state and default local state"
|
||||
|
||||
cat <<EOF > $fstate
|
||||
<base-config xmlns="urn:example:lib">
|
||||
<parameter>
|
||||
<name>a</name>
|
||||
<param-state>
|
||||
<lbos>lbos</lbos>
|
||||
<laos xmlns="urn:example:augment">laos</laos>
|
||||
</param-state>
|
||||
</parameter>
|
||||
</base-config>
|
||||
EOF
|
||||
|
||||
EXPSTATE=$(cat <<EOF
|
||||
<global-state xmlns="urn:example:lib"><gbds>gbds</gbds><aug:gads xmlns:aug="urn:example:augment">gads</aug:gads></global-state><base-config xmlns="urn:example:lib"><parameter><name>a</name><param-state><lbds>lbds</lbds><lbos>lbos</lbos><aug:lads xmlns:aug="urn:example:augment">lads</aug:lads><laos xmlns="urn:example:augment">laos</laos></param-state></parameter></base-config>
|
||||
EOF
|
||||
)
|
||||
|
||||
testrun "$CONFIG" "$EXPSTATE"
|
||||
|
||||
#-----------------------------
|
||||
|
||||
if [ $BE -eq 0 ]; then
|
||||
exit # BE
|
||||
fi
|
||||
|
||||
new "Kill backend"
|
||||
# Check if premature kill
|
||||
pid=$(pgrep -u root -f clixon_backend)
|
||||
if [ -z "$pid" ]; then
|
||||
err "backend already dead"
|
||||
fi
|
||||
# kill backend
|
||||
stop_backend -f $cfg
|
||||
|
||||
rm -rf $dir
|
||||
|
|
@ -227,7 +227,7 @@ expectpart "$(curl $CURLOPTS -X GET $RCPROTO://localhost/restconf/data/augment:r
|
|||
#----------------------------------------------
|
||||
# Also generate an invalid state XML. This should generate an "Internal" error and the name of the
|
||||
new "restconf GET failed state"
|
||||
expectpart "$(curl $CURLOPTS -X GET -H 'Accept: application/yang-data+xml' $RCPROTO://localhost/restconf/data?content=nonconfig)" 0 '412 Precondition Failed' '<errors xmlns="urn:ietf:params:xml:ns:yang:ietf-restconf"><error><error-type>application</error-type><error-tag>operation-failed</error-tag><error-info><bad-element>mystate</bad-element></error-info><error-severity>error</error-severity><error-message>Failed to find YANG spec of XML node: mystate with parent: top in namespace: urn:example:foobar. Internal error, state callback returned invalid XML: example_backend</error-message></error></errors>'
|
||||
expectpart "$(curl $CURLOPTS -X GET -H 'Accept: application/yang-data+xml' $RCPROTO://localhost/restconf/data?content=nonconfig)" 0 '412 Precondition Failed' '<errors xmlns="urn:ietf:params:xml:ns:yang:ietf-restconf"><error><error-type>application</error-type><error-tag>operation-failed</error-tag><error-info><bad-element>mystate</bad-element></error-info><error-severity>error</error-severity><error-message>Failed to find YANG spec of XML node: mystate with parent: config in namespace: urn:example:foobar. Internal error, state callback returned invalid XML from plugin: example_backend</error-message></error></errors>'
|
||||
|
||||
# Add error XML a[4242] , it should fail on autocommit but may not be discarded, therefore still
|
||||
# there in candidate when want to add something else
|
||||
|
|
|
|||
|
|
@ -227,7 +227,7 @@ EOF
|
|||
echo "$STATE0" > $fstate
|
||||
|
||||
new "Get state (negative test)"
|
||||
expecteof "$clixon_netconf -qf $cfg" 0 "<rpc $DEFAULTNS><get content=\"nonconfig\"></get></rpc>]]>]]>" "error-message>Failed to find YANG spec of XML node: u5 with parent: sb in namespace: urn:example:unknown. Internal error, state callback returned invalid XML: example_backend</error-message>"
|
||||
expecteof "$clixon_netconf -qf $cfg" 0 "<rpc $DEFAULTNS><get content=\"nonconfig\"></get></rpc>]]>]]>" "error-message>Failed to find YANG spec of XML node: u5 with parent: sb in namespace: urn:example:unknown. Internal error, state callback returned invalid XML from plugin: example_backend</error-message>"
|
||||
|
||||
new "restconf get state(negative)"
|
||||
expectpart "$(curl $CURLOPTS -X GET -H "Accept: application/yang-data+xml" $RCPROTO://localhost/restconf/data?content=nonconfig)" 0 "HTTP/1.1 412 Precondition Failed" "<error-tag>operation-failed</error-tag><error-info><bad-element>u5</bad-element></error-info>"
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue