From 54a8f51bfddddb9404cb1c5b8f0942096bff9ee1 Mon Sep 17 00:00:00 2001 From: Olof hagsand Date: Mon, 28 Oct 2024 10:39:04 +0100 Subject: [PATCH] Fixed show mem yspec vs ydomain issue --- apps/backend/backend_client.c | 10 +-- apps/cli/cli_show.c | 4 ++ test/test_grouping_multi.sh | 117 ++++++++++++++++++++++++++++++++++ 3 files changed, 126 insertions(+), 5 deletions(-) create mode 100755 test/test_grouping_multi.sh diff --git a/apps/backend/backend_client.c b/apps/backend/backend_client.c index f0eb57ae..d6f7f993 100644 --- a/apps/backend/backend_client.c +++ b/apps/backend/backend_client.c @@ -425,9 +425,9 @@ clixon_stats_datastore_get(clixon_handle h, * @retval -1 Error */ static int -clixon_stats_module_get(clixon_handle h, - yang_stmt *ys, - cbuf *cb) +clixon_stats_yang_get(clixon_handle h, + yang_stmt *ys, + cbuf *cb) { int retval = -1; uint64_t nr = 0; @@ -1466,13 +1466,13 @@ from_client_stats(clixon_handle h, while ((yspec = yn_iter(ydomain, &inext2)) != NULL) { cprintf(cbret, ""); cprintf(cbret, "%s/%s", domain, yang_argument_get(yspec)); - if (clixon_stats_module_get(h, ydomain, cbret) < 0) + if (clixon_stats_yang_get(h, yspec, cbret) < 0) goto done; if (modules){ inext3 = 0; while ((ymodule = yn_iter(yspec, &inext3)) != NULL) { cprintf(cbret, "%s", yang_argument_get(ymodule)); - if (clixon_stats_module_get(h, ymodule, cbret) < 0) + if (clixon_stats_yang_get(h, ymodule, cbret) < 0) goto done; cprintf(cbret, ""); } diff --git a/apps/cli/cli_show.c b/apps/cli/cli_show.c index 2482f9de..10a2df81 100644 --- a/apps/cli/cli_show.c +++ b/apps/cli/cli_show.c @@ -1936,6 +1936,8 @@ cli_show_statistics(clixon_handle h, goto done; } if (cli) { + if (backend) + cligen_output(stdout, "CLI:\n====\n"); if (!detail) { cligen_output(stdout, "%-25s %-10s\n", "YANG", "Mem"); } @@ -2004,6 +2006,8 @@ cli_show_statistics(clixon_handle h, } } if (backend) { + if (cli) + cligen_output(stdout, "\nBackend:\n========\n"); cprintf(cb, ""); diff --git a/test/test_grouping_multi.sh b/test/test_grouping_multi.sh new file mode 100755 index 00000000..7c11d763 --- /dev/null +++ b/test/test_grouping_multi.sh @@ -0,0 +1,117 @@ +#!/usr/bin/env bash +# Tests multiple level groupings +# See https://github.com/clicon/clixon/issues/572 + +# 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 +fyang=$dir/example.yang + +# XXX try -E? +cat < $cfg + + $cfg + ${YANG_INSTALLDIR} + $dir + $dir + /usr/local/lib/$APPNAME/backend + $dir + /usr/local/lib/$APPNAME/cli + $APPNAME + /usr/local/var/run/$APPNAME.sock + /usr/local/var/run/$APPNAME.pidfile + $dir + false + +EOF + +cat < $dir/example.cli +CLICON_MODE="example"; +CLICON_PROMPT="%U@%H %W> "; + +# Autocli syntax tree operations +edit @datamodel, cli_auto_edit("datamodel"); +up, cli_auto_up("datamodel"); +top, cli_auto_top("datamodel"); +set @datamodel, cli_auto_set(); +merge @datamodel, cli_auto_merge(); +create @datamodel, cli_auto_create(); +commit("Commit the changes"), cli_commit(); +validate("Validate changes"), cli_validate(); +delete("Delete a configuration item") { + @datamodel, cli_auto_del(); + all("Delete whole candidate configuration"), delete_all("candidate"); +} +show("Show a particular state of the system"){ + configuration("Show configuration"), cli_show_auto_mode("candidate", "xml", false, false); +} +EOF + +# Yang specs must be here first for backend. But then the specs are changed but just for CLI +# Annotate original Yang spec example directly +# First annotate /table/parameter +# Had a problem with unknown in grouping -> test uses uses/grouping +cat < $fyang +module example { + namespace "urn:example:clixon"; + prefix ex; + grouping L3-top { + leaf L3{ + type string; + } + } + grouping L2-top { + container L2 { + uses L3-top { + when 'false'; + } + } + } + container L1x { + /* Does not work */ + uses L2-top; + } + container L1y { + /* Works */ + container L2 { + uses L3-top { + when 'false'; + } + } + } +} +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 +fi + +new "wait backend" +wait_backend + + +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