clixon/test/test_insert.sh
Olof hagsand 19e21be0bc Very large commit for upcoming 4.4 release
Major New features

* New and updated search functions using xpath, api-path and instance-id
  * New search functions using api-path and instance_id:
    * C search functions: `clixon_find_instance_id()` and `clixon_find_api_path()`
  * Binary search optimization in lists for indexed leafs in all three formats.
    * This improves search performance to O(logN) which is drastical improvements for large lists.
  * You can also register explicit indexes for making binary search (not only list keys)
  * For more info, see docs at [paths](https://clixon-docs.readthedocs.io/en/latest/paths.html) and
[search](https://clixon-docs.readthedocs.io/en/latest/xml.html#searching-in-xml)

API changes on existing features (you may need to change your code)
* On failed validation of leafrefs, error message changed from: `No such leaf` to `No leaf <name> matching path <path>`.
* CLI Error message (clicon_rpc_generate_error()) changed when backend returns netconf error to be more descriptive:
  * Original: `Config error: Validate failed. Edit and try again or discard changes: Invalid argument`
  * New (example): `Netconf error: application operation-failed Identityref validation failed, undefined not derived from acl-base . Validate failed. Edit and try again or discard changes"

Minor changes

* Test framework
  * Added `-- -S <file>` command-line to main example to be able to return any state to main example.
  * Added `test/cicd` test scripts for running on a set of other hosts
* C-code restructuring
  * clixon_yang.c partitioned and moved code into clixon_yang_parse_lib.c and clixon_yang_module.c and move back some code from clixon_yang_type.c.
    * partly to reduce size, but most important to limit code that accesses internal yang structures, only clixon_yang.c does this now.
2020-02-02 15:52:30 +01:00

216 lines
5 KiB
Bash
Executable file

#!/usr/bin/env bash
# XML Insert elements and test if they are sorted according to yang
# First a list with 0-5 base elements, insert in different places
# Second varying yangs: container, leaf, list, leaf-list, choice, user-order list
# 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_insert:=clixon_util_insert}
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{
list a{
key x;
leaf x{
type int32;
}
}
}
}
EOF
testrun(){
x0=$1
xi="<c xmlns=\"urn:example:example\">$2</c>"
xp=c
new "random list add leaf-list"
# First run sorted (assume this is the refernce == correct)
rs=$($clixon_util_insert -y $fyang -x "$xi" -b "$x0" -p $xp $OPTS -s)
# Then run actual insert
r0=$($clixon_util_insert -y $fyang -x "$xi" -b "$x0" -p $xp $OPTS)
# If both are null something is amiss
if [ -z "$r0" -a -z "$rs" ]; then
err "length of retval is zero"
fi
# echo "rs:$rs"
# echo "r0:$r0"
# Check they are equal
if [[ "$r0" != "$rs" ]]; then
err "$rs" "$r0"
fi
}
new "test params: -y $fyang $OPTS"
# Empty element base list
x0='<c xmlns="urn:example:example"></c>'
new "empty list"
testrun "$x0" "<a><x>1</x></a>"
# One element base list
x0='<c xmlns="urn:example:example"><a><x>99</x></a></c>'
new "one element list first"
testrun "$x0" "<a><x>1</x></a>"
new "one element list last"
testrun "$x0" "<a><x>100</x></a>"
# Two element base list
x0='<c xmlns="urn:example:example"><a><x>2</x></a><a><x>99</x></a></c>'
new "two element list first"
testrun "$x0" "<a><x>1</x></a>"
new "two element list mid"
testrun "$x0" "<a><x>12</x></a>"
new "two element list last"
testrun "$x0" "<a><x>3000</x></a>"
# Three element base list
x0='<c xmlns="urn:example:example"><a><x>2</x></a><a><x>99</x></a><a><x>101</x></a></c>'
new "three element list first"
testrun "$x0" "<a><x>1</x></a>"
new "three element list second"
testrun "$x0" "<a><x>10</x></a>"
new "three element list third"
testrun "$x0" "<a><x>100</x></a>"
new "three element list last"
testrun "$x0" "<a><x>1000</x></a>"
# Four element base list
x0='<c xmlns="urn:example:example"><a><x>2</x></a><a><x>99</x></a><a><x>101</x></a><a><x>200</x></a></c>'
new "four element list first"
testrun "$x0" "<a><x>1</x></a>"
new "four element list second"
testrun "$x0" "<a><x>10</x></a>"
new "four element list third"
testrun "$x0" "<a><x>100</x></a>"
new "four element list fourth"
testrun "$x0" "<a><x>102</x></a>"
new "four element list last"
testrun "$x0" "<a><x>1000</x></a>"
# Five element base list
x0='<c xmlns="urn:example:example"><a><x>2</x></a><a><x>99</x></a><a><x>101</x></a><a><x>200</x></a><a><x>300</x></a></c>'
new "five element list first"
testrun "$x0" "<a><x>1</x></a>"
new "five element list mid"
testrun "$x0" "<a><x>100</x></a>"
new "five element list last"
testrun "$x0" "<a><x>1000</x></a>"
cat <<EOF > $fyang
module example {
yang-version 1.1;
namespace "urn:example:example";
prefix ex;
revision 2019-01-13;
container c{
leaf a{
type string;
}
container b{
leaf a {
type string;
}
}
choice c1{
case a{
leaf x{
type string;
}
}
case b{
leaf y{
type int32;
}
}
}
choice c2{
leaf z{
type string;
}
leaf t{
type int32;
}
}
list d{
key x;
leaf x{
type int32;
}
ordered-by user;
}
leaf-list e{
type int32;
}
}
}
EOF
# Advanced list
# Empty base list
x0='<c xmlns="urn:example:example"></c>'
xp=c
new "adv empty list add leaf"
testrun "$x0" "<a>leaf</a>"
new "adv empty list add choice c1"
testrun "$x0" "<x>choice1</x>"
xi='<c xmlns="urn:example:example"><e>33</e></c>'
new "adv empty list add leaf-list"
testrun "$x0" "<e>33</e>"
# base list
x0='<c xmlns="urn:example:example"><a>leaf</a><x>choice</x><d><x>1</x></d><e>33</e></c>'
new "adv list add leaf-list"
testrun "$x0" "<e>32</e>"
new "adv list add leaf-list"
testrun "$x0" "<e>32</e>"
rm -rf $dir
# unset conditional parameters
unset clixon_util_insert