From 463be96d99c9801f8968fa42c5f2b5fb48e5e967 Mon Sep 17 00:00:00 2001 From: Miouge1 Date: Fri, 27 Mar 2020 12:20:31 +0100 Subject: [PATCH] Add molecule test for bootstrap-os --- .gitlab-ci.yml | 1 + .gitlab-ci/vagrant.yml | 16 +++++++ roles/bootstrap-os/defaults/main.yml | 2 + .../molecule/default/molecule.yml | 44 +++++++++++++++++++ .../molecule/default/playbook.yml | 6 +++ .../molecule/default/tests/test_default.py | 11 +++++ tests/requirements.txt | 2 + tests/scripts/molecule_run.sh | 12 +++++ 8 files changed, 94 insertions(+) create mode 100644 .gitlab-ci/vagrant.yml create mode 100644 roles/bootstrap-os/molecule/default/molecule.yml create mode 100644 roles/bootstrap-os/molecule/default/playbook.yml create mode 100644 roles/bootstrap-os/molecule/default/tests/test_default.py create mode 100755 tests/scripts/molecule_run.sh diff --git a/.gitlab-ci.yml b/.gitlab-ci.yml index 99d71f71f27..afca9f9e7b1 100644 --- a/.gitlab-ci.yml +++ b/.gitlab-ci.yml @@ -71,3 +71,4 @@ include: - .gitlab-ci/shellcheck.yml - .gitlab-ci/terraform.yml - .gitlab-ci/packet.yml + - .gitlab-ci/vagrant.yml diff --git a/.gitlab-ci/vagrant.yml b/.gitlab-ci/vagrant.yml new file mode 100644 index 00000000000..b374843a77c --- /dev/null +++ b/.gitlab-ci/vagrant.yml @@ -0,0 +1,16 @@ +--- + +molecule_tests: + tags: [vagrant] + only: [/^pr-.*$/] + except: ['triggers'] + image: quay.io/miouge/kubespray-vagrant + services: [] + stage: deploy-part1 + before_script: + - tests/scripts/rebase.sh + - apt-get update && apt-get install -y python3-pip + - update-alternatives --install /usr/bin/python python /usr/bin/python3 10 + - python -m pip install -r tests/requirements.txt + script: + - ./tests/scripts/molecule_run.sh diff --git a/roles/bootstrap-os/defaults/main.yml b/roles/bootstrap-os/defaults/main.yml index ad8b7aa8c3c..d0b328168dc 100644 --- a/roles/bootstrap-os/defaults/main.yml +++ b/roles/bootstrap-os/defaults/main.yml @@ -23,3 +23,5 @@ fedora_coreos_packages: ## General # Set the hostname to inventory_hostname override_system_hostname: true + +is_fedora_coreos: false \ No newline at end of file diff --git a/roles/bootstrap-os/molecule/default/molecule.yml b/roles/bootstrap-os/molecule/default/molecule.yml new file mode 100644 index 00000000000..8c6c6bd285e --- /dev/null +++ b/roles/bootstrap-os/molecule/default/molecule.yml @@ -0,0 +1,44 @@ +--- +scenario: + name: default + test_sequence: + - lint + - destroy + - dependency + - syntax + - create + - prepare + - converge + # - idempotence # skip + - side_effect + - verify + - destroy +dependency: + name: galaxy +lint: + name: yamllint + options: + config-file: ../../.yamllint +driver: + name: vagrant + provider: + name: libvirt +platforms: + - name: ubuntu18 + box: generic/ubuntu1804 + cpus: 2 + memory: 2048 +provisioner: + name: ansible + lint: + name: ansible-lint + inventory: + group_vars: + all: + user: + name: foo + comment: My test comment +verifier: + name: testinfra + lint: + name: flake8 diff --git a/roles/bootstrap-os/molecule/default/playbook.yml b/roles/bootstrap-os/molecule/default/playbook.yml new file mode 100644 index 00000000000..1f44ec9ca2c --- /dev/null +++ b/roles/bootstrap-os/molecule/default/playbook.yml @@ -0,0 +1,6 @@ +--- +- name: Converge + hosts: all + gather_facts: no + roles: + - role: bootstrap-os diff --git a/roles/bootstrap-os/molecule/default/tests/test_default.py b/roles/bootstrap-os/molecule/default/tests/test_default.py new file mode 100644 index 00000000000..64c59dd150f --- /dev/null +++ b/roles/bootstrap-os/molecule/default/tests/test_default.py @@ -0,0 +1,11 @@ +import os + +import testinfra.utils.ansible_runner + +testinfra_hosts = testinfra.utils.ansible_runner.AnsibleRunner( + os.environ['MOLECULE_INVENTORY_FILE'] +).get_hosts('all') + + +def test_python(host): + assert host.exists('python3') or host.exists('python') diff --git a/tests/requirements.txt b/tests/requirements.txt index 242d3a28633..c9782264fd0 100644 --- a/tests/requirements.txt +++ b/tests/requirements.txt @@ -6,3 +6,5 @@ dopy==0.3.7 cryptography==2.8 ansible-lint==4.2.0 openshift==0.8.8 +molecule==2.22 +python-vagrant==0.5.15 diff --git a/tests/scripts/molecule_run.sh b/tests/scripts/molecule_run.sh new file mode 100755 index 00000000000..deb06426840 --- /dev/null +++ b/tests/scripts/molecule_run.sh @@ -0,0 +1,12 @@ +#!/bin/bash +set -euxo pipefail + +export LC_ALL=C.UTF-8 +export LANG=C.UTF-8 + +for d in $(find roles -name molecule -type d) +do + cd $(dirname $d) + molecule test --all + cd - +done \ No newline at end of file