#!/bin/bash # Yang features. if-feature. # The test has a example module with FEATURES A and B, where A is enabled and # B is disabled. # It also uses an ietf-router module where (only) router-id is enabled # Also check modules-state (RFC7895) announces the enabled features. # # From RFC7950: # 7.20.1 Schema nodes tagged with an "if-feature" statement are _ignored_ by # the server unless the server supports the given feature expression. # 8.1: There MUST be no nodes tagged with "if-feature" present if the # "if-feature" expression evaluates to "false" in the server. # - Should the server just "ignore" these nodes or actively reject them? # # Clixon has a strict implementation of the features so that setting # data with disabled features is same as if they are not present in the Yang. # Which means no cli syntax or edit operations were syntactically allowed # (and therefore invalid). # 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/test.yang # Note ietf-routing@2018-03-13 assumed cat < $cfg $APPNAME:A ietf-routing:router-id $cfg /usr/local/share/clixon $IETFRFC $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 true EOF cat < $fyang module example{ yang-version 1.1; namespace "urn:example:clixon"; prefix ex; import ietf-routing { prefix rt; } feature A{ description "This test feature is enabled"; } feature B{ 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 "test params: -f $cfg -y $fyang" if [ $BE -ne 0 ]; then 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_backend -s init -f $cfg -y $fyang new "waiting" sleep $RCWAIT 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 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 ribs rib default-rib false" 255 "CLI syntax error: \"set routing ribs rib default-rib false\": 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]]>]]>' '^applicationunknown-elementyerrorUnassigned yang spec]]>]]>$' # This test has been broken up into all different modules instead of one large # reply since the modules change so often new "netconf schema resource, RFC 7895" ret=$($clixon_netconf -qf $cfg -y $fyang<]]>]]> EOF ) new "netconf modules-state header" expect='^' match=`echo "$ret" | grep -GZo "$expect"` if [ -z "$match" ]; then err "$expect" "$ret" fi new "netconf module A" expect="exampleurn:example:clixonAimplement" match=`echo "$ret" | grep -GZo "$expect"` if [ -z "$match" ]; then err "$expect" "$ret" fi if false ; then # clixon "config" bug new "netconf module clixon-config" expect="clixon-config2018-09-30" match=`echo "$ret" | grep -GZo "$expect"` if [ -z "$match" ]; then err "$expect" "$ret" fi fi # false new "netconf module ietf-inet-types" expect="ietf-inet-types2013-07-15urn:ietf:params:xml:ns:yang:ietf-inet-typesimplement" match=`echo "$ret" | grep -GZo "$expect"` if [ -z "$match" ]; then err "$expect" "$ret" fi new "netconf module ietf-interfaces" expect="ietf-interfaces2018-02-20urn:ietf:params:xml:ns:yang:ietf-interfacesimplement" match=`echo "$ret" | grep -GZo "$expect"` if [ -z "$match" ]; then err "$expect" "$ret" fi # Note order of features in ietf-netconf yang is alphabetically: candidate, startup, validate, xpath new "netconf module ietf-netconf" expect="ietf-netconf2011-06-01urn:ietf:params:xml:ns:netconf:base:1.0candidatevalidatestartupxpathimplement" match=`echo "$ret" | grep -GZo "$expect"` if [ -z "$match" ]; then err "$expect" "$ret" fi new "netconf module ietf-routing" expect="ietf-routing2018-03-13urn:ietf:params:xml:ns:yang:ietf-routingrouter-idimplement" match=`echo "$ret" | grep -GZo "$expect"` if [ -z "$match" ]; then err "$expect" "$ret" fi expect="ietf-yang-library2016-06-21urn:ietf:params:xml:ns:yang:ietf-yang-libraryimplement" match=`echo "$ret" | grep -GZo "$expect"` if [ -z "$match" ]; then err "$expect" "$ret" fi new "netconf module ietf-yang_types" expect="ietf-yang-types2013-07-15urn:ietf:params:xml:ns:yang:ietf-yang-typesimplement" match=`echo "$ret" | grep -GZo "$expect"` if [ -z "$match" ]; then err "$expect" "$ret" fi if [ $BE -eq 0 ]; then exit # BE fi 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 rm -rf $dir