From a7e72a46d972dd982f6dcd4d95aaacb4e5f6ebfa Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Mattias=20Walstr=C3=B6m?= Date: Fri, 6 Jun 2025 20:44:14 +0200 Subject: [PATCH] confd: Simplify enabling features in YANG models If a extra infix feature require features to be added to an already loaded module. Instead of have the exact module definition in multiple places (with date), this will allow a much more flexible sytax: MODULES=( "infix-interfaces -e containers" ) This require that the infix-interfaces is loaded *before* this file is run. --- src/confd/yang/confd.inc | 1 - src/confd/yang/containers.inc | 3 +-- utils/srload | 19 +++++++++++++------ 3 files changed, 14 insertions(+), 9 deletions(-) diff --git a/src/confd/yang/confd.inc b/src/confd/yang/confd.inc index f6074cfa..257e51e2 100644 --- a/src/confd/yang/confd.inc +++ b/src/confd/yang/confd.inc @@ -1,5 +1,4 @@ # -*- sh -*- -# REMEMBER TO UPDATE infix-interfaces ALSO IN containers.inc MODULES=( "ietf-system@2014-08-06.yang -e authentication -e local-users -e ntp -e ntp-udp-port -e timezone-name" diff --git a/src/confd/yang/containers.inc b/src/confd/yang/containers.inc index b7e66044..50447cf8 100644 --- a/src/confd/yang/containers.inc +++ b/src/confd/yang/containers.inc @@ -1,6 +1,5 @@ # -*- sh -*- -# REMEMBER TO UPDATE infix-interfaces ALSO IN confd.inc MODULES=( - "infix-interfaces@2025-01-09.yang -e vlan-filtering -e containers" + "infix-interfaces -e containers" "infix-containers@2025-05-14.yang" ) diff --git a/utils/srload b/utils/srload index 5996bf74..65d9a14a 100755 --- a/utils/srload +++ b/utils/srload @@ -82,7 +82,10 @@ chperm() enable() { - $SYSREPOCTL -c "$1" -e "$2" -v2 + local module=$1 + local feature=$2 + echo "*** Enable feature $feature in $module." + $SYSREPOCTL -c $module -e $feature -v2 local rc=$? if [ $rc -ne 0 ]; then exit $rc @@ -93,7 +96,7 @@ enable() SCTL_MODULES=$($SYSREPOCTL -l |tail -n +5 |head -n -3) for module in "${MODULES[@]}"; do - name=$(echo "$module" | awk -F'[@.]' '{print $1}') + name=$(echo "$module" | awk '{match($1, /[^@.]+/); print substr($1, RSTART, RLENGTH)}') date=$(echo "$module" | awk -F'[@.]' '{print $2}') for dir in $SEARCH_PATH; do if [ -n "${date}" ]; then @@ -105,10 +108,15 @@ for module in "${MODULES[@]}"; do MODDIR="${dir}" fi done - [ -z "${MODDIR}" ] && echo "Could not find ${yang} in ${SEARCH_PATH}" && exit 1 + # If no .yang we just modfify an existing model + if [[ "$module" == *.yang* && -z "$MODDIR" ]]; then + echo "Could not find ${yang} in ${SEARCH_PATH}" + exit 1 + fi SCTL_MODULE=$(echo "$SCTL_MODULES" | grep "^$name \+|[^|]*| I") + if [ -z "$SCTL_MODULE" ]; then # prepare command to install module with all its features echo "*** Installing YANG model $name ..." @@ -117,7 +125,7 @@ for module in "${MODULES[@]}"; do fi rev=$(echo "$SCTL_MODULE" | awk '{print $3}') - if [ "$rev" != "$date" ] || echo "$FORCE_UPDATE" | grep -qw "$name"; then + if [ -n "$date" ] && [ "$rev" != "$date" ] || echo "$FORCE_UPDATE" | grep -qw "$name"; then # update module without any features file=$(echo "$module" | cut -d' ' -f 1) echo "*** Updating YANG model $name ($file) ..." @@ -133,8 +141,7 @@ for module in "${MODULES[@]}"; do chperm "$name" fi - # parse sysrepoctl features and add extra space at the end for easier matching - sctl_features="`echo "$SCTL_MODULE" | sed 's/\([^|]*|\)\{6\}\(.*\)/\2/'` " + sctl_features="`echo "$SCTL_MODULE" | awk -F '|' '{print $NF}' | xargs`" # parse features we want to enable features=`echo "$module" | sed 's/[^ ]* \(.*\)/\1/'` while [ "${features:0:3}" = "-e " ]; do