Fixed: [Diff of top-level default values on startup stopped working in 7.3](https://github.com/clicon/clixon/issues/596)

This commit is contained in:
Olof hagsand 2025-03-13 14:10:20 +01:00
parent 40d674bbbc
commit ea64bb3f3d
4 changed files with 132 additions and 8 deletions

View file

@ -24,6 +24,7 @@ Planned: April 2025
### Corrected Bugs
* Fixed: [Diff of top-level default values on startup stopped working in 7.3](https://github.com/clicon/clixon/issues/596)
* Fixed: [cli_show_auto don't work](https://github.com/clicon/clixon/issues/595)
* Fixed: [XPath * stopped working in 7.3](https://github.com/clicon/clixon/issues/594)
* Fixed: [Templates with nc:operation "merge" causes bad diffs to be shows](https://github.com/clicon/clixon-controller/issues/187)

View file

@ -357,12 +357,6 @@ startup_common(clixon_handle h,
/* Handcraft transition with with only add tree */
td->td_target = xt;
xt = NULL;
/* Add global src defaults. */
if (xml_global_defaults(h, td->td_src, NULL, NULL, yspec, 0) < 0)
goto done;
/* Apply default values (removed in clear function) */
if (xml_default_recurse(td->td_src, 0, 0) < 0)
goto done;
if (compute_diffs(h, td) < 0)
goto done;
/* 4. Call plugin transaction start callbacks */

View file

@ -152,8 +152,8 @@ if [ $BE -ne 0 ]; then
if [ $? -ne 0 ]; then
err
fi
new "start backend -s init -f $cfg -l f$flog -- -t -v \"/x/y[a='$errnr']\""
start_backend -s init -f $cfg -l f$flog -- -t -v "/x/y[a='$errnr']" # -t means transaction logging
new "start backend -s init -f $cfg -l f$flog -- -t -V \"/x/y[a='$errnr']\""
start_backend -s init -f $cfg -l f$flog -- -t -V "/x/y[a='$errnr']" # -t means transaction logging
fi
new "wait backend"

129
test/test_transaction_startup.sh Executable file
View file

@ -0,0 +1,129 @@
#!/usr/bin/env bash
# Transaction functionality: Start from startup and ensure
# first transaction is OK including diff
# See eg https://github.com/clicon/clixon/issues/596
# 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/trans.yang
flog=$dir/backend.log
touch $flog
# Used as a trigger for user-validation errors, eg <a>$errnr</a> = <a>42</a> is invalid
errnr=42
cat <<EOF > $fyang
module trans{
yang-version 1.1;
namespace "urn:example:clixon";
prefix ex;
container x {
leaf y {
type string;
default "abc";
}
leaf z {
type string;
}
}
}
EOF
cat <<EOF > $cfg
<clixon-config xmlns="http://clicon.org/config">
<CLICON_CONFIGFILE>$cfg</CLICON_CONFIGFILE>
<CLICON_FEATURE>ietf-netconf:startup</CLICON_FEATURE>
<CLICON_YANG_DIR>${YANG_INSTALLDIR}</CLICON_YANG_DIR>
<CLICON_YANG_MAIN_FILE>$fyang</CLICON_YANG_MAIN_FILE>
<CLICON_CLISPEC_DIR>/usr/local/lib/$APPNAME/clispec</CLICON_CLISPEC_DIR>
<CLICON_BACKEND_DIR>/usr/local/lib/$APPNAME/backend</CLICON_BACKEND_DIR>
<CLICON_NETCONF_DIR>/usr/local/lib/$APPNAME/netconf</CLICON_NETCONF_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>$dir/$APPNAME.sock</CLICON_SOCK>
<CLICON_BACKEND_PIDFILE>/usr/local/var/run/$APPNAME.pidfile</CLICON_BACKEND_PIDFILE>
<CLICON_XMLDB_DIR>$dir</CLICON_XMLDB_DIR>
</clixon-config>
EOF
# Create startup db revision from 2014-05-08 to be upgraded to 2018-02-20
# This is 2014 syntax
cat <<EOF > $dir/startup_db
<${DATASTORE_TOP}>
<x xmlns="urn:example:clixon">
<z>efg</z>
</x>
</${DATASTORE_TOP}>
EOF
# Check statements in log
# arg1: a statement to look for
# arg2: expected line number
function checklog(){
s=$1 # statement
l0=$2 # linenr
new "Check $s in log"
echo "grep \"transaction_log $s line:$l0\" $flog"
t=$(grep -n "transaction_log $s" $flog)
if [ -z "$t" ]; then
echo -e "\e[31m\nError in Test$testnr [$testname]:"
if [ $# -gt 0 ]; then
echo "Not found \"$s\" on line $l0"
echo
fi
echo -e "\e[0m"
exit -1
fi
l1=$(echo "$t" | awk -F ":" '{print $1}')
if [ $l1 -ne $l0 ]; then
echo -e "\e[31m\nError in Test$testnr [$testname]:"
if [ $# -gt 0 ]; then
echo "Expected match on line $l0, found on $l1"
echo
fi
echo -e "\e[0m"
exit -1
fi
}
new "test params: -f $cfg -l f$flog -- -t"
# Bring your own backend
if [ $BE -ne 0 ]; then
# kill old backend (if any)
new "kill old backend"
sudo clixon_backend -zf $cfg
if [ $? -ne 0 ]; then
err
fi
new "start backend -s init -f $cfg -l f$flog -- -t"
start_backend -s startup -f $cfg -l f$flog -- -t # -t means transaction logging
fi
new "wait backend"
wait_backend
let line=0 # Skipping basic transaction
let line++
checklog "0 main_begin add: <x xmlns=\"urn:example:clixon\"><y>abc</y><z>efg</z></x>" $line
if [ $BE -ne 0 ]; then
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
new "endtest"
endtest