diff options
author | Ostap Batih <o.batih@samsung.com> | 2022-02-23 11:16:06 +0000 |
---|---|---|
committer | Bartek Grzybowski <b.grzybowski@partner.samsung.com> | 2022-03-16 10:10:33 +0000 |
commit | 8fc0e0d0ba8e93dfb1d789e5bb143740da3c383f (patch) | |
tree | 87f20fc14f39486578abbbe3d5ed666f6fab250f | |
parent | eb8bad1dc2a0228fccca3e843b8f2a1a54a5fdd4 (diff) |
[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 <o.batih@samsung.com>
Change-Id: Iff17b0b9439f3fcb52eb6c4f3829f0c65b55c1a3
10 files changed, 113 insertions, 1 deletions
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 }}" diff --git a/ansible/test/roles/cleanup-application-override/tasks/main.yml b/ansible/test/roles/cleanup-application-override/tasks/main.yml new file mode 100644 index 00000000..084d7ae0 --- /dev/null +++ b/ansible/test/roles/cleanup-application-override/tasks/main.yml @@ -0,0 +1,5 @@ +- name: "Clean application-override mocked certificate directory" + file: + path: "{{ playbook_dir }}/certs" + state: absent + delegate_to: localhost diff --git a/ansible/test/roles/prepare-application-override/tasks/main.yml b/ansible/test/roles/prepare-application-override/tasks/main.yml new file mode 100644 index 00000000..e601c90a --- /dev/null +++ b/ansible/test/roles/prepare-application-override/tasks/main.yml @@ -0,0 +1,13 @@ +- name: "Create certificate directory" + file: + path: "{{ playbook_dir }}/certs" + state: directory + delegate_to: localhost + +- name: "Create dummy cert file" + copy: + content: | + this is dummy server certificate value + dest: certs/rootCA.crt + delegate_to: localhost + |