From f6d7413d0085306d73b919ce4a7fd345d03f3197 Mon Sep 17 00:00:00 2001 From: Theo Chatzimichos Date: Jan 21 2018 12:12:08 +0000 Subject: bin/test_nginx.sh: clean the /etc/nginx dir completely - rename the prepare_test_show_highstate_env.sh script to prepare_test_highstate_env.sh as it is used not only for show_highstate any more, but for various other highstate related tests - add flag to prepare_test_highstate_env to install extra packages needed for testing - install the nginx package, take backup of the /etc/nginx dir and then reset it before running the nginx tests --- diff --git a/.gitlab-ci.yml b/.gitlab-ci.yml index d517369..2103c6f 100644 --- a/.gitlab-ci.yml +++ b/.gitlab-ci.yml @@ -33,7 +33,7 @@ test_custom_grains: test_show_highstate_against_upstream_formulas: stage: test before_script: - - bin/prepare_test_show_highstate_env.sh -s + - bin/prepare_test_highstate_env.sh -s - bin/get_formulas.py -c -d /srv/formula -s script: bin/test_show_highstate.sh allow_failure: true @@ -48,7 +48,7 @@ test_show_highstate_against_forked_formulas: # TODO: get rid of GIT_SSL_NO_VERIFY as soon as we switch to letsencrypt wildcard certs GIT_SSL_NO_VERIFY: 'true' before_script: - - bin/prepare_test_show_highstate_env.sh -s + - bin/prepare_test_highstate_env.sh -s - bin/get_formulas.py -c -d /srv/formula -s --clone-from 'https://gitlab.infra.opensuse.org/saltstack-formulas' --clone-branch production script: bin/test_show_highstate.sh tags: @@ -60,7 +60,8 @@ test_nginx: # TODO: get rid of GIT_SSL_NO_VERIFY as soon as we switch to letsencrypt wildcard certs GIT_SSL_NO_VERIFY: 'true' before_script: - - bin/prepare_test_show_highstate_env.sh -s + - bin/prepare_test_highstate_env.sh -s -p nginx + - cp -rp /etc/nginx /etc/nginx_orig - bin/get_formulas.py -c -d /srv/formula -s --clone-from 'https://gitlab.infra.opensuse.org/saltstack-formulas' --clone-branch production script: bin/test_nginx.sh tags: diff --git a/bin/prepare_test_highstate_env.sh b/bin/prepare_test_highstate_env.sh new file mode 100755 index 0000000..910bdd8 --- /dev/null +++ b/bin/prepare_test_highstate_env.sh @@ -0,0 +1,45 @@ +#!/bin/bash + +# See the description at the help() + +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 + +help() { + echo "Prepares the CI runner or workstation environment to run highstate or show_highstate tests" + echo + echo "Arguments:" + echo + echo "-p Comma-separated list of additional packages to be installed" + echo "-s Strip out secrets files (CI runner can't read them)" + echo +} + +[[ $1 == '--help' ]] && help && exit + +while getopts p:sh arg; do + case ${arg} in + p) PKG=(${OPTARG//,/ }) ;; + s) STRIP_SECRETS=1 ;; + h) help && exit ;; + *) help && exit 1 ;; + esac +done + +$SUDO zypper -qn in --no-recommends salt git python3 python3-PyYAML ${PKG} +$SUDO rm -rf /srv/{salt,pillar} +$SUDO ln -s $PWD/salt /srv/salt +$SUDO ln -s $PWD/pillar /srv/pillar +ID=$(hostname -f) +ROLES=$(bin/get_roles.py -o yaml) +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 +printf "nothing: nothing" | $SUDO tee pillar/id/${ID//./_}.sls > /dev/null +[[ -n $STRIP_SECRETS ]] && sed -i -e "s#\- secrets\..*#- id.${ID//./_}#g" $(grep -lr "\- secrets\." pillar) diff --git a/bin/prepare_test_show_highstate_env.sh b/bin/prepare_test_show_highstate_env.sh deleted file mode 100755 index 056b62f..0000000 --- a/bin/prepare_test_show_highstate_env.sh +++ /dev/null @@ -1,43 +0,0 @@ -#!/bin/bash - -# Prepares the CI runner environment to run the show_highstate tests - -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 - -help() { - echo "Prepares the CI runner or workstation environment to run the show_highstate tests" - echo - echo "Arguments:" - echo - echo "-s Strip out secrets files (CI runner can't read them)" - echo -} - -[[ $1 == '--help' ]] && help && exit - -while getopts sh arg; do - case ${arg} in - s) STRIP_SECRETS=1 ;; - h) help && exit ;; - *) help && exit 1 ;; - esac -done - -$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 -ID=$(hostname -f) -ROLES=$(bin/get_roles.py -o yaml) -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 -printf "nothing: nothing" | $SUDO tee pillar/id/${ID//./_}.sls > /dev/null -[[ -n $STRIP_SECRETS ]] && sed -i -e "s#\- secrets\..*#- id.${ID//./_}#g" $(grep -lr "\- secrets\." pillar) diff --git a/bin/test_nginx.sh b/bin/test_nginx.sh index 1f4df1a..bbda54c 100755 --- a/bin/test_nginx.sh +++ b/bin/test_nginx.sh @@ -12,7 +12,8 @@ if [[ $(whoami) != 'root' ]]; then fi reset_nginx() { - $SUDO rm -rf /etc/nginx/vhosts.d/* + rm -rf /etc/nginx + cp -a /etc/nginx_orig /etc/nginx printf "roles:\n- $role" | $SUDO tee /etc/salt/grains > /dev/null } @@ -32,7 +33,6 @@ create_fake_certs() { done } - WEB_ROLES=( $(bin/get_roles.py | grep web_) ) for role in ${WEB_ROLES[@]}; do