utils/ixyang: Simplify linting of infix YANG models

Usage examples:

Run yanglint on all infix models:

    ixyang check

Lint a single model:

    ixyang lint infix-interfaces

Dump a tree of ietf-interfaces with all infix augments:

    ixyang lint infix-interfaces ietf-interfaces -- -f tree
This commit is contained in:
Tobias Waldekranz
2025-01-10 10:12:22 +01:00
parent 805ddf6c92
commit 41b96e8a01
2 changed files with 118 additions and 4 deletions
Executable
+114
View File
@@ -0,0 +1,114 @@
#!/bin/sh
ixdir=$(readlink -f $(dirname "$0")/../)
. "$ixdir/utils/libix.sh"
resolve_host_dir
YANGLINT="$HOST_DIR/bin/yanglint"
[ -x "$YANGLINT" ] || {
echo "*** Error: yanglint is not installed" >&2
exit 1
}
yangdir="$ixdir/src/confd/yang"
check()
{
find "$yangdir" -type f -name '*infix*.yang' | while read file; do
head -n1 "$file" | grep -q "submodule" && continue
printf "%-40s " $(basename "$file")
"$YANGLINT" -p "$yangdir" -i "$file" || {
printf "%-40s FAIL\n" $(basename "$file")
continue
}
echo ok
done
}
resolve_model()
{
local model="$1"
if [ -e "$model" ]; then
file="$model"
elif [ -e "$yangdir/$model" ]; then
file="$yangdir/$model"
elif [ -e "$yangdir/$model.yang" ]; then
file="$yangdir/$model.yang"
else
file=$(find "$yangdir" -name "$model*" -print -quit)
fi
if [ -z "$file" ]; then
echo "*** Error: Found no model matching \"$model\"" >&2
exit 1
fi
echo "$file"
}
lint()
{
local files=
while [ $# -gt 0 ]; do
if [ "$1" = "--" ]; then
shift
break
fi
files="$files $(resolve_model $1)"
shift
done
"$YANGLINT" -p "$yangdir" -i "$@" $files
}
yanger()
{
local model="$1"
"$ixdir/src/statd/python/yanger/yanger" \
-t "$ixdir/test/case/cli/system-output" \
"$model"
}
yangerlint()
{
local model="$1"
yanger "$model" >/tmp/ixyang-yangerlint.json || {
echo "*** Error: Failed to dump \"$model\"" >&2
exit 1
}
case "$model" in
ietf-interfaces)
lint \
ietf-interfaces \
ieee802-ethernet-interface \
infix-interfaces \
infix-ethernet-interface \
\
/tmp/ixyang-yangerlint.json \
-- -i -t data
;;
*)
echo "*** Error: yangerlint not implemented for \"$model\"" >&2
;;
esac
rm /tmp/ixyang-yangerlint.json
}
case "$1" in
check|lint|yanger|yangerlint)
"$@"
;;
*)
echo "*** Error: Unknown command \"$1\"" >&2
return 1
esac
+4 -4
View File
@@ -5,13 +5,13 @@ resolve_o()
if [ -f ".config" ] && [ -d "output" ]; then
# Buildroot
O=./output
O=$(readlink -f ./output)
elif [ -f "output/.config" ]; then
# BR2_EXTERNAL
O=./output
O=$(readlink -f ./output)
elif [ -f ".config" ] && [ -d "host" ]; then
# Called from inside output/ directory
O=.
O=$(readlink -f .)
else
echo "*** Error: cannot find Buildroot output dir!" >&2
exit 1
@@ -22,7 +22,7 @@ resolve_host_dir()
{
[ -n "$HOST_DIR" ] && return
resolve_o || exit 1
resolve_o
if ! [ -d "$O/host" ]; then
echo "*** Error: cannot find Buildroot host binaries dir!" >&2