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
Theo Chatzimichos 1f0a34
RUN_TEST="salt-call --local --retcode-passthrough state.show_highstate"
Theo Chatzimichos 9cb0af
ALL_VIRTUAL=(
Theo Chatzimichos 9cb0af
    kvm
Theo Chatzimichos 9cb0af
)
Theo Chatzimichos 7cceb8
ALL_LOCATIONS=( $(bin/get_valid_custom_grains.py) )
Theo Chatzimichos 1f0a34
a5a5f7
write_grains() {
Theo Chatzimichos 15a116
    $SUDO sed -i -e "s/\(city:\).*/\1 $2/" -e "s/\(country:\).*/\1 $1/" -e "s/\(virt_cluster:\).*/\1 $3/" -e "s/\(virtual:\).*/\1 $4/" /etc/salt/grains
Theo Chatzimichos 15a116
    echo_INFO "Grains: city: $2, country: $1, virt_cluster: $3, virtual: $4"
a5a5f7
}
Theo Chatzimichos 1f0a34
Theo Chatzimichos 15a116
for location in ${ALL_LOCATIONS[@]}; do
Theo Chatzimichos 15a116
    for virtual in ${ALL_VIRTUAL[@]}; do
Theo Chatzimichos 15a116
        write_grains ${location//,/ } ${virtual}
Theo Chatzimichos 15a116
        $RUN_TEST > /dev/null
Theo Chatzimichos 15a116
        _STATUS=$(echo $?)
Theo Chatzimichos 15a116
        # We ignore exit code 2 as it means that an empty file is produced
Theo Chatzimichos 15a116
        # See https://github.com/saltstack/salt/issues/39172
Theo Chatzimichos 15a116
        if [[ $_STATUS -eq 0 ]] || [[ $_STATUS -eq 2 ]]; then
Theo Chatzimichos 15a116
            echo_PASSED
Theo Chatzimichos 15a116
        else
Theo Chatzimichos 15a116
            echo_FAILED
Theo Chatzimichos 15a116
            STATUS=1
Theo Chatzimichos 15a116
        fi
Theo Chatzimichos 15a116
        echo
a5a5f7
    done
a5a5f7
done
a5a5f7
a5a5f7
exit $STATUS