#!/usr/bin/env bash
# Load startup with non-compatible and invalid module A with rev 0814-01-28
# Go into fail-safe with invalid startup
# Repair by copying startup into candidate, editing and commit it
# 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
fyangA0=$dir/A@0814-01-28.yang
fyangA1=$dir/A@2019-01-01.yang
OLDXML='old version'
SAMEXML='always work'
NEWXML='new version'
# Yang module A revision "0814-01-28"
# Note that this Yang model will exist in the DIR but will not be loaded
# by the system. Just here for reference
# XXX: Maybe it should be loaded and used in draft-wu?
cat < $fyangA0
module A{
prefix a;
revision 0814-01-28;
namespace "urn:example:a";
leaf a0{
type string;
}
leaf a1{
type string;
}
}
EOF
# Yang module A revision "2019-01-01"
cat < $fyangA1
module A{
prefix a;
revision 2019-01-01;
revision 0814-01-28;
namespace "urn:example:a";
/* leaf a0 has been removed */
leaf a1{
description "exists in both versions";
type string;
}
leaf a2{
description "has been added";
type string;
}
}
EOF
# Create configuration
cat < $cfg
$cfgietf-netconf:startup/usr/local/share/clixon$dir/usr/local/var/$APPNAME/$APPNAME.sock/usr/local/lib/example/backend/usr/local/var/$APPNAME/$APPNAME.pidfile$dirtrue/usr/local/lib/$APPNAME/clispec/usr/local/lib/$APPNAME/cli$APPNAME
EOF
# Create failsafe db
cat < $dir/failsafe_db
$SAMEXML
EOF
# Create non-compat startup db
# startup config XML with following (A obsolete, B OK, C lacking)
cat < $dir/non-compat-invalid.xml
42A0814-01-28urn:example:a
$OLDXML
$SAMEXML
EOF
(cd $dir; rm -f tmp_db candidate_db running_db startup_db) # remove databases
(cd $dir; cp non-compat-invalid.xml startup_db)
mode=startup
new "test params: -s $mode -f $cfg"
# 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 $mode -f $cfg"
start_backend -s $mode -f $cfg
fi
new "kill old restconf daemon"
sudo pkill -u www-data clixon_restconf
new "start restconf daemon"
start_restconf -f $cfg
new "waiting"
wait_backend
wait_restconf
new "Check running db content is failsafe"
expecteof "$clixon_netconf -qf $cfg" 0 ']]>]]>' "^$SAMEXML]]>]]>$"
new "copy startup->candidate"
expecteof "$clixon_netconf -qf $cfg" 0 "]]>]]>" "^]]>]]>$"
new "Check candidate db content is startup"
expecteof "$clixon_netconf -qf $cfg" 0 ']]>]]>' "^$OLDXML$SAMEXML]]>]]>$"
# Note you cannot edit invalid XML since a0 lacks namespace
new "Put new version into candidate"
expecteof "$clixon_netconf -qf $cfg" 0 "$NEWXML$SAMEXML]]>]]>" "^]]>]]>$"
new "Check candidate db content is updated"
expecteof "$clixon_netconf -qf $cfg" 0 ']]>]]>' "^$SAMEXML$NEWXML]]>]]>$"
new "commit to running"
expecteof "$clixon_netconf -qf $cfg" 0 "]]>]]>" "^]]>]]>$"
new "Check running db content is updated"
expecteof "$clixon_netconf -qf $cfg" 0 ']]>]]>' "^$SAMEXML$NEWXML]]>]]>$"
new "Kill restconf daemon"
stop_restconf
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
rm -rf $dir
fi