From a5a5f796c2857b5e263a4de7005e88c03dc643b0 Mon Sep 17 00:00:00 2001 From: Theo Chatzimichos Date: Nov 15 2017 18:01:41 +0000 Subject: bin/test_show_highstate.py: various improvements - add ability to run the script as non root with sudo where needed - add ability to run against multiple operating systems and make it run against each declared OS and each declared location combination - print the OS and location that it is running against - do not fail when a show_highstate command fails. Instead, let them all run with various combinations to show the user all the errors, and exit with the appropriate status code --- diff --git a/bin/prepare_test_show_highstate_env.sh b/bin/prepare_test_show_highstate_env.sh index ccb74b9..29fdb73 100755 --- a/bin/prepare_test_show_highstate_env.sh +++ b/bin/prepare_test_show_highstate_env.sh @@ -6,18 +6,18 @@ set -e if [[ $(whoami) != 'root' ]]; then if [[ -f /usr/bin/sudo ]]; then - SUDO='/usr/bin/sudo' - else - echo 'Please install sudo first, or run this script as root' - exit 1 - fi + SUDO='/usr/bin/sudo' + else + echo 'Please install sudo first, or run this script as root' + exit 1 + fi fi $SUDO zypper -qn in --no-recommends salt git python3 python3-PyYAML $SUDO rm -rf /srv/{salt,pillar} $SUDO ln -s $PWD/salt /srv/salt $SUDO ln -s $PWD/pillar /srv/pillar -echo 'domain: infra.opensuse.org' | $SUDO tee /etc/salt/grains > /dev/null +printf "domain: infra.opensuse.org\nosfullname:\nosmajorrelease:\nosrelease_info:" | $SUDO tee /etc/salt/grains > /dev/null sed -i -e 's/^production:$/base:/' /srv/{salt,pillar}/top.sls ROLES=$(bin/get_roles.py --yaml) printf "city:\ncountry:\nsalt_cluster: opensuse\nvirt_cluster:\n$ROLES" > pillar/id/${HOSTNAME}.sls diff --git a/bin/test_show_highstate.sh b/bin/test_show_highstate.sh index d85d18b..5ee198c 100755 --- a/bin/test_show_highstate.sh +++ b/bin/test_show_highstate.sh @@ -2,14 +2,42 @@ # Runs state.show_highstate using all localized grains' combinations -set -e +if [[ $(whoami) != 'root' ]]; then + if [[ -f /usr/bin/sudo ]]; then + SUDO='/usr/bin/sudo' + else + echo 'Please install sudo first, or run this script as root' + exit 1 + fi +fi RUN_TEST="salt-call --local --retcode-passthrough state.show_highstate" +ALL_OS=( + Leap,42,3 + SLES,11,4 + SLES,12,3 +) +ALL_LOCATIONS=( + nuremberg,de,atreju + provo,us,bryce +) -sed -i -e 's/\(city:\).*/\1 nuremberg/' -e 's/\(country:\).*/\1 de/' -e 's/\(virt_cluster:\).*/\1 atreju/' pillar/id/${HOSTNAME}.sls -$RUN_TEST > /dev/null -echo "PASSED: country: de" +write_grains() { + $SUDO sed -i -e "s/\(city:\).*/\1 $1/" -e "s/\(country:\).*/\1 $2/" -e "s/\(osfullname:\).*/\1 $1/" -e "s/\(osmajorrelease:\).*/\1 $2/" \ + -e "s/\(osrelease_info:\).*/\1 [$2, $3]/" -e "s/\(virt_cluster:\).*/\1 $3/ "etc/salt/grains + echo "Grains: osfullname: $4, osmajorrelease: $5, city: $1, country: $2, virt_cluster: $3" + if $($SUDO $RUN_TEST > /dev/null); then + echo 'PASSED' + else + STATUS=1 + fi + echo +} -sed -i -e 's/\(city:\).*/\1 provo/' -e 's/\(country:\).*/\1 us/' -e 's/\(virt_cluster:\).*/\1 bryce/' pillar/id/${HOSTNAME}.sls -$RUN_TEST > /dev/null -echo "PASSED: country: us" +for os in ${ALL_OS[@]}; do + for location in ${ALL_LOCATIONS[@]}; do + write_grains ${location//,/ } ${os//,/ } + done +done + +exit $STATUS