#!/bin/bash # Yang features. if-feature. and schema resources according to RFC7895 APPNAME=example # include err() and new() functions and creates $dir . ./lib.sh cfg=$dir/conf_yang.xml fyang=$dir/test.yang cat < $cfg $APPNAME:A ietf-routing:router-id $cfg /usr/local/share/$APPNAME/yang $APPNAME /usr/local/lib/$APPNAME/clispec /usr/local/lib/$APPNAME/cli $APPNAME /usr/local/var/$APPNAME/$APPNAME.sock /usr/local/var/$APPNAME/$APPNAME.pidfile 1 /usr/local/var/$APPNAME /usr/local/lib/xmldb/text.so true EOF cat < $fyang module $APPNAME{ prefix ex; import ietf-routing { prefix rt; } feature A{ description "This test feature is enabled"; } feature B{ description "This test feature is disabled"; } feature C{ description "This test feature is disabled"; } leaf x{ if-feature A; type "string"; } leaf y{ if-feature B; type "string"; } leaf z{ type "string"; } } EOF new "start backend -s init -f $cfg -y $fyang" # kill old backend (if any) new "kill old backend" sudo clixon_backend -zf $cfg -y $fyang if [ $? -ne 0 ]; then err fi new "start backend -s init -f $cfg -y $fyang" # start new backend sudo $clixon_backend -s init -f $cfg -y $fyang if [ $? -ne 0 ]; then err fi new "cli enabled feature" expectfn "$clixon_cli -1f $cfg -y $fyang set x foo" 0 "" new "cli disabled feature" expectfn "$clixon_cli -1f $cfg -l o -y $fyang set y foo" 255 "CLI syntax error: \"set y foo\": Unknown command" new "cli enabled feature in other module" expectfn "$clixon_cli -1f $cfg -y $fyang set routing routing-instance A router-id 1.2.3.4" 0 "" new "cli disabled feature in other module" expectfn "$clixon_cli -1f $cfg -l o -y $fyang set routing routing-instance A default-ribs" 255 "CLI syntax error: \"set routing routing-instance A default-ribs\": Unknown command" new "netconf discard-changes" expecteof "$clixon_netconf -qf $cfg -y $fyang" 0 "]]>]]>" "^]]>]]>$" new "netconf enabled feature" expecteof "$clixon_netconf -qf $cfg -y $fyang" 0 "foo]]>]]>" "^]]>]]>$" new "netconf validate enabled feature" expecteof "$clixon_netconf -qf $cfg -y $fyang" 0 "]]>]]>" "^]]>]]>$" new "netconf disabled feature" expecteof "$clixon_netconf -qf $cfg -y $fyang" 0 "foo]]>]]>" '^operation-failedprotocolerrorXML node config/A has no corresponding yang specification \(Invalid XML or wrong Yang spec?' new "netconf schema resource, RFC 7895" expecteof "$clixon_netconf -qf $cfg -y $fyang" 0 ']]>]]>' '^exampleAietf-inet-types2013-07-15urn:ietf:params:xml:ns:yang:ietf-inet-typesietf-interfaces2014-05-08urn:ietf:params:xml:ns:yang:ietf-interfacesietf-routing2014-10-26urn:ietf:params:xml:ns:yang:ietf-routingrouter-idietf-yang-library2016-06-21urn:ietf:params:xml:ns:yang:ietf-yang-libraryietf-yang-types2013-07-15urn:ietf:params:xml:ns:yang:ietf-yang-types]]>]]>$' new "Kill backend" # kill backend sudo clixon_backend -zf $cfg if [ $? -ne 0 ]; then err "kill backend" fi # Check if still alive pid=`pgrep clixon_backend` if [ -n "$pid" ]; then sudo kill $pid fi rm -rf $dir