* Replaces the hardcoded "config" keyword. * Implemented by a compile-time option called `DATASTORE_TOP_SYMBOL` option in clixon_custom.h * Tests: added endtest to all tests. Removed all premature exits if BE=0
84 lines
2.7 KiB
Bash
Executable file
84 lines
2.7 KiB
Bash
Executable file
#!/usr/bin/env bash
|
|
# CLI test for CLI translation function
|
|
# Typical usecase is translate a cleartext to encrypt passwords.
|
|
# This example does not use crypt but increment a string and needs the
|
|
# "cli_incstr()" function in the example cli plugin and the clixon-example.yang
|
|
# The test adds a new cli statement but is based on examle_cli.cli
|
|
# The diff here is the "translate" command that adds entry table/parameter=translate
|
|
|
|
# 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
|
|
|
|
# Use yang in example
|
|
|
|
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_MODULE_MAIN>clixon-example</CLICON_YANG_MODULE_MAIN>
|
|
<CLICON_CLISPEC_DIR>$dir</CLICON_CLISPEC_DIR>
|
|
<CLICON_CLI_DIR>/usr/local/lib/$APPNAME/cli</CLICON_CLI_DIR>
|
|
<CLICON_CLI_MODE>$APPNAME</CLICON_CLI_MODE>
|
|
<CLICON_CLI_GENMODEL_TYPE>ALL</CLICON_CLI_GENMODEL_TYPE>
|
|
<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>/usr/local/var/$APPNAME</CLICON_XMLDB_DIR>
|
|
</clixon-config>
|
|
EOF
|
|
|
|
# The diff here is the "translate" command that adds entry table/parameter=translate
|
|
cat<<EOF > $dir/example_cli.cli
|
|
# Clixon example specification
|
|
CLICON_MODE="example";
|
|
CLICON_PROMPT="%U@%H %W> ";
|
|
CLICON_PLUGIN="example_cli";
|
|
|
|
translate <value:string translate:cli_incstr()>, cli_set("/clixon-example:table/parameter=translate/value");
|
|
|
|
show("Show a particular state of the system"){
|
|
configuration("Show configuration"), cli_auto_show("datamodel", "candidate", "xml", false, false);
|
|
}
|
|
validate("Validate changes"), cli_validate();
|
|
commit("Commit the changes"), cli_commit();
|
|
quit("Quit"), cli_quit();
|
|
EOF
|
|
|
|
new "test params: -f $cfg"
|
|
if [ $BE -ne 0 ]; then
|
|
new "kill old backend"
|
|
sudo clixon_backend -z -f $cfg
|
|
if [ $? -ne 0 ]; then
|
|
err
|
|
fi
|
|
new "start backend -s init -f $cfg"
|
|
start_backend -s init -f $cfg
|
|
|
|
new "waiting"
|
|
wait_backend
|
|
fi
|
|
|
|
new "translate abc -> table/parameter=translate/value = bcd"
|
|
expectpart "$($clixon_cli -1 -f $cfg translate abc)" 0 ""
|
|
|
|
new "show config"
|
|
expectpart "$($clixon_cli -1 -f $cfg show config)" 0 "<table xmlns=\"urn:example:clixon\"><parameter><name>translate</name><value>bcd</value></parameter></table>"
|
|
|
|
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
|