mirror of
https://github.com/ansible-collections/kubernetes.core.git
synced 2026-07-28 18:34:42 +00:00
[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:
3
tests/integration/targets/k8s_patched/aliases
Normal file
3
tests/integration/targets/k8s_patched/aliases
Normal file
@@ -0,0 +1,3 @@
|
||||
time=20
|
||||
k8s
|
||||
k8s_info
|
||||
4
tests/integration/targets/k8s_patched/defaults/main.yml
Normal file
4
tests/integration/targets/k8s_patched/defaults/main.yml
Normal file
@@ -0,0 +1,4 @@
|
||||
---
|
||||
test_namespace:
|
||||
- patched-namespace-1
|
||||
- patched-namespace-2
|
||||
2
tests/integration/targets/k8s_patched/meta/main.yml
Normal file
2
tests/integration/targets/k8s_patched/meta/main.yml
Normal file
@@ -0,0 +1,2 @@
|
||||
dependencies:
|
||||
- remove_namespace
|
||||
121
tests/integration/targets/k8s_patched/tasks/main.yml
Normal file
121
tests/integration/targets/k8s_patched/tasks/main.yml
Normal 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
|
||||
Reference in New Issue
Block a user