[ad-hoc] Fix test case exit conditions

While working on another change, I discovered conditions
in many test cases that echoed fail messages but did not
actually exit, so the gate could succeed even though some
tests failed. This patchset aims to fix those problems, and
then fix the problems masked by those problems:

1) fix bug in revert function of file permissions module
preventing permissions from being reverted.
2) fix various syntax and logic problems in test script
3) add wait_for_tiller_ready function to avoid race condition
with test script using helm too early
4) add install for ethtool in test script
5) ignore ethtool pod failures (see note #1 in [0])
6) make logging of test results more uniform
7) Fix error message logic in perm.sh
8) Fix case in _shcommon.tpl where error message was not
logged, causing test script to unnecessarily wait for
container timeout

[0]: https://review.opendev.org/676010

Change-Id: I22182d35250c37c96e73d9f5f49abfb2246f2a35
This commit is contained in:
Crank, Daniel 2020-01-22 15:57:09 -06:00 committed by Dan Crank
parent 7d968220c7
commit f0eb0b7582
5 changed files with 386 additions and 237 deletions

View File

@ -59,7 +59,7 @@ load_package_list_with_versions $(dpkg -l | awk 'NR>5 {print $2"="$3}')
{{- if hasKey .Values.conf "apt" }} {{- if hasKey .Values.conf "apt" }}
{{- if hasKey .Values.conf.apt "repositories" }} {{- if hasKey .Values.conf.apt "repositories" }}
echo -n "" > /etc/apt/trusted.gpg.d/divindbell_temp.gpg echo -n "" > /etc/apt/trusted.gpg.d/divingbell_temp.gpg
echo "#The list of repositories managed by Divingbell" > /etc/apt/sources.list.divingbell echo "#The list of repositories managed by Divingbell" > /etc/apt/sources.list.divingbell
{{- range .Values.conf.apt.repositories }} {{- range .Values.conf.apt.repositories }}
{{- $url := .url }} {{- $url := .url }}
@ -75,16 +75,16 @@ echo "{{ printf "deb %s %s-%s %s" $url $distribution . $components }}" >>/etc/ap
{{- end }} {{- end }}
{{- end }} {{- end }}
{{- if hasKey . "gpgkey" }} {{- if hasKey . "gpgkey" }}
apt-key --keyring /etc/apt/trusted.gpg.d/divindbell_temp.gpg add - <<"ENDKEY" apt-key --keyring /etc/apt/trusted.gpg.d/divingbell_temp.gpg add - <<"ENDKEY"
{{ .gpgkey }} {{ .gpgkey }}
ENDKEY ENDKEY
{{- end }} {{- end }}
{{- end }} {{- end }}
mv /etc/apt/sources.list.divingbell /etc/apt/sources.list mv /etc/apt/sources.list.divingbell /etc/apt/sources.list
rm -rf /etc/apt/sources.list.d/* rm -rf /etc/apt/sources.list.d/*
mv /etc/apt/trusted.gpg.d/divindbell_temp.gpg /etc/apt/trusted.gpg.d/divindbell.gpg mv /etc/apt/trusted.gpg.d/divingbell_temp.gpg /etc/apt/trusted.gpg.d/divingbell.gpg
rm -f /etc/apt/trusted.gpg rm -f /etc/apt/trusted.gpg
find /etc/apt/trusted.gpg.d/ -type f ! -name 'divindbell.gpg' -exec rm {{ "{}" }} \; find /etc/apt/trusted.gpg.d/ -type f ! -name 'divingbell.gpg' -exec rm {{ "{}" }} \;
DEBIAN_FRONTEND=noninteractive apt-get update DEBIAN_FRONTEND=noninteractive apt-get update
{{- end }} {{- end }}
{{- if hasKey .Values.conf.apt "packages" }} {{- if hasKey .Values.conf.apt "packages" }}

View File

@ -97,11 +97,11 @@ revert_perm(){
for o_perm in ${revert_list}; do for o_perm in ${revert_list}; do
first=1 first=1
while IFS=' ' read -r a1 a2; do while IFS=' ' read -r a1 a2; do
if [ "$first" -eq 1 && -e "$a2"]; then if [ "$first" -eq 1 ] && [ -e "$a2" ]; then
$(chmod "$a1" "$a2") chmod "$a1" "$a2"
first=0 first=0
elif [ -e "$a2"]; then elif [ -e "$a2" ]; then
$(chown "$a1" "$a2") chown "$a1" "$a2"
else else
log.WARN "Unable to revert permissions on $a2" log.WARN "Unable to revert permissions on $a2"
continue continue
@ -180,7 +180,7 @@ if [[ $hash_check = pass ]] && [[ $interval_check = pass ]]; then
fi fi
# write timestamp at beginning of execution # write timestamp at beginning of execution
log.INFO 'All permissions successfully applied on this node.' log.INFO 'All permissions successfully applied on this node.'
echo $(date +"%s") > "${hash}/last_run_timestamp" date +"%s" > "${hash}/last_run_timestamp"
{{- range $perm := .Values.conf.perm.paths }} {{- range $perm := .Values.conf.perm.paths }}
add_perm {{ $perm.path | squote }} {{ $perm.owner | squote }} {{ $perm.group | squote }} {{ $perm.permissions | squote }} add_perm {{ $perm.path | squote }} {{ $perm.owner | squote }} {{ $perm.group | squote }} {{ $perm.permissions | squote }}
@ -189,7 +189,7 @@ if [[ $hash_check = pass ]] && [[ $interval_check = pass ]]; then
revert_perm revert_perm
if [ -n "${curr_settings}" ]; then if [ -n "${applied_perm}" ]; then
log.INFO 'All permissions successfully applied on this node.' log.INFO 'All permissions successfully applied on this node.'
else else
log.WARN 'No permissions overrides defined for this node.' log.WARN 'No permissions overrides defined for this node.'

View File

@ -75,7 +75,6 @@ exec >& >(while read line; do
done) done)
die(){ die(){
set +x
# write to stderr any passed error message # write to stderr any passed error message
if [[ $@ = *[!\ ]* ]]; then if [[ $@ = *[!\ ]* ]]; then
log.ERROR "$@" log.ERROR "$@"
@ -85,6 +84,8 @@ die(){
log.TRACE $(caller $i) log.TRACE $(caller $i)
done done
echo __EXIT_MARKER__ echo __EXIT_MARKER__
log.ERROR "Exiting with unspecified error."
set +x
# Exit after pipe closes to ensure all output is flushed first # Exit after pipe closes to ensure all output is flushed first
while : ; do while : ; do
echo "Waiting on exit..." || exit 1 echo "Waiting on exit..." || exit 1

View File

@ -207,7 +207,7 @@ Used to execute scripts on nodes in ``systemd`` (PID=1) namespace, for ex.::
002-script2.sh: 002-script2.sh:
data: | data: |
#!/bin/bash #!/bin/bash
echo ${BASH_SOURCE} echo ${BASH_SOURCE[0]}
001-script1.sh: 001-script1.sh:
blocking_policy: foreground_halt_pod_on_failure blocking_policy: foreground_halt_pod_on_failure
env: env:
@ -218,7 +218,7 @@ Used to execute scripts on nodes in ``systemd`` (PID=1) namespace, for ex.::
- arg2 - arg2
data: | data: |
#!/bin/bash #!/bin/bash
echo script name: ${BASH_SOURCE} echo script name: ${BASH_SOURCE[0]}
echo args: $@ echo args: $@
echo env: $env1 $env2 $env3 echo env: $env1 $env2 $env3

File diff suppressed because it is too large Load Diff