Theo Chatzimichos 1f0a34
#!/bin/bash
Theo Chatzimichos 1f0a34
Theo Chatzimichos 1f0a34
# Runs state.show_highstate using all localized grains' combinations
Theo Chatzimichos 1f0a34
Theo Chatzimichos f8666c
source bin/get_colors.sh
Theo Chatzimichos f8666c
a5a5f7
if [[ $(whoami) != 'root' ]]; then
a5a5f7
    if [[ -f /usr/bin/sudo ]]; then
a5a5f7
        SUDO='/usr/bin/sudo'
a5a5f7
    else
a5a5f7
        echo 'Please install sudo first, or run this script as root'
a5a5f7
        exit 1
a5a5f7
    fi
a5a5f7
fi
Theo Chatzimichos 1f0a34
450fa5
RUN_TEST='salt-call --local --retcode-passthrough state.show_highstate'
450fa5
STATUS=0
Martin Čaj 0e8bcf
a5a5f7
write_grains() {
04eaa2
    $SUDO sed -i -e "s/\(country:\).*/\1 $1/" -e "s/\(domain:\).*/\1 $2/" -e "s/\(virtual:\).*/\1 $3/" /etc/salt/grains
04eaa2
    echo_INFO "Grains: country: $1, domain: $2, virtual: $3"
Theo Chatzimichos 12b8f9
}
Theo Chatzimichos 12b8f9
Theo Chatzimichos 12b8f9
show_highstate() {
04eaa2
    local domain="$2"
86fbd9
    local outfile="$domain.txt"
04eaa2
    write_grains "$1" "$domain" "$3"
86fbd9
    $RUN_TEST > "$outfile" 2>&1
Theo Chatzimichos dc69e9
    _STATUS=$?
Theo Chatzimichos 12b8f9
    # We ignore exit code 2 as it means that an empty file is produced
Theo Chatzimichos 12b8f9
    # See https://github.com/saltstack/salt/issues/39172
Theo Chatzimichos 12b8f9
    if [[ $_STATUS -eq 0 ]] || [[ $_STATUS -eq 2 ]]; then
Theo Chatzimichos 12b8f9
        echo_PASSED
Theo Chatzimichos 12b8f9
    else
450fa5
      {
450fa5
        cat /etc/salt/grains
450fa5
        salt-call --local grains.get id
450fa5
        salt-call --local grains.get domain
450fa5
        salt-call --local grains.get virtual
450fa5
      } >> "$outfile"
450fa5
      echo 'Dumping the last 100 log lines - the full output can be found in the CI artifacts'
450fa5
      tail -n100 "$outfile"
450fa5
      echo_FAILED
450fa5
      STATUS=1
Theo Chatzimichos 12b8f9
    fi
Theo Chatzimichos 12b8f9
    echo
a5a5f7
}
Theo Chatzimichos 1f0a34
Theo Chatzimichos 12b8f9
ALL_LOCATIONS=( $(bin/get_valid_custom_grains.py) )
450fa5
for country in "${ALL_LOCATIONS[@]}"; do
04eaa2
    show_highstate "$country" 'infra.opensuse.org' 'kvm'
a5a5f7
done
a5a5f7
450fa5
exit "$STATUS"