|
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"
|
|
Martin Čaj |
0e8bcf |
## in case of problems feel free to temporally enable line 18 and commend out line 16.
|
|
Martin Čaj |
0e8bcf |
#RUN_TEST="salt-call --local --retcode-passthrough --log-level=debug state.show_highstate"
|
|
Martin Čaj |
0e8bcf |
|
|
Theo Chatzimichos |
9cb0af |
ALL_VIRTUAL=(
|
|
Theo Chatzimichos |
9cb0af |
kvm
|
|
Theo Chatzimichos |
9cb0af |
)
|
|
Theo Chatzimichos |
18791d |
PHYSICAL_ONLY_VIRT_CLUSTER=( $(bin/get_valid_custom_grains.py -p) )
|
|
Theo Chatzimichos |
1f0a34 |
|
|
 |
a5a5f7 |
write_grains() {
|
|
Theo Chatzimichos |
12b8f9 |
$SUDO sed -i -e "s/\(city:\).*/\1 $2/" -e "s/\(country:\).*/\1 $1/" -e "s/\(domain:\).*/\1 $5/" -e "s/\(virt_cluster:\).*/\1 $3/" -e "s/\(virtual:\).*/\1 $4/" /etc/salt/grains
|
|
Theo Chatzimichos |
12b8f9 |
echo_INFO "Grains: city: $2, country: $1, domain: $5, virt_cluster: $3, virtual: $4"
|
|
Theo Chatzimichos |
12b8f9 |
}
|
|
Theo Chatzimichos |
12b8f9 |
|
|
Theo Chatzimichos |
12b8f9 |
show_highstate() {
|
|
Theo Chatzimichos |
12b8f9 |
write_grains $country $city $virt_cluster $virtual $domain
|
|
Theo Chatzimichos |
12b8f9 |
$RUN_TEST > /dev/null
|
|
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
|
|
Christian Boltz |
c1a1bd |
echo
|
|
Christian Boltz |
c1a1bd |
# errors like conflicting IDs get displayed on stdout, not stderr, see https://github.com/saltstack/salt/issues/52653
|
|
Christian Boltz |
c1a1bd |
echo "== running test again without /dev/null'ing stdout =="
|
|
Christian Boltz |
c1a1bd |
$RUN_TEST
|
|
Theo Chatzimichos |
12b8f9 |
echo_FAILED
|
|
Theo Chatzimichos |
12b8f9 |
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) )
|
|
Theo Chatzimichos |
15a116 |
for location in ${ALL_LOCATIONS[@]}; do
|
|
Theo Chatzimichos |
12b8f9 |
LOCATION=(${location//,/ })
|
|
Theo Chatzimichos |
12b8f9 |
country=${LOCATION[0]}
|
|
Theo Chatzimichos |
12b8f9 |
city=${LOCATION[1]}
|
|
Theo Chatzimichos |
12b8f9 |
virt_cluster=${LOCATION[2]}
|
|
Theo Chatzimichos |
12b8f9 |
domain=$(bin/get_valid_custom_grains.py --default-domain $country)
|
|
Theo Chatzimichos |
15a116 |
for virtual in ${ALL_VIRTUAL[@]}; do
|
|
Theo Chatzimichos |
12b8f9 |
if [[ $virtual == 'kvm' ]] && [[ ${PHYSICAL_ONLY_VIRT_CLUSTER[@]} =~ $virt_cluster ]]; then
|
|
Theo Chatzimichos |
18791d |
continue
|
|
Theo Chatzimichos |
18791d |
fi
|
|
Theo Chatzimichos |
12b8f9 |
show_highstate
|
|
Theo Chatzimichos |
12b8f9 |
done
|
|
Theo Chatzimichos |
12b8f9 |
done
|
|
Theo Chatzimichos |
12b8f9 |
|
|
Theo Chatzimichos |
12b8f9 |
ALL_LOCATIONS=( $(bin/get_valid_custom_grains.py -v) )
|
|
Theo Chatzimichos |
12b8f9 |
for location in ${ALL_LOCATIONS[@]}; do
|
|
Theo Chatzimichos |
12b8f9 |
LOCATION=(${location//,/ })
|
|
Theo Chatzimichos |
12b8f9 |
country=${LOCATION[0]}
|
|
Theo Chatzimichos |
12b8f9 |
city=${LOCATION[1]}
|
|
Theo Chatzimichos |
12b8f9 |
virt_cluster=${LOCATION[2]}
|
|
Theo Chatzimichos |
12b8f9 |
default_domain=$(bin/get_valid_custom_grains.py --default-domain $country)
|
|
Theo Chatzimichos |
12b8f9 |
virtual='kvm'
|
|
Theo Chatzimichos |
12b8f9 |
DOMAINS=( $(bin/get_valid_custom_grains.py -d $country) )
|
|
Theo Chatzimichos |
12b8f9 |
for domain in ${DOMAINS[@]}; do
|
|
Theo Chatzimichos |
12b8f9 |
[[ $domain == $default_domain ]] || show_highstate
|
|
 |
a5a5f7 |
done
|
|
 |
a5a5f7 |
done
|
|
 |
a5a5f7 |
|
|
 |
a5a5f7 |
exit $STATUS
|