* Changed base OS in clixon-system container to Alpine

* Moved datastore/text/ code to datastore/ since there is only one type of datastore.
* Added "magic script line" to test script for sourced and scriped exits
This commit is contained in:
Olof Hagsand 2019-02-13 21:33:40 +01:00
parent 9fc8ac2e8e
commit d64d433468
58 changed files with 579 additions and 538 deletions

View file

@ -1,12 +1,15 @@
#!/bin/bash
# Test5: datastore tests.
# Magic line must be first in script (see README.md)
s="$_" ; . ./lib.sh || if [ "$s" = $0 ]; then exit 0; else return 0; fi
# datastore tests.
# Just run a binary direct to datastore. No clixon.
# include err() and new() functions and creates $dir
. ./lib.sh
fyang=$dir/ietf-ip.yang
datastore=../datastore/datastore_client
# If set, enable debugging (of backend)
: ${clixon_util_datastore:=clixon_util_datastore}
: ${clixon_datastore_lib:=/usr/local/lib/xmldb/text.so}
cat <<EOF > $fyang
module ietf-ip{
@ -46,126 +49,124 @@ module ietf-ip{
}
EOF
xml='<config><x xmlns="urn:example:clixon"><y><a>1</a><b>2</b><c>first-entry</c></y><y><a>1</a><b>3</b><c>second-entry</c></y><y><a>2</a><b>3</b><c>third-entry</c></y><d/><f><e>a</e><e>b</e><e>c</e></f><g>astring</g></x></config>'
run(){
name=$1
mydir=$dir/$name
if [ ! -d $mydir ]; then
mkdir $mydir
fi
rm -rf $mydir/*
name=text
conf="-d candidate -b $mydir -p ../datastore/$name/$name.so -y $dir/ietf-ip.yang"
new "datastore $name init"
expectfn "$datastore $conf init" 0 ""
new "datastore $name put all replace"
ret=$($datastore $conf put replace "$xml")
expectmatch "$ret" $? "0" ""
mydir=$dir/$name
new "datastore $name get"
expectfn "$datastore $conf get /" 0 "^$xml$"
if [ ! -d $mydir ]; then
mkdir $mydir
fi
rm -rf $mydir/*
new "datastore $name put all remove"
expectfn "$datastore $conf put remove <config/>" 0 ""
# XXX static link
conf="-d candidate -b $mydir -p $clixon_datastore_lib -y $dir/ietf-ip.yang"
new "datastore $name get"
expectfn "$datastore $conf get /" 0 "^<config/>$"
new "datastore init"
expectfn "$clixon_util_datastore $conf init" 0 ""
new "datastore $name put all merge"
ret=$($datastore $conf put merge "$xml")
expectmatch "$ret" $? "0" ""
# expectfn "$datastore $conf put merge $xml" 0 ""
new "datastore put all replace"
ret=$($clixon_util_datastore $conf put replace "$xml")
expectmatch "$ret" $? "0" ""
new "datastore $name get"
expectfn "$datastore $conf get /" 0 "^$xml$"
new "datastore get"
expectfn "$clixon_util_datastore $conf get /" 0 "^$xml$"
new "datastore $name put all delete"
expectfn "$datastore $conf put remove <config/>" 0 ""
new "datastore put all remove"
expectfn "$clixon_util_datastore $conf put remove <config/>" 0 ""
new "datastore $name get"
expectfn "$datastore $conf get /" 0 "^<config/>$"
new "datastore get"
expectfn "$clixon_util_datastore $conf get /" 0 "^<config/>$"
new "datastore $name put all create"
ret=$($datastore $conf put create "$xml")
expectmatch "$ret" $? "0" ""
new "datastore put all merge"
ret=$($clixon_util_datastore $conf put merge "$xml")
expectmatch "$ret" $? "0" ""
new "datastore $name get"
expectfn "$datastore $conf get /" 0 "^$xml$"
# expectfn "$clixon_util_datastore $conf put merge $xml" 0 ""
new "datastore $name put top create"
expectfn "$datastore $conf put create <config><x/></config>" 0 "" # error
new "datastore get"
expectfn "$clixon_util_datastore $conf get /" 0 "^$xml$"
# Single key operations
# leaf
new "datastore $name put all delete"
expectfn "$datastore $conf delete" 0 ""
new "datastore put all delete"
expectfn "$clixon_util_datastore $conf put remove <config/>" 0 ""
new "datastore $name init"
expectfn "$datastore $conf init" 0 ""
new "datastore get"
expectfn "$clixon_util_datastore $conf get /" 0 "^<config/>$"
new "datastore $name create leaf"
expectfn "$datastore $conf put create <config><x><y><a>1</a><b>3</b><c>newentry</c></y></x></config>" 0 ""
new "datastore put all create"
ret=$($clixon_util_datastore $conf put create "$xml")
expectmatch "$ret" $? "0" ""
new "datastore $name create leaf"
expectfn "$datastore $conf put create <config><x><y><a>1</a><b>3</b><c>newentry</c></y></x></config>" 0 ""
new "datastore get"
expectfn "$clixon_util_datastore $conf get /" 0 "^$xml$"
new "datastore $name delete leaf"
expectfn "$datastore $conf put delete <config><x><y><a>1</a><b>3</b></y></x></config>" 0 ""
new "datastore put top create"
expectfn "$clixon_util_datastore $conf put create <config><x/></config>" 0 "" # error
new "datastore $name replace leaf"
expectfn "$datastore $conf put create <config><x><y><a>1</a><b>3</b><c>newentry</c></y></x></config>" 0 ""
# Single key operations
# leaf
new "datastore put all delete"
expectfn "$clixon_util_datastore $conf delete" 0 ""
new "datastore $name remove leaf"
expectfn "$datastore $conf put remove <config><x><g/></x></config>" 0 ""
new "datastore init"
expectfn "$clixon_util_datastore $conf init" 0 ""
new "datastore $name remove leaf"
expectfn "$datastore $conf put remove <config><x><y><a>1</a><b>3</b><c/></y></x></config>" 0 ""
new "datastore create leaf"
expectfn "$clixon_util_datastore $conf put create <config><x><y><a>1</a><b>3</b><c>newentry</c></y></x></config>" 0 ""
new "datastore $name delete leaf"
expectfn "$datastore $conf put delete <config><x><g/></x></config>" 0 ""
new "datastore create leaf"
expectfn "$clixon_util_datastore $conf put create <config><x><y><a>1</a><b>3</b><c>newentry</c></y></x></config>" 0 ""
new "datastore $name merge leaf"
expectfn "$datastore $conf put merge <config><x><g>nalle</g></x></config>" 0 ""
new "datastore delete leaf"
expectfn "$clixon_util_datastore $conf put delete <config><x><y><a>1</a><b>3</b></y></x></config>" 0 ""
new "datastore $name replace leaf"
expectfn "$datastore $conf put replace <config><x><g>nalle</g></x></config>" 0 ""
new "datastore replace leaf"
expectfn "$clixon_util_datastore $conf put create <config><x><y><a>1</a><b>3</b><c>newentry</c></y></x></config>" 0 ""
new "datastore $name merge leaf"
expectfn "$datastore $conf put merge <config><x><y><a>1</a><b>3</b><c>newentry</c></y></x></config>" 0 ""
new "datastore remove leaf"
expectfn "$clixon_util_datastore $conf put remove <config><x><g/></x></config>" 0 ""
new "datastore $name replace leaf"
expectfn "$datastore $conf put replace <config><x><y><a>1</a><b>3</b><c>newentry</c></y></x></config>" 0 ""
new "datastore remove leaf"
expectfn "$clixon_util_datastore $conf put remove <config><x><y><a>1</a><b>3</b><c/></y></x></config>" 0 ""
new "datastore $name create leaf"
expectfn "$datastore $conf put create <config><x><h><j>aaa</j></h></x></config>" 0 ""
new "datastore delete leaf"
expectfn "$clixon_util_datastore $conf put delete <config><x><g/></x></config>" 0 ""
new "datastore $name create leaf"
expectfn "$datastore $conf put create <config><x><y><a>1</a><b>3</b><c>newentry</c></y></x></config>" 0 ""
new "datastore merge leaf"
expectfn "$clixon_util_datastore $conf put merge <config><x><g>nalle</g></x></config>" 0 ""
new "datastore other db init"
expectfn "$datastore -d kalle -b $mydir -p ../datastore/$name/$name.so -y $dir/ietf-ip.yang init" 0 ""
new "datastore replace leaf"
expectfn "$clixon_util_datastore $conf put replace <config><x><g>nalle</g></x></config>" 0 ""
new "datastore other db copy"
expectfn "$datastore $conf copy kalle" 0 ""
new "datastore merge leaf"
expectfn "$clixon_util_datastore $conf put merge <config><x><y><a>1</a><b>3</b><c>newentry</c></y></x></config>" 0 ""
diff $mydir/kalle_db $mydir/candidate_db
new "datastore replace leaf"
expectfn "$clixon_util_datastore $conf put replace <config><x><y><a>1</a><b>3</b><c>newentry</c></y></x></config>" 0 ""
new "datastore lock"
expectfn "$datastore $conf lock 756" 0 ""
new "datastore create leaf"
expectfn "$clixon_util_datastore $conf put create <config><x><h><j>aaa</j></h></x></config>" 0 ""
new "datastore create leaf"
expectfn "$clixon_util_datastore $conf put create <config><x><y><a>1</a><b>3</b><c>newentry</c></y></x></config>" 0 ""
new "datastore other db init"
expectfn "$clixon_util_datastore -d kalle -b $mydir -p $clixon_datastore_lib -y $dir/ietf-ip.yang init" 0 ""
new "datastore other db copy"
expectfn "$clixon_util_datastore $conf copy kalle" 0 ""
diff $mydir/kalle_db $mydir/candidate_db
new "datastore lock"
expectfn "$clixon_util_datastore $conf lock 756" 0 ""
#leaf-list
rm -rf $mydir
}
run text
rm -rf $mydir
rm -rf $dir