-
Notifications
You must be signed in to change notification settings - Fork 11
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
hu-weihua
wants to merge
15
commits into
migtools:master
Choose a base branch
from
hu-weihua:24688
base: master
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from 12 commits
Commits
Show all changes
15 commits
Select commit
Hold shift + click to select a range
a21cd59
add test case for 24688
hu-weihua 8afa871
update1
hu-weihua 7b49fcb
deploy.yml
hu-weihua adfb951
add ns cleanup
hu-weihua fcdce1d
update
hu-weihua a4ece87
update
hu-weihua 445e26a
add attribute
hu-weihua 1080a51
update
hu-weihua 3e21cbb
replaced k8s_info by k8s_facts
hu-weihua 1526dcc
add case 24688 to e2e_mig_samples
hu-weihua 4d9ae9d
add sleep for configuation working
hu-weihua be741f1
make the check more stably
hu-weihua fbef360
update typo
hu-weihua 0ed80eb
fix some logic error
hu-weihua 06228b4
remove TC 24688 from e2e_mig_samples.yml
hu-weihua File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 | ||
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 }}" | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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') }}" | ||
|
||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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) | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,16 @@ | ||
- name: get all storageclasses infornamtion of migration target cluster | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe 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 )" | ||
|
||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,88 @@ | ||
- name: get all storageclasses infornamtion of migration target cluster | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe 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)" | ||
|
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
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....