diff --git a/bin/prepare_test_show_highstate_env.sh b/bin/prepare_test_show_highstate_env.sh index b3ba14b..fe68558 100755 --- a/bin/prepare_test_show_highstate_env.sh +++ b/bin/prepare_test_show_highstate_env.sh @@ -38,7 +38,7 @@ $SUDO ln -s $PWD/salt /srv/salt $SUDO ln -s $PWD/pillar /srv/pillar ID=$(hostname -f) ROLES=$(bin/get_roles.py --yaml) -printf "city:\ncountry:\ndomain: infra.opensuse.org\nosfullname:\nosmajorrelease:\nosrelease_info:\n$ROLES\nsalt_cluster: opensuse\nvirt_cluster:" | $SUDO tee /etc/salt/grains > /dev/null +printf "city:\ncountry:\ndomain: infra.opensuse.org\nosfullname:\nosmajorrelease:\nosrelease_info:\n$ROLES\nsalt_cluster: opensuse\nvirt_cluster:\n" | $SUDO tee /etc/salt/grains > /dev/null sed -i -e 's/^production:$/base:/' /srv/{salt,pillar}/top.sls touch pillar/id/${ID//./_}.sls [[ -n $STRIP_SECRETS ]] && sed -i -e "s#\- secrets\..*#- id.${ID//./_}#g" $(grep -lr "\- secrets\." pillar) diff --git a/bin/run_tests_locally.sh b/bin/run_tests_locally.sh new file mode 100755 index 0000000..ba986f1 --- /dev/null +++ b/bin/run_tests_locally.sh @@ -0,0 +1,57 @@ +#!/bin/bash + +help() { + echo "Runs all the tests on the user's workstation." + echo "Needs to be run as normal user." + echo + echo "Arguments:" + echo "-d Absolute path of the destination directory where the formulas are / should be cloned" + echo +} + +[[ $(whoami) == 'root' ]] && help && exit 1 + +[[ $1 == '--help' ]] && help && exit + +while getopts d:h arg; do + case ${arg} in + d) DESTINATION=${OPTARG} ;; + h) help && exit ;; + *) help && exit 1 ;; + esac +done + +[[ -z $DESTINATION ]] && help && exit 1 + +SALT_DIRS=( + /etc/salt + /var/log/salt + /var/cache/salt +) + +bin/test_roles.py +bin/test_custom_grains.py +bin/prepare_test_show_highstate_env.sh +bin/get_formulas.py --destination $DESTINATION --clone --symlink --use-pygit2 --update opensuse \ + --add-remote opensuse no_prefix gitlab@gitlab.infra.opensuse.org: saltstack-formulas +for dir in ${SALT_DIRS[@]}; do + sudo chown -R ${USER}: $dir +done +echo "virtual: kvm" >> /etc/salt/grains +ln -s ~/.gnupg /etc/salt/gpgkeys +echo "Running against upstream formulas" +LC_ALL=C bin/test_show_highstate.sh +bin/get_formulas.py --destination $DESTINATION --checkout opensuse/production +echo "Running against forked formulas" +LC_ALL=C bin/test_show_highstate.sh + +# Cleanup +bin/get_formulas.py --destination $DESTINATION --remove-symlinks --checkout origin/master +sed -i -e 's/^base:$/production:/' /srv/{salt,pillar}/top.sls +for dir in ${SALT_DIRS[@]}; do + sudo chown -R root: $dir +done +sudo rm /srv/{salt,pillar} /etc/salt/{grains,gpgkeys} +sudo mkdir /srv/{salt,pillar} +ID=$(hostname -f) +rm pillar/id/${ID//./_}.sls diff --git a/bin/test_show_highstate.sh b/bin/test_show_highstate.sh index b787c74..f43a36e 100755 --- a/bin/test_show_highstate.sh +++ b/bin/test_show_highstate.sh @@ -31,7 +31,7 @@ write_grains() { for os in ${ALL_OS[@]}; do for location in ${ALL_LOCATIONS[@]}; do write_grains ${location//,/ } ${os//,/ } - if $($SUDO $RUN_TEST > /dev/null); then + if $($RUN_TEST > /dev/null); then echo 'PASSED' else STATUS=1