Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add automated test case for OCP-24688 #68

Open
wants to merge 15 commits into
base: master
Choose a base branch
from
1 change: 1 addition & 0 deletions e2e_mig_samples.yml
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@
- { role: ocp-26160-max-pvs, tags: ["ocp-26160-max-pvs", "ocp"] }
- { role: ocp-24787-redis, tags: ["ocp-24787-redis", "ocp"] }
- { role: ocp-24797-mongodb, tags: ["ocp-24797-mongodb", "ocp"] }
- { role: ocp-24688-storageclasses, tags: ["ocp-24688-storageclasses", "ocp"] }
vars_files:
- "{{ playbook_dir }}/config/mig_controller.yml"
- "{{ playbook_dir }}/config/defaults.yml"
16 changes: 16 additions & 0 deletions roles/ocp-24688-storageclasses/defaults/main.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
namespace: ocp-24688-storageclasses

bogus_storageclass_name: test-storageclass
source_cluster_sc_name_list_tmp_file: ./roles/{{ namespace }}/files/source_cluster_sc_name_list_tmp_file.tmp
source_cluster_sc_name_list_tmp_file2: ./roles/{{ namespace }}/files/source_cluster_sc_name_list_tmp_file.tmp2

migration_sample_name: "{{ namespace }}"
migration_plan_name: "{{ migration_sample_name }}-migplan-{{ ansible_date_time.epoch }}"
migration_name: "{{ migration_sample_name }}-mig-{{ ansible_date_time.epoch }}"
with_deploy: true
with_migrate: true
with_cleanup: true
with_validate: true
pv: false
quiesce: false

7 changes: 7 additions & 0 deletions roles/ocp-24688-storageclasses/files/test_storageclasses.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
apiVersion: storage.k8s.io/v1
kind: StorageClass
metadata:
name: test-storageclass
provisioner: kubernetes.io/no-provisioner
reclaimPolicy: Delete
volumeBindingMode: WaitForFirstConsumer
52 changes: 52 additions & 0 deletions roles/ocp-24688-storageclasses/tasks/deploy_source.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,52 @@
- name: Check existing StorageClass for {{ bogus_storageclass_name }} in migration source cluster {{ migcluster_source_name }}
k8s_facts:
api_version: v1
kind: StorageClass
register: all_sc

#- debug:
# msg: "{{ all_sc }}"

- block:

- name: Extract StorageClass for {{ bogus_storageclass_name }} in migration source cluster {{ migcluster_source_name }}
set_fact:
sc_to_remove: "{{ all_sc | json_query('resources[].metadata.name') | select('match', bogus_storageclass_name) | list }}"

- debug:
msg:
- "These existing StorageClass will be removed :"
- "{{ sc_to_remove }}"

- name: Remove existing storageclass for {{ bogus_storageclass_name }} from migration source cluster {{ migcluster_source_name }}
k8s:
state: absent
api_version: v1
kind: StorageClass
name: "{{ item }}"
wait: yes
loop: "{{ sc_to_remove }}"

when: "bogus_storageclass_name in (all_sc | json_query('resources[].metadata.name') | string )"


- name: Create bogus storageclasses in migration source cluster {{ migcluster_source_name }}
k8s:
state: present
definition: "{{ lookup('file', 'test_storageclasses.yml') }}"


- name: clear the expired source cluster sc name list in tmp file
file:
path: "{{ source_cluster_sc_name_list_tmp_file }}"
state: absent
when: source_cluster_sc_name_list_tmp_file is defined

- name: sleep a while to wait configuration working
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We could use the pause module with seconds 60 on this instead of calling the shell module, ideally we would check for the condition expected in a loop with retries perhaps until it is satisfied....

shell: sleep 60

- name: save the source cluster sc name list to tmp file
copy:
content: "{{ all_sc | json_query('resources[].metadata.name') |list }}"
dest: "{{ source_cluster_sc_name_list_tmp_file }}"

38 changes: 38 additions & 0 deletions roles/ocp-24688-storageclasses/tasks/deploy_target.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,38 @@
- name: Check existing StorageClass for {{ bogus_storageclass_name }} in migration target cluster {{ migcluster_target_name }}
k8s_facts:
api_version: v1
kind: StorageClass
register: all_sc

#- debug:
# msg: "{{ all_sc }}"

- block:

- name: Extract StorageClass for {{ bogus_storageclass_name }} in migration target cluster {{ migcluster_target_name }}
set_fact:
sc_to_remove: "{{ all_sc | json_query('resources[].metadata.name') | select('match', bogus_storageclass_name) | list }}"

- debug:
msg:
- "These existing StorageClass will be removed :"
- "{{ sc_to_remove }}"

- name: Remove existing storageclass for {{ bogus_storageclass_name }} from migration target cluster {{ migcluster_target_name }}
k8s:
state: absent
api_version: v1
kind: StorageClass
name: "{{ item }}"
wait: yes
loop: "{{ sc_to_remove }}"

when: "bogus_storageclass_name in (all_sc | json_query('resources[].metadata.name') | string )"


- name: Create bogus storageclasses in migration target cluster {{ migcluster_target_name }}
k8s:
state: present
definition: "{{ lookup('file', 'test_storageclasses.yml') }}"


21 changes: 21 additions & 0 deletions roles/ocp-24688-storageclasses/tasks/main.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
- name: Cleanup resources
include_role:
name: migration_cleanup
when: with_cleanup|bool

- name: Create bogus storageclasses in migration source cluster
import_tasks: deploy_source.yml
when: with_deploy|bool

- name: Create bogus storageclasses in migration target cluster
import_tasks: deploy_target.yml
when: with_migrate|bool

- name: Validate source
import_tasks: validate-source.yml
when: (with_validate|bool) and (with_deploy|bool)

- name: Validate migration
import_tasks: validate-target.yml
when: (with_validate|bool) and (with_migrate|bool)

16 changes: 16 additions & 0 deletions roles/ocp-24688-storageclasses/tasks/validate-source.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
- name: get all storageclasses infornamtion of migration target cluster
Copy link
Contributor

@fbladilo fbladilo Feb 18, 2020

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

typo in information...

k8s_facts:
api_version: v1
kind: StorageClass
register: all_sc

- name: get all storageclasses name list of migration target cluster
set_fact:
sc_name_list: "{{ all_sc | json_query('resources[].metadata.name') |list }}"

- name: verify bogus storageclasses setting in migration target cluster
fail:
msg: "setting bogus storageclasses {{ bogus_storageclass_name }} failed in migration target cluster"
when: "bogus_storageclass_name not in (sc_name_list | string )"


88 changes: 88 additions & 0 deletions roles/ocp-24688-storageclasses/tasks/validate-target.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,88 @@
- name: get all storageclasses infornamtion of migration target cluster
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

small typo also in information

k8s_facts:
api_version: v1
kind: StorageClass
register: all_sc

- name: get all storageclasses name list of migration target cluster
set_fact:
sc_name_list: "{{ all_sc | json_query('resources[].metadata.name') |list }}"

- name: verify bogus storageclasses setting in migration target cluster
fail:
msg: "setting bogus storageclasses {{ bogus_storageclass_name }} failed in migration target cluster"
when: "bogus_storageclass_name not in (sc_name_list | string )"


- name: verify migcluster definition of target cluster {{ migcluster_target_name }}
k8s_facts:
api_version: v1alpha1
kind: MigCluster
namespace: "{{ migration_namespace }}"
field_selectors:
- metadata.name={{ migcluster_target_name }}
register: target_sc
until: sc_name_list |difference(target_sc | json_query('resources[].spec.storageClasses[].name')|list)| length == 0
retries: 30
delay: 10

- name: set fact for string
set_fact:
expected_string: "The cluster is ready"

#- debug:
# msg: "{{ target_sc }}"

- name: Vefify migcluster definition of target cluster is ready
fail:
msg: "there is no statement {{ expected_string }} in migcluter definition of target cluster {{ migcluster_target_name }}"
when: "expected_string not in (target_sc| json_query('resources[].status.conditions[].message')|string)"

- when: source_cluster_sc_name_list_tmp_file is not defined
block:
- name: Verity migcluster definition of source cluster {{ migcluster_source_name }}
k8s_facts:
api_version: v1alpha1
kind: MigCluster
namespace: "{{ migration_namespace }}"
field_selectors:
- metadata.name={{ migcluster_source_name }}
register: source_sc
until: "bogus_storageclass_name in (source_sc | json_query('resources[].spec.storageClasses[].name') | string)"
retries: 30

- name: Vefify migcluster definition of source cluster is ready
fail:
msg: "there is no statement {{ expected_string }} in migcluter definition of source cluster {{ migcluster_source_name }}"
when: "expected_string not in (source_sc| json_query('resources[].status.conditions[].message')|string)"

- when: source_cluster_sc_name_list_tmp_file is defined
block:
- name: Verity migcluster definition of source cluster {{ migcluster_source_name }}
k8s_facts:
api_version: v1alpha1
kind: MigCluster
namespace: "{{ migration_namespace }}"
field_selectors:
- metadata.name={{ migcluster_source_name }}
register: source_sc

- name: save the source cluster sc name list in migcluster definition to tmp file
copy:
content: "{{ source_sc | json_query('resources[].spec.storageClasses[].name')|list }}"
dest: "{{ source_cluster_sc_name_list_tmp_file2 }}"

- name: compare the 2 tmp files
shell: diff -y {{ source_cluster_sc_name_list_tmp_file }} {{ source_cluster_sc_name_list_tmp_file2 }}
register: diff_result

- name: check the diff result
fail:
msg: "the StorageClass of source cluster in migcluster {{ migcluster_source_name }} is wrong"
when: diff_result.rc != 0

- name: Vefify migcluster definition of source cluster is ready
fail:
msg: "there is no statement {{ expected_string }} in migcluter definition of source cluster {{ migcluster_source_name }}"
when: "expected_string not in (source_sc| json_query('resources[].status.conditions[].message')|string)"