autocli sub fixes
This commit is contained in:
parent
75f85e0253
commit
542c0495b3
5 changed files with 86 additions and 41 deletions
|
|
@ -63,6 +63,8 @@ Developers may need to change their code
|
|||
|
||||
### Minor changes
|
||||
|
||||
* Change comment character to be active anywhere to beginning of _word_ only.
|
||||
* See [Change CLIgen comments](https://github.com/clicon/cligen/issues/55)
|
||||
* Improved performance of parsing files as described in [Bytewise read() of files is slow #146](https://github.com/clicon/clixon/issues/146), thanks: @hjelmeland
|
||||
* Added new backend plugin: ca_pre-demon called if backend is daemonized just prior to forking.
|
||||
* Added XPATH functions `position`
|
||||
|
|
|
|||
|
|
@ -289,8 +289,7 @@ cli_auto_top(clicon_handle h,
|
|||
cligen_ph_workpoint_set(ph, NULL);
|
||||
/* Store this as edit-mode */
|
||||
clicon_data_set(h, "cli-edit-mode", "");
|
||||
if (clicon_data_cvec_get(h, "cli-edit-cvv") != NULL)
|
||||
clicon_data_del(h, "cli-edit-cvv");
|
||||
clicon_data_cvec_del(h, "cli-edit-cvv");
|
||||
retval = 0;
|
||||
done:
|
||||
return retval;
|
||||
|
|
@ -622,6 +621,7 @@ cli_auto_sub_enter(clicon_handle h,
|
|||
char *api_path = NULL;
|
||||
char *treename;
|
||||
cvec *cvv1 = NULL;
|
||||
cvec *cvv2 = NULL;
|
||||
int i;
|
||||
cg_var *cv = NULL;
|
||||
pt_head *ph;
|
||||
|
|
@ -662,22 +662,27 @@ cli_auto_sub_enter(clicon_handle h,
|
|||
}
|
||||
if (api_path_fmt2api_path(api_path_fmt, cvv1, &api_path) < 0)
|
||||
goto done;
|
||||
/* Set the mode as a static variable to this command */
|
||||
/* Assign the variables */
|
||||
if ((cvv2 = cvec_append(clicon_data_cvec_get(h, "cli-edit-cvv"), cvv1)) == NULL)
|
||||
goto done;
|
||||
/* Store this as edit-mode */
|
||||
if (clicon_data_set(h, "cli-edit-mode", api_path) < 0)
|
||||
goto done;
|
||||
/* Assign the variables */
|
||||
if (cvec_append(clicon_data_cvec_get(h, "cli-edit-cvv"), cvv1) == NULL)
|
||||
if (clicon_data_cvec_set(h, "cli-edit-cvv", cvv2) < 0)
|
||||
goto done;
|
||||
/* Find current cligen tree */
|
||||
if ((ph = cligen_ph_find(cli_cligen(h), treename)) == NULL){
|
||||
clicon_err(OE_PLUGIN, 0, "No such parsetree header: %s", treename);
|
||||
clicon_err(OE_PLUGIN, ENOENT, "No such parsetree header: %s", treename);
|
||||
goto done;
|
||||
}
|
||||
/* Find the point in the generated clispec tree where workpoint should be set */
|
||||
fa.fa_str = api_path_fmt;
|
||||
if (pt_apply(cligen_ph_parsetree_get(ph), cli_auto_findpt, &fa) < 0)
|
||||
goto done;
|
||||
if (fa.fa_co)
|
||||
if (fa.fa_co == NULL){
|
||||
clicon_err(OE_PLUGIN, ENOENT, "No such cligen object found %s", api_path);
|
||||
goto done;
|
||||
}
|
||||
cligen_ph_workpoint_set(ph, fa.fa_co);
|
||||
retval = 0;
|
||||
done:
|
||||
|
|
|
|||
|
|
@ -159,7 +159,7 @@ clicon_data_cvec_get(clicon_handle h,
|
|||
return NULL;
|
||||
}
|
||||
|
||||
/*! Set generic cligen varaibel vector (cvv) on the form <name>=<val> where <val> is cvv
|
||||
/*! Set generic cligen variable vector (cvv) on the form <name>=<val> where <val> is cvv
|
||||
* @param[in] h Clicon handle
|
||||
* @param[in] name Name
|
||||
* @param[in] cvv CLIgen variable vector (cvv) (malloced)
|
||||
|
|
@ -182,7 +182,7 @@ clicon_data_cvec_set(clicon_handle h,
|
|||
return 0;
|
||||
}
|
||||
|
||||
/*! Delete generic cligen varaibel vector (cvv)
|
||||
/*! Delete generic cligen variable vector (cvv)
|
||||
* @param[in] h Clicon handle
|
||||
* @param[in] name Name
|
||||
*/
|
||||
|
|
|
|||
|
|
@ -57,7 +57,7 @@ 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", "xml", false, false);{
|
||||
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);
|
||||
|
|
@ -105,25 +105,25 @@ fi
|
|||
|
||||
# First go down in structure and show config
|
||||
new "show top tree"
|
||||
expectpart "$(echo "show config" | $clixon_cli -f $cfg 2>&1)" 0 '<table xmlns="urn:example:clixon"><parameter><name>a</name><value>42</value></parameter></table>$'
|
||||
expectpart "$(echo "show config xml" | $clixon_cli -f $cfg 2>&1)" 0 '<table xmlns="urn:example:clixon"><parameter><name>a</name><value>42</value></parameter></table>$'
|
||||
|
||||
cat <<EOF > $fin
|
||||
up
|
||||
show config
|
||||
show config xml
|
||||
EOF
|
||||
new "up show"
|
||||
expectpart "$(cat $fin | $clixon_cli -f $cfg 2>&1)" 0 '<table xmlns="urn:example:clixon"><parameter><name>a</name><value>42</value></parameter></table>$'
|
||||
|
||||
cat <<EOF > $fin
|
||||
edit table
|
||||
show config
|
||||
show config xml
|
||||
EOF
|
||||
new "edit table; show"
|
||||
expectpart "$(cat $fin | $clixon_cli -f $cfg 2>&1)" 0 "/clixon-example:table>" "<parameter><name>a</name><value>42</value></parameter>$" --not-- '<table xmlns="urn:example:clixon">'
|
||||
|
||||
cat <<EOF > $fin
|
||||
edit table parameter a
|
||||
show config
|
||||
show config xml
|
||||
EOF
|
||||
new "edit table parameter a; show"
|
||||
expectpart "$(cat $fin | $clixon_cli -f $cfg 2>&1)" 0 "/clixon-example:table/parameter=a/>" "<name>a</name><value>42</value>" --not-- '<table xmlns="urn:example:clixon">' "<parameter>"
|
||||
|
|
@ -131,14 +131,14 @@ expectpart "$(cat $fin | $clixon_cli -f $cfg 2>&1)" 0 "/clixon-example:table/par
|
|||
cat <<EOF > $fin
|
||||
edit table
|
||||
edit parameter a
|
||||
show config
|
||||
show config xml
|
||||
EOF
|
||||
new "edit table; edit parameter a; show"
|
||||
expectpart "$(cat $fin | $clixon_cli -f $cfg 2>&1)" 0 "<name>a</name><value>42</value>" --not-- '<table xmlns="urn:example:clixon">' "<parameter>"
|
||||
|
||||
cat <<EOF > $fin
|
||||
edit table parameter a value 42
|
||||
show config
|
||||
show config xml
|
||||
EOF
|
||||
new "edit table parameter a value 42; show"
|
||||
expectpart "$(cat $fin | $clixon_cli -f $cfg 2>&1)" 0 --not-- '<table xmlns="urn:example:clixon">' "<parameter>" "<name>a</name>" "<value>42</value>"
|
||||
|
|
@ -147,7 +147,7 @@ expectpart "$(cat $fin | $clixon_cli -f $cfg 2>&1)" 0 --not-- '<table xmlns="urn
|
|||
cat <<EOF > $fin
|
||||
edit table parameter a value 42
|
||||
top
|
||||
show config
|
||||
show config xml
|
||||
EOF
|
||||
new "edit table parameter a value 42; top; show"
|
||||
expectpart "$(cat $fin | $clixon_cli -f $cfg 2>&1)" 0 '<table xmlns="urn:example:clixon"><parameter><name>a</name><value>42</value></parameter></table>$'
|
||||
|
|
@ -155,7 +155,7 @@ expectpart "$(cat $fin | $clixon_cli -f $cfg 2>&1)" 0 '<table xmlns="urn:example
|
|||
cat <<EOF > $fin
|
||||
edit table parameter a
|
||||
top
|
||||
show config
|
||||
show config xml
|
||||
EOF
|
||||
new "edit table parameter a; top; show"
|
||||
expectpart "$(cat $fin | $clixon_cli -f $cfg 2>&1)" 0 '<table xmlns="urn:example:clixon"><parameter><name>a</name><value>42</value></parameter></table>$'
|
||||
|
|
@ -165,7 +165,7 @@ expectpart "$(cat $fin | $clixon_cli -f $cfg 2>&1)" 0 '<table xmlns="urn:example
|
|||
cat <<EOF > $fin
|
||||
edit table
|
||||
up
|
||||
show config
|
||||
show config xml
|
||||
EOF
|
||||
new "edit table; up; show"
|
||||
expectpart "$(cat $fin | $clixon_cli -f $cfg 2>&1)" 0 '<table xmlns="urn:example:clixon"><parameter><name>a</name><value>42</value></parameter></table>$'
|
||||
|
|
@ -173,7 +173,7 @@ expectpart "$(cat $fin | $clixon_cli -f $cfg 2>&1)" 0 '<table xmlns="urn:example
|
|||
cat <<EOF > $fin
|
||||
edit table parameter a
|
||||
up
|
||||
show config
|
||||
show config xml
|
||||
EOF
|
||||
new "edit table parameter a; up; show"
|
||||
expectpart "$(cat $fin | $clixon_cli -f $cfg 2>&1)" 0 "/clixon-example:table>" "<parameter><name>a</name><value>42</value></parameter>$" --not-- '<table xmlns="urn:example:clixon">'
|
||||
|
|
@ -182,7 +182,7 @@ cat <<EOF > $fin
|
|||
edit table parameter a
|
||||
up
|
||||
up
|
||||
show config
|
||||
show config xml
|
||||
EOF
|
||||
new "edit table parameter a; up up; show"
|
||||
expectpart "$(cat $fin | $clixon_cli -f $cfg 2>&1)" 0 '<table xmlns="urn:example:clixon"><parameter><name>a</name><value>42</value></parameter></table>$'
|
||||
|
|
@ -191,7 +191,7 @@ cat <<EOF > $fin
|
|||
edit table parameter a
|
||||
up
|
||||
edit parameter a
|
||||
show config
|
||||
show config xml
|
||||
EOF
|
||||
new "edit table parameter a; up; edit parameter a; show"
|
||||
expectpart "$(cat $fin | $clixon_cli -f $cfg 2>&1)" 0 "/clixon-example:table/parameter=a/>" "<name>a</name><value>42</value>" --not-- '<table xmlns="urn:example:clixon">' "<parameter>"
|
||||
|
|
@ -199,7 +199,7 @@ expectpart "$(cat $fin | $clixon_cli -f $cfg 2>&1)" 0 "/clixon-example:table/par
|
|||
# Create new field b, and remove it
|
||||
cat <<EOF > $fin
|
||||
edit table parameter b
|
||||
show config
|
||||
show config xml
|
||||
EOF
|
||||
new "edit table parameter b; show"
|
||||
expectpart "$(cat $fin | $clixon_cli -f $cfg 2>&1)" 0 "/clixon-example:table/parameter=b/>" --not-- "<name>a</name><value>42</value>" '<table xmlns="urn:example:clixon">' "<parameter>"
|
||||
|
|
@ -208,7 +208,7 @@ cat <<EOF > $fin
|
|||
edit table parameter b
|
||||
set value 71
|
||||
up
|
||||
show config
|
||||
show config xml
|
||||
EOF
|
||||
new "set value 71"
|
||||
expectpart "$(cat $fin | $clixon_cli -f $cfg 2>&1)" 0 "/clixon-example:table>" "<parameter><name>a</name><value>42</value></parameter><parameter><name>b</name><value>71</value></parameter>"
|
||||
|
|
@ -217,7 +217,7 @@ cat <<EOF > $fin
|
|||
edit table parameter a
|
||||
top
|
||||
edit table parameter b
|
||||
show config
|
||||
show config xml
|
||||
EOF
|
||||
new "edit parameter b show"
|
||||
expectpart "$(cat $fin | $clixon_cli -f $cfg 2>&1)" 0 "/clixon-example:table/parameter=b/>" "<name>b</name><value>71</value>" --not-- "<parameter>"
|
||||
|
|
@ -225,7 +225,7 @@ expectpart "$(cat $fin | $clixon_cli -f $cfg 2>&1)" 0 "/clixon-example:table/par
|
|||
cat <<EOF > $fin
|
||||
edit table parameter b
|
||||
delete value 17
|
||||
show config
|
||||
show config xml
|
||||
EOF
|
||||
new "delete value 71"
|
||||
expectpart "$(cat $fin | $clixon_cli -f $cfg 2>&1)" 0 "<name>b</name>" --not-- "<value>71</value>"
|
||||
|
|
@ -234,7 +234,7 @@ cat <<EOF > $fin
|
|||
edit table
|
||||
delete parameter b
|
||||
up
|
||||
show config
|
||||
show config xml
|
||||
EOF
|
||||
new "delete parameter b"
|
||||
expectpart "$(cat $fin | $clixon_cli -f $cfg 2>&1)" 0 '<table xmlns="urn:example:clixon"><parameter><name>a</name><value>42</value></parameter></table>$'
|
||||
|
|
|
|||
|
|
@ -24,6 +24,7 @@ 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>$dir</CLICON_YANG_DIR>
|
||||
<CLICON_YANG_MAIN_FILE>$fyang</CLICON_YANG_MAIN_FILE>
|
||||
|
|
@ -35,7 +36,7 @@ cat <<EOF > $cfg
|
|||
<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_XMLDB_DIR>$dir</CLICON_XMLDB_DIR>
|
||||
<CLICON_MODULE_LIBRARY_RFC7895>false</CLICON_MODULE_LIBRARY_RFC7895>
|
||||
</clixon-config>
|
||||
EOF
|
||||
|
|
@ -58,6 +59,9 @@ module $APPNAME {
|
|||
leaf i{
|
||||
type string;
|
||||
}
|
||||
leaf iv{
|
||||
type string;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
@ -66,13 +70,14 @@ EOF
|
|||
|
||||
cat <<EOF > $clidir/ex.cli
|
||||
CLICON_MODE="example";
|
||||
CLICON_PROMPT="%U@%H> ";
|
||||
CLICON_PROMPT="%U@%H %W> ";
|
||||
|
||||
# Manual command form where a sub-mode is created from @datamodel
|
||||
# It gives: cvv eg:
|
||||
# 0 : cmd = parameter 123
|
||||
# 1 : string = "123"
|
||||
enter <string>, cli_auto_sub_enter("datamodel", "/example:table/parameter=%s/index=%s/", "x");
|
||||
enter0 <string>, cli_auto_sub_enter("datamodel", "/example:table/parameter=%s/");
|
||||
enter1 <string>, cli_auto_sub_enter("datamodel", "/example:table/parameter=%s/index=%s/", "p1");
|
||||
leave, cli_auto_top("datamodel", "candidate");
|
||||
|
||||
# Autocli syntax tree operations
|
||||
|
|
@ -87,8 +92,25 @@ delete("Delete a configuration item") {
|
|||
all("Delete whole candidate configuration"), delete_all("candidate");
|
||||
}
|
||||
show("Show a particular state of the system"){
|
||||
configuration("Show configuration"), cli_auto_show("datamodel", "candidate", "text", true, false);
|
||||
configuration("Show configuration"), cli_auto_show("datamodel", "candidate", "text", true, false);{
|
||||
xml("Show configuration as XML"), cli_auto_show("datamodel", "candidate", "xml", false, false);
|
||||
}
|
||||
}
|
||||
EOF
|
||||
|
||||
cat <<EOF > $dir/startup_db
|
||||
<config>
|
||||
<table xmlns="urn:example:clixon">
|
||||
<parameter>
|
||||
<name>p1</name>
|
||||
<value>42</value>
|
||||
<index>
|
||||
<i>i1</i>
|
||||
<iv>abc</iv>
|
||||
</index>
|
||||
</parameter>
|
||||
</table>
|
||||
</config>
|
||||
EOF
|
||||
|
||||
new "test params: -f $cfg"
|
||||
|
|
@ -98,21 +120,37 @@ if [ $BE -ne 0 ]; then
|
|||
if [ $? -ne 0 ]; then
|
||||
err
|
||||
fi
|
||||
new "start backend -s init -f $cfg"
|
||||
start_backend -s init -f $cfg
|
||||
new "start backend -s startup -f $cfg"
|
||||
start_backend -s startup -f $cfg
|
||||
|
||||
new "waiting"
|
||||
wait_backend
|
||||
fi
|
||||
|
||||
cat <<EOF > $fin
|
||||
enter a
|
||||
enter0 p1 # table/parameter=p1
|
||||
show config xml
|
||||
leave
|
||||
EOF
|
||||
new "enter leave"
|
||||
expectpart "$(cat $fin | $clixon_cli -f $cfg 2>&1)" 0 'enter a' 'leave'
|
||||
new "enter; show config; leave"
|
||||
expectpart "$(cat $fin | $clixon_cli -f $cfg 2>&1)" 0 'enter0 p1' 'leave' '<name>p1</name><value>42</value><index><i>i1</i><iv>abc</iv></index>' --not-- '<table>' '<parameter>'
|
||||
|
||||
# XXX much more
|
||||
cat <<EOF > $fin
|
||||
enter0 p1 # table/parameter=p1
|
||||
leave
|
||||
show config xml
|
||||
EOF
|
||||
new "enter; leave; show config"
|
||||
expectpart "$(cat $fin | $clixon_cli -f $cfg 2>&1)" 0 'enter0 p1' 'leave' '<table xmlns="urn:example:clixon"><parameter><name>p1</name><value>42</value><index><i>i1</i><iv>abc</iv></index></parameter></table>'
|
||||
|
||||
cat <<EOF > $fin
|
||||
enter0 p1 # table/parameter=p1
|
||||
set set index i2 iv def
|
||||
leave
|
||||
show config xml
|
||||
EOF
|
||||
new "set p1 i2"
|
||||
expectpart "$(cat $fin | $clixon_cli -f $cfg 2>&1)" 0 '<table xmlns="urn:example:clixon"><parameter><name>p1</name><value>42</value><index><i>i1</i><iv>abc</iv></index></parameter></table>'
|
||||
|
||||
new "Kill backend"
|
||||
# Check if premature kill
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue