TT#177550 check: Add a YAML schema and validation for sites.yml

We add support for YAML schemas, and hook it into the check command to
validate the sites.yml file.

Change-Id: Ic6ed43e36361d395b485230af4ec3cf7e77758bb
mr11.0
Guillem Jover 3 years ago committed by ngcp-config
parent 6100f2002b
commit 0f20e0ffe5

@ -15,6 +15,9 @@ PERL_SCRIPTS = \
sbin/ngcp-sync-constants \
sbin/ngcp-sync-grants \
# EOL
YAML_SCHEMAS = \
schemas/sites.yml \
# EOL
RESULTS ?= results
all: docs
@ -40,7 +43,7 @@ dist-clean: clean
rm -rf results
# check for syntax errors
syntaxcheck: shellcheck perlcheck
syntaxcheck: shellcheck perlcheck yamlcheck
shellcheck:
@echo -n "Checking for shell syntax errors"; \
@ -59,6 +62,15 @@ perlcheck:
done; \
echo "-> perl check done."; \
yamlcheck:
@echo "Checking for yaml syntax errors:"; \
for YAML in $(YAML_SCHEMAS); do \
test -r $${YAML} || continue ; \
perl -MYAML::XS -E "YAML::XS::LoadFile('$${YAML}')" || exit ; \
done; \
echo "-> yaml check done."; \
:
test:
mkdir -p $(RESULTS)
cd t ; py.test-3 --junit-xml=$(RESULTS)/pytest.xml -vv -l

@ -20,6 +20,7 @@ sbin/ngcp-network-validator usr/sbin/
sbin/ngcp-sync-constants usr/sbin/
sbin/ngcp-sync-grants usr/sbin/
sbin/ngcpcfg usr/sbin/
schemas/sites.yml usr/share/ngcp-ngcpcfg/schemas/
scripts/apply usr/share/ngcp-ngcpcfg/scripts/
scripts/build usr/share/ngcp-ngcpcfg/scripts/
scripts/cat usr/share/ngcp-ngcpcfg/scripts/

@ -0,0 +1,16 @@
name: sites.yml
desc: Kwalify schema for NGCP sites.yml
type: map
mapping:
"sites":
type: map
required: yes
mapping:
=:
type: map
required: yes
mapping:
"id": { type: int, required: yes, range: { min: 1 },
desc: "Specify the site ID. Must be unique." }
"role": { type: str, required: yes,
desc: "Specify the site role." }

@ -9,6 +9,7 @@ set -u
FUNCTIONS="${FUNCTIONS:-/usr/share/ngcp-ngcpcfg/functions/}"
HELPER="${HELPER:-/usr/share/ngcp-ngcpcfg/helper/}"
SCRIPTS="${SCRIPTS:-/usr/share/ngcp-ngcpcfg/scripts/}"
SCHEMAS="${SCHEMAS:-/usr/share/ngcp-ngcpcfg/schemas/}"
if ! [ -r "${FUNCTIONS}"/main ] ; then
printf "Error: %s/main could not be read. Exiting.\n" "${FUNCTIONS}" >&2
@ -169,7 +170,19 @@ validate_config() {
fi
else
local schema
schema="/usr/share/ngcp-cfg-schema/validate/${name}"
case "${name}" in
sites.yml)
if ! [ -e "${f}" ]; then
continue
fi
schema="${SCHEMAS}/${name}"
;;
*)
schema="/usr/share/ngcp-cfg-schema/validate/${name}"
;;
esac
if ! [ -f "${schema}" ] ; then
continue
@ -261,7 +274,8 @@ check_shared_storage() {
}
if [ "$*" = "" ] ; then
config_files="${NGCPCTL_CONFIG:-} ${NODE_CONFIG:-} ${PAIR_CONFIG:-} ${HOST_CONFIG:-} ${LOCAL_CONFIG:-} ${NETWORK_CONFIG:-} ${EXTRA_CONFIG_FILES[*]} ${CONSTANTS_CONFIG:-}"
SITES_FILE="${SITES_FILE:-${NGCPCTL_MAIN}/sites.yml}"
config_files="${NGCPCTL_CONFIG:-} ${NODE_CONFIG:-} ${PAIR_CONFIG:-} ${HOST_CONFIG:-} ${LOCAL_CONFIG:-} ${NETWORK_CONFIG:-} ${EXTRA_CONFIG_FILES[*]} ${CONSTANTS_CONFIG:-} ${SITES_FILE:-}"
else
config_files="$*"
fi

Loading…
Cancel
Save