#!/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 fyang=$dir/clixon-example.yang cat < $cfg $cfg /usr/local/share/clixon $fyang $dir /usr/local/lib/$APPNAME/cli $APPNAME ALL /usr/local/var/$APPNAME/$APPNAME.sock /usr/local/var/$APPNAME/$APPNAME.pidfile /usr/local/var/$APPNAME EOF cat < $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; } } } } EOF # The diff here is the "translate" command that adds entry table/parameter=translate cat< $dir/example_cli.cli # Clixon example specification CLICON_MODE="example"; CLICON_PROMPT="%U@%H %W> "; CLICON_PLUGIN="example_cli"; translate , 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 fi new "wait backend" wait_backend 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 "translatebcd
" 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