[PDF] check-jinja: Replace encrypted str w/ dummy
[pharos.git] / config / utils / check-jinja2.sh
1 #!/bin/bash
2 # SPDX-license-identifier: Apache-2.0
3 ##############################################################################
4 # Copyright (c) 2016 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 ##############################################################################
10
11 set +x
12 set +o errexit
13 export PATH=$PATH:/usr/local/bin/
14
15 GEN_CFG='./config/utils/generate_config.py'
16 INSTALLER_ADAPTERS='./config/installers/*'
17 TMPF='/tmp/out.yml' # should be outside Jenkins WS to prevent data leakage
18 RC=0
19
20 echo "Using $(yamllint --version)"
21
22 # Build a table header, using ';' as column sep
23 SUMMARY='PDF Verify Matrix;YAML Lint;'
24 for adapter in ${INSTALLER_ADAPTERS}; do
25     SUMMARY+="$(basename "${adapter}");"
26 done
27
28 # Iterate all PDFs, check with each installer adapter, log results
29 while IFS= read -r lab_config; do
30     valid_yaml='OK'
31     echo -e "\n###################### ${lab_config} ######################\n"
32     echo -e "\n\nyamllint -s ${lab_config}"
33     if ! yamllint -s "${lab_config}"; then valid_yaml='FAIL'; fi
34     SUMMARY+="\n${lab_config#labs/};${valid_yaml};"
35     for adapter in ${INSTALLER_ADAPTERS}; do
36         pdf_inst=0
37         pdf_inst_pass=0
38         pdf_yaml_pass=0
39         while IFS= read -r jinja_template; do
40             echo -e "\n${GEN_CFG} -y ${lab_config} -j ${jinja_template}"
41             if "${GEN_CFG}" -y "${lab_config}" \
42                             -j "${jinja_template}" > "${TMPF}"; then
43                 echo 'Result: PASS'
44                 ((pdf_inst_pass+=1))
45                 echo -e "\nyamllint -s ${jinja_template%.j2}"
46                 if yamllint -s <(sed 's|ENC\[PKCS.*\]|opnfv|g' "${TMPF}"); then
47                     ((pdf_yaml_pass+=1));
48                 fi
49             else
50                 echo 'Result: FAIL'
51                 RC=1
52             fi
53             ((pdf_inst+=1))
54         done < <(find "${adapter}" -name '*.j2')
55         SUMMARY+="${pdf_yaml_pass}/${pdf_inst_pass}/${pdf_inst};"
56     done
57 done < <(find 'labs' -name 'pod*.yaml')
58
59 rm -f "${TMPF}"
60 echo -e '\n\nNOTE: tuple fmt: (valid YAML output/sucessful parse/templates).\n'
61 echo -e "${SUMMARY}" | sed -e 's/^/;/g' -e 's/;/;| /g' | column -t -s ';'
62
63 cat <<EOF
64
65 To troubleshoot PDF parsing against a specific installer adapter,
66 execute the following commands locally (e.g. for zte-pod2/joid):
67 $ ./config/utils/generate_config.py \\
68     -y labs/zte/pod2.yaml \\
69     -j config/installers/joid/pod_config.yaml.j2
70
71 EOF
72 exit "${RC}"