check-jinja: Suppress PDF output logging
[securedlab.git] / check-jinja2.sh
1 #!/bin/bash
2 set +x
3 set +o errexit
4
5 git submodule update --init --remote 2>/dev/null
6 GEN_CFG='./pharos/config/utils/generate_config.py'
7 INSTALLER_ADAPTERS='./pharos/config/installers/*'
8 RC=0
9
10 # Build a table header, using ';' as column sep
11 SUMMARY='PDF/Installer;'
12 for adapter in ${INSTALLER_ADAPTERS}; do
13     SUMMARY+="$(basename "${adapter}");"
14 done
15
16 # Iterate all PDFs, check with each installer adapter, log results
17 while IFS= read -r lab_config; do
18     SUMMARY+="\n${lab_config#labs/};"
19     for adapter in ${INSTALLER_ADAPTERS}; do
20         pdf_inst=0
21         pdf_inst_pass=0
22         while IFS= read -r jinja_template; do
23             echo -e "\n${GEN_CFG} -y ${lab_config} -j ${jinja_template}"
24             if "${GEN_CFG}" -y "${lab_config}" \
25                             -j "${jinja_template}" > /dev/null; then
26                 echo 'Result: PASS'
27                 ((pdf_inst_pass+=1))
28             else
29                 echo 'Result: FAIL'
30                 RC=1
31             fi
32             ((pdf_inst+=1))
33         done < <(find "${adapter}" -name '*.j2')
34         SUMMARY+="${pdf_inst_pass}/${pdf_inst};"
35     done
36 done < <(find 'pharos/config' 'labs' -name 'pod*.yaml')
37
38 echo -e '\n'
39 echo -e "${SUMMARY}" | sed -e 's/^/;/g' -e 's/;/;| /g' | column -t -s ';'
40
41 cat <<EOF
42
43 To troubleshoot PDF parsing against a specific installer adapter,
44 execute the following commands locally (e.g. for zte-pod2/joid):
45 $ git submodule update --remote --init
46 $ ./pharos/config/utils/generate_config.py \\
47     -y labs/zte/pod2.yaml \\
48     -j ./pharos/config/installers/joid/pod_config.yaml.j2
49
50 EOF
51 exit "${RC}"