#!/usr/bin/env bash # Parse "all" openconfig yangs from https://github.com/openconfig/public # Notes: # Notes: # - A simple smoketest (CLI check) is made, essentially YANG parsing. # - A full system is worked on # - Env-var OPENCONFIG should point to checkout place. (define it in site.sh for example) # - Env variable YANGMODELS should point to checkout place. (define it in site.sh for example) # - Some DIFFs are necessary in yangmodels # release/models/wifi/openconfig-ap-interfaces.yang # 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?" echo "...skipped: OPENCONFIG not set" if [ "$s" = $0 ]; then exit 0; else return 0; fi fi OCDIR=$OPENCONFIG/release/models cat < $cfg $cfg ietf-netconf:startup /usr/local/share/clixon $OCDIR $OCDIR/acl $OCDIR/aft $OCDIR/bfd $OCDIR/bgp $OCDIR/catalog $OCDIR/interfaces $OCDIR/isis $OCDIR/lacp $OCDIR/lldp $OCDIR/local-routing $OCDIR/macsec $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/lib/$APPNAME/clispec /usr/local/lib/$APPNAME/cli $APPNAME /usr/local/var/$APPNAME/$APPNAME.sock /usr/local/var/$APPNAME/$APPNAME.pidfile $dir 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 -D $DBG -1f $cfg -y $f show version" expectpart "$($clixon_cli -D $DBG -1f $cfg -y $f show version)" 0 "${CLIXON_VERSION}" fi done if false; then # NYI # Example system cat < $dir/startup_db eth0 ianaift:usb 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 -y openconfig-interfaces -p /usr/local/share/openconfig/public/release/models/interfaces" start_backend -s startup -f $cfg -y /usr/local/share/openconfig/public/release/models/interfaces/openconfig-interfaces.yang new "wait backend" wait_backend fi new "$clixon_cli -D $DBG -1f $cfg -y $f show version" expectpart "$($clixon_cli -D $DBG -1f $cfg -y $f show version)" 0 "${CLIXON_VERSION}" 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 fi rm -rf $dir