Add yang check script to distribution 25/85025/3
authorLuis Gomez <ecelgp@gmail.com>
Thu, 10 Oct 2019 02:52:35 +0000 (19:52 -0700)
committerLuis Gomez <ecelgp@gmail.com>
Thu, 10 Oct 2019 15:57:20 +0000 (08:57 -0700)
This script will check (using pyang) the yang
modules generated by the extract_modules script.

Also add cosmetic changes to yang extract script.

Change-Id: I35780f40e70260882fbd2cd4609bdc5046128acf
Signed-off-by: Luis Gomez <ecelgp@gmail.com>
karaf-scripts/src/main/assembly/bin/check_modules.sh [new file with mode: 0755]
karaf-scripts/src/main/assembly/bin/extract_modules.sh

diff --git a/karaf-scripts/src/main/assembly/bin/check_modules.sh b/karaf-scripts/src/main/assembly/bin/check_modules.sh
new file mode 100755 (executable)
index 0000000..56b96e2
--- /dev/null
@@ -0,0 +1,41 @@
+#!/bin/sh
+#
+# Copyright (c) 2019 Lumina Networks, Inc. and others. All rights reserved.
+#
+# This program and the accompanying materials are made available under the
+# terms of the Eclipse Public License v1.0 which accompanies this distribution,
+# and is available at http://www.eclipse.org/legal/epl-v10.html
+#
+#
+# This script checks the YANG modules collected by the extract_modules.sh
+# scripti. The check is done by the pyang tool and an error text file is
+# generated for every opendaylight project so proper actions can be taken
+# to fix the modules.
+#
+
+BIN_DIR=`dirname $0`
+OUTPUT="$BIN_DIR/../opendaylight-models"
+
+# Exit if no yang module folder is found
+[ ! -d "$OUTPUT" ] && echo "ERROR: no modules found, run extract_module.sh first" && exit 1
+
+# Assemble the pyang command options
+flags=""
+PROJECTS=`ls -d $OUTPUT/*`
+for proj in $PROJECTS; do
+    proj=`basename $proj`
+    flags="$flags -p  $OUTPUT/$proj"
+done
+
+# Run pyang on opendaylight yang modules and generate error file per project
+for proj in $PROJECTS; do
+    proj=`basename $proj`
+    [ -f "$OUTPUT/$proj/errors.txt" ] && rm $OUTPUT/$proj/errors.txt
+    touch $OUTPUT/$proj/errors.txt
+    YANGS=`find $OUTPUT/$proj -type f -name '*.yang'`
+    for yang in $YANGS; do
+        less $yang | grep -q namespace.*opendaylight &&
+        echo $yang && pyang $flags $yang 2>> $OUTPUT/$proj/errors.txt
+    done
+    echo "Write error file: $OUTPUT/$proj/errors.txt"
+done
index 6b3cfe896dfc18dabc3c376486929eb9c7957e79..7da5cbc73e21ae895861a9e67c29010c1160b360 100644 (file)
@@ -1,46 +1,54 @@
 #!/bin/sh
 #
 # Copyright (c) 2018 Pantheon Technologies, s.r.o. and others.  All rights reserved.
+# Copyright (c) 2019 Lumina Networks, Inc. and others. All rights reserved.
 #
 # This program and the accompanying materials are made available under the
 # terms of the Eclipse Public License v1.0 which accompanies this distribution,
 # and is available at http://www.eclipse.org/legal/epl-v10.html
 #
-
 #
-# This script visits all jars within the OpenDaylight karaf distribution and extracts
-# all production YANG modules (as located in META-INF/yang)
+# This script visits all jars within the OpenDaylight karaf distribution and
+# extracts all production YANG modules (as located in META-INF/yang).
 #
-set -e
+
 BIN_DIR=`dirname $0`
 OUTPUT="$BIN_DIR/../opendaylight-models"
 INPUT="$BIN_DIR/.."
 
-# FIXME: also wipe output?
-[ -d "$OUTPUT" ] || mkdir "$OUTPUT"
+# Create folder for external yang modules
+[ -d "$OUTPUT" ] && rm -rf $OUTPUT
+mkdir $OUTPUT
+mkdir $OUTPUT/external
 
 PROJECTS=`ls -d $INPUT/system/org/opendaylight/*`
 for proj in $PROJECTS; do
     proj=`basename $proj`
+    # Create folder for project yang modules
+    [ -d "$OUTPUT/$proj" ] || mkdir $OUTPUT/$proj
+    # Extract yang modules from jars
     echo "Extracting yang modules from $proj"
     JARS=`find $INPUT/system/org/opendaylight/$proj -type f -name '*.jar' | sort -u`
-    [ -d "$OUTPUT/$proj" ] || mkdir $OUTPUT/$proj
     for jar in $JARS; do
         unzip -l "$jar" | grep -q -e "\.yang$" &&
         unzip -q "$jar" 'META-INF/yang/*' -d "$OUTPUT/$proj"
     done
+    # Remove folder if no yang modules found
     if [ -z "$(ls -A $OUTPUT/$proj)" ]; then
         rm -rf $OUTPUT/$proj
+    # Copy yang modules to project or external folder
     else
-        rm -f $OUTPUT/$proj/*.yang
         YANGS=`find $OUTPUT/$proj/META-INF/yang/ -type f -name '*.yang'`
         for yang in $YANGS; do
             name=`basename $yang`
             less $yang | grep -q namespace.*opendaylight &&
-            mv $OUTPUT/$proj/META-INF/yang/$name $OUTPUT/$proj &&
+            cp $OUTPUT/$proj/META-INF/yang/$name $OUTPUT/$proj
+            less $yang | grep -q namespace.*opendaylight ||
+            cp $OUTPUT/$proj/META-INF/yang/$name $OUTPUT/external
             echo "  $name"
         done
+        # Clean temp folders
         rm -rf $OUTPUT/$proj/META-INF
     fi
 done
-echo -e "\nYang Modules are extracted to `readlink -f $OUTPUT`"
+echo "Yang Modules are extracted to `readlink -f $OUTPUT`"