[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,4 @@
k8s_service
k8s
k8s_info
time=75

View File

@@ -0,0 +1,3 @@
---
test_namespace: "template-test"
k8s_wait_timeout: 400

View File

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

View File

@@ -0,0 +1,259 @@
---
- block:
- set_fact:
template_namespace: "{{ test_namespace }}"
- name: Check if k8s_service does not inherit parameter
kubernetes.core.k8s_service:
template: "pod_one.j2"
state: present
ignore_errors: yes
register: r
- name: Check for expected failures in last tasks
assert:
that:
- r.failed
- "'is only a supported parameter for' in r.msg"
- name: Specify both definition and template
kubernetes.core.k8s:
state: present
template: "pod_one.j2"
definition:
apiVersion: apps/v1
kind: Deployment
metadata:
name: apply-deploy
namespace: "{{ template_namespace }}"
spec:
replicas: 1
selector:
matchLabels:
app: "{{ k8s_pod_name_one }}"
vars:
k8s_pod_name_one: pod
k8s_pod_namespace: "{{ template_namespace }}"
register: r
ignore_errors: yes
- name: Check if definition and template are mutually exclusive
assert:
that:
- r.failed
- "'parameters are mutually exclusive' in r.msg"
- name: Specify both src and template
kubernetes.core.k8s:
state: present
src: "../templates/pod_one.j2"
template: "pod_one.j2"
vars:
k8s_pod_name_one: pod
k8s_pod_namespace: "{{ template_namespace }}"
register: r
ignore_errors: yes
- name: Check if src and template are mutually exclusive
assert:
that:
- r.failed
- "'parameters are mutually exclusive' in r.msg"
- name: Create pod using template (direct specification)
kubernetes.core.k8s:
template: "pod_one.j2"
wait: yes
wait_timeout: "{{ k8s_wait_timeout | default(omit) }}"
vars:
k8s_pod_name_one: pod-1
k8s_pod_namespace: "{{ template_namespace }}"
register: r
- name: Assert that pod creation succeeded using template
assert:
that:
- r is successful
- name: Create pod using template with wrong parameter
kubernetes.core.k8s:
template:
- default
wait: yes
wait_timeout: "{{ k8s_wait_timeout | default(omit) }}"
vars:
k8s_pod_name_one: pod-2
k8s_pod_namespace: "{{ template_namespace }}"
register: r
ignore_errors: True
- name: Assert that pod creation failed using template due to wrong parameter
assert:
that:
- r is failed
- name: Create pod using template (path parameter)
kubernetes.core.k8s:
template:
path: "pod_one.j2"
wait: yes
wait_timeout: "{{ k8s_wait_timeout | default(omit) }}"
vars:
k8s_pod_name_one: pod-3
k8s_pod_namespace: "{{ template_namespace }}"
register: r
- name: Assert that pod creation succeeded using template
assert:
that:
- r is successful
- name: Create pod using template (different variable string)
kubernetes.core.k8s:
template:
path: "pod_two.j2"
variable_start_string: '[['
variable_end_string: ']]'
wait: yes
wait_timeout: "{{ k8s_wait_timeout | default(omit) }}"
vars:
k8s_pod_name_two: pod-4
k8s_pod_namespace: "[[ template_namespace ]]"
ansible_python_interpreter: "[[ ansible_playbook_python ]]"
register: r
- name: Assert that pod creation succeeded using template
assert:
that:
- r is successful
- name: Create pods using multi-resource template
kubernetes.core.k8s:
template:
path: "pod_three.j2"
wait: yes
wait_timeout: "{{ k8s_wait_timeout | default(omit) }}"
vars:
k8s_pod_name_three_one: pod-5
k8s_pod_name_three_two: pod-6
k8s_pod_namespace: "{{ template_namespace }}"
register: r
- name: Assert that pod creation succeeded using template
assert:
that:
- r is successful
- name: Create pods using list of template
kubernetes.core.k8s:
template:
- pod_one.j2
- path: "pod_two.j2"
variable_start_string: '[['
variable_end_string: ']]'
- path: "pod_three.j2"
wait: yes
wait_timeout: "{{ k8s_wait_timeout | default(omit) }}"
vars:
k8s_pod_name_one: pod-7
k8s_pod_name_two: pod-8
k8s_pod_name_three_one: pod-9
k8s_pod_name_three_two: pod-10
k8s_pod_namespace: "template-test"
register: r
- name: Assert that pod creation succeeded using template
assert:
that:
- r is successful
# continue_on_error
- name: define variable for test
set_fact:
k8s_pod_name_one: pod-11
k8s_pod_bad_name: pod-12
k8s_pod_namespace: "{{ template_namespace }}"
k8s_pod_bad_namespace: "dummy-namespace-012345"
- name: delete pod if it exists
kubernetes.core.k8s:
template: pod_one.j2
wait: true
wait_timeout: "{{ k8s_wait_timeout | default(omit) }}"
state: absent
- name: create pod on bad namespace ( continue_on_error set to default(false) )
kubernetes.core.k8s:
template:
- pod_with_bad_namespace.j2
- pod_one.j2
register: resource
ignore_errors: true
- name: validate that creation failed
assert:
that:
- resource is failed
- '"Failed to create object" in resource.msg'
- name: assert pod has not been created
kubernetes.core.k8s_info:
kind: "{{ item.kind }}"
namespace: "{{ item.namespace }}"
name: "{{ item.name }}"
with_items:
- kind: pod
namespace: "{{ k8s_pod_bad_namespace }}"
name: "{{ k8s_pod_bad_name }}"
- kind: pod
namespace: "{{ k8s_pod_name_one }}"
name: "{{ k8s_pod_namespace }}"
register: resource
- name: check that resources creation failed
assert:
that:
- '{{ resource.results[0].resources | length == 0 }}'
- '{{ resource.results[1].resources | length == 0 }}'
- name: create pod without namespace (continue_on_error = true)
kubernetes.core.k8s:
template:
- pod_with_bad_namespace.j2
- pod_one.j2
continue_on_error: true
wait: true
wait_timeout: "{{ k8s_wait_timeout | default(omit) }}"
register: resource
ignore_errors: true
- name: validate that creation succeeded
assert:
that:
- resource is successful
- name: validate resource creation succeeded for some and failed for others
assert:
that:
- resource is successful
- resource.result.results | selectattr('changed') | list | length == 1
- resource.result.results | selectattr('error', 'defined') | list | length == 1
- name: Remove Pod (Cleanup)
kubernetes.core.k8s:
api_version: v1
kind: Pod
name: "pod-{{ item }}"
namespace: "{{ template_namespace }}"
state: absent
wait: yes
ignore_errors: yes
loop: "{{ range(1, 12) | list }}"
always:
- name: Remove namespace (Cleanup)
kubernetes.core.k8s:
kind: Namespace
name: "{{ template_namespace }}"
state: absent
ignore_errors: true

View File

@@ -0,0 +1,16 @@
apiVersion: v1
kind: Pod
metadata:
labels:
app: "{{ k8s_pod_name_one }}"
name: '{{ k8s_pod_name_one }}'
namespace: '{{ k8s_pod_namespace }}'
spec:
containers:
- args:
- /bin/sh
- -c
- while true; do echo $(date); sleep 10; done
image: python:3.7-alpine
imagePullPolicy: Always
name: '{{ k8s_pod_name_one }}'

View File

@@ -0,0 +1,35 @@
---
apiVersion: v1
kind: Pod
metadata:
labels:
app: "{{ k8s_pod_name_three_one }}"
name: '{{ k8s_pod_name_three_one }}'
namespace: '{{ k8s_pod_namespace }}'
spec:
containers:
- args:
- /bin/sh
- -c
- while true; do echo $(date); sleep 10; done
image: python:3.7-alpine
imagePullPolicy: Always
name: '{{ k8s_pod_name_three_one }}'
---
apiVersion: v1
kind: Pod
metadata:
labels:
app: "{{ k8s_pod_name_three_two }}"
name: '{{ k8s_pod_name_three_two }}'
namespace: '{{ k8s_pod_namespace }}'
spec:
containers:
- args:
- /bin/sh
- -c
- while true; do echo $(date); sleep 10; done
image: python:3.7-alpine
imagePullPolicy: Always
name: '{{ k8s_pod_name_three_two }}'

View File

@@ -0,0 +1,16 @@
apiVersion: v1
kind: Pod
metadata:
labels:
app: '[[ k8s_pod_name_two ]]'
name: '[[ k8s_pod_name_two ]]'
namespace: '[[ k8s_pod_namespace ]]'
spec:
containers:
- args:
- /bin/sh
- -c
- while true; do echo $(date); sleep 10; done
image: python:3.7-alpine
imagePullPolicy: Always
name: '[[ k8s_pod_name_two ]]'

View File

@@ -0,0 +1,16 @@
apiVersion: v1
kind: Pod
metadata:
labels:
app: "{{ k8s_pod_bad_name }}"
name: '{{ k8s_pod_bad_name }}'
namespace: '{{ k8s_pod_bad_namespace }}'
spec:
containers:
- args:
- /bin/sh
- -c
- while true; do echo $(date); sleep 10; done
image: python:3.7-alpine
imagePullPolicy: Always
name: '{{ k8s_pod_bad_name }}'