From c29734e418cd4407d53bea35d625302ff2a63992 Mon Sep 17 00:00:00 2001 From: gardar Date: Wed, 11 Jan 2023 19:53:03 +0000 Subject: [PATCH] feat: add ansible-test integration test for executing molecule Signed-off-by: gardar --- tests/integration/molecule.sh | 42 +++++++++++++++++++ .../runme.sh | 4 ++ .../molecule-alertmanager-default/runme.sh | 4 ++ .../molecule-alertmanager-latest/runme.sh | 4 ++ .../runme.sh | 4 ++ .../runme.sh | 4 ++ .../runme.sh | 4 ++ .../molecule-node_exporter-default/runme.sh | 4 ++ .../molecule-node_exporter-latest/runme.sh | 4 ++ .../molecule-prometheus-alternative/runme.sh | 4 ++ .../molecule-prometheus-default/runme.sh | 4 ++ .../molecule-prometheus-latest/runme.sh | 4 ++ .../runme.sh | 4 ++ .../molecule-snmp_exporter-default/runme.sh | 4 ++ 14 files changed, 94 insertions(+) create mode 100755 tests/integration/molecule.sh create mode 100755 tests/integration/targets/molecule-alertmanager-alternative/runme.sh create mode 100755 tests/integration/targets/molecule-alertmanager-default/runme.sh create mode 100755 tests/integration/targets/molecule-alertmanager-latest/runme.sh create mode 100755 tests/integration/targets/molecule-blackbox_exporter-alternative/runme.sh create mode 100755 tests/integration/targets/molecule-blackbox_exporter-default/runme.sh create mode 100755 tests/integration/targets/molecule-node_exporter-alternative/runme.sh create mode 100755 tests/integration/targets/molecule-node_exporter-default/runme.sh create mode 100755 tests/integration/targets/molecule-node_exporter-latest/runme.sh create mode 100755 tests/integration/targets/molecule-prometheus-alternative/runme.sh create mode 100755 tests/integration/targets/molecule-prometheus-default/runme.sh create mode 100755 tests/integration/targets/molecule-prometheus-latest/runme.sh create mode 100755 tests/integration/targets/molecule-snmp_exporter-alternative/runme.sh create mode 100755 tests/integration/targets/molecule-snmp_exporter-default/runme.sh diff --git a/tests/integration/molecule.sh b/tests/integration/molecule.sh new file mode 100755 index 00000000..6f8294af --- /dev/null +++ b/tests/integration/molecule.sh @@ -0,0 +1,42 @@ +#!/usr/bin/env bash + +collection_root=$(pwd | grep -oP ".+\/ansible_collections\/\w+?\/\w+") +targetname=${PWD##*/} +role=$(expr "$targetname" : '\w*-\(\w*\)-\w*') +role_root="$collection_root/roles/$role" +scenario=$(expr "$targetname" : '\w*-\w*-\(\w*\)') +ansible_version="$(ansible --version | head -1 | sed 's/[^0-9\.]*//g')" + +# Install package requirements +apt -y update +apt -y install docker.io + +# Install test requirements from role +if [ -f "$role_root/test-requirements.txt" ]; then + python -m pip install -r "$role_root/test-requirements.txt" +fi +# Install test requirements from collection +if [ -f "$collection_root/test-requirements.txt" ]; then + python -m pip install -r "$collection_root/test-requirements.txt" +fi + +# Install ansible version specific requirements +if [ "$(printf '%s\n' "2.12" "$ansible_version" | sort -V | head -n1)" = "2.12" ]; then + python -m pip install molecule molecule-plugins[docker] +else + python -m pip install molecule molecule-docker + ansible-galaxy collection install community.docker + ansible-galaxy collection install -r "$collection_root/requirements.yml" +fi + +# Define config locations within collection +export MOLECULE_FILE=$collection_root/.config/molecule/config.yml +export YAMLLINT_CONFIG_FILE=$collection_root/.config/yamllint/config.yml + +# Unset ansible-test variables that break molecule +unset _ANSIBLE_COVERAGE_CONFIG +unset ANSIBLE_PYTHON_INTERPRETER + +# Run molecule test +cd "$role_root" +molecule -c "$collection_root/.config/molecule/config.yml" test -s "$scenario" diff --git a/tests/integration/targets/molecule-alertmanager-alternative/runme.sh b/tests/integration/targets/molecule-alertmanager-alternative/runme.sh new file mode 100755 index 00000000..d094c3e1 --- /dev/null +++ b/tests/integration/targets/molecule-alertmanager-alternative/runme.sh @@ -0,0 +1,4 @@ +#!/usr/bin/env bash + +collection_root=$(pwd | grep -oP ".+\/ansible_collections\/\w+?\/\w+") +source "$collection_root/tests/integration/molecule.sh" diff --git a/tests/integration/targets/molecule-alertmanager-default/runme.sh b/tests/integration/targets/molecule-alertmanager-default/runme.sh new file mode 100755 index 00000000..d094c3e1 --- /dev/null +++ b/tests/integration/targets/molecule-alertmanager-default/runme.sh @@ -0,0 +1,4 @@ +#!/usr/bin/env bash + +collection_root=$(pwd | grep -oP ".+\/ansible_collections\/\w+?\/\w+") +source "$collection_root/tests/integration/molecule.sh" diff --git a/tests/integration/targets/molecule-alertmanager-latest/runme.sh b/tests/integration/targets/molecule-alertmanager-latest/runme.sh new file mode 100755 index 00000000..d094c3e1 --- /dev/null +++ b/tests/integration/targets/molecule-alertmanager-latest/runme.sh @@ -0,0 +1,4 @@ +#!/usr/bin/env bash + +collection_root=$(pwd | grep -oP ".+\/ansible_collections\/\w+?\/\w+") +source "$collection_root/tests/integration/molecule.sh" diff --git a/tests/integration/targets/molecule-blackbox_exporter-alternative/runme.sh b/tests/integration/targets/molecule-blackbox_exporter-alternative/runme.sh new file mode 100755 index 00000000..d094c3e1 --- /dev/null +++ b/tests/integration/targets/molecule-blackbox_exporter-alternative/runme.sh @@ -0,0 +1,4 @@ +#!/usr/bin/env bash + +collection_root=$(pwd | grep -oP ".+\/ansible_collections\/\w+?\/\w+") +source "$collection_root/tests/integration/molecule.sh" diff --git a/tests/integration/targets/molecule-blackbox_exporter-default/runme.sh b/tests/integration/targets/molecule-blackbox_exporter-default/runme.sh new file mode 100755 index 00000000..d094c3e1 --- /dev/null +++ b/tests/integration/targets/molecule-blackbox_exporter-default/runme.sh @@ -0,0 +1,4 @@ +#!/usr/bin/env bash + +collection_root=$(pwd | grep -oP ".+\/ansible_collections\/\w+?\/\w+") +source "$collection_root/tests/integration/molecule.sh" diff --git a/tests/integration/targets/molecule-node_exporter-alternative/runme.sh b/tests/integration/targets/molecule-node_exporter-alternative/runme.sh new file mode 100755 index 00000000..d094c3e1 --- /dev/null +++ b/tests/integration/targets/molecule-node_exporter-alternative/runme.sh @@ -0,0 +1,4 @@ +#!/usr/bin/env bash + +collection_root=$(pwd | grep -oP ".+\/ansible_collections\/\w+?\/\w+") +source "$collection_root/tests/integration/molecule.sh" diff --git a/tests/integration/targets/molecule-node_exporter-default/runme.sh b/tests/integration/targets/molecule-node_exporter-default/runme.sh new file mode 100755 index 00000000..d094c3e1 --- /dev/null +++ b/tests/integration/targets/molecule-node_exporter-default/runme.sh @@ -0,0 +1,4 @@ +#!/usr/bin/env bash + +collection_root=$(pwd | grep -oP ".+\/ansible_collections\/\w+?\/\w+") +source "$collection_root/tests/integration/molecule.sh" diff --git a/tests/integration/targets/molecule-node_exporter-latest/runme.sh b/tests/integration/targets/molecule-node_exporter-latest/runme.sh new file mode 100755 index 00000000..d094c3e1 --- /dev/null +++ b/tests/integration/targets/molecule-node_exporter-latest/runme.sh @@ -0,0 +1,4 @@ +#!/usr/bin/env bash + +collection_root=$(pwd | grep -oP ".+\/ansible_collections\/\w+?\/\w+") +source "$collection_root/tests/integration/molecule.sh" diff --git a/tests/integration/targets/molecule-prometheus-alternative/runme.sh b/tests/integration/targets/molecule-prometheus-alternative/runme.sh new file mode 100755 index 00000000..d094c3e1 --- /dev/null +++ b/tests/integration/targets/molecule-prometheus-alternative/runme.sh @@ -0,0 +1,4 @@ +#!/usr/bin/env bash + +collection_root=$(pwd | grep -oP ".+\/ansible_collections\/\w+?\/\w+") +source "$collection_root/tests/integration/molecule.sh" diff --git a/tests/integration/targets/molecule-prometheus-default/runme.sh b/tests/integration/targets/molecule-prometheus-default/runme.sh new file mode 100755 index 00000000..d094c3e1 --- /dev/null +++ b/tests/integration/targets/molecule-prometheus-default/runme.sh @@ -0,0 +1,4 @@ +#!/usr/bin/env bash + +collection_root=$(pwd | grep -oP ".+\/ansible_collections\/\w+?\/\w+") +source "$collection_root/tests/integration/molecule.sh" diff --git a/tests/integration/targets/molecule-prometheus-latest/runme.sh b/tests/integration/targets/molecule-prometheus-latest/runme.sh new file mode 100755 index 00000000..d094c3e1 --- /dev/null +++ b/tests/integration/targets/molecule-prometheus-latest/runme.sh @@ -0,0 +1,4 @@ +#!/usr/bin/env bash + +collection_root=$(pwd | grep -oP ".+\/ansible_collections\/\w+?\/\w+") +source "$collection_root/tests/integration/molecule.sh" diff --git a/tests/integration/targets/molecule-snmp_exporter-alternative/runme.sh b/tests/integration/targets/molecule-snmp_exporter-alternative/runme.sh new file mode 100755 index 00000000..d094c3e1 --- /dev/null +++ b/tests/integration/targets/molecule-snmp_exporter-alternative/runme.sh @@ -0,0 +1,4 @@ +#!/usr/bin/env bash + +collection_root=$(pwd | grep -oP ".+\/ansible_collections\/\w+?\/\w+") +source "$collection_root/tests/integration/molecule.sh" diff --git a/tests/integration/targets/molecule-snmp_exporter-default/runme.sh b/tests/integration/targets/molecule-snmp_exporter-default/runme.sh new file mode 100755 index 00000000..d094c3e1 --- /dev/null +++ b/tests/integration/targets/molecule-snmp_exporter-default/runme.sh @@ -0,0 +1,4 @@ +#!/usr/bin/env bash + +collection_root=$(pwd | grep -oP ".+\/ansible_collections\/\w+?\/\w+") +source "$collection_root/tests/integration/molecule.sh"