From f07f291bdd58af6c31d640cad2ecde242a545dbf Mon Sep 17 00:00:00 2001 From: Olof hagsand Date: Sat, 17 Oct 2020 23:13:47 +0200 Subject: [PATCH] Main examples uses new auto-mode --- apps/cli/cli_auto.c | 4 +-- example/main/example_cli.cli | 47 +++++++++++++++--------------------- test/test_perf_state.sh | 12 ++++----- 3 files changed, 28 insertions(+), 35 deletions(-) diff --git a/apps/cli/cli_auto.c b/apps/cli/cli_auto.c index e36faef5..f98342f8 100644 --- a/apps/cli/cli_auto.c +++ b/apps/cli/cli_auto.c @@ -303,7 +303,7 @@ cli_auto_show(clicon_handle h, cvec *cvv, cvec *argv) { - int retval = 1; + int retval = -1; char *treename; char *db; char *api_path = NULL; @@ -318,7 +318,7 @@ cli_auto_show(clicon_handle h, yang_stmt *yspec; cxobj *xerr; cxobj *xt = NULL; - cxobj **vec; + cxobj **vec = NULL; size_t veclen; int i; int isroot; diff --git a/example/main/example_cli.cli b/example/main/example_cli.cli index 6bef7e9f..84fddcc2 100644 --- a/example/main/example_cli.cli +++ b/example/main/example_cli.cli @@ -32,19 +32,24 @@ # Clixon example specification CLICON_MODE="example"; -CLICON_PROMPT="%U@%H> "; +CLICON_PROMPT="%U@%H %W> "; CLICON_PLUGIN="example_cli"; -# Note, when switching to PT, change datamodel to only @datamodel -set @datamodel, cli_set(); -merge @datamodel, cli_merge(); -create @datamodel, cli_create(); -delete("Delete a configuration item") @datamodel, cli_del(); +# Autocli syntax tree operations +edit @datamodel, cli_auto_edit("datamodel", "candidate"); +up, cli_auto_up("datamodel", "candidate"); +top, cli_auto_top("datamodel", "candidate"); +set @datamodel, cli_auto_set(); +merge @datamodel, cli_auto_merge(); +create @datamodel, cli_auto_create(); +delete("Delete a configuration item") { + @datamodel, cli_auto_del(); + all("Delete whole candidate configuration"), delete_all("candidate"); +} validate("Validate changes"), cli_validate(); commit("Commit the changes"), cli_commit(); quit("Quit"), cli_quit(); -delete("Delete a configuration item") all("Delete whole candidate configuration"), delete_all("candidate"); no("Negate or remove") debug("Debugging parts of the system"), cli_debug_cli((int32)0); debug("Debugging parts of the system"), cli_debug_cli((int32)1);{ @@ -67,27 +72,15 @@ show("Show a particular state of the system"){ xml("Show comparison in xml"), compare_dbs((int32)0); text("Show comparison in text"), compare_dbs((int32)1); } - state("Show configuration and state"), cli_show_config_state("running", "text", "/");{ - xml("Show configuration and state as XML"), cli_show_config_state("running", "xml", "/");{ - @datamodel, cli_show_auto_state("running", "xml"); - } + configuration("Show configuration"), cli_auto_show("datamodel", "candidate", "text", false, 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); } - configuration("Show configuration"), cli_show_config("candidate", "text", "/");{ - xml("Show configuration as XML"), cli_show_config("candidate", "xml", "/");{ - @datamodel, cli_show_auto("candidate", "xml"); - } - cli("Show configuration as CLI commands"), cli_show_config("candidate", "cli", "/", 0, "set ");{ - @datamodel, cli_show_auto("candidate", "cli", "set "); - } - netconf("Show configuration as netconf edit-config operation"), cli_show_config("candidate", "netconf", "/");{ - @datamodel, cli_show_auto("candidate", "netconf"); - } - text("Show configuration as text"), cli_show_config("candidate","text","/");{ - @datamodel, cli_show_auto("candidate", "text"); - } - json("Show configuration as JSON"), cli_show_config("candidate", "json", "/");{ - @datamodel, cli_show_auto("candidate", "json"); - } + state("Show configuration and state"), cli_auto_show("datamodel", "running", "text", false, true); { + xml("Show configuration and state as XML"), cli_auto_show("datamodel", "running", "xml", false, true); } } diff --git a/test/test_perf_state.sh b/test/test_perf_state.sh index d4bf232e..16478f85 100755 --- a/test/test_perf_state.sh +++ b/test/test_perf_state.sh @@ -7,6 +7,7 @@ # Magic line must be first in script (see README.md) s="$_" ; . ./lib.sh || if [ "$s" = $0 ]; then exit 0; else return 0; fi +fin=$dir/fin # Which format to use as datastore format internally : ${format:=xml} @@ -160,13 +161,12 @@ new "restconf get $perfreq single reqs" done } 2>&1 | awk '/real/ {print $2}' # CLI get +cat <> $fin +edit interfaces a foo b interface e1 +show state xml +EOF new "cli get test single req" -expectfn "$clixon_cli -1 -1f $cfg -l o show state xml interfaces a foo b interface e1" 0 '^ - e1 - eth - true - up -$' +expectpart "$($clixon_cli -F $fin -f $cfg)" 0 "e1ex:ethtrueup$" new "cli get $perfreq single reqs" { time -p for (( i=0; i<$perfreq; i++ )); do