From b6341287bb513b6d118c9c53cb3ec661f13ee7dc Mon Sep 17 00:00:00 2001 From: aharrisson Date: Thu, 16 Apr 2020 08:28:45 +0200 Subject: [PATCH] Add Molecule to Docker role (#5129) * Add Molecule for container-engine/docker * Add bootstrap-os to Molecule prepare stage --- .../docker/molecule/default/molecule.yml | 29 +++++++++++++++++++ .../docker/molecule/default/playbook.yml | 7 +++++ .../docker/molecule/default/prepare.yml | 6 ++++ .../molecule/default/tests/test_default.py | 19 ++++++++++++ 4 files changed, 61 insertions(+) create mode 100644 roles/container-engine/docker/molecule/default/molecule.yml create mode 100644 roles/container-engine/docker/molecule/default/playbook.yml create mode 100644 roles/container-engine/docker/molecule/default/prepare.yml create mode 100644 roles/container-engine/docker/molecule/default/tests/test_default.py diff --git a/roles/container-engine/docker/molecule/default/molecule.yml b/roles/container-engine/docker/molecule/default/molecule.yml new file mode 100644 index 000000000..689649e1a --- /dev/null +++ b/roles/container-engine/docker/molecule/default/molecule.yml @@ -0,0 +1,29 @@ +--- +driver: + name: vagrant + provider: + name: libvirt +lint: + name: yamllint + options: + config-file: ../../../.yamllint +platforms: + - name: kubespray-docker + box: generic/ubuntu1804 + cpus: 2 + memory: 1024 +provisioner: + name: ansible + env: + ANSIBLE_ROLES_PATH: ../../../../ + config_options: + defaults: + callback_whitelist: profile_tasks + lint: + name: ansible-lint + options: + c: ../../../.ansible-lint +verifier: + name: testinfra + lint: + name: flake8 diff --git a/roles/container-engine/docker/molecule/default/playbook.yml b/roles/container-engine/docker/molecule/default/playbook.yml new file mode 100644 index 000000000..68c44d26d --- /dev/null +++ b/roles/container-engine/docker/molecule/default/playbook.yml @@ -0,0 +1,7 @@ +--- +- name: Converge + hosts: all + become: true + roles: + - role: kubespray-defaults + - role: docker diff --git a/roles/container-engine/docker/molecule/default/prepare.yml b/roles/container-engine/docker/molecule/default/prepare.yml new file mode 100644 index 000000000..1afc51a04 --- /dev/null +++ b/roles/container-engine/docker/molecule/default/prepare.yml @@ -0,0 +1,6 @@ +--- +- name: Prepare + hosts: all + gather_facts: False + roles: + - role: bootstrap-os diff --git a/roles/container-engine/docker/molecule/default/tests/test_default.py b/roles/container-engine/docker/molecule/default/tests/test_default.py new file mode 100644 index 000000000..5a18cc8f7 --- /dev/null +++ b/roles/container-engine/docker/molecule/default/tests/test_default.py @@ -0,0 +1,19 @@ +import os + +import testinfra.utils.ansible_runner + +testinfra_hosts = testinfra.utils.ansible_runner.AnsibleRunner( + os.environ['MOLECULE_INVENTORY_FILE']).get_hosts('all') + + +def test_docker_service(host): + docker = host.service("docker") + assert docker.is_running + assert docker.is_enabled + + +def test_docker_run(host): + with host.sudo(): + cmd = host.command("docker run hello-world") + assert cmd.rc == 0 + assert "Hello from Docker!" in cmd.stdout