* Renamed clixon-clispec.yang to clixon-autocli.yang
* First version of clixon-autocli.yang semantics * Default rules for module exclusion, list-keywords, completion, treeref-state * Specialized rules for compress and exclusion of modules * See [autocli documentation](https://clixon-docs.readthedocs.io/en/latest/cli.html#autocli) * Obsoleted and moved autocli config options from clixon-config.yang to clixon-autocli.yang as follows: * `CLICON_CLI_GENMODEL`, use: `autocli/module-default=false` instead * Removed `clicon_cli_genmodel()` * `CLICON_CLI_GENMODEL_TYPE`, use `autocli/list-keyword-default` and compress rules instead) * Removed `clicon_cli_genmodel_type()` * `CLICON_CLI_GENMODEL_COMPLETION`, use `autocli/completion-default` instead * Removed `clicon_cli_genmodel_completion()` * `CLICON_CLI_AUTOCLI_EXCLUDE`, use `autocli/rule/operation=exclude` instead * `CLICON_CLI_MODEL_TREENAME`, use constant `AUTOCLI_TREENAME` instead * Removed `clicon_cli_model_treename()` * New YANG functions: yang_single_child_type, yang_find_namespace_by_prefix, yang_str2key * Changed return values of yang_find_prefix_by_namespace * Merged `cli_cli2xml()` into `cli2xml()`
This commit is contained in:
parent
dec05e2cae
commit
081e6871b3
45 changed files with 1804 additions and 900 deletions
|
|
@ -24,11 +24,17 @@ cat <<EOF > $cfg
|
|||
<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_CLI_GENMODEL_COMPLETION>1</CLICON_CLI_GENMODEL_COMPLETION>
|
||||
<CLICON_CLI_GENMODEL_TYPE>VARS</CLICON_CLI_GENMODEL_TYPE>
|
||||
<CLICON_CLI_AUTOCLI_EXCLUDE>clixon-restconf</CLICON_CLI_AUTOCLI_EXCLUDE>
|
||||
<CLICON_CLI_LINESCROLLING>0</CLICON_CLI_LINESCROLLING>
|
||||
<CLICON_CLI_TAB_MODE>0</CLICON_CLI_TAB_MODE>
|
||||
<autocli>
|
||||
<enable-autocli>true</enable-autocli>
|
||||
<module-default>false</module-default>
|
||||
<rule>
|
||||
<name>include $APPNAME</name>
|
||||
<operation>enable</operation>
|
||||
<module-name>$APPNAME/module-name>
|
||||
</rule>
|
||||
</autocli>
|
||||
</clixon-config>
|
||||
EOF
|
||||
|
||||
|
|
|
|||
|
|
@ -24,9 +24,6 @@ cat <<EOF > $cfg
|
|||
<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_CLI_GENMODEL_COMPLETION>1</CLICON_CLI_GENMODEL_COMPLETION>
|
||||
<CLICON_CLI_GENMODEL_TYPE>VARS</CLICON_CLI_GENMODEL_TYPE>
|
||||
<CLICON_CLI_AUTOCLI_EXCLUDE>clixon-restconf</CLICON_CLI_AUTOCLI_EXCLUDE>
|
||||
<CLICON_CLI_LINESCROLLING>0</CLICON_CLI_LINESCROLLING>
|
||||
<CLICON_CLI_TAB_MODE>0</CLICON_CLI_TAB_MODE>
|
||||
</clixon-config>
|
||||
|
|
|
|||
29
test/lib.sh
29
test/lib.sh
|
|
@ -249,6 +249,35 @@ function restconf_config()
|
|||
fi
|
||||
}
|
||||
|
||||
# Default autocli configuration
|
||||
# Can be placed in clixon-config
|
||||
# Exclude all modules instead as defined by arg1
|
||||
# Args:
|
||||
# 1: modname module name pattern to be included
|
||||
# 2: list-keyword
|
||||
# 3: treerefstate
|
||||
function autocli_config()
|
||||
{
|
||||
modname=$1
|
||||
listkw=$2
|
||||
state=$3
|
||||
|
||||
TMP=$(cat <<EOF
|
||||
<autocli>
|
||||
<module-default>false</module-default>
|
||||
<list-keyword-default>$listkw</list-keyword-default>
|
||||
<treeref-state-default>$state</treeref-state-default>
|
||||
<rule>
|
||||
<name>include $modname</name>
|
||||
<operation>enable</operation>
|
||||
<module-name>$modname</module-name>
|
||||
</rule>
|
||||
</autocli>
|
||||
EOF
|
||||
)
|
||||
echo "${TMP}"
|
||||
}
|
||||
|
||||
# Some tests may set owner of testdir to something strange and quit, need
|
||||
# to reset to me
|
||||
if [ ! -G $dir ]; then
|
||||
|
|
|
|||
|
|
@ -18,7 +18,8 @@ else
|
|||
mkdir $clidir
|
||||
fi
|
||||
|
||||
# Use yang in example
|
||||
# Generate autocli for these modules
|
||||
AUTOCLI=$(autocli_config ${APPNAME} kw-all false)
|
||||
|
||||
cat <<EOF > $cfg
|
||||
<clixon-config xmlns="http://clicon.org/config">
|
||||
|
|
@ -29,11 +30,10 @@ cat <<EOF > $cfg
|
|||
<CLICON_CLISPEC_DIR>$clidir</CLICON_CLISPEC_DIR>
|
||||
<CLICON_CLI_DIR>/usr/local/lib/$APPNAME/cli</CLICON_CLI_DIR>
|
||||
<CLICON_CLI_MODE>$APPNAME</CLICON_CLI_MODE>
|
||||
<!-- ALL or VARS -->
|
||||
<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>
|
||||
${AUTOCLI}
|
||||
</clixon-config>
|
||||
EOF
|
||||
|
||||
|
|
|
|||
|
|
@ -22,6 +22,9 @@ fi
|
|||
|
||||
# Use yang in example
|
||||
|
||||
# Generate autocli for these modules
|
||||
AUTOCLI=$(autocli_config ${APPNAME}\* kw-nokey false)
|
||||
|
||||
cat <<EOF > $cfg
|
||||
<clixon-config xmlns="http://clicon.org/config">
|
||||
<CLICON_CONFIGFILE>$cfg</CLICON_CONFIGFILE>
|
||||
|
|
@ -33,17 +36,14 @@ cat <<EOF > $cfg
|
|||
<CLICON_CLISPEC_DIR>$clidir</CLICON_CLISPEC_DIR>
|
||||
<CLICON_CLI_DIR>/usr/local/lib/$APPNAME/cli</CLICON_CLI_DIR>
|
||||
<CLICON_CLI_MODE>$APPNAME</CLICON_CLI_MODE>
|
||||
<CLICON_CLI_GENMODEL>2</CLICON_CLI_GENMODEL>
|
||||
<CLICON_CLI_GENMODEL_TYPE>VARS</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>$dir</CLICON_XMLDB_DIR>
|
||||
<CLICON_MODULE_LIBRARY_RFC7895>false</CLICON_MODULE_LIBRARY_RFC7895>
|
||||
<CLICON_CLI_AUTOCLI_EXCLUDE>clixon-restconf</CLICON_CLI_AUTOCLI_EXCLUDE>
|
||||
${AUTOCLI}
|
||||
</clixon-config>
|
||||
EOF
|
||||
|
||||
|
||||
cat <<EOF > $clidir/ex.cli
|
||||
CLICON_MODE="example";
|
||||
CLICON_PROMPT="%U@%H %W> ";
|
||||
|
|
|
|||
|
|
@ -4,7 +4,7 @@
|
|||
# In particular setting a config, displaying as cli commands and reconfigure it
|
||||
# Tests:
|
||||
# Make a config in CLI. Show output as CLI, save it and ensure it is the same
|
||||
# Try the different GENMODEL settings
|
||||
# Try different list-keyword and compress settings (see clixon-autocli.yang)
|
||||
# NOTE this uses the "Old" autocli (eg cli_set()), see test_cli_auto.sh for "new" autocli using the cli_auto_*() API
|
||||
|
||||
# Magic line must be first in script (see README.md)
|
||||
|
|
@ -32,27 +32,7 @@ if [ ! -d "$OPENCONFIG" ]; then
|
|||
echo "...skipped: OPENCONFIG not set"
|
||||
if [ "$s" = $0 ]; then exit 0; else return 0; fi
|
||||
fi
|
||||
|
||||
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_DIR>$dir</CLICON_YANG_DIR>
|
||||
<CLICON_YANG_DIR>$OPENCONFIG/</CLICON_YANG_DIR>
|
||||
<CLICON_YANG_MAIN_DIR>$dir</CLICON_YANG_MAIN_DIR>
|
||||
<CLICON_BACKEND_DIR>/usr/local/lib/$APPNAME/backend</CLICON_BACKEND_DIR>
|
||||
<CLICON_CLISPEC_DIR>$clidir</CLICON_CLISPEC_DIR>
|
||||
<CLICON_CLI_DIR>/usr/local/lib/$APPNAME/cli</CLICON_CLI_DIR>
|
||||
<CLICON_CLI_MODE>$APPNAME</CLICON_CLI_MODE>
|
||||
<CLICON_CLI_GENMODEL>2</CLICON_CLI_GENMODEL>
|
||||
<CLICON_CLI_GENMODEL_TYPE>VARS</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>
|
||||
<CLICON_MODULE_LIBRARY_RFC7895>false</CLICON_MODULE_LIBRARY_RFC7895>
|
||||
<CLICON_CLI_AUTOCLI_EXCLUDE>clixon-restconf</CLICON_CLI_AUTOCLI_EXCLUDE>
|
||||
</clixon-config>
|
||||
EOF
|
||||
OCDIR=$OPENCONFIG/release/models
|
||||
|
||||
cat <<EOF > $fyang
|
||||
module $APPNAME {
|
||||
|
|
@ -181,6 +161,79 @@ discard, discard_changes();
|
|||
|
||||
EOF
|
||||
|
||||
# Set config for CLI
|
||||
# 1. listkw - either none, vars, all
|
||||
# 2 compress - surrounding container entities are removed from list nodes
|
||||
# 3. openconfig - config and state containers are "compressed" out of the schema in openconfig modules
|
||||
function setconfig()
|
||||
{
|
||||
listkw=$1
|
||||
compress=$2
|
||||
openconfig=$3
|
||||
|
||||
if $compress; then
|
||||
COMPRESS=$(cat <<EOF
|
||||
<rule>
|
||||
<name>compress</name>
|
||||
<operation>compress</operation>
|
||||
<yang-keyword>container</yang-keyword>
|
||||
<yang-keyword-child>list</yang-keyword-child>
|
||||
</rule>
|
||||
EOF
|
||||
)
|
||||
else
|
||||
COMPRESS=""
|
||||
fi
|
||||
if $openconfig; then
|
||||
OCOMPRESS=$(cat <<EOF
|
||||
<rule>
|
||||
<name>openconfig compress</name>
|
||||
<operation>compress</operation>
|
||||
<yang-keyword>container</yang-keyword>
|
||||
<schema-nodeid>config</schema-nodeid>
|
||||
<!--schema-nodeid>state</schema-nodeid-->
|
||||
<!--module-name>openconfig*</module-name-->
|
||||
<extension>oc-ext:openconfig-version</extension>
|
||||
</rule>"
|
||||
EOF
|
||||
)
|
||||
else
|
||||
OCOMPRESS=""
|
||||
fi
|
||||
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_DIR>$dir</CLICON_YANG_DIR>
|
||||
<CLICON_YANG_DIR>$OCDIR/</CLICON_YANG_DIR>
|
||||
<CLICON_YANG_MAIN_DIR>$dir</CLICON_YANG_MAIN_DIR>
|
||||
<CLICON_BACKEND_DIR>/usr/local/lib/$APPNAME/backend</CLICON_BACKEND_DIR>
|
||||
<CLICON_CLISPEC_DIR>$clidir</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>/usr/local/var/$APPNAME</CLICON_XMLDB_DIR>
|
||||
<CLICON_MODULE_LIBRARY_RFC7895>false</CLICON_MODULE_LIBRARY_RFC7895>
|
||||
<autocli>
|
||||
<module-default>false</module-default>
|
||||
<list-keyword-default>${listkw}</list-keyword-default>
|
||||
<treeref-state-default>true</treeref-state-default>
|
||||
<rule>
|
||||
<name>include ${APPNAME}</name>
|
||||
<operation>enable</operation>
|
||||
<module-name>${APPNAME}*</module-name>
|
||||
</rule>
|
||||
${COMPRESS}
|
||||
${OCOMPRESS}
|
||||
</autocli>
|
||||
</clixon-config>
|
||||
EOF
|
||||
} # setconfig
|
||||
|
||||
new "Set config before backend start"
|
||||
setconfig kw-nokey false false
|
||||
|
||||
new "test params: -f $cfg"
|
||||
if [ $BE -ne 0 ]; then
|
||||
new "kill old backend"
|
||||
|
|
@ -199,90 +252,112 @@ wait_backend
|
|||
# then deleting it, and reloading it
|
||||
# 1. mode - either VARS Keywords on non-key variables: a <x> y <y> or
|
||||
# ALL Keywords on all variables: a x <x> y <y>
|
||||
# HIDE
|
||||
# OC_COMPRESS
|
||||
# 2. listkw - either none, vars, all
|
||||
# 3. compress - surrounding container entities are removed from list nodes
|
||||
# 4. openconfig - config and state containers are "compressed" out of the schema in openconfig modules
|
||||
function testrun()
|
||||
{
|
||||
mode=$1
|
||||
if [ $mode = ALL ]; then
|
||||
table=" table"
|
||||
listkw=$2
|
||||
compress=$3
|
||||
|
||||
if [ $listkw = kw-all ]; then
|
||||
name=" name"
|
||||
elif [ $mode = HIDE ]; then
|
||||
table=
|
||||
else
|
||||
name=
|
||||
elif [ $mode = OC_COMPRESS ]; then
|
||||
fi
|
||||
if $compress; then
|
||||
table=
|
||||
name=
|
||||
else
|
||||
table=" table"
|
||||
name=
|
||||
fi
|
||||
|
||||
new "set a"
|
||||
expectpart "$($clixon_cli -1 -o CLICON_CLI_GENMODEL_TYPE=$mode -f $cfg set$table parameter$name a value x)" 0 ""
|
||||
|
||||
echo "$clixon_cli -1 -f $cfg set$table parameter$name a value x"
|
||||
expectpart "$($clixon_cli -1 -f $cfg set$table parameter$name a value x)" 0 ""
|
||||
|
||||
new "set b"
|
||||
expectpart "$($clixon_cli -1 -o CLICON_CLI_GENMODEL_TYPE=$mode -f $cfg set$table parameter$name b value y)" 0 ""
|
||||
expectpart "$($clixon_cli -1 -f $cfg set$table parameter$name b value y)" 0 ""
|
||||
|
||||
new "reset b"
|
||||
expectpart "$($clixon_cli -1 -o CLICON_CLI_GENMODEL_TYPE=$mode -f $cfg set$table parameter$name b value z)" 0 ""
|
||||
expectpart "$($clixon_cli -1 -f $cfg set$table parameter$name b value z)" 0 ""
|
||||
|
||||
new "show match a & b"
|
||||
expectpart "$($clixon_cli -1 -o CLICON_CLI_GENMODEL_TYPE=$mode -f $cfg show config)" 0 "set$table parameter$name a" "set$table parameter$name a value x" "set$table parameter$name b" "set$table parameter$name b value z" --not-- "set$table parameter$name b value y"
|
||||
SAVED=$($clixon_cli -1 -o CLICON_CLI_GENMODEL_TYPE=$mode -f $cfg show config)
|
||||
expectpart "$($clixon_cli -1 -f $cfg show config)" 0 "set$table parameter$name a" "set$table parameter$name a value x" "set$table parameter$name b" "set$table parameter$name b value z" --not-- "set$table parameter$name b value y"
|
||||
|
||||
SAVED=$($clixon_cli -1 -f $cfg show config)
|
||||
# awkward having pretty-printed xml in matching strings
|
||||
|
||||
new "show match a & b xml"
|
||||
expectpart "$($clixon_cli -1 -o CLICON_CLI_GENMODEL_TYPE=$mode -f $cfg show xml)" 0 "<table xmlns=\"urn:example:clixon\">" "<parameter>" "<name>a</name>" "<value>x</value>" "</parameter>" "<parameter>" "<name>b</name>" "<value>z</value>" "</parameter>" "</table>"
|
||||
expectpart "$($clixon_cli -1 -f $cfg show xml)" 0 "<table xmlns=\"urn:example:clixon\">" "<parameter>" "<name>a</name>" "<value>x</value>" "</parameter>" "<parameter>" "<name>b</name>" "<value>z</value>" "</parameter>" "</table>"
|
||||
|
||||
# https://github.com/clicon/clixon/issues/157
|
||||
new "delete a y expect fail"
|
||||
expectpart "$($clixon_cli -1 -o CLICON_CLI_GENMODEL_TYPE=$mode -f $cfg delete$table parameter$name a value y 2>&1)" 0 ""
|
||||
expectpart "$($clixon_cli -1 -f $cfg delete$table parameter$name a value y 2>&1)" 0 ""
|
||||
|
||||
new "show match a & b xml" # Expect same
|
||||
expectpart "$($clixon_cli -1 -o CLICON_CLI_GENMODEL_TYPE=$mode -f $cfg show xml)" 0 "<table xmlns=\"urn:example:clixon\">" "<parameter>" "<name>a</name>" "<value>x</value>" "</parameter>" "<parameter>" "<name>b</name>" "<value>z</value>" "</parameter>" "</table>"
|
||||
expectpart "$($clixon_cli -1 -f $cfg show xml)" 0 "<table xmlns=\"urn:example:clixon\">" "<parameter>" "<name>a</name>" "<value>x</value>" "</parameter>" "<parameter>" "<name>b</name>" "<value>z</value>" "</parameter>" "</table>"
|
||||
|
||||
new "delete a x"
|
||||
expectpart "$($clixon_cli -1 -o CLICON_CLI_GENMODEL_TYPE=$mode -f $cfg delete$table parameter$name a value x)" 0 ""
|
||||
expectpart "$($clixon_cli -1 -f $cfg delete$table parameter$name a value x)" 0 ""
|
||||
|
||||
new "show match a & b xml"
|
||||
expectpart "$($clixon_cli -1 -o CLICON_CLI_GENMODEL_TYPE=$mode -f $cfg show xml)" 0 "<table xmlns=\"urn:example:clixon\">" "<parameter>" "<name>a</name>" "</parameter>" "<parameter>" "<name>b</name>" "<value>z</value>" "</parameter>" "</table>" --not-- "<value>x</value>"
|
||||
expectpart "$($clixon_cli -1 -f $cfg show xml)" 0 "<table xmlns=\"urn:example:clixon\">" "<parameter>" "<name>a</name>" "</parameter>" "<parameter>" "<name>b</name>" "<value>z</value>" "</parameter>" "</table>" --not-- "<value>x</value>"
|
||||
|
||||
new "delete a"
|
||||
expectpart "$($clixon_cli -1 -o CLICON_CLI_GENMODEL_TYPE=$mode -f $cfg delete$table parameter$name a)" 0 ""
|
||||
expectpart "$($clixon_cli -1 -f $cfg delete$table parameter$name a)" 0 ""
|
||||
|
||||
new "show match b"
|
||||
expectpart "$($clixon_cli -1 -o CLICON_CLI_GENMODEL_TYPE=$mode -f $cfg show config)" 0 "$table parameter$name b" "$table parameter$name b value z" --not-- "$table parameter$name a" "$table parameter$name a value x" "$table parameter$name b value y"
|
||||
expectpart "$($clixon_cli -1 -f $cfg show config)" 0 "$table parameter$name b" "$table parameter$name b value z" --not-- "$table parameter$name a" "$table parameter$name a value x" "$table parameter$name b value y"
|
||||
|
||||
new "discard"
|
||||
expectpart "$($clixon_cli -1 -o CLICON_CLI_GENMODEL_TYPE=$mode -f $cfg discard)" 0 ""
|
||||
expectpart "$($clixon_cli -1 -f $cfg discard)" 0 ""
|
||||
|
||||
new "show match empty"
|
||||
expectpart "$($clixon_cli -1 -o CLICON_CLI_GENMODEL_TYPE=$mode -f $cfg show config)" 0 --not-- "$table parameter$name b" "$table parameter$name b value z" "$table parameter$name a" "$table parameter$name a value x" "$table parameter$name b value y"
|
||||
expectpart "$($clixon_cli -1 -f $cfg show config)" 0 --not-- "$table parameter$name b" "$table parameter$name b value z" "$table parameter$name a" "$table parameter$name a value x" "$table parameter$name b value y"
|
||||
|
||||
new "load saved cli config"
|
||||
expectpart "$(echo "$SAVED" | $clixon_cli -o CLICON_CLI_GENMODEL_TYPE=$mode -f $cfg)" 0 ""
|
||||
expectpart "$(echo "$SAVED" | $clixon_cli -f $cfg)" 0 ""
|
||||
|
||||
new "show saved a & b"
|
||||
expectpart "$($clixon_cli -1 -o CLICON_CLI_GENMODEL_TYPE=$mode -f $cfg show config)" 0 "set$table parameter$name a" "set$table parameter$name a value x" "set$table parameter$name b" "set$table parameter$name b value z" --not-- "set$table parameter$name b value y"
|
||||
expectpart "$($clixon_cli -1 -f $cfg show config)" 0 "set$table parameter$name a" "set$table parameter$name a value x" "set$table parameter$name b" "set$table parameter$name b value z" --not-- "set$table parameter$name b value y"
|
||||
|
||||
new "discard"
|
||||
expectpart "$($clixon_cli -1 -o CLICON_CLI_GENMODEL_TYPE=$mode -f $cfg discard)" 0 ""
|
||||
expectpart "$($clixon_cli -1 -f $cfg discard)" 0 ""
|
||||
} # testrun
|
||||
|
||||
new "keywords=HIDE"
|
||||
testrun HIDE
|
||||
new "Config: Keywords on non-keys"
|
||||
setconfig kw-nokey false false
|
||||
|
||||
new "keywords=ALL"
|
||||
testrun ALL
|
||||
new "Keywords on non-keys"
|
||||
testrun VARS kw-nokey false
|
||||
|
||||
new "keywords=OC_COMPRESS"
|
||||
testrun OC_COMPRESS
|
||||
new "Config: Keywords on all"
|
||||
setconfig kw-all false false
|
||||
|
||||
new "keywords=VARS"
|
||||
testrun VARS
|
||||
new "Keywords on all"
|
||||
testrun ALL kw-all false
|
||||
|
||||
new "Config: Keywords on non-keys, container compress"
|
||||
setconfig kw-nokey true false
|
||||
|
||||
new "Keywords on non-keys, container compress"
|
||||
testrun HIDE kw-nokey true
|
||||
|
||||
new "Config:Keywords on non-keys, container and openconfig compress"
|
||||
setconfig kw-nokey true true
|
||||
|
||||
new "Keywords on non-keys, container and openconfig compress"
|
||||
testrun OC_COMPRESS kw-nokey true
|
||||
|
||||
new "Config:default"
|
||||
setconfig kw-nokey false false
|
||||
|
||||
# show state
|
||||
new "set a"
|
||||
expectpart "$($clixon_cli -1 -f $cfg set$table parameter a value x)" 0 ""
|
||||
expectpart "$($clixon_cli -1 -f $cfg set table parameter a value x)" 0 ""
|
||||
|
||||
new "commit"
|
||||
expectpart "$($clixon_cli -1 -f $cfg commit)" 0 ""
|
||||
|
|
@ -295,23 +370,29 @@ expectpart "$($clixon_cli -1 -f $cfg show state exstate)" 0 "state sender x" --n
|
|||
|
||||
#---- openconfig path compression
|
||||
|
||||
new "Config:Openconfig compression"
|
||||
setconfig kw-nokey true true
|
||||
|
||||
new "Openconfig: OC_COMPRESS+extension: compressed)"
|
||||
expectpart "$($clixon_cli -1 -f $cfg -o CLICON_CLI_GENMODEL_TYPE=OC_COMPRESS set interface e enabled true 2>&1)" 0 "^$"
|
||||
expectpart "$($clixon_cli -1 -f $cfg set interface e enabled true 2>&1)" 0 "^$"
|
||||
|
||||
new "Openconfig: OC_COMPRESS+extension: no config (negative)"
|
||||
expectpart "$($clixon_cli -1 -f $cfg -o CLICON_CLI_GENMODEL_TYPE=OC_COMPRESS set interface e config enabled true 2>&1)" 255 "Unknown command"
|
||||
expectpart "$($clixon_cli -1 -f $cfg set interface e config enabled true 2>&1)" 255 "Unknown command"
|
||||
|
||||
new "Openconfig: OC_COMPRESS+no-extension: no config"
|
||||
expectpart "$($clixon_cli -1 -f $cfg -o CLICON_CLI_GENMODEL_TYPE=OC_COMPRESS set interface2 e config enabled true 2>&1)" 0 "^$"
|
||||
expectpart "$($clixon_cli -1 -f $cfg set interface2 e config enabled true 2>&1)" 0 "^$"
|
||||
|
||||
new "Openconfig: OC_COMPRESS+no-extension: no config (negative)"
|
||||
expectpart "$($clixon_cli -1 -f $cfg -o CLICON_CLI_GENMODEL_TYPE=OC_COMPRESS set interface2 e enabled true 2>&1)" 255 "Unknown command"
|
||||
expectpart "$($clixon_cli -1 -f $cfg set interface2 e enabled true 2>&1)" 255 "Unknown command"
|
||||
|
||||
new "Config: default"
|
||||
setconfig kw-nokey false false
|
||||
|
||||
new "Openconfig: OC_VARS+extension: no compresssion"
|
||||
expectpart "$($clixon_cli -1 -f $cfg -o CLICON_CLI_GENMODEL_TYPE=VARS set interfaces interface e config enabled true 2>&1)" 0 "^$"
|
||||
expectpart "$($clixon_cli -1 -f $cfg set interfaces interface e config enabled true 2>&1)" 0 "^$"
|
||||
|
||||
new "Openconfig: OC_VARS+extension: no compresssion (negative)"
|
||||
expectpart "$($clixon_cli -1 -f $cfg -o CLICON_CLI_GENMODEL_TYPE=VARS set interfaces interface e enabled true 2>&1)" 255 "Unknown command"
|
||||
expectpart "$($clixon_cli -1 -f $cfg set interfaces interface e enabled true 2>&1)" 255 "Unknown command"
|
||||
|
||||
new "Kill backend"
|
||||
# Check if premature kill
|
||||
|
|
|
|||
222
test/test_cli_auto_spec.sh
Executable file
222
test/test_cli_auto_spec.sh
Executable file
|
|
@ -0,0 +1,222 @@
|
|||
#!/usr/bin/env bash
|
||||
# Test of clixon-clispec.yang and cli_clispec.[ch]
|
||||
|
||||
# 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
|
||||
|
||||
# include err() and new() functions and creates $dir
|
||||
|
||||
cfg=$dir/conf_yang.xml
|
||||
fspec=$dir/automode.cli
|
||||
fin=$dir/in
|
||||
fstate=$dir/state.xml
|
||||
fyang=$dir/clixon-example.yang
|
||||
fyang2=$dir/clixon-example2.yang
|
||||
|
||||
cat <<EOF > $fyang
|
||||
module clixon-example {
|
||||
yang-version 1.1;
|
||||
namespace "urn:example:clixon";
|
||||
prefix ex;
|
||||
/* Generic config data */
|
||||
container table{
|
||||
list parameter{
|
||||
key name;
|
||||
leaf name{
|
||||
type string;
|
||||
}
|
||||
leaf value{
|
||||
type string;
|
||||
}
|
||||
leaf stat{
|
||||
description "Inline state data for example application";
|
||||
config false;
|
||||
type int32;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
EOF
|
||||
|
||||
cat <<EOF > $fyang2
|
||||
module clixon-example2 {
|
||||
yang-version 1.1;
|
||||
namespace "urn:example:clixon2";
|
||||
prefix ex2;
|
||||
/* Alt config data */
|
||||
container table2{
|
||||
list parameter{
|
||||
key name;
|
||||
leaf name{
|
||||
type string;
|
||||
}
|
||||
leaf value{
|
||||
type string;
|
||||
}
|
||||
leaf stat{
|
||||
description "Inline state data for example application";
|
||||
config false;
|
||||
type int32;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
EOF
|
||||
|
||||
cat <<EOF > $fspec
|
||||
CLICON_MODE="example";
|
||||
CLICON_PROMPT="%U@%H %W> ";
|
||||
CLICON_PLUGIN="example_cli";
|
||||
|
||||
# Autocli syntax tree operations
|
||||
edit @datamodelshow, cli_auto_edit("basemodel");
|
||||
up, cli_auto_up("basemodel");
|
||||
top, cli_auto_top("basemodel");
|
||||
set @datamodel, cli_auto_set();
|
||||
merge @datamodel, cli_auto_merge();
|
||||
create @datamodel, cli_auto_create();
|
||||
delete("Delete a configuration item") @datamodel, cli_auto_del();
|
||||
validate("Validate changes"), cli_validate();
|
||||
commit("Commit the changes"), cli_commit();
|
||||
quit("Quit"), cli_quit();
|
||||
show("Show a particular state of the system"){
|
||||
configuration("Show configuration"), cli_auto_show("datamodel", "candidate", "text", true, false);{
|
||||
xml("Show configuration as XML"), cli_auto_show("datamodel", "candidate", "xml", false, false);
|
||||
cli("Show configuration as CLI commands"), cli_auto_show("datamodel", "candidate", "cli", false, false, "set ");
|
||||
netconf("Show configuration as netconf edit-config operation"), cli_auto_show("datamodel", "candidate", "netconf", false, false);
|
||||
text("Show configuration as text"), cli_auto_show("datamodel", "candidate", "text", false, false);
|
||||
json("Show configuration as JSON"), cli_auto_show("datamodel", "candidate", "json", false, false);
|
||||
}
|
||||
state("Show configuration and state"), cli_auto_show("datamodel", "running", "xml", false, true);
|
||||
}
|
||||
EOF
|
||||
|
||||
cat <<EOF > $dir/startup_db
|
||||
<${DATASTORE_TOP}>
|
||||
<table xmlns="urn:example:clixon">
|
||||
<parameter>
|
||||
<name>a</name>
|
||||
<value>42</value>
|
||||
</parameter>
|
||||
</table>
|
||||
</${DATASTORE_TOP}>
|
||||
EOF
|
||||
|
||||
# Add inline state
|
||||
cat <<EOF > $fstate
|
||||
<table xmlns="urn:example:clixon">
|
||||
<parameter>
|
||||
<name>a</name>
|
||||
<stat>99</stat>
|
||||
</parameter>
|
||||
</table>
|
||||
EOF
|
||||
|
||||
# Make a new variant of clixon config file
|
||||
# Arg 1: autocli-spec
|
||||
function runconfig()
|
||||
{
|
||||
AUTOCLI="$1"
|
||||
|
||||
# Use yang in example
|
||||
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>/usr/local/share/clixon</CLICON_YANG_DIR>
|
||||
<CLICON_YANG_DIR>$IETFRFC</CLICON_YANG_DIR>
|
||||
<CLICON_YANG_MAIN_DIR>$dir</CLICON_YANG_MAIN_DIR>
|
||||
<CLICON_BACKEND_DIR>/usr/local/lib/$APPNAME/backend</CLICON_BACKEND_DIR>
|
||||
<CLICON_CLI_MODE>$APPNAME</CLICON_CLI_MODE>
|
||||
<CLICON_CLI_DIR>/usr/local/lib/$APPNAME/cli</CLICON_CLI_DIR>
|
||||
<CLICON_CLISPEC_DIR>$dir</CLICON_CLISPEC_DIR>
|
||||
<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>
|
||||
<CLICON_XMLDB_PRETTY>false</CLICON_XMLDB_PRETTY>
|
||||
${AUTOCLI}
|
||||
</clixon-config>
|
||||
EOF
|
||||
}
|
||||
|
||||
new "backend config"
|
||||
runconfig ""
|
||||
|
||||
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 startup -f $cfg -- -sS $fstate"
|
||||
start_backend -s startup -f $cfg -- -sS $fstate
|
||||
fi
|
||||
|
||||
new "wait backend"
|
||||
wait_backend
|
||||
|
||||
AUTOCLI=$(cat <<EOF
|
||||
<autocli>
|
||||
<module-default>false</module-default>
|
||||
</autocli>
|
||||
EOF
|
||||
)
|
||||
new "disable autocli"
|
||||
runconfig "$AUTOCLI"
|
||||
|
||||
new "set table expected fail"
|
||||
expectpart "$(echo "set table" | $clixon_cli -f $cfg 2>&1)" 255 "CLIgen tree 'datamodel' not found"
|
||||
|
||||
AUTOCLI=$(cat <<EOF
|
||||
<autocli>
|
||||
<module-default>true</module-default>
|
||||
</autocli>
|
||||
EOF
|
||||
)
|
||||
|
||||
new "enable autocli"
|
||||
runconfig "$AUTOCLI"
|
||||
|
||||
new "set table OK"
|
||||
expectpart "$(echo "set table" | $clixon_cli -f $cfg 2>&1)" 0 ""
|
||||
|
||||
AUTOCLI=$(cat <<EOF
|
||||
<autocli>
|
||||
<module-default>false</module-default>
|
||||
<rule>
|
||||
<name>include example</name>
|
||||
<operation>enable</operation>
|
||||
<description>Include the example module for autocli generation</description>
|
||||
<module-name>clixon-example</module-name>
|
||||
</rule>
|
||||
</autocli>
|
||||
EOF
|
||||
)
|
||||
|
||||
new "exclude example2 using default"
|
||||
runconfig "$AUTOCLI"
|
||||
|
||||
new "set table"
|
||||
expectpart "$(echo "set table" | $clixon_cli -f $cfg 2>&1)" 0 ""
|
||||
|
||||
new "set table2 expect fail"
|
||||
expectpart "$(echo "set table2" | $clixon_cli -f $cfg 2>&1)" 0 "CLI syntax error" "Unknown command"
|
||||
|
||||
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
|
||||
|
|
@ -19,7 +19,8 @@ else
|
|||
mkdir $clidir
|
||||
fi
|
||||
|
||||
# Use yang in example
|
||||
# Generate autocli for these modules
|
||||
AUTOCLI=$(autocli_config ${APPNAME}\* kw-nokey false)
|
||||
|
||||
cat <<EOF > $cfg
|
||||
<clixon-config xmlns="http://clicon.org/config">
|
||||
|
|
@ -32,13 +33,11 @@ cat <<EOF > $cfg
|
|||
<CLICON_CLISPEC_DIR>$clidir</CLICON_CLISPEC_DIR>
|
||||
<CLICON_CLI_DIR>/usr/local/lib/$APPNAME/cli</CLICON_CLI_DIR>
|
||||
<CLICON_CLI_MODE>$APPNAME</CLICON_CLI_MODE>
|
||||
<CLICON_CLI_GENMODEL>2</CLICON_CLI_GENMODEL>
|
||||
<CLICON_CLI_GENMODEL_TYPE>VARS</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>$dir</CLICON_XMLDB_DIR>
|
||||
<CLICON_MODULE_LIBRARY_RFC7895>false</CLICON_MODULE_LIBRARY_RFC7895>
|
||||
<CLICON_CLI_AUTOCLI_EXCLUDE>clixon-restconf</CLICON_CLI_AUTOCLI_EXCLUDE>
|
||||
${AUTOCLI}
|
||||
</clixon-config>
|
||||
EOF
|
||||
|
||||
|
|
|
|||
|
|
@ -20,7 +20,8 @@ else
|
|||
mkdir $clidir
|
||||
fi
|
||||
|
||||
# Use yang in example
|
||||
# Generate autocli for these modules
|
||||
AUTOCLI=$(autocli_config ${APPNAME}\* kw-nokey true)
|
||||
|
||||
cat <<EOF > $cfg
|
||||
<clixon-config xmlns="http://clicon.org/config">
|
||||
|
|
@ -32,13 +33,11 @@ cat <<EOF > $cfg
|
|||
<CLICON_CLISPEC_DIR>$clidir</CLICON_CLISPEC_DIR>
|
||||
<CLICON_CLI_DIR>/usr/local/lib/$APPNAME/cli</CLICON_CLI_DIR>
|
||||
<CLICON_CLI_MODE>$APPNAME</CLICON_CLI_MODE>
|
||||
<CLICON_CLI_GENMODEL>2</CLICON_CLI_GENMODEL>
|
||||
<CLICON_CLI_GENMODEL_TYPE>VARS</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>
|
||||
<CLICON_MODULE_LIBRARY_RFC7895>false</CLICON_MODULE_LIBRARY_RFC7895>
|
||||
<CLICON_CLI_AUTOCLI_EXCLUDE>clixon-restconf</CLICON_CLI_AUTOCLI_EXCLUDE>
|
||||
${AUTOCLI}
|
||||
</clixon-config>
|
||||
EOF
|
||||
|
||||
|
|
|
|||
|
|
@ -12,7 +12,8 @@ APPNAME=example
|
|||
cfg=$dir/conf_yang.xml
|
||||
fyang=$dir/$APPNAME.yang
|
||||
|
||||
# Use yang in example
|
||||
# Generate autocli for these modules
|
||||
AUTOCLI=$(autocli_config ${APPNAME} kw-all false)
|
||||
|
||||
cat <<EOF > $cfg
|
||||
<clixon-config xmlns="http://clicon.org/config">
|
||||
|
|
@ -23,11 +24,10 @@ cat <<EOF > $cfg
|
|||
<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>
|
||||
<!-- ALL or VARS -->
|
||||
<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>
|
||||
${AUTOCLI}
|
||||
</clixon-config>
|
||||
EOF
|
||||
|
||||
|
|
|
|||
|
|
@ -14,6 +14,8 @@ APPNAME=example
|
|||
cfg=$dir/conf_yang.xml
|
||||
|
||||
fyang=$dir/clixon-example.yang
|
||||
# Generate autocli for these modules
|
||||
AUTOCLI=$(autocli_config ${APPNAME} kw-all false)
|
||||
|
||||
cat <<EOF > $cfg
|
||||
<clixon-config xmlns="http://clicon.org/config">
|
||||
|
|
@ -23,10 +25,10 @@ cat <<EOF > $cfg
|
|||
<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>
|
||||
${AUTOCLI}
|
||||
</clixon-config>
|
||||
EOF
|
||||
|
||||
|
|
|
|||
|
|
@ -23,24 +23,11 @@ if [ ! -d "$OPENCONFIG" ]; then
|
|||
if [ "$s" = $0 ]; then exit 0; else return 0; fi
|
||||
fi
|
||||
|
||||
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>/usr/local/share/clixon</CLICON_YANG_DIR>
|
||||
<CLICON_YANG_DIR>$OPENCONFIG</CLICON_YANG_DIR>
|
||||
<CLICON_YANG_AUGMENT_ACCEPT_BROKEN>true</CLICON_YANG_AUGMENT_ACCEPT_BROKEN>
|
||||
<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>
|
||||
<CLICON_MODULE_LIBRARY_RFC7895>true</CLICON_MODULE_LIBRARY_RFC7895>
|
||||
</clixon-config>
|
||||
EOF
|
||||
# OPENCONFIG dir has a small number of extra yangs apart from OCDIR
|
||||
OCDIR=$OPENCONFIG/release/models
|
||||
|
||||
files=$(find ${OPENCONFIG} -name "*.yang")
|
||||
|
||||
files=$(find $OPENCONFIG -name "*.yang")
|
||||
# Count nr of modules (exclude submodule) Assume "module" or "submodule"
|
||||
# first word on first line
|
||||
let ms=0; # Nr of modules
|
||||
|
|
@ -67,7 +54,29 @@ done
|
|||
new "Openconfig test: $clixon_cli -1f $cfg show version ($m modules)"
|
||||
for f in $files; do
|
||||
if [ -n "$(head -1 $f|grep '^module')" ]; then
|
||||
new "$clixon_cli -D $DBG -1f $cfg -y $f show version"
|
||||
modname=$(basename $f | awk -F "." '{print $1}')
|
||||
# Generate autocli for these modules
|
||||
AUTOCLI=$(autocli_config $modname kw-nokey false)
|
||||
|
||||
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>/usr/local/share/clixon</CLICON_YANG_DIR>
|
||||
<CLICON_YANG_DIR>${OPENCONFIG}</CLICON_YANG_DIR>
|
||||
<CLICON_YANG_AUGMENT_ACCEPT_BROKEN>true</CLICON_YANG_AUGMENT_ACCEPT_BROKEN>
|
||||
<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>
|
||||
<CLICON_MODULE_LIBRARY_RFC7895>true</CLICON_MODULE_LIBRARY_RFC7895>
|
||||
${AUTOCLI}
|
||||
</clixon-config>
|
||||
EOF
|
||||
|
||||
new "$clixon_cli -D $DBG -1f $cfg -o CLICON_YANG_MAIN_FILE=$f show version"
|
||||
expectpart "$($clixon_cli -D $DBG -1f $cfg -y $f show version)" 0 "${CLIXON_VERSION}"
|
||||
fi
|
||||
done
|
||||
|
|
|
|||
|
|
@ -19,6 +19,9 @@ fi
|
|||
|
||||
OCDIR=$OPENCONFIG/release/models
|
||||
|
||||
# Generate autocli for these modules
|
||||
AUTOCLI=$(autocli_config clixon-example kw-nokey false)
|
||||
|
||||
cat <<EOF > $cfg
|
||||
<clixon-config xmlns="http://clicon.org/config">
|
||||
<CLICON_CONFIGFILE>$cfg</CLICON_CONFIGFILE>
|
||||
|
|
@ -31,11 +34,11 @@ cat <<EOF > $cfg
|
|||
<CLICON_CLI_DIR>/usr/local/lib/$APPNAME/cli</CLICON_CLI_DIR>
|
||||
<CLICON_CLI_MODE>$APPNAME</CLICON_CLI_MODE>
|
||||
<CLICON_CLI_MODE>$APPNAME</CLICON_CLI_MODE>
|
||||
<CLICON_CLI_AUTOCLI_EXCLUDE>clixon-restconf ietf-interfaces</CLICON_CLI_AUTOCLI_EXCLUDE>
|
||||
<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>
|
||||
<CLICON_MODULE_LIBRARY_RFC7895>true</CLICON_MODULE_LIBRARY_RFC7895>
|
||||
${AUTOCLI}
|
||||
</clixon-config>
|
||||
EOF
|
||||
|
||||
|
|
|
|||
|
|
@ -27,16 +27,29 @@ cat <<EOF > $cfg
|
|||
<CLICON_YANG_DIR>$IETFRFC</CLICON_YANG_DIR>
|
||||
<CLICON_YANG_DIR>$OCDIR</CLICON_YANG_DIR>
|
||||
<CLICON_YANG_MAIN_FILE>$fyang</CLICON_YANG_MAIN_FILE>
|
||||
<CLICON_CLISPEC_DIR>/usr/local/lib/$APPNAME/clispec</CLICON_CLISPEC_DIR>
|
||||
<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_MODE>$APPNAME</CLICON_CLI_MODE>
|
||||
<CLICON_CLI_AUTOCLI_EXCLUDE>clixon-restconf ietf-interfaces</CLICON_CLI_AUTOCLI_EXCLUDE>
|
||||
<CLICON_CLI_GENMODEL_TYPE>VARS</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>$dir</CLICON_XMLDB_DIR>
|
||||
<CLICON_MODULE_LIBRARY_RFC7895>true</CLICON_MODULE_LIBRARY_RFC7895>
|
||||
<autocli>
|
||||
<module-default>false</module-default>
|
||||
<list-keyword-default>kw-nokey</list-keyword-default>
|
||||
<treeref-state-default>false</treeref-state-default>
|
||||
<rule>
|
||||
<name>openconfig1</name>
|
||||
<operation>enable</operation>
|
||||
<module-name>openconfig-bgp</module-name>
|
||||
</rule>
|
||||
<rule>
|
||||
<name>openconfig2</name>
|
||||
<operation>enable</operation>
|
||||
<module-name>openconfig-network-instance</module-name>
|
||||
</rule>
|
||||
</autocli>
|
||||
</clixon-config>
|
||||
EOF
|
||||
|
||||
|
|
@ -82,6 +95,25 @@ cat <<EOF > $dir/startup_db
|
|||
</config>
|
||||
EOF
|
||||
|
||||
cat<<EOF > $dir/example_cli.cli
|
||||
# Clixon example specification
|
||||
CLICON_MODE="example";
|
||||
CLICON_PROMPT="%U@%H %W> ";
|
||||
CLICON_PLUGIN="example_cli";
|
||||
|
||||
set @datamodel, cli_auto_set();
|
||||
save("Save candidate configuration to XML file") <filename:string>("Filename (local filename)"), save_config_file("candidate","filename", "xml");{
|
||||
cli("Save configuration as CLI commands"), save_config_file("candidate","filename", "cli");
|
||||
}
|
||||
show("Show a particular state of the system"){
|
||||
configuration("Show configuration"), cli_auto_show("datamodel", "candidate", "xml", false, false);
|
||||
version("Show version"), cli_show_version("candidate", "text", "/");
|
||||
}
|
||||
validate("Validate changes"), cli_validate();
|
||||
commit("Commit the changes"), cli_commit();
|
||||
quit("Quit"), cli_quit();
|
||||
EOF
|
||||
|
||||
if [ $BE -ne 0 ]; then
|
||||
new "kill old backend"
|
||||
sudo clixon_backend -zf $cfg
|
||||
|
|
@ -101,14 +133,13 @@ new "$clixon_cli -D $DBG -1f $cfg show version"
|
|||
expectpart "$($clixon_cli -D $DBG -1f $cfg show version)" 0 "${CLIXON_VERSION}"
|
||||
|
||||
new "$clixon_cli -D $DBG -1f $cfg save config as cli"
|
||||
expectpart "$($clixon_cli -D $DBG -1f $cfg save $dir/config.cli cli)" 0 "^$"
|
||||
expectpart "$($clixon_cli -D $DBG -1f $cfg save $dir/config.dump cli)" 0 "^$"
|
||||
|
||||
new "Check saved config"
|
||||
expectpart "$(cat $dir/config.cli)" 0 "set network-instances network-instance default config type oc-ni-types:DEFAULT_INSTANCE" "set network-instances network-instance default config router-id 1.2.3.4"
|
||||
expectpart "$(cat $dir/config.dump)" 0 "set network-instances network-instance default config type oc-ni-types:DEFAULT_INSTANCE" "set network-instances network-instance default config router-id 1.2.3.4"
|
||||
|
||||
new "load saved cli config"
|
||||
expectpart "$(cat $dir/config.cli | $clixon_cli -D $DBG -f $cfg 2>&1 > /dev/null)" 0 "^$"
|
||||
#time cat $dir/config.cli | $clixon_cli -D $DBG -f $cfg
|
||||
expectpart "$(cat $dir/config.dump | $clixon_cli -D $DBG -f $cfg 2>&1 > /dev/null)" 0 "^$"
|
||||
|
||||
if [ $BE -ne 0 ]; then
|
||||
new "Kill backend"
|
||||
|
|
|
|||
|
|
@ -22,6 +22,9 @@ fi
|
|||
|
||||
OCDIR=$OPENCONFIG/release/models
|
||||
|
||||
# Generate autocli for these modules
|
||||
AUTOCLI=$(autocli_config clixon-example kw-nokey false)
|
||||
|
||||
cat <<EOF > $cfg
|
||||
<clixon-config xmlns="http://clicon.org/config">
|
||||
<CLICON_CONFIGFILE>$cfg</CLICON_CONFIGFILE>
|
||||
|
|
@ -33,11 +36,11 @@ cat <<EOF > $cfg
|
|||
<CLICON_CLI_DIR>/usr/local/lib/$APPNAME/cli</CLICON_CLI_DIR>
|
||||
<CLICON_CLI_MODE>$APPNAME</CLICON_CLI_MODE>
|
||||
<CLICON_CLI_MODE>$APPNAME</CLICON_CLI_MODE>
|
||||
<CLICON_CLI_AUTOCLI_EXCLUDE>clixon-restconf ietf-interfaces</CLICON_CLI_AUTOCLI_EXCLUDE>
|
||||
<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>
|
||||
<CLICON_MODULE_LIBRARY_RFC7895>true</CLICON_MODULE_LIBRARY_RFC7895>
|
||||
${AUTOCLI}
|
||||
</clixon-config>
|
||||
EOF
|
||||
|
||||
|
|
|
|||
|
|
@ -20,7 +20,8 @@ else
|
|||
mkdir $clidir
|
||||
fi
|
||||
|
||||
# Use yang in example
|
||||
# Generate autocli for these modules
|
||||
AUTOCLI=$(autocli_config ${APPNAME}\* kw-nokey false)
|
||||
|
||||
cat <<EOF > $cfg
|
||||
<clixon-config xmlns="http://clicon.org/config">
|
||||
|
|
@ -33,13 +34,11 @@ cat <<EOF > $cfg
|
|||
<CLICON_CLISPEC_DIR>$clidir</CLICON_CLISPEC_DIR>
|
||||
<CLICON_CLI_DIR>/usr/local/lib/$APPNAME/cli</CLICON_CLI_DIR>
|
||||
<CLICON_CLI_MODE>$APPNAME</CLICON_CLI_MODE>
|
||||
<CLICON_CLI_GENMODEL>2</CLICON_CLI_GENMODEL>
|
||||
<CLICON_CLI_GENMODEL_TYPE>VARS</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>$dir</CLICON_XMLDB_DIR>
|
||||
<CLICON_MODULE_LIBRARY_RFC7895>false</CLICON_MODULE_LIBRARY_RFC7895>
|
||||
<CLICON_CLI_AUTOCLI_EXCLUDE>clixon-restconf</CLICON_CLI_AUTOCLI_EXCLUDE>
|
||||
${AUTOCLI}
|
||||
</clixon-config>
|
||||
EOF
|
||||
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue