#!/bin/bash # Parse yang openconfig yangs from https://github.com/openconfig/public # Notes: # - openconfig test suites are patched to counter Clixon issues as follows: # - release/models/mpls/openconfig-mpls-te.yang # issue: https://github.com/clicon/clixon/issues/6 # - Env-var MODELS should be 1 # - Env-var OPENCONFIG should point to checkout place. (define it in site.sh for example) # 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 new "openconfig" if [ ! -d "$OPENCONFIG" ]; then # err "Hmm Openconfig dir does not seem to exist, try git clone https://github.com/openconfig/public?" if [ "$s" = $0 ]; then exit 0; else return 0; fi fi OCDIR=$OPENCONFIG/release/models cat < $cfg $cfg $OCDIR $OCDIR/acl $OCDIR/aft $OCDIR/bfd $OCDIR/bgp $OCDIR/catalog $OCDIR/interfaces $OCDIR/isis $OCDIR/lacp $OCDIR/lldp $OCDIR/local-routing $OCDIR/mpls $OCDIR/multicast $OCDIR/network-instance $OCDIR/openflow $OCDIR/optical-transport $OCDIR/ospf $OCDIR/platform $OCDIR/policy $OCDIR/policy-forwarding $OCDIR/probes $OCDIR/qos $OCDIR/relay-agent $OCDIR/rib $OCDIR/segment-routing $OCDIR/stp $OCDIR/system $OCDIR/telemetry $OCDIR/types $OCDIR/vlan $OCDIR/wifi $OCDIR/wifi/access-points $OCDIR/wifi/ap-manager $OCDIR/wifi/mac $OCDIR/wifi/phy $OCDIR/wifi/types /usr/local/share/clixon $IETFRFC /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 files=$(find $OPENCONFIG -name "*.yang") # Count nr of modules (exclude submodule) Assume "module" or "submodule" # first word on first line let ms=0; # Nr of modules let ss=0; # Nr of smodules for f in $files; do let m=0; # Nr of modules let s=0; # Nr of modules if [ -n "$(head -15 $f|grep '^[ ]*module')" ]; then let m++; let ms++; elif [ -n "$(head -15 $f|grep '^[ ]*submodule')" ]; then let s++; let ss++; else echo "No module or submodule found $f" exit fi if [ $m -eq 1 -a $s -eq 1 ]; then echo "Double match $f" exit fi done new "Openconfig test: $clixon_cli -1f $cfg -y $f show version ($m modules)" for f in $files; do if [ -n "$(head -1 $f|grep '^module')" ]; then new "$clixon_cli -1f $cfg -y $f show version" expectfn "$clixon_cli -1f $cfg -y $f show version" 0 "$version." fi done rm -rf $dir