diff --git a/.gitlab-ci.yml b/.gitlab-ci.yml index 444792c..6581e88 100644 --- a/.gitlab-ci.yml +++ b/.gitlab-ci.yml @@ -6,13 +6,57 @@ stages: validate: stage: validate before_script: + - bin/prepare_test_env.sh -i opensuse + script: bin/test_validate.sh + tags: + - docker + +validate_show_highstate_leap_15.0: + stage: validate + before_script: - bin/prepare_test_env.sh -i opensuse -g - 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 + script: bin/test_show_highstate.sh + tags: + - docker + +validate_show_highstate_leap_42.3: + stage: validate + before_script: + - bin/prepare_test_env.sh -i opensuse -g -o Leap,42,3 + - 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: + - docker + +validate_show_highstate_sle15: + stage: validate + before_script: + - bin/prepare_test_env.sh -i opensuse -g -o SLES,15,0 + - 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: + - docker + +validate_show_highstate_sle12sp3: + stage: validate + before_script: + - bin/prepare_test_env.sh -i opensuse -g -o SLES,12,3 + - 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: + - docker + +validate_show_highstate_sle11sp4: + stage: validate + before_script: + - bin/prepare_test_env.sh -i opensuse -g -o SLES,11,4 + - 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: - docker -validate_show_highstate_against_upstream_formulas: +validate_show_highstate_latest_leap_upstream_formulas: stage: validate before_script: - bin/prepare_test_env.sh -i opensuse -g diff --git a/bin/prepare_test_env.sh b/bin/prepare_test_env.sh index 71d02fd..4773cac 100755 --- a/bin/prepare_test_env.sh +++ b/bin/prepare_test_env.sh @@ -20,6 +20,7 @@ help() { echo echo "-p Comma-separated list of additional packages to be installed" echo "-i Choose gitlab instance. Choices: opensuse, suse" + echo "-o OPTIONAL: Specify different OS. Examples: \"Leap,42,3\", \"SLES,12,3\"" echo "-g OPTIONAL: Make preparation for show_highstate" echo "-s OPTIONAL: Include secrets files (disabed because CI runner can't decrypt them due to lack of GPG key)" echo @@ -31,10 +32,11 @@ help() { SECRETS="False" #REPO_URL=${PRETTY_NAME// /_} -while getopts p:i:gsh arg; do +while getopts p:i:o:gsh arg; do case ${arg} in p) PKG=(${OPTARG//,/ }) ;; i) INSTANCE=${OPTARG} ;; + o) OS=(${OPTARG//,/ }) ;; g) HIGHSTATE=1 ;; s) SECRETS="True" ;; h) help && exit ;; @@ -67,5 +69,6 @@ ID=$(hostname -f) printf "grains:\n city: nuremberg\n country: de\n hostusage: test\n salt_cluster: $SALT_CLUSTER\n virt_cluster: $VIRT_CLUSTER\n" > pillar/id/${ID//./_}.sls if [[ -n $HIGHSTATE ]]; then ROLES=$(bin/get_roles.py -o yaml) - printf "city:\ncountry:\ndomain: $DOMAIN\ninclude_secrets: $SECRETS\nosfullname:\nosmajorrelease:\nosrelease_info:\n$ROLES\nsalt_cluster: $SALT_CLUSTER\nvirt_cluster:\nvirtual:\n" > /etc/salt/grains + [[ -n $OS ]] && OS_GRAINS="osfullname: ${OS[0]}\nosmajorrelease: ${OS[1]}\nosrelease_info: [${OS[1]}, ${OS[2]}]\n" + printf "city:\ncountry:\ndomain: $DOMAIN\ninclude_secrets: $SECRETS\n$OS_GRAINS$ROLES\nsalt_cluster: $SALT_CLUSTER\nvirt_cluster:\nvirtual:\n" > /etc/salt/grains fi diff --git a/bin/test_show_highstate.sh b/bin/test_show_highstate.sh index 45ca046..5229606 100755 --- a/bin/test_show_highstate.sh +++ b/bin/test_show_highstate.sh @@ -17,36 +17,27 @@ RUN_TEST="salt-call --local --retcode-passthrough state.show_highstate" ALL_VIRTUAL=( kvm ) -ALL_OS=( - Leap,15,0 - Leap,42,3 - SLES,11,4 - SLES,12,3 -) ALL_LOCATIONS=( $(bin/get_valid_custom_grains.py) ) write_grains() { - $SUDO sed -i -e "s/\(city:\).*/\1 $2/" -e "s/\(country:\).*/\1 $1/" -e "s/\(osfullname:\).*/\1 $4/" -e "s/\(osmajorrelease:\).*/\1 $5/" \ - -e "s/\(osrelease_info:\).*/\1 [$5, $6]/" -e "s/\(virt_cluster:\).*/\1 $3/" -e "s/\(virtual:\).*/\1 $7/" /etc/salt/grains - echo_INFO "Grains: osfullname: $4, osmajorrelease: $5, city: $2, country: $1, virt_cluster: $3, virtual: $7" + $SUDO sed -i -e "s/\(city:\).*/\1 $2/" -e "s/\(country:\).*/\1 $1/" -e "s/\(virt_cluster:\).*/\1 $3/" -e "s/\(virtual:\).*/\1 $4/" /etc/salt/grains + echo_INFO "Grains: city: $2, country: $1, virt_cluster: $3, virtual: $4" } -for os in ${ALL_OS[@]}; do - for location in ${ALL_LOCATIONS[@]}; do - for virtual in ${ALL_VIRTUAL[@]}; do - write_grains ${location//,/ } ${os//,/ } ${virtual} - $RUN_TEST > /dev/null - _STATUS=$(echo $?) - # We ignore exit code 2 as it means that an empty file is produced - # See https://github.com/saltstack/salt/issues/39172 - if [[ $_STATUS -eq 0 ]] || [[ $_STATUS -eq 2 ]]; then - echo_PASSED - else - echo_FAILED - STATUS=1 - fi - echo - done +for location in ${ALL_LOCATIONS[@]}; do + for virtual in ${ALL_VIRTUAL[@]}; do + write_grains ${location//,/ } ${virtual} + $RUN_TEST > /dev/null + _STATUS=$(echo $?) + # We ignore exit code 2 as it means that an empty file is produced + # See https://github.com/saltstack/salt/issues/39172 + if [[ $_STATUS -eq 0 ]] || [[ $_STATUS -eq 2 ]]; then + echo_PASSED + else + echo_FAILED + STATUS=1 + fi + echo done done diff --git a/bin/test_validate.sh b/bin/test_validate.sh index bc456a2..edaebf5 100755 --- a/bin/test_validate.sh +++ b/bin/test_validate.sh @@ -10,7 +10,6 @@ TESTS=( secrets.sh roles.py custom_grains.py - show_highstate.sh ) for _test in ${TESTS[@]}; do