From f20c9c9c3b4b3cd04dabfa61b5e9998c99ce66d7 Mon Sep 17 00:00:00 2001 From: Ostap Batih Date: Wed, 23 Feb 2022 11:16:06 +0000 Subject: [MOLECULE] Configure and write tests for application-overrides role * configured molecule for application-override role for centos and ubuntu * wrote testinfra test for role Issue-ID: OOM-2889 Signed-off-by: Ostap Batih Change-Id: Iff17b0b9439f3fcb52eb6c4f3829f0c65b55c1a3 --- ansible/roles/application-override/.yamllint | 12 ++++++++++ .../molecule/default/cleanup.yml | 6 +++++ .../molecule/default/converge.yml | 7 ++++++ .../molecule/default/molecule.yml | 23 ++++++++++++++++++ .../molecule/default/prepare.yml | 5 ++++ .../molecule/default/tests/test_default.py | 13 ++++++++++ .../molecule/ubuntu/molecule.yml | 28 ++++++++++++++++++++++ ansible/roles/application-override/tasks/main.yml | 2 +- 8 files changed, 95 insertions(+), 1 deletion(-) create mode 100644 ansible/roles/application-override/.yamllint create mode 100644 ansible/roles/application-override/molecule/default/cleanup.yml create mode 100644 ansible/roles/application-override/molecule/default/converge.yml create mode 100644 ansible/roles/application-override/molecule/default/molecule.yml create mode 100644 ansible/roles/application-override/molecule/default/prepare.yml create mode 100644 ansible/roles/application-override/molecule/default/tests/test_default.py create mode 100644 ansible/roles/application-override/molecule/ubuntu/molecule.yml (limited to 'ansible/roles/application-override') diff --git a/ansible/roles/application-override/.yamllint b/ansible/roles/application-override/.yamllint new file mode 100644 index 00000000..c5ae64be --- /dev/null +++ b/ansible/roles/application-override/.yamllint @@ -0,0 +1,12 @@ +--- +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/application-override/molecule/default/cleanup.yml b/ansible/roles/application-override/molecule/default/cleanup.yml new file mode 100644 index 00000000..6a0dbf4b --- /dev/null +++ b/ansible/roles/application-override/molecule/default/cleanup.yml @@ -0,0 +1,6 @@ +--- +- name: Cleanup infra + hosts: all + ignore_unreachable: true + roles: + - cleanup-application-override diff --git a/ansible/roles/application-override/molecule/default/converge.yml b/ansible/roles/application-override/molecule/default/converge.yml new file mode 100644 index 00000000..9f5eb235 --- /dev/null +++ b/ansible/roles/application-override/molecule/default/converge.yml @@ -0,0 +1,7 @@ +--- +- name: Converge + hosts: all + tasks: + - name: "Include application-override" + include_role: + name: "application-override" diff --git a/ansible/roles/application-override/molecule/default/molecule.yml b/ansible/roles/application-override/molecule/default/molecule.yml new file mode 100644 index 00000000..d80e2f10 --- /dev/null +++ b/ansible/roles/application-override/molecule/default/molecule.yml @@ -0,0 +1,23 @@ +--- +dependency: + name: galaxy +driver: + name: docker +lint: | + set -e + yamllint . + ansible-lint . + flake8 +platforms: + - name: instance + image: centos:7 +provisioner: + name: ansible + env: + ANSIBLE_ROLES_PATH: ../../../../test/roles + inventory: + group_vars: + all: + app_helm_override_file: "/override.yml" +verifier: + name: testinfra diff --git a/ansible/roles/application-override/molecule/default/prepare.yml b/ansible/roles/application-override/molecule/default/prepare.yml new file mode 100644 index 00000000..a2f608b0 --- /dev/null +++ b/ansible/roles/application-override/molecule/default/prepare.yml @@ -0,0 +1,5 @@ +--- +- name: Prepare infra + hosts: all + roles: + - prepare-application-override diff --git a/ansible/roles/application-override/molecule/default/tests/test_default.py b/ansible/roles/application-override/molecule/default/tests/test_default.py new file mode 100644 index 00000000..4b504bee --- /dev/null +++ b/ansible/roles/application-override/molecule/default/tests/test_default.py @@ -0,0 +1,13 @@ +import yaml + + +def test_override_file(host): + y = None + f = host.file("/override.yml") + assert f.exists + assert f.is_file + try: + y = yaml.safe_load(f.content) + except yaml.YAMLError: + assert False + assert y['global']['cacert'] == 'this is dummy server certificate value\n' diff --git a/ansible/roles/application-override/molecule/ubuntu/molecule.yml b/ansible/roles/application-override/molecule/ubuntu/molecule.yml new file mode 100644 index 00000000..9d97f716 --- /dev/null +++ b/ansible/roles/application-override/molecule/ubuntu/molecule.yml @@ -0,0 +1,28 @@ +--- +dependency: + name: galaxy +driver: + name: docker +lint: | + set -e + yamllint . + ansible-lint . + flake8 +platforms: + - name: instance + image: ubuntu:18.04 +provisioner: + name: ansible + env: + ANSIBLE_ROLES_PATH: ../../../../test/roles + inventory: + group_vars: + all: + app_helm_override_file: "/override.yml" + playbooks: + prepare: ../default/prepare.yml + converge: ../default/converge.yml + cleanup: ../default/cleanup.yml +verifier: + name: testinfra + directory: ../default/tests/ diff --git a/ansible/roles/application-override/tasks/main.yml b/ansible/roles/application-override/tasks/main.yml index 1ecf7c79..9bfeae81 100644 --- a/ansible/roles/application-override/tasks/main.yml +++ b/ansible/roles/application-override/tasks/main.yml @@ -10,7 +10,7 @@ set_fact: merged_overrides: "{{ overrides | default({}) | combine({'global': {'cacert': root_cert.content | b64decode}}, recursive=True) }}" -- name: "Create {{ app_helm_override_file }}" +- name: "Create override file" copy: dest: "{{ app_helm_override_file }}" content: "{{ merged_overrides | to_nice_yaml }}" -- cgit 1.2.3-korg