2 # SPDX-license-identifier: Apache-2.0
3 ##############################################################################
4 # Copyright (c) 2018 Linux Foundation and others.
5 # All rights reserved. This program and the accompanying materials
6 # are made available under the terms of the Apache License, Version 2.0
7 # which accompanies this distribution, and is available at
8 # http://www.apache.org/licenses/LICENSE-2.0
9 ##############################################################################
13 export PATH=$PATH:/usr/local/bin/
15 # Optional filtering of test matrix: per-lab, per-pod, per-installer
16 # e.g. To check zte-pod{2,3} against all installer adapters:
17 # ./config/utils/check-jinja2.sh zte 'pod(2|3)'
18 FILTER_LAB=${1:-*} # e.g. 'zte' (glob)
19 FILTER_POD=${2:-(pod|virtual)[[:digit:]]+} # e.g. 'pod1' (regex)
20 FILTER_IA=${3:-*} # e.g. 'fuel' (glob)
22 GEN_CFG='python ./config/utils/generate_config.py'
23 INSTALLER_ADAPTERS="./config/installers/${FILTER_IA}"
24 TMPF='/tmp/out.yml' # should be outside Jenkins WS to prevent data leakage
27 echo "Using $(yamllint --version)"
29 # Build a table header, using ';' as column sep
30 for adapter in 'PDF Verify Matrix' ${INSTALLER_ADAPTERS}; do
31 SUMMARY+="$(basename "${adapter}");"
34 # Iterate all PDFs, check with each installer adapter, log results
35 # shellcheck disable=SC2086
36 while IFS= read -r lab_config; do
37 SUMMARY+="\n${lab_config#labs/};"
38 idf_config="$(dirname "${lab_config}")/idf-$(basename "${lab_config}")"
39 idf_installer=$(grep 'installer:' "${idf_config}" 2>/dev/null || echo)
40 echo "###################### ${lab_config} ######################"
41 for adapter in ${INSTALLER_ADAPTERS}; do
45 installer_name=$(basename "${adapter}")
46 if [ -n "${idf_installer}" ] && echo "${idf_installer}" | \
47 grep -vq "${installer_name}"; then
49 echo -n "[GENERATE] [SKIP] idf.installer defined and "
50 echo -e "${installer_name} not listed, skipping.\n"
53 while IFS= read -r jinja_template; do
54 pdf_gen_cmd="${GEN_CFG} -y ${lab_config} -j ${jinja_template}"
55 if ${pdf_gen_cmd} > "${TMPF}"; then
57 echo "[GENERATE] [OK] ${pdf_gen_cmd}"
58 if yamllint -s <(sed 's|ENC\[PKCS.*\]|opnfv|g' "${TMPF}"); then
60 echo "[YAMLLINT] [OK] yamllint -s ${jinja_template%.j2}"
62 echo "[YAMLLINT] [ERROR] yamllint -s ${jinja_template%.j2}"
65 echo "[GENERATE] [ERROR] ${pdf_gen_cmd}"
70 done < <(find "${adapter}" -name '*.j2')
71 SUMMARY+="${pdf_yaml_pass}/${pdf_inst_pass}/${pdf_inst};"
73 done < <(find labs/${FILTER_LAB} -regextype egrep \
74 -regex "labs/.+/${FILTER_POD}.yaml")
78 ###################### Result Matrix ######################
80 NOTE: tuple fmt: (valid YAML output/sucessful parse/templates).
82 $(echo -e "${SUMMARY}" | sed -e 's/^/;/g' -e 's/;/;| /g' | column -t -s ';')
84 To troubleshoot PDF parsing against a specific installer adapter,
85 execute the following commands locally (e.g. for zte-pod2/joid):
86 $ ./config/utils/generate_config.py \\
87 -y labs/zte/pod2.yaml \\
88 -j config/installers/joid/pod_config.yaml.j2