#!/usr/bin/env bash # Tests for openconfig network-instances # See eg https://github.com/clicon/clixon/issues/287 # 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 new "openconfig" if [ ! -d "$OPENCONFIG" ]; then # err "Hmm Openconfig dir does not seem to exist, try git clone https://github.com/openconfig/public?" echo "...skipped: OPENCONFIG not set" rm -rf $dir if [ "$s" = $0 ]; then exit 0; else return 0; fi fi OCDIR=$OPENCONFIG/release/models cat < $cfg $cfg ietf-netconf:startup ${YANG_INSTALLDIR} $IETFRFC $OCDIR $fyang $dir /usr/local/lib/$APPNAME/cli $APPNAME $APPNAME /usr/local/var/$APPNAME/$APPNAME.sock /usr/local/var/$APPNAME/$APPNAME.pidfile $dir false kw-nokey false openconfig1 enable clixon-example openconfig2 enable openconfig-network-instance EOF # First using ietf-interfaces (not openconfig-interfaces) # Example yang cat < $fyang module clixon-example{ yang-version 1.1; namespace "urn:example:example"; prefix ex; import openconfig-network-instance { prefix oc-netinst; } } EOF # Example system cat < $dir/startup_db default false default oc-ni-types:DEFAULT_INSTANCE 1.2.3.4 EOF cat< $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 (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_show_auto_mode("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 if [ $? -ne 0 ]; then err fi sudo pkill -f clixon_backend # to be sure new "start backend -s startup -f $cfg" start_backend -s startup -f $cfg fi new "wait backend" wait_backend 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.dump cli)" 0 "^$" new "Check saved config" 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.dump | $clixon_cli -D $DBG -f $cfg 2>&1 > /dev/null)" 0 "^$" 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