[backport/2.2] Move integration test suite from molecule to ansible-test (#392) (#457)

[backport/2.2] Move integration test suite from molecule to ansible-test (#392)

Move integration test suite from molecule to ansible-test
SUMMARY
molecule has been replaced with ansible-test
some test cases have been updated
k8s_apply : remove duplicated tasks increasing the running time of the test
helm: use different namespaces for different test cases in order to wait for the namespace deletion before moving to the next test.
all: remove wait: yes at the end of each test when deleting namespace, the role used to create namespace will ensure that it is deleted before if existing.
ISSUE TYPE
Feature Pull Request
COMPONENT NAME
integration testing
Reviewed-by: Mike Graves mgraves@redhat.com
Reviewed-by: Gonéri Le Bouder goneri@lebouder.net
Reviewed-by: None 
(cherry picked from commit fd61f8b)
SUMMARY


ISSUE TYPE


Bugfix Pull Request
Docs Pull Request
Feature Pull Request
New Module Pull Request

COMPONENT NAME

ADDITIONAL INFORMATION
This commit is contained in:
Mike Graves
2022-05-11 14:56:23 -04:00
committed by GitHub
parent 0d9c4d3459
commit 11c800d6ed
190 changed files with 1261 additions and 1768 deletions

View File

@@ -0,0 +1,3 @@
time=20
k8s
k8s_info

View File

@@ -0,0 +1,4 @@
---
test_namespace:
- patched-namespace-1
- patched-namespace-2

View File

@@ -0,0 +1,2 @@
dependencies:
- remove_namespace

View File

@@ -0,0 +1,121 @@
---
- block:
- set_fact:
patch_only_namespace: "{{ test_namespace }}"
- name: Ensure namespace {{ patch_only_namespace[0] }} exist
kubernetes.core.k8s:
definition:
apiVersion: v1
kind: Namespace
metadata:
name: "{{ patch_only_namespace[0] }}"
labels:
existingLabel: "labelValue"
annotations:
existingAnnotation: "annotationValue"
wait: yes
- name: Ensure namespace {{ patch_only_namespace[1] }} does not exist
kubernetes.core.k8s_info:
kind: namespace
name: "{{ patch_only_namespace[1] }}"
register: second_namespace
- name: assert that second namespace does not exist
assert:
that:
- second_namespace.resources | length == 0
- name: apply patch on existing resource
kubernetes.core.k8s:
state: patched
wait: yes
definition: |
---
apiVersion: v1
kind: Namespace
metadata:
name: "{{ patch_only_namespace[0] }}"
labels:
ansible: patched
---
apiVersion: v1
kind: Namespace
metadata:
name: "{{ patch_only_namespace[1] }}"
labels:
ansible: patched
register: patch_resource
- name: assert that patch succeed
assert:
that:
- patch_resource.changed
- patch_resource.result.results | selectattr('warning', 'defined') | list | length == 1
- name: Ensure namespace {{ patch_only_namespace[0] }} was patched correctly
kubernetes.core.k8s_info:
kind: namespace
name: "{{ patch_only_namespace[0] }}"
register: first_namespace
- name: assert labels are as expected
assert:
that:
- first_namespace.resources[0].metadata.labels.ansible == "patched"
- first_namespace.resources[0].metadata.labels.existingLabel == "labelValue"
- first_namespace.resources[0].metadata.annotations.existingAnnotation == "annotationValue"
- name: Ensure namespace {{ patch_only_namespace[1] }} was not created
kubernetes.core.k8s_info:
kind: namespace
name: "{{ patch_only_namespace[1] }}"
register: second_namespace
- name: assert that second namespace does not exist
assert:
that:
- second_namespace.resources | length == 0
- name: patch all resources (create if does not exist)
kubernetes.core.k8s:
state: present
definition: |
---
apiVersion: v1
kind: Namespace
metadata:
name: "{{ patch_only_namespace[0] }}"
labels:
patch: ansible
---
apiVersion: v1
kind: Namespace
metadata:
name: "{{ patch_only_namespace[1] }}"
labels:
patch: ansible
wait: yes
register: patch_resource
- name: Ensure namespace {{ patch_only_namespace[1] }} was created
kubernetes.core.k8s_info:
kind: namespace
name: "{{ patch_only_namespace[1] }}"
register: second_namespace
- name: assert that second namespace exist
assert:
that:
- second_namespace.resources | length == 1
always:
- name: Remove namespace
kubernetes.core.k8s:
kind: Namespace
name: "{{ item }}"
state: absent
with_items:
- "{{ patch_only_namespace[0] }}"
- "{{ patch_only_namespace[1] }}"
ignore_errors: true