-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathcheck_module.sh
More file actions
117 lines (110 loc) · 2.86 KB
/
Copy pathcheck_module.sh
File metadata and controls
117 lines (110 loc) · 2.86 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
#!/bin/sh
#
# Simple run of pyang with the "--lint" flag over all yang files in
# this directory, ignoring some warnings. Prior to pushing to git, the
# validation was run with pyang 1.5. This script should be run with
# the working doirectory set to a directory containing the yang files
# to run "pyang --lint" over.
#
# The modules as uploaded exhibit a number of RFC 6087 amd RFC 6020
# errors and warnings that are judged to be cosmetic at this time and
# which do not impact the ability of a client to interact with a
# device supporting the module. The exact content ignored may be
# identified by reviewing the "grep -v" commands below.
#
EGREP=`command -v egrep`
GREP=`command -v grep`
PYANG=`command -v pyang`
CHECK_BC=""
PYANG_FLAGS="-p ../standard/ietf/DRAFT"
#
# simple function to check for existence of a binary on the current
# path
#
checkExists() {
bin=`command -v $1`
if [ -z "$bin" ]
then
echo this script requires $1 to be on your path
exit 1
fi
}
#
# check we have the utilties we need
#
checkExists pyang
checkExists egrep
checkExists grep
#
# brief help for the options we support
#
show_help () {
echo Options for check-models.sh:
printf "\n"
printf " -h Show this help\n"
printf " -b <ver> Check backwards compatibility\n"
printf "\n"
}
OPTIND=1
while getopts "hb:" opt; do
case "$opt" in
h|\?)
show_help
exit 0
;;
b) CHECK_BC="$OPTARG"
;;
esac
done
#
# Run pyang over all the yang modules, ignoring certain errors and
# warnings.
#
echo Checking all models with "--lint" flag
for m in *.yang
do
pyang $PYANG_FLAGS --lint $m 2>&1 | \
grep -v "warning: RFC 6087" | \
grep -v "error: RFC 6087: 4.2" | \
grep -v "error: RFC 6087: 4.7" | \
grep -v "error: RFC 6087: 4.11,4.12" | \
grep -v "error: RFC 6087: 4.12" | \
grep -v "not in canonical order" | \
grep -v "warning: locally scoped grouping" | \
egrep -v "warning: imported module\s[a-zA-Z0-9\-]+\snot used"
done
#
# Check if we're doing a BC check, if not, exit status 0
#
if [ -z "$CHECK_BC" ]; then
exit 0
fi
#
# Run pyang over all the models in the directory that also exist
# in the 532 peer directory, using the --check-update-from option.
# This requires pyang 1.5 or better, so we check this first.
#
version=`pyang --version | awk '{print $NF}'`
if ! awk -v ver="$version" 'BEGIN { if (ver < 1.5) exit 1; }'; then
printf 'ERROR: pyang version 2.5 or higher required\n'
exit 1
fi
UPDATE_FROM_PATH=../standard/ietf/RFC
echo Comparing all models that also exist in ../$CHECK_BC AND that have
echo changed since version that version with "--check-update-from" flag:
echo
for m in *.yang
do
VER_FROM="../$CHECK_BC/$m"
if [ -e "$VER_FROM" ]
then
DIFF=`diff $VER_FROM $m`
if [ ! -z "$DIFF" ]
then
pyang \
--check-update-from $VER_FROM \
--check-update-from-path $UPDATE_FROM_PATH \
$m > $m.json
fi
fi
done