From a452cbbfc98bd85ae1ae63deb0610dd74fa59da0 Mon Sep 17 00:00:00 2001 From: Theo Chatzimichos Date: Feb 02 2018 22:12:36 +0000 Subject: updates in bin/prepare_test_env.sh - rename from prepare_test_highstate_env.sh to prepare_test_env.sh as it is used for tests that don't do highstate at all - use a new flag -g to install packages needed for highstate, and to do various other preparations like the /etc/salt/grains - restructure the secrets conditionals to make it a bit faster by avoiding the grep if the -s flag is not set --- diff --git a/.gitlab-ci.yml b/.gitlab-ci.yml index ba49f36..bb4b54d 100644 --- a/.gitlab-ci.yml +++ b/.gitlab-ci.yml @@ -9,7 +9,7 @@ validate: # 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_highstate_env.sh -s + - bin/prepare_test_env.sh -g -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_validate.sh tags: @@ -18,7 +18,7 @@ validate: validate_show_highstate_against_upstream_formulas: stage: validate before_script: - - bin/prepare_test_highstate_env.sh -s + - bin/prepare_test_env.sh -g -s - bin/get_formulas.py -c -d /srv/formula -s script: bin/test_show_highstate.sh allow_failure: true @@ -33,7 +33,7 @@ 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_highstate_env.sh -s -p nginx + - bin/prepare_test_env.sh -g -p nginx - cp -a /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 -f nginx script: bin/test_nginx.sh diff --git a/bin/prepare_test_env.sh b/bin/prepare_test_env.sh new file mode 100755 index 0000000..ba3c0c5 --- /dev/null +++ b/bin/prepare_test_env.sh @@ -0,0 +1,54 @@ +#!/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 "-g Make preparation for show_highstate" + echo "-s Strip out secrets files (CI runner can't read them)" + echo +} + +[[ $1 == '--help' ]] && help && exit + +while getopts p:gsh arg; do + case ${arg} in + p) PKG=(${OPTARG//,/ }) ;; + g) HIGHSTATE=1 ;; + s) STRIP_SECRETS=1 ;; + h) help && exit ;; + *) help && exit 1 ;; + esac +done + +[[ -n $HIGHSTATE ]] && HIGHSTATE_PKGS=( git python3-PyYAML ) + +$SUDO zypper -qn in --no-recommends salt ${HIGHSTATE_PKGS[@]} ${PKG[@]} +$SUDO rm -rf /srv/{salt,pillar} +$SUDO ln -s $PWD/salt /srv/salt +$SUDO ln -s $PWD/pillar /srv/pillar +ID=$(hostname -f) +printf "grains:\n city: nuremberg\n country: de\n hostusage: test\n salt_cluster: opensuse\n virt_cluster: atreju\n" > pillar/id/${ID//./_}.sls +if [[ -n $HIGHSTATE ]]; then + 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:\nvirtual:\n" > /etc/salt/grains + if [[ -n $STRIP_SECRETS ]]; then + SECRETS=$(grep -lr "\- secrets\." pillar) + [[ -n $SECRETS ]] && sed -i -e "s#\- secrets\..*#- id.${ID//./_}#g" $SECRETS + fi +fi diff --git a/bin/prepare_test_highstate_env.sh b/bin/prepare_test_highstate_env.sh deleted file mode 100755 index b33d368..0000000 --- a/bin/prepare_test_highstate_env.sh +++ /dev/null @@ -1,48 +0,0 @@ -#!/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:\nvirtual:\n" > /etc/salt/grains -printf "grains:\n city: nuremberg\n country: de\n hostusage: test\n salt_cluster: opensuse\n virt_cluster: atreju\n" > pillar/id/${ID//./_}.sls -SECRETS=$(grep -lr "\- secrets\." pillar) -if [[ -n $STRIP_SECRETS ]] && [[ -n $SECRETS ]]; then - sed -i -e "s#\- secrets\..*#- id.${ID//./_}#g" $SECRETS -fi diff --git a/bin/run_tests_locally.sh b/bin/run_tests_locally.sh index 6d66256..133766b 100755 --- a/bin/run_tests_locally.sh +++ b/bin/run_tests_locally.sh @@ -33,7 +33,7 @@ SALT_DIRS=( for dir in ${SALT_DIRS[@]}; do sudo chown -R ${USER}: $dir done -bin/prepare_test_highstate_env.sh +bin/prepare_test_env.sh -g -p python3-pygit2 bin/get_formulas.py --destination $DESTINATION --clone --symlink --use-pygit2 --update opensuse \ --add-remote opensuse no_prefix gitlab@gitlab.infra.opensuse.org: saltstack-formulas ln -s ~/.gnupg /etc/salt/gpgkeys