From 5f6e33397ce71d9731d330778402220b44cf96a9 Mon Sep 17 00:00:00 2001 From: Bartek Grzybowski Date: Wed, 12 Jun 2019 16:17:18 +0200 Subject: Add role level tests for 'vncserver' role A cleanup stage is also added to clean testing artifacts. Change-Id: I2255a0e90a0f609bd927d3d44dd05b5847fbdfb0 Issue-ID: OOM-1926 Signed-off-by: Bartek Grzybowski --- ansible/roles/vncserver/.yamllint | 11 ++++++++ .../roles/vncserver/molecule/default/cleanup.yml | 6 ++++ .../roles/vncserver/molecule/default/molecule.yml | 32 ++++++++++++++++++++++ .../roles/vncserver/molecule/default/playbook.yml | 5 ++++ .../roles/vncserver/molecule/default/prepare.yml | 8 ++++++ .../molecule/default/tests/test_default.py | 10 +++++++ .../molecule/default/cleanup.yml | 1 + .../test/roles/cleanup-vncserver/tasks/main.yml | 6 ++++ 8 files changed, 79 insertions(+) create mode 100644 ansible/roles/vncserver/.yamllint create mode 100644 ansible/roles/vncserver/molecule/default/cleanup.yml create mode 100644 ansible/roles/vncserver/molecule/default/molecule.yml create mode 100644 ansible/roles/vncserver/molecule/default/playbook.yml create mode 100644 ansible/roles/vncserver/molecule/default/prepare.yml create mode 100644 ansible/roles/vncserver/molecule/default/tests/test_default.py create mode 100644 ansible/test/roles/cleanup-vncserver/tasks/main.yml diff --git a/ansible/roles/vncserver/.yamllint b/ansible/roles/vncserver/.yamllint new file mode 100644 index 00000000..ad0be760 --- /dev/null +++ b/ansible/roles/vncserver/.yamllint @@ -0,0 +1,11 @@ +extends: default + +rules: + braces: + max-spaces-inside: 1 + level: error + brackets: + max-spaces-inside: 1 + level: error + line-length: disable + truthy: disable diff --git a/ansible/roles/vncserver/molecule/default/cleanup.yml b/ansible/roles/vncserver/molecule/default/cleanup.yml new file mode 100644 index 00000000..16be86ef --- /dev/null +++ b/ansible/roles/vncserver/molecule/default/cleanup.yml @@ -0,0 +1,6 @@ +--- +- name: Cleanup + hosts: all + ignore_unreachable: true + roles: + - cleanup-vncserver diff --git a/ansible/roles/vncserver/molecule/default/molecule.yml b/ansible/roles/vncserver/molecule/default/molecule.yml new file mode 100644 index 00000000..5f7e4062 --- /dev/null +++ b/ansible/roles/vncserver/molecule/default/molecule.yml @@ -0,0 +1,32 @@ +--- +dependency: + name: galaxy +driver: + name: docker +lint: + name: yamllint +platforms: + - name: infrastructure-server + image: molecule-${PREBUILD_PLATFORM_DISTRO:-centos}:${PREBUILD_DISTRO_VERSION:-centos7.6} + pre_build_image: True + privileged: true + volumes: + - /var/lib/docker + override_command: False + groups: + - infrastructure +provisioner: + name: ansible + lint: + name: ansible-lint + env: + ANSIBLE_ROLES_PATH: ../../../../test/roles + inventory: + links: + group_vars: ../../../../group_vars +verifier: + name: testinfra + lint: + name: flake8 + options: + v: 1 diff --git a/ansible/roles/vncserver/molecule/default/playbook.yml b/ansible/roles/vncserver/molecule/default/playbook.yml new file mode 100644 index 00000000..1b253495 --- /dev/null +++ b/ansible/roles/vncserver/molecule/default/playbook.yml @@ -0,0 +1,5 @@ +--- +- name: Converge + hosts: infrastructure + roles: + - vncserver diff --git a/ansible/roles/vncserver/molecule/default/prepare.yml b/ansible/roles/vncserver/molecule/default/prepare.yml new file mode 100644 index 00000000..55edb8f8 --- /dev/null +++ b/ansible/roles/vncserver/molecule/default/prepare.yml @@ -0,0 +1,8 @@ +--- +- name: Prepare + hosts: all + vars_files: + - ../../defaults/main.yml + roles: + - prepare-docker-dind + - prepare-vncserver diff --git a/ansible/roles/vncserver/molecule/default/tests/test_default.py b/ansible/roles/vncserver/molecule/default/tests/test_default.py new file mode 100644 index 00000000..0164a3ee --- /dev/null +++ b/ansible/roles/vncserver/molecule/default/tests/test_default.py @@ -0,0 +1,10 @@ +import os + +import testinfra.utils.ansible_runner + +testinfra_hosts = testinfra.utils.ansible_runner.AnsibleRunner( + os.environ['MOLECULE_INVENTORY_FILE']).get_hosts('infrastructure') + + +def test_container_running(host): + assert host.docker('vnc-server').is_running diff --git a/ansible/test/play-infrastructure/molecule/default/cleanup.yml b/ansible/test/play-infrastructure/molecule/default/cleanup.yml index 9870a553..107ec8ca 100644 --- a/ansible/test/play-infrastructure/molecule/default/cleanup.yml +++ b/ansible/test/play-infrastructure/molecule/default/cleanup.yml @@ -4,3 +4,4 @@ ignore_unreachable: true roles: - cleanup-nginx + - cleanup-vncserver diff --git a/ansible/test/roles/cleanup-vncserver/tasks/main.yml b/ansible/test/roles/cleanup-vncserver/tasks/main.yml new file mode 100644 index 00000000..1fcb37d8 --- /dev/null +++ b/ansible/test/roles/cleanup-vncserver/tasks/main.yml @@ -0,0 +1,6 @@ +--- +- name: Remove saved vncserver docker image + delegate_to: localhost + file: + path: /tmp/vncserver.tar + state: absent -- cgit 1.2.3-korg