#!/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 IETFRFC should point to checkout place, derived from YANG_STANDARD_DIR config option # - 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 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 or dir not exist" rm -rf $dir if [ "$s" = $0 ]; then exit 0; else return 0; fi fi # OPENCONFIG dir has a small number of extra yangs apart from OCDIR OCDIR=$OPENCONFIG/release/models files=$(find ${OPENCONFIG} -type f -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 show version ($m modules)" for f in $files; do if [ -n "$(head -1 $f|grep '^module')" ]; then modname=$(basename $f | awk -F "." '{print $1}') # Generate autocli for these modules AUTOCLI=$(autocli_config $modname kw-nokey false) cat < $cfg $cfg ietf-netconf:startup ${OPENCONFIG} ${YANG_INSTALLDIR} true /usr/local/lib/$APPNAME/clispec /usr/local/lib/$APPNAME/cli $APPNAME /usr/local/var/run/$APPNAME.sock /usr/local/var/run/$APPNAME.pidfile $dir ${AUTOCLI} EOF 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 # The following test is a special case: A deviation of a grouped type did not appear in # type resolution f=$dir/my.yang cat < $f module my { namespace "urn:example:clixon"; prefix "ex"; import "openconfig-network-instance" { prefix "oc-netinst"; } deviation "/oc-netinst:network-instances/oc-netinst:network-instance/oc-netinst:protocols/oc-netinst:protocol/oc-netinst:isis/oc-netinst:interfaces/oc-netinst:interface/oc-netinst:levels/oc-netinst:level/oc-netinst:afi-safi/oc-netinst:af/oc-netinst:config/oc-netinst:metric" { description "metric range is restricted"; deviate "replace" { type "union" { type "uint32"; type "enumeration" { enum "MYTEXT"; } } default "MYTEXT"; } } } EOF modname=$(basename $f | awk -F "." '{print $1}') # Generate autocli for these modules AUTOCLI=$(autocli_config openconfig-* kw-nokey false) cat < $cfg $cfg ietf-netconf:startup ${OPENCONFIG} ${YANG_INSTALLDIR} true /usr/local/lib/$APPNAME/clispec /usr/local/lib/$APPNAME/cli $APPNAME /usr/local/var/run/$APPNAME.sock /usr/local/var/run/$APPNAME.pidfile $dir ${AUTOCLI} EOF new "deviation: $clixon_cli -D $DBG -1f $cfg -y $f show version" expectpart "$($clixon_cli -D $DBG -1f $cfg -y $f show version)" 0 "${CLIXON_VERSION}" rm -rf $dir new "endtest" endtest