#!/bin/bash # Advanced union types and generated code # and enum w values APPNAME=example # include err() and new() functions and creates $dir . ./lib.sh cfg=$dir/conf_yang.xml fyang=$dir/type.yang fyang2=$dir/example2.yang fyang3=$dir/example3.yang cat < $cfg $cfg $dir /usr/local/share/$APPNAME/yang /usr/local/share/clixon example /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 false EOF # transitive type, exists in fyang3, referenced from fyang2, but not declared in fyang cat < $fyang3 module example3{ prefix ex3; namespace "urn:example:example3"; typedef w{ type union{ type int32{ range "4..44"; } } } typedef u{ type union { type w; type enumeration { enum "bounded"; enum "unbounded"; } } } typedef t{ type string{ pattern '[a-z][0-9]*'; } } } EOF cat < $fyang2 module example2{ import example3 { prefix ex3; } namespace "urn:example:example2"; prefix ex2; grouping gr2 { leaf talle{ type ex3:t; } leaf ulle{ type ex3:u; } } } EOF cat < $fyang module example{ yang-version 1.1; namespace "urn:example:clixon"; prefix ex; import example2 { prefix ex2; } typedef ab { type string { pattern '(([a-b])\.){3}[a-b]'; } } typedef cd { type string { pattern '(([c-d])\.){3}[c-d]'; } } typedef ef { type string { pattern '(([e-f])\.){3}[e-f]'; length "1..253"; } } typedef ad { type union { type ab; type cd; } } typedef af { type union { type ad; type ef; } } list list { key ip; leaf ip { type af; } } leaf status { type enumeration { enum up { value 1; } enum down; } } leaf length1 { type string { length "1"; } } /* leaf length2 { type string { length "max"; } } leaf length3 { type string { length "min"; } }*/ leaf length4 { type string { length "4..4000"; } } /* leaf length5 { type string { length "min..max"; } }*/ leaf num1 { type int32 { range "1"; } } /* leaf num2 { type int32 { range "min"; } } leaf num3 { type int32 { range "max"; } } */ leaf num4 { type int32 { range "4..4000"; } } /* leaf num5 { type int32 { range "min..max"; } }*/ typedef mybits { description "Test adding several bits"; type bits { bit create; bit read; bit write; } } leaf mbits{ type mybits; } container c{ description "transitive type- exists in ex3"; uses ex2:gr2; } } EOF new "test params: -f $cfg -y $fyang" if [ $BE -ne 0 ]; then new "kill old backend" sudo clixon_backend -zf $cfg if [ $? -ne 0 ]; then err fi new "start backend -s init -f $cfg -y $fyang" sudo $clixon_backend -s init -f $cfg -y $fyang if [ $? -ne 0 ]; then err fi fi new "cli set transitive string" expectfn "$clixon_cli -1f $cfg -l o -y $fyang set c talle x99" 0 "^$" new "cli set transitive string error" expectfn "$clixon_cli -1f $cfg -l o -y $fyang set c talle 9xx" 255 "^$" new "netconf set transitive string error" expecteof "$clixon_netconf -qf $cfg -y $fyang" 0 "9xx]]>]]>" "^]]>]]>" new "netconf validate should fail" expecteof "$clixon_netconf -qf $cfg -y $fyang" 0 "]]>]]>" 'applicationbad-elementtalleerrorregexp match fail: "9xx" does not match \[a-z\]\[0-9\]\*]]>]]>$' new "netconf discard-changes" expecteof "$clixon_netconf -qf $cfg -y $fyang" 0 "]]>]]>" "^]]>]]>$" new "cli set transitive union int" expectfn "$clixon_cli -1f $cfg -l o -y $fyang set c ulle 33" 0 "^$" new "cli validate" expectfn "$clixon_cli -1f $cfg -l o -y $fyang -l o validate" 0 "^$" new "cli set transitive union string" expectfn "$clixon_cli -1f $cfg -l o -y $fyang set c ulle unbounded" 0 "^$" new "cli validate" expectfn "$clixon_cli -1f $cfg -l o -y $fyang -l o validate" 0 "^$" new "cli set transitive union error. should fail" expectfn "$clixon_cli -1f $cfg -l o -y $fyang set c ulle kalle" 255 "" new "cli set transitive union error int" expectfn "$clixon_cli -1f $cfg -l o -y $fyang set c ulle 55" 255 "" new "netconf set transitive union error int" expecteof "$clixon_netconf -qf $cfg -y $fyang" 0 "55]]>]]>" "^]]>]]>" new "netconf validate should fail" expecteof "$clixon_netconf -qf $cfg -y $fyang" 0 "]]>]]>" "^applicationbad-elementulleerror'55' does not match enumeration]]>]]>$" new "netconf discard-changes" expecteof "$clixon_netconf -qf $cfg -y $fyang" 0 "]]>]]>" "^]]>]]>$" #----------- new "cli set ab" expectfn "$clixon_cli -1f $cfg -l o -y $fyang set list a.b.a.b" 0 "^$" new "cli set cd" expectfn "$clixon_cli -1f $cfg -l o -y $fyang set list c.d.c.d" 0 "^$" new "cli set ef" expectfn "$clixon_cli -1f $cfg -l o -y $fyang set list e.f.e.f" 0 "^$" new "cli set ab fail" expectfn "$clixon_cli -1f $cfg -l o -y $fyang set list a&b&a&b" 255 "^CLI syntax error" new "cli set ad fail" expectfn "$clixon_cli -1f $cfg -l o -y $fyang set list a.b.c.d" 255 "^CLI syntax error" new "cli validate" expectfn "$clixon_cli -1f $cfg -l o -y $fyang -l o validate" 0 "^$" new "cli commit" expectfn "$clixon_cli -1f $cfg -l o -y $fyang -l o commit" 0 "^$" new "netconf validate ok" expecteof "$clixon_netconf -qf $cfg -y $fyang" 0 "]]>]]>" "^]]>]]>$" new "netconf set ab wrong" expecteof "$clixon_netconf -qf $cfg -y $fyang" 0 "a.b& c.d]]>]]>" "^]]>]]>$" new "netconf validate" expecteof "$clixon_netconf -qf $cfg -y $fyang" 0 "]]>]]>" "^" new "netconf discard-changes" expecteof "$clixon_netconf -qf $cfg -y $fyang" 0 "]]>]]>" "^]]>]]>$" new "netconf commit" expecteof "$clixon_netconf -qf $cfg -y $fyang" 0 "]]>]]>" "^]]>]]>$" new "cli enum value" expectfn "$clixon_cli -1f $cfg -l o -y $fyang set status down" 0 "^$" new "cli bits value" expectfn "$clixon_cli -1f $cfg -l o -y $fyang set mbits create" 0 "^$" #XXX No, cli cant assign two bit values #new "cli bits two values" #expectfn "$clixon_cli -1f $cfg -l o -y $fyang set mbits \"create read\"" 0 "^$" new "netconf bits two values" expecteof "$clixon_netconf -qf $cfg -y $fyang" 0 "create read]]>]]>" "^]]>]]>$" new "cli bits validate" expectfn "$clixon_cli -1f $cfg -l o -y $fyang validate" 0 "^$" 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 sudo clixon_backend -z -f $cfg if [ $? -ne 0 ]; then err "kill backend" fi rm -rf $dir