diff --git a/.gitlab-ci.yml b/.gitlab-ci.yml new file mode 100644 index 0000000..7c39fc7 --- /dev/null +++ b/.gitlab-ci.yml @@ -0,0 +1,68 @@ +stages: + - sanity + - integration + +test:sanity1-devel-py38: + stage: sanity + image: python:3.8-buster + except: + - tags + script: + - bash tests/utils/gitlab/gitlab.sh sanity/1 + tags: + - hc-bladerunner + +test:sanity2-devel-py38: + stage: sanity + image: python:3.8-buster + except: + - tags + script: + - bash tests/utils/gitlab/gitlab.sh sanity/2 + tags: + - hc-bladerunner + +test:sanity3-devel-py38: + stage: sanity + image: python:3.8-buster + except: + - tags + script: + - bash tests/utils/gitlab/gitlab.sh sanity/3 + tags: + - hc-bladerunner + +test:sanity4-devel-py38: + stage: sanity + image: python:3.8-buster + except: + - tags + script: + - bash tests/utils/gitlab/gitlab.sh sanity/4 + tags: + - hc-bladerunner + +test:integration1-devel-py38: + stage: integration + image: python:3.8-buster + except: + - tags + script: + - echo "$HCLOUD_TOKEN" >> "$(pwd)/hcloud_token.txt" + - echo "py38-$CI_JOB_ID" >> "$(pwd)/prefix.txt" + - bash tests/utils/gitlab/gitlab.sh integration/1 + tags: + - hc-bladerunner + + +test:integration2-devel-py38: + stage: integration + image: python:3.8-buster + except: + - tags + script: + - echo "$HCLOUD_TOKEN" >> "$(pwd)/hcloud_token.txt" + - echo "py39-$CI_JOB_ID" >> "$(pwd)/prefix.txt" + - bash tests/utils/gitlab/gitlab.sh integration/2 + tags: + - hc-bladerunner diff --git a/plugins/modules/hcloud_floating_ip.py b/plugins/modules/hcloud_floating_ip.py index d131d84..72edcbb 100644 --- a/plugins/modules/hcloud_floating_ip.py +++ b/plugins/modules/hcloud_floating_ip.py @@ -220,6 +220,7 @@ class AnsibleHcloudFloatingIP(Hcloud): self.module.fail_on_missing_params( required_params=["type"] ) + params = { "description": self.module.params.get("description"), "type": self.module.params.get("type"), diff --git a/plugins/modules/hcloud_server.py b/plugins/modules/hcloud_server.py index dcc7179..06c1057 100644 --- a/plugins/modules/hcloud_server.py +++ b/plugins/modules/hcloud_server.py @@ -306,6 +306,7 @@ class AnsibleHcloudServer(Hcloud): self.module.fail_on_missing_params( required_params=["name", "server_type", "image"] ) + params = { "name": self.module.params.get("name"), "server_type": self.client.server_types.get_by_name( diff --git a/tests/utils/gitlab/gitlab.sh b/tests/utils/gitlab/gitlab.sh new file mode 100755 index 0000000..4c91c97 --- /dev/null +++ b/tests/utils/gitlab/gitlab.sh @@ -0,0 +1,80 @@ +#!/usr/bin/env bash + +set -o pipefail -eux + +declare -a args + +IFS='/:' read -ra args <<< "$1" + +test="${args[0]}" +command -v python +python -V + +function retry +{ + for repetition in 1 2 3; do + set +e + "$@" + result=$? + set -e + if [ ${result} == 0 ]; then + return ${result} + fi + echo "$@ -> ${result}" + done + echo "Command '$@' failed 3 times!" + exit -1 +} + +command -v pip +pip --version +pip list --disable-pip-version-check +retry pip install https://github.com/ansible/ansible/archive/devel.tar.gz --disable-pip-version-check + +export ANSIBLE_COLLECTIONS_PATHS="${HOME}/.ansible" +SHIPPABLE_RESULT_DIR="$(pwd)/shippable" +TEST_DIR="${ANSIBLE_COLLECTIONS_PATHS}/ansible_collections/hetzner/hcloud" +mkdir -p "${TEST_DIR}" +cp -r "." "${TEST_DIR}" +cd "${TEST_DIR}" + +# STAR: HACK install dependencies +retry ansible-galaxy -vvv collection install community.general +retry ansible-galaxy -vvv collection install ansible.netcommon + +retry pip install netaddr --disable-pip-version-check +retry pip install hcloud +# END: HACK + +export PYTHONIOENCODING='utf-8' + +if [ "${JOB_TRIGGERED_BY_NAME:-}" == "nightly-trigger" ]; then + COMPLETE=yes +fi + + +if [ -n "${COMPLETE:-}" ]; then + # disable change detection triggered by setting the COMPLETE environment variable to a non-empty value + export CHANGED="" +elif [[ "${CI_COMMIT_MESSAGE}" =~ ci_complete ]]; then + # disable change detection triggered by having 'ci_complete' in the latest commit message + export CHANGED="" +else + # enable change detection (default behavior) + export CHANGED="" +fi + + +export UNSTABLE="--allow-unstable-changed" + +# remove empty core/extras module directories from PRs created prior to the repo-merge +find plugins -type d -empty -print -delete + +ansible-test env --dump --show --timeout "50" --color -v + +group="${args[1]}" +if [[ "${test}" =~ integration ]]; then + bash tests/utils/gitlab/integration.sh "shippable/hcloud/group${group}/" +else + bash tests/utils/gitlab/sanity.sh "sanity/${group}" +fi diff --git a/tests/utils/gitlab/integration.sh b/tests/utils/gitlab/integration.sh new file mode 100755 index 0000000..54c9859 --- /dev/null +++ b/tests/utils/gitlab/integration.sh @@ -0,0 +1,15 @@ +#!/usr/bin/env bash + +target="$1" + +HCLOUD_TOKEN=$(cat hcloud_token.txt) +changed_all_target="shippable/${cloud}/smoketest/" + +echo "[default] +hcloud_api_token=${HCLOUD_TOKEN} +" >> $(pwd)/tests/integration/cloud-config-hcloud.ini +# shellcheck disable=SC2086 +export SHIPPABLE="true" +export SHIPPABLE_BUILD_NUMBER="gl-$(cat prefix.txt)" +export SHIPPABLE_JOB_NUMBER="$(cat /dev/urandom | tr -dc 'a-zA-Z0-9' | fold -w 2 | head -n 1)" +ansible-test integration --color --local -v "${target}" ${COVERAGE:+"$COVERAGE"} ${CHANGED:+"$CHANGED"} ${UNSTABLE:+"$UNSTABLE"} diff --git a/tests/utils/gitlab/sanity.sh b/tests/utils/gitlab/sanity.sh new file mode 100755 index 0000000..5b0a68d --- /dev/null +++ b/tests/utils/gitlab/sanity.sh @@ -0,0 +1,42 @@ +#!/usr/bin/env bash + +set -o pipefail -eux + +declare -a args +IFS='/:' read -ra args <<< "$1" + +group="${args[1]}" + +if [ "${BASE_BRANCH:-}" ]; then + base_branch="origin/${BASE_BRANCH}" +else + base_branch="" +fi + +case "${group}" in + 1) options=(--skip-test pylint --skip-test ansible-doc --skip-test validate-modules) ;; + 2) options=( --test ansible-doc --test validate-modules) ;; + 3) options=(--test pylint plugins/modules/) ;; + 4) options=(--test pylint --exclude plugins/modules/) ;; +esac + +# allow collection migration sanity tests for groups 3 and 4 to pass without updating this script during migration +network_path="lib/ansible/modules/network/" + +if [ -d "${network_path}" ]; then + if [ "${group}" -eq 3 ]; then + options+=(--exclude "${network_path}") + elif [ "${group}" -eq 4 ]; then + options+=("${network_path}") + fi +fi + +pip install pycodestyle +pip install yamllint +pip install voluptuous +pip install pylint +# shellcheck disable=SC2086 +ansible-test sanity --color -v --junit ${COVERAGE:+"$COVERAGE"} ${CHANGED:+"$CHANGED"} \ + --base-branch "${base_branch}" \ + --exclude shippable.yml --exclude tests/utils/ \ + "${options[@]}" --allow-disabled