* Fixed instance-id multiple results
* Fixed last NACM write paths
This commit is contained in:
parent
04017c97ba
commit
dc36282874
15 changed files with 806 additions and 211 deletions
|
|
@ -156,8 +156,10 @@ trigger_rpc(clicon_handle h, /* Clicon handle */
|
|||
goto done;
|
||||
cv_name_set(cv, "k");
|
||||
cv_string_set(cv, "5");
|
||||
if ((xv = clixon_xvec_new()) == NULL)
|
||||
goto done;
|
||||
/* Use form 2c use spec of xc + name */
|
||||
if (clixon_xml_find_index(xc, NULL, NULL, "y3", cvk, &xv) < 0)
|
||||
if (clixon_xml_find_index(xc, NULL, NULL, "y3", cvk, xv) < 0)
|
||||
goto done;
|
||||
if (clixon_xvec_len(xv))
|
||||
val = xml_find_body(clixon_xvec_i(xv,0), "val");
|
||||
|
|
|
|||
102
test/test_instance_id_multi.sh
Executable file
102
test/test_instance_id_multi.sh
Executable file
|
|
@ -0,0 +1,102 @@
|
|||
#!/usr/bin/env bash
|
||||
# Instance-id tests with multiple results
|
||||
# RFC 7950 Sections 9.13 and 14 says that:
|
||||
# Predicates are used only for specifying the values for the key nodes for list entries
|
||||
# but does not explicitly say that list nodes can skip them
|
||||
# And in RFC8341 node-instance-identifiers are defined as:
|
||||
# All the same rules as an instance-identifier apply, except that predicates for keys are optional.
|
||||
# If a key predicate is missing, then the node-instance-identifier represents all possible server
|
||||
# instances for that key.
|
||||
|
||||
# Magic line must be first in script (see README.md)
|
||||
s="$_" ; . ./lib.sh || if [ "$s" = $0 ]; then exit 0; else return 0; fi
|
||||
|
||||
: ${clixon_util_path:=clixon_util_path -D $DBG}
|
||||
|
||||
xml1=$dir/xml1.xml
|
||||
ydir=$dir/yang
|
||||
|
||||
if [ ! -d $ydir ]; then
|
||||
mkdir $ydir
|
||||
fi
|
||||
|
||||
# Nested lists
|
||||
cat <<EOF > $ydir/example.yang
|
||||
module example{
|
||||
yang-version 1.1;
|
||||
namespace "urn:example:id";
|
||||
prefix ex;
|
||||
container table{
|
||||
list parameter{
|
||||
key name;
|
||||
leaf name{
|
||||
type string;
|
||||
}
|
||||
container next{
|
||||
list parameter{
|
||||
key name;
|
||||
leaf name{
|
||||
type string;
|
||||
}
|
||||
leaf value{
|
||||
type string;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
EOF
|
||||
|
||||
cat <<EOF > $xml1
|
||||
<table xmlns="urn:example:id">
|
||||
<parameter>
|
||||
<name>a</name>
|
||||
<next>
|
||||
<parameter>
|
||||
<name>a</name>
|
||||
<value>11</value>
|
||||
</parameter>
|
||||
<parameter>
|
||||
<name>b</name>
|
||||
<value>22</value>
|
||||
</parameter>
|
||||
</next>
|
||||
</parameter>
|
||||
<parameter>
|
||||
<name>b</name>
|
||||
<next>
|
||||
<parameter>
|
||||
<name>a</name>
|
||||
<value>33</value>
|
||||
</parameter>
|
||||
</next>
|
||||
</parameter>
|
||||
</table>
|
||||
EOF
|
||||
|
||||
new "instance-id top-level param"
|
||||
expectpart "$($clixon_util_path -f $xml1 -y $ydir -p /ex:table/ex:parameter)" 0 "0: <parameter><name>a</name><next><parameter><name>a</name><value>11</value></parameter><parameter><name>b</name><value>22</value></parameter></next></parameter>" "1: <parameter><name>b</name><next><parameter><name>a</name><value>33</value></parameter></next></parameter>"
|
||||
|
||||
new "instance-id a/next"
|
||||
expectpart "$($clixon_util_path -f $xml1 -y $ydir -p /ex:table/ex:parameter[ex:name=\"a\"]/ex:next)" 0 "0: <next><parameter><name>a</name><value>11</value></parameter><parameter><name>b</name><value>22</value></parameter></next>"
|
||||
|
||||
new "instance-id a/next/param"
|
||||
expectpart "$($clixon_util_path -f $xml1 -y $ydir -p /ex:table/ex:parameter[ex:name=\"a\"]/ex:next/ex:parameter)" 0 "0: <parameter><name>a</name><value>11</value></parameter>" "1: <parameter><name>b</name><value>22</value></parameter>"
|
||||
|
||||
new "instance-id a/next/param/a"
|
||||
expectpart "$($clixon_util_path -f $xml1 -y $ydir -p /ex:table/ex:parameter[ex:name=\"a\"]/ex:next/ex:parameter[ex:name=\"a\"])" 0 "0: <parameter><name>a</name><value>11</value></parameter>" "0: <parameter><name>a</name><value>11</value></parameter>"
|
||||
|
||||
new "instance-id a/next/param/a/value"
|
||||
expectpart "$($clixon_util_path -f $xml1 -y $ydir -p /ex:table/ex:parameter[ex:name=\"a\"]/ex:next/ex:parameter[ex:name=\"a\"]/ex:value)" 0 "0: <value>11</value>"
|
||||
|
||||
new "instance-id top-level parameter/next"
|
||||
expectpart "$($clixon_util_path -f $xml1 -y $ydir -p /ex:table/ex:parameter/ex:next)" 0 "0: <next><parameter><name>a</name><value>11</value></parameter><parameter><name>b</name><value>22</value></parameter></next>" "1: <next><parameter><name>a</name><value>33</value></parameter></next>"
|
||||
|
||||
new "instance-id top-level parameter/next/parameter"
|
||||
expectpart "$($clixon_util_path -f $xml1 -y $ydir -p /ex:table/ex:parameter/ex:next/ex:parameter)" 0 "0: <parameter><name>a</name><value>11</value></parameter>" "1: <parameter><name>b</name><value>22</value></parameter>" "2: <parameter><name>a</name><value>33</value></parameter>"
|
||||
|
||||
rm -rf $dir
|
||||
unset clixon_util_path # for other script reusing it
|
||||
|
||||
|
||||
296
test/test_nacm_datanode_write.sh
Executable file
296
test/test_nacm_datanode_write.sh
Executable file
|
|
@ -0,0 +1,296 @@
|
|||
#!/usr/bin/env bash
|
||||
# Authentication and authorization and IETF NACM
|
||||
# NACM data node rules
|
||||
# The RFC 8341 examples in the appendix are very limited.
|
||||
# Here focus on datanode paths from a write perspective.
|
||||
# Especially a list in a list to test vector rules
|
||||
# The test uses a nested list and makes CRUD operations on one object "b"
|
||||
|
||||
# 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
|
||||
|
||||
# Common NACM scripts
|
||||
. ./nacm.sh
|
||||
|
||||
cfg=$dir/conf_yang.xml
|
||||
fyang=$dir/nacm-example.yang
|
||||
|
||||
cat <<EOF > $cfg
|
||||
<clixon-config xmlns="http://clicon.org/config">
|
||||
<CLICON_CONFIGFILE>$cfg</CLICON_CONFIGFILE>
|
||||
<CLICON_YANG_DIR>/usr/local/share/clixon</CLICON_YANG_DIR>
|
||||
<CLICON_YANG_DIR>$IETFRFC</CLICON_YANG_DIR>
|
||||
<CLICON_YANG_DIR>$dir</CLICON_YANG_DIR>
|
||||
<CLICON_YANG_MAIN_FILE>$fyang</CLICON_YANG_MAIN_FILE>
|
||||
<CLICON_CLISPEC_DIR>/usr/local/lib/$APPNAME/clispec</CLICON_CLISPEC_DIR>
|
||||
<CLICON_RESTCONF_DIR>/usr/local/lib/$APPNAME/restconf</CLICON_RESTCONF_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_DIR>/usr/local/lib/$APPNAME/backend</CLICON_BACKEND_DIR>
|
||||
<CLICON_BACKEND_PIDFILE>/usr/local/var/$APPNAME/$APPNAME.pidfile</CLICON_BACKEND_PIDFILE>
|
||||
<CLICON_XMLDB_DIR>/usr/local/var/$APPNAME</CLICON_XMLDB_DIR>
|
||||
<CLICON_RESTCONF_PRETTY>false</CLICON_RESTCONF_PRETTY>
|
||||
<CLICON_NACM_MODE>internal</CLICON_NACM_MODE>
|
||||
<CLICON_NACM_CREDENTIALS>none</CLICON_NACM_CREDENTIALS>
|
||||
</clixon-config>
|
||||
EOF
|
||||
|
||||
cat <<EOF > $fyang
|
||||
module nacm-example{
|
||||
yang-version 1.1;
|
||||
namespace "urn:example:nacm";
|
||||
prefix ex;
|
||||
import ietf-netconf-acm {
|
||||
prefix nacm;
|
||||
}
|
||||
container table{
|
||||
list parameter{
|
||||
key name;
|
||||
leaf name{
|
||||
type string;
|
||||
}
|
||||
container next{
|
||||
list parameter{
|
||||
key name;
|
||||
leaf name{
|
||||
type string;
|
||||
}
|
||||
leaf value{
|
||||
type string;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
EOF
|
||||
|
||||
RULES=$(cat <<EOF
|
||||
<nacm xmlns="urn:ietf:params:xml:ns:yang:ietf-netconf-acm">
|
||||
<enable-nacm>false</enable-nacm>
|
||||
<read-default>deny</read-default>
|
||||
<write-default>deny</write-default>
|
||||
<exec-default>permit</exec-default>
|
||||
|
||||
$NGROUPS
|
||||
|
||||
<rule-list>
|
||||
<name>limited-acl</name>
|
||||
<group>limited</group>
|
||||
|
||||
<rule>
|
||||
<name>value</name>
|
||||
<module-name>nacm-example</module-name>
|
||||
<access-operations>create delete update</access-operations>
|
||||
<path xmlns:ex="urn:example:nacm">/ex:table/ex:parameter/ex:next/ex:parameter/ex:value</path>
|
||||
<action>permit</action>
|
||||
</rule>
|
||||
<rule>
|
||||
<name>parameter</name>
|
||||
<module-name>nacm-example</module-name>
|
||||
<access-operations>read update</access-operations>
|
||||
<path xmlns:ex="urn:example:nacm">/ex:table/ex:parameter/ex:next/ex:parameter</path>
|
||||
<action>permit</action>
|
||||
</rule>
|
||||
|
||||
</rule-list>
|
||||
|
||||
$NADMIN
|
||||
|
||||
</nacm>
|
||||
EOF
|
||||
)
|
||||
|
||||
CONFIG=$(cat <<EOF
|
||||
<table xmlns="urn:example:nacm">
|
||||
<parameter>
|
||||
<name>a</name>
|
||||
<next>
|
||||
<parameter>
|
||||
<name>a</name>
|
||||
<value>72</value>
|
||||
</parameter>
|
||||
</next>
|
||||
</parameter>
|
||||
<parameter>
|
||||
<name>b</name>
|
||||
<next>
|
||||
<parameter>
|
||||
<name>a</name>
|
||||
<value>99</value>
|
||||
</parameter>
|
||||
</next>
|
||||
</parameter>
|
||||
</table>
|
||||
EOF
|
||||
)
|
||||
|
||||
#
|
||||
# Arguments, permit/deny on different levels:
|
||||
# Configs (permit/deny):
|
||||
# - write-default
|
||||
# - param access
|
||||
# - param action
|
||||
# - value access
|
||||
# - value action
|
||||
# Tests, epxect true/false:
|
||||
# - create
|
||||
# - read
|
||||
# - update
|
||||
# - delete
|
||||
testrun(){
|
||||
writedefault=$1
|
||||
paramaccess=$2
|
||||
paramaction=$3
|
||||
valueaccess=$4
|
||||
valueaction=$5
|
||||
testc=$6
|
||||
testr=$7
|
||||
testu=$8
|
||||
testd=$9
|
||||
|
||||
new "set write-default $writedefault"
|
||||
expectpart "$(curl -u andy:bar -siS -X PUT -H "Content-Type: application/yang-data+json" http://localhost/restconf/data/ietf-netconf-acm:nacm/write-default -d "{\"ietf-netconf-acm:write-default\":\"$writedefault\"}" )" 0 "HTTP/1.1 204 No Content"
|
||||
|
||||
new "set param rule access: $paramaccess"
|
||||
expectpart "$(curl -u andy:bar -siS -X PUT -H "Content-Type: application/yang-data+json" http://localhost/restconf/data/ietf-netconf-acm:nacm/rule-list=limited-acl/rule=parameter/access-operations -d "{\"ietf-netconf-acm:access-operations\":\"$paramaccess\"}" )" 0 "HTTP/1.1 204 No Content"
|
||||
|
||||
new "set param rule access: $paramaction"
|
||||
expectpart "$(curl -u andy:bar -siS -X PUT -H "Content-Type: application/yang-data+json" http://localhost/restconf/data/ietf-netconf-acm:nacm/rule-list=limited-acl/rule=parameter/action -d "{\"ietf-netconf-acm:action\":\"$paramaction\"}" )" 0 "HTTP/1.1 204 No Content"
|
||||
|
||||
new "set value rule access: $valueaccess"
|
||||
expectpart "$(curl -u andy:bar -siS -X PUT -H "Content-Type: application/yang-data+json" http://localhost/restconf/data/ietf-netconf-acm:nacm/rule-list=limited-acl/rule=value/access-operations -d "{\"ietf-netconf-acm:access-operations\":\"$valueaccess\"}" )" 0 "HTTP/1.1 204 No Content"
|
||||
|
||||
new "set value rule access: $valueaction"
|
||||
expectpart "$(curl -u andy:bar -siS -X PUT -H "Content-Type: application/yang-data+json" http://localhost/restconf/data/ietf-netconf-acm:nacm/rule-list=limited-acl/rule=value/action -d "{\"ietf-netconf-acm:action\":\"$valueaction\"}" )" 0 "HTTP/1.1 204 No Content"
|
||||
|
||||
#--------------- Here tests: create/update/read/delete
|
||||
|
||||
new "create object b"
|
||||
if $testc; then
|
||||
expectpart "$(curl -u wilma:bar -siS -X POST -H "Content-Type: application/yang-data+json" http://localhost/restconf/data/nacm-example:table/parameter=a/next -d '{"nacm-example:parameter":[{"name":"b","value":"17"}]}')" 0 'HTTP/1.1 201 Created'
|
||||
else
|
||||
expectpart "$(curl -u wilma:bar -siS -X POST -H "Content-Type: application/yang-data+json" http://localhost/restconf/data/nacm-example:table/parameter=a/next -d '{"nacm-example:parameter":[{"name":"b","value":"17"}]}')" 0 'HTTP/1.1 403 Forbidden' '{"ietf-restconf:errors":{"error":{"error-type":"application","error-tag":"access-denied","error-severity":"error","error-message":"access denied"}}}'
|
||||
fi
|
||||
new "read object b"
|
||||
if $testr; then
|
||||
expectpart "$(curl -u wilma:bar -siS -X GET http://localhost/restconf/data/nacm-example:table/parameter=a/next/parameter=b)" 0 'HTTP/1.1 200 OK' '{"nacm-example:parameter":\[{"name":"b","value":"17"}\]}'
|
||||
else
|
||||
expectpart "$(curl -u wilma:bar -siS -X GET http://localhost/restconf/data/nacm-example:table/parameter=a/next/parameter=b)" 0 'HTTP/1.1 404 Not Found'
|
||||
fi
|
||||
|
||||
new "update object b"
|
||||
if $testu; then
|
||||
expectpart "$(curl -u wilma:bar -siS -X PUT -H "Content-Type: application/yang-data+json" http://localhost/restconf/data/nacm-example:table/parameter=a/next/parameter=b -d '{"nacm-example:parameter":[{"name":"b","value":"92"}]}')" 0 'HTTP/1.1 204 No Content'
|
||||
else
|
||||
expectpart "$(curl -u wilma:bar -siS -X PUT -H "Content-Type: application/yang-data+json" http://localhost/restconf/data/nacm-example:table/parameter=a/next/parameter=b -d '{"nacm-example:parameter":[{"name":"b","value":"92"}]}')" 0 'HTTP/1.1 403 Forbidden'
|
||||
# '{"ietf-restconf:errors":{"error":{"error-type":"application","error-tag":"access-denied","error-severity":"error","error-message":"access denied"}}}'
|
||||
fi
|
||||
|
||||
new "delete object b"
|
||||
if $testd; then
|
||||
expectpart "$(curl -u wilma:bar -siS -X DELETE http://localhost/restconf/data/nacm-example:table/parameter=a/next/parameter=b)" 0 'HTTP/1.1 204 No Content'
|
||||
else # XXX can vara olika
|
||||
ret=$(curl -u wilma:bar -siS -X DELETE http://localhost/restconf/data/nacm-example:table/parameter=a/next/parameter=b)
|
||||
r=$?
|
||||
if [ $r != 0 ]; then
|
||||
err "retval: $r" "0"
|
||||
fi
|
||||
match1=$(echo "$ret" | grep --null -o 'HTTP/1.1 403 Forbidden')
|
||||
r1=$?
|
||||
match2=$(echo "$ret" | grep --null -o 'HTTP/1.1 409 Conflict')
|
||||
r2=$?
|
||||
if [ $r1 != 0 -a $r2 != 0 ]; then
|
||||
err "'HTTP/1.1 403 Forbidden' or 'HTTP/1.1 409 Conflict'" "$ret"
|
||||
fi
|
||||
# Ensure delete
|
||||
new "ensure delete object b"
|
||||
expectpart "$(curl -u andy:bar -siS -X DELETE http://localhost/restconf/data/nacm-example:table/parameter=a/next/parameter=b)" 0 'HTTP/1.1' # ignore error
|
||||
fi
|
||||
|
||||
} # testrun
|
||||
|
||||
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"
|
||||
start_backend -s init -f $cfg
|
||||
fi
|
||||
|
||||
new "waiting"
|
||||
wait_backend
|
||||
|
||||
if [ $RC -ne 0 ]; then
|
||||
new "kill old restconf daemon"
|
||||
sudo pkill -u $wwwuser -f clixon_restconf
|
||||
|
||||
new "start restconf daemon (-a is enable basic authentication)"
|
||||
start_restconf -f $cfg -- -a
|
||||
|
||||
new "waiting"
|
||||
wait_restconf
|
||||
fi
|
||||
|
||||
new "auth set authentication config"
|
||||
expecteof "$clixon_netconf -qf $cfg" 0 "<rpc><edit-config><target><candidate/></target><config>$RULES</config></edit-config></rpc>]]>]]>" "^<rpc-reply><ok/></rpc-reply>]]>]]>$"
|
||||
|
||||
new "set app config"
|
||||
expecteof "$clixon_netconf -qf $cfg" 0 "<rpc><edit-config><target><candidate/></target><config>$CONFIG</config></edit-config></rpc>]]>]]>" "^<rpc-reply><ok/></rpc-reply>]]>]]>$"
|
||||
|
||||
new "commit it"
|
||||
expecteof "$clixon_netconf -qf $cfg" 0 "<rpc><commit/></rpc>]]>]]>" "^<rpc-reply><ok/></rpc-reply>]]>]]>$"
|
||||
|
||||
new "enable nacm"
|
||||
expectpart "$(curl -u andy:bar -siS -X PUT -H "Content-Type: application/yang-data+json" -d '{"ietf-netconf-acm:enable-nacm": true}' http://localhost/restconf/data/ietf-netconf-acm:nacm/enable-nacm)" 0 "HTTP/1.1 204 No Content"
|
||||
|
||||
#--------------- nacm enabled
|
||||
# config: def param:access/action value:access/action
|
||||
# test: create read update delete
|
||||
# default deny
|
||||
testrun permit "*" permit "*" permit true true true true
|
||||
testrun permit "*" deny "*" deny false false false false
|
||||
testrun permit "*" permit "*" deny false false false false
|
||||
testrun permit "*" permit "update delete" deny true true false false
|
||||
testrun permit "*" permit "delete" deny true true true false
|
||||
testrun permit "delete" deny "*" permit true true true false
|
||||
testrun permit "update" deny "*" permit true true false true
|
||||
testrun permit "read" deny "*" permit true false true true
|
||||
|
||||
testrun deny "*" permit "*" permit true true true true
|
||||
testrun deny "*" permit "*" deny false false false false
|
||||
testrun deny "create" permit "*" permit true true false false
|
||||
# strange: a read permit on a sub-object while default read deny opens up all
|
||||
testrun deny "create read" permit "*" permit true true false false
|
||||
testrun deny "create" permit "create" permit true false false false
|
||||
testrun deny "create update" permit "create update" permit true false true false
|
||||
testrun deny "create update delete" permit "create update delete" permit true false true true
|
||||
testrun deny "create update delete" permit "update" deny true false false true
|
||||
testrun deny "create update delete" permit "delete" deny true false true false
|
||||
# OK but only gives sub-.object (not value) too complex to test
|
||||
# testrun deny "create update read" permit "read" deny true true true false
|
||||
testrun deny "*" deny "*" deny false false false false
|
||||
|
||||
if [ $RC -ne 0 ]; then
|
||||
new "Kill restconf daemon"
|
||||
stop_restconf
|
||||
fi
|
||||
if [ $BE -ne 0 ]; then # Bring your own backend
|
||||
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
|
||||
fi
|
||||
|
||||
rm -rf $dir
|
||||
128
test/test_xml_trees.sh
Executable file
128
test/test_xml_trees.sh
Executable file
|
|
@ -0,0 +1,128 @@
|
|||
#!/usr/bin/env bash
|
||||
# XML inserty and merge two trees
|
||||
# This is mainly a development API check
|
||||
|
||||
# Magic line must be first in script (see README.md)
|
||||
s="$_" ; . ./lib.sh || if [ "$s" = $0 ]; then exit 0; else return 0; fi
|
||||
|
||||
: ${clixon_util_xml_mod:=clixon_util_xml_mod}
|
||||
|
||||
OPTS="-D $DBG"
|
||||
|
||||
APPNAME=example
|
||||
|
||||
cfg=$dir/conf_yang.xml
|
||||
fyang=$dir/example.yang
|
||||
|
||||
cat <<EOF > $cfg
|
||||
<clixon-config xmlns="http://clicon.org/config">
|
||||
<CLICON_CONFIGFILE>$cfg</CLICON_CONFIGFILE>
|
||||
<CLICON_YANG_DIR>$dir</CLICON_YANG_DIR>
|
||||
<CLICON_YANG_DIR>/usr/local/share/clixon</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>$dir</CLICON_XMLDB_DIR>
|
||||
</clixon-config>
|
||||
EOF
|
||||
|
||||
cat <<EOF > $fyang
|
||||
module example {
|
||||
yang-version 1.1;
|
||||
namespace "urn:example:example";
|
||||
prefix ex;
|
||||
revision 2019-01-13;
|
||||
container c{
|
||||
leaf d{
|
||||
type int32;
|
||||
}
|
||||
list a{
|
||||
key x;
|
||||
leaf x{
|
||||
type int32;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
EOF
|
||||
|
||||
# insert/merge a tree into a base tree
|
||||
# Args:
|
||||
# 1: operation
|
||||
# 2: base tree
|
||||
# 3: insert tree
|
||||
# 4: xpath
|
||||
# 5: retval
|
||||
# 6: result
|
||||
testrun(){
|
||||
op=$1
|
||||
x0=$2
|
||||
x1=$3
|
||||
xp=$4
|
||||
ret=$5
|
||||
res=$6
|
||||
|
||||
echo "$clixon_util_xml_mod -o $op -y $fyang -b "$x0" -x "$x1" -p $xp $OPTS"
|
||||
expectpart "$($clixon_util_xml_mod -o $op -y $fyang -b "$x0" -x "$x1" -p $xp $OPTS)" $ret "$res"
|
||||
}
|
||||
|
||||
new "test params: -y $fyang $OPTS"
|
||||
|
||||
# -------- insert
|
||||
# Empty element base list
|
||||
x0a='<c xmlns="urn:example:example">'
|
||||
x0b='</c>'
|
||||
p=c
|
||||
|
||||
new "insert 1st element"
|
||||
testrun insert "$x0a$x0b" "$x0a<a><x>1</x></a>$x0b" $p 0 '<c xmlns="urn:example:example"><a><x>1</x></a></c>'
|
||||
|
||||
new "insert 2nd element"
|
||||
testrun insert "$x0a<a><x>2</x></a>$x0b" "$x0a<a><x>1</x></a>$x0b" $p 0 '<c xmlns="urn:example:example"><a><x>1</x></a><a><x>2</x></a></c>'
|
||||
|
||||
new "insert container"
|
||||
testrun insert "$x0a<a><x>1</x></a>$x0b" "$x0a<d>42</d>$x0b" c 0 '<c xmlns="urn:example:example"><d>42</d><a><x>1</x></a></c>'
|
||||
|
||||
# -------- parse parent
|
||||
new "parent 1st element"
|
||||
testrun parent "$x0a$x0b" "<a><x>1</x></a>" $p 0 '<c xmlns="urn:example:example"><a><x>1</x></a></c>'
|
||||
|
||||
new "patrse parent element"
|
||||
testrun parent "$x0a<a><x>2</x></a>$x0b" '<a><x>1</x></a>' $p 0 '<c xmlns="urn:example:example"><a><x>1</x></a><a><x>2</x></a></c>'
|
||||
|
||||
|
||||
new "parse parent container"
|
||||
testrun parent "$x0a<a><x>1</x></a>$x0b" '<d>42</d>' c 0 '<c xmlns="urn:example:example"><d>42</d><a><x>1</x></a></c>'
|
||||
|
||||
# -------- merge
|
||||
|
||||
new "merge empty"
|
||||
testrun merge "$x0a$x0b" "$x0a$x0b" $p 0 '<c xmlns="urn:example:example"/>'
|
||||
|
||||
new "merge single w empty"
|
||||
testrun merge "$x0a<a><x>1</x></a>$x0b" "$x0a$x0b" . 0 '<c xmlns="urn:example:example"><a><x>1</x></a></c>'
|
||||
|
||||
new "merge empty w single"
|
||||
testrun merge "$x0a$x0b" "$x0a<a><x>1</x></a>$x0b" . 0 '<c xmlns="urn:example:example"><a><x>1</x></a></c>'
|
||||
|
||||
new "merge equal single"
|
||||
testrun merge "$x0a<a><x>1</x></a>$x0b" "$x0a<a><x>1</x></a>$x0b" . 0 '<c xmlns="urn:example:example"><a><x>1</x></a></c>'
|
||||
|
||||
new "merge overlap"
|
||||
testrun merge "$x0a<a><x>1</x></a><a><x>2</x></a>$x0b" "$x0a<a><x>2</x></a><a><x>3</x></a>$x0b" . 0 '<c xmlns="urn:example:example"><a><x>1</x></a><a><x>2</x></a><a><x>3</x></a></c>'
|
||||
|
||||
new "merge list and leaf"
|
||||
testrun merge "$x0a<a><x>1</x></a><a><x>2</x></a>$x0b" "$x0a<d>42</d>$x0b" . 0 '<c xmlns="urn:example:example"><d>42</d><a><x>1</x></a><a><x>2</x></a></c>'
|
||||
|
||||
new "merge leaf and list"
|
||||
testrun merge "$x0a<d>42</d>$x0b" "$x0a<a><x>1</x></a><a><x>2</x></a>$x0b" . 0 '<c xmlns="urn:example:example"><d>42</d><a><x>1</x></a><a><x>2</x></a></c>'
|
||||
|
||||
new "merge overlap with path fail, merge does not work w subtrees"
|
||||
testrun merge "$x0a<a><x>1</x></a><a><x>2</x></a>$x0b" "$x0a<a><x>2</x></a><a><x>3</x></a>$x0b" c 255 ''
|
||||
|
||||
rm -rf $dir
|
||||
|
||||
# unset conditional parameters
|
||||
unset clixon_util_xml_mod
|
||||
Loading…
Add table
Add a link
Reference in a new issue