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 lab_nodes=$(grep -ce 'node:' "${lab_config}")
39 lab_tmacs=$(grep -ce 'mac_address:' "${lab_config}")
40 ((lab_amacs=lab_tmacs/lab_nodes)); ((lab_nodes-=1))
41 echo "###################### ${lab_config} ######################"
42 for adapter in ${INSTALLER_ADAPTERS}; do
46 ia_nodes=$(grep -hPo 'nodes\W+\K\d+' -R "${adapter}" | tail -1)
47 ia_rmacs=$(grep -hPo 'interfaces\W+\K\d+' -R "${adapter}" | sort | tail -1)
48 ((ia_nodes+=1)); ((ia_rmacs+=1))
49 if [[ ${ia_nodes} -gt ${lab_nodes} ]]; then
51 echo -n "[GENERATE] [SKIP] $(basename "${adapter}") requires at least"
52 echo -e " ${ia_nodes} nodes, but found only ${lab_nodes}, skipping.\n"
55 if [[ ${ia_rmacs} -ge ${lab_amacs} ]]; then
57 echo -n "[GENERATE] [SKIP] $(basename "${adapter}") requires at least"
58 echo -e " ${ia_rmacs} nics, but found ~ ${lab_amacs}, skipping.\n"
61 while IFS= read -r jinja_template; do
62 pdf_gen_cmd="${GEN_CFG} -y ${lab_config} -j ${jinja_template}"
63 if ${pdf_gen_cmd} > "${TMPF}"; then
65 echo "[GENERATE] [OK] ${pdf_gen_cmd}"
66 if yamllint -s <(sed 's|ENC\[PKCS.*\]|opnfv|g' "${TMPF}"); then
68 echo "[YAMLLINT] [OK] yamllint -s ${jinja_template%.j2}"
70 echo "[YAMLLINT] [ERROR] yamllint -s ${jinja_template%.j2}"
73 echo "[GENERATE] [ERROR] ${pdf_gen_cmd}"
78 done < <(find "${adapter}" -name '*.j2')
79 SUMMARY+="${pdf_yaml_pass}/${pdf_inst_pass}/${pdf_inst};"
81 done < <(find labs/${FILTER_LAB} -regextype egrep \
82 -regex "labs/.+/${FILTER_POD}.yaml")
86 ###################### Result Matrix ######################
88 NOTE: tuple fmt: (valid YAML output/sucessful parse/templates).
90 $(echo -e "${SUMMARY}" | sed -e 's/^/;/g' -e 's/;/;| /g' | column -t -s ';')
92 To troubleshoot PDF parsing against a specific installer adapter,
93 execute the following commands locally (e.g. for zte-pod2/joid):
94 $ ./config/utils/generate_config.py \\
95 -y labs/zte/pod2.yaml \\
96 -j config/installers/joid/pod_config.yaml.j2