--- /dev/null
+#!/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
#!/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`"