From f60c159f9466e399d0fa21fb1e9548272b67afaf Mon Sep 17 00:00:00 2001 From: Sergio Date: Thu, 2 Jul 2020 15:30:09 +0000 Subject: [PATCH] Add ocp-32075-retry testcase --- roles/ocp-32075-retry/defaults/main.yml | 14 +++++ roles/ocp-32075-retry/tasks/deploy.yml | 12 ++++ .../tasks/disable_internal_registry.yml | 11 ++++ .../tasks/enable_internal_registry.yml | 11 ++++ roles/ocp-32075-retry/tasks/main.yml | 27 +++++++++ roles/ocp-32075-retry/tasks/migrate.yml | 33 +++++++++++ roles/ocp-32075-retry/tasks/track.yml | 3 + .../ocp-32075-retry/tasks/validate-source.yml | 55 +++++++++++++++++++ .../ocp-32075-retry/tasks/validate-target.yml | 53 ++++++++++++++++++ 9 files changed, 219 insertions(+) create mode 100644 roles/ocp-32075-retry/defaults/main.yml create mode 100644 roles/ocp-32075-retry/tasks/deploy.yml create mode 100644 roles/ocp-32075-retry/tasks/disable_internal_registry.yml create mode 100644 roles/ocp-32075-retry/tasks/enable_internal_registry.yml create mode 100644 roles/ocp-32075-retry/tasks/main.yml create mode 100644 roles/ocp-32075-retry/tasks/migrate.yml create mode 100644 roles/ocp-32075-retry/tasks/track.yml create mode 100644 roles/ocp-32075-retry/tasks/validate-source.yml create mode 100644 roles/ocp-32075-retry/tasks/validate-target.yml diff --git a/roles/ocp-32075-retry/defaults/main.yml b/roles/ocp-32075-retry/defaults/main.yml new file mode 100644 index 0000000..22e408c --- /dev/null +++ b/roles/ocp-32075-retry/defaults/main.yml @@ -0,0 +1,14 @@ +namespace: "ocp-32075-retry" + +num_visits: 5 + +migration_sample_name: "ocp-32075-retry" +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 diff --git a/roles/ocp-32075-retry/tasks/deploy.yml b/roles/ocp-32075-retry/tasks/deploy.yml new file mode 100644 index 0000000..2877d14 --- /dev/null +++ b/roles/ocp-32075-retry/tasks/deploy.yml @@ -0,0 +1,12 @@ +- name: Check namespace + k8s_facts: + kind: Namespace + name: "{{ namespace }}" + register: ns + +- name: Create namespace + shell: "{{ oc_binary }} new-project {{ namespace }} --skip-config-write=true" + when: ns.resources | length == 0 + +- name: Create openshift cake-php application from openshift templates + shell: "{{ oc_binary }} -n {{ namespace }} new-app --template django-psql-persistent" diff --git a/roles/ocp-32075-retry/tasks/disable_internal_registry.yml b/roles/ocp-32075-retry/tasks/disable_internal_registry.yml new file mode 100644 index 0000000..f59f167 --- /dev/null +++ b/roles/ocp-32075-retry/tasks/disable_internal_registry.yml @@ -0,0 +1,11 @@ +- name: Disable internal registry. 3x cluster. + shell: oc scale --replicas 0 -n openshift-cluster-version deployments/cluster-version-operator + register: disable3_command + until: disable3_command.rc == 0 + when: oc_version is version('4.1', '<') + +- name: Disable internal registry. 4x cluster. + shell: "oc patch configs.imageregistry.operator.openshift.io cluster -p '{\"spec\":{\"managementState\": \"Removed\"} }' --type='merge'" + register: disable3_command + until: disable3_command.rc == 0 + when: not oc_version is version('4.1', '<') diff --git a/roles/ocp-32075-retry/tasks/enable_internal_registry.yml b/roles/ocp-32075-retry/tasks/enable_internal_registry.yml new file mode 100644 index 0000000..468f7d9 --- /dev/null +++ b/roles/ocp-32075-retry/tasks/enable_internal_registry.yml @@ -0,0 +1,11 @@ +- name: Enable internal registry. 3x cluster. + shell: oc scale --replicas 1 -n openshift-cluster-version deployments/cluster-version-operator + register: disable3_command + until: disable3_command.rc == 0 + when: oc_version is version('4.1', '<') + +- name: Enable internal registry. 4x cluster. + shell: "oc patch configs.imageregistry.operator.openshift.io cluster -p '{\"spec\":{\"managementState\": \"Managed\"} }' --type='merge'" + register: disable3_command + until: disable3_command.rc == 0 + when: not oc_version is version('4.1', '<') diff --git a/roles/ocp-32075-retry/tasks/main.yml b/roles/ocp-32075-retry/tasks/main.yml new file mode 100644 index 0000000..96e49f5 --- /dev/null +++ b/roles/ocp-32075-retry/tasks/main.yml @@ -0,0 +1,27 @@ +- name: Get oc version + include_role: + name: migration_getfacts + +- name: Cleanup resources + include_role: + name: migration_cleanup + when: with_cleanup|bool + +- name: Create resources + import_tasks: deploy.yml + when: with_deploy|bool + +- name: Start migration + import_tasks: migrate.yml + +- name: Track migration + import_tasks: track.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) diff --git a/roles/ocp-32075-retry/tasks/migrate.yml b/roles/ocp-32075-retry/tasks/migrate.yml new file mode 100644 index 0000000..71ec28d --- /dev/null +++ b/roles/ocp-32075-retry/tasks/migrate.yml @@ -0,0 +1,33 @@ +- name: Migrate forcing a failue + block: + - name: Disable internal registry to create a connection problem + import_tasks: disable_internal_registry.yml + + - name: Get velero last log line + shell: "oc -n openshift-migration logs $(oc get pods -n openshift-migration -l component=velero -o name)| tail -1" + register: velero_last_log + until: velero_last_log.rc == 0 + + - name: Execute migration + include_role: + name: migration_run + + - name: Wait until velero reports a connection problem and retries once at least + shell: "oc -n openshift-migration logs $(oc get pods -n openshift-migration -l component=velero -o name) | tail -100" + register: velero_log + retries: 45 + delay: 10 + until: > + velero_log.rc == 0 and + ( + velero_log.stdout|replace('\n', '') is search( velero_last_log.stdout_lines[-1] + '.*copying image.*' + namespace+ '.*#0 failed, waiting.*#1 failed, waiting.*#2 failed, waiting') or + ( + not velero_log.stdout|replace('\n', '') is search( velero_last_log.stdout_lines[-1]) and + velero_log.stdout|replace('\n', '') is search( 'copying image.*' + namespace+ '.*#0 failed, waiting [0-9+]s and then retrying') + ) + ) + + always: + - name: Enable internal registry to fix the connection problem + import_tasks: enable_internal_registry.yml + when: with_migrate|bool diff --git a/roles/ocp-32075-retry/tasks/track.yml b/roles/ocp-32075-retry/tasks/track.yml new file mode 100644 index 0000000..8a3cf7c --- /dev/null +++ b/roles/ocp-32075-retry/tasks/track.yml @@ -0,0 +1,3 @@ +- name: Track migration + include_role: + name: migration_track diff --git a/roles/ocp-32075-retry/tasks/validate-source.yml b/roles/ocp-32075-retry/tasks/validate-source.yml new file mode 100644 index 0000000..56f1431 --- /dev/null +++ b/roles/ocp-32075-retry/tasks/validate-source.yml @@ -0,0 +1,55 @@ +- name: Check postgresql pod status + k8s_facts: + kind: Pod + namespace: "{{ namespace }}" + label_selectors: "name=postgresql" + field_selectors: + - status.phase=Running + register: psqlpod + until: "true in (psqlpod | json_query('resources[].status.containerStatuses[].ready'))" + retries: 30 + +- name: Check application pod status + k8s_facts: + kind: Pod + namespace: "{{ namespace }}" + label_selectors: "name=django-psql-persistent" + field_selectors: + - status.phase=Running + register: apppod + until: "true in (apppod | json_query('resources[].status.containerStatuses[].ready'))" + retries: 30 + +- name: Get route + k8s_facts: + kind: Route + namespace: "{{ namespace }}" + label_selectors: "app=django-psql-persistent" + register: app_route + until: app_route.resources | length > 0 + retries: 30 + +- name: Acces the html file + uri: + url: http://{{ app_route.resources[0].spec.host }} + method: GET + status_code: 200 + return_content: true + register: page_content + until: page_content.status == 200 + with_sequence: "1-{{ num_visits }}" + +# /health uri will return the number of visits that the database has stored +- name: Get num visits up to now + uri: + url: http://{{ app_route.resources[0].spec.host }}/health + method: GET + status_code: 200 + return_content: true + register: django_num_visits + until: django_num_visits.status == 200 + +- name: Check num visits + fail: + msg: "Num visits has not the expected value. It should be {{ num_visits }} and the value retreived was {{ django_num_visits.content }}" + when: django_num_visits.content|int != num_visits|int diff --git a/roles/ocp-32075-retry/tasks/validate-target.yml b/roles/ocp-32075-retry/tasks/validate-target.yml new file mode 100644 index 0000000..bca7a6e --- /dev/null +++ b/roles/ocp-32075-retry/tasks/validate-target.yml @@ -0,0 +1,53 @@ +- name: Check mysql pod status + k8s_facts: + kind: Pod + namespace: "{{ namespace }}" + label_selectors: "name=postgresql" + field_selectors: + - status.phase=Running + register: psqlpod + until: "true in (psqlpod | json_query('resources[].status.containerStatuses[].ready'))" + retries: 30 + +- name: Check application pod status + k8s_facts: + kind: Pod + namespace: "{{ namespace }}" + label_selectors: "name=django-psql-persistent" + field_selectors: + - status.phase=Running + register: apppod + until: "true in (apppod | json_query('resources[].status.containerStatuses[].ready'))" + retries: 30 + +- name: Get route + k8s_facts: + kind: Route + namespace: "{{ namespace }}" + label_selectors: "app=django-psql-persistent" + register: app_route + until: app_route.resources | length > 0 + retries: 30 + +- name: Acces the html file + uri: + url: http://{{ app_route.resources[0].spec.host }} + method: GET + status_code: 200 + return_content: true + register: page_content + +# /health uri will return the number of visits that the database has stored +- name: Get num visits up to now + uri: + url: http://{{ app_route.resources[0].spec.host }}/health + method: GET + status_code: 200 + return_content: true + register: django_num_visits + until: django_num_visits.status == 200 + +- name: Check num visits + fail: + msg: "Num visits has not the expected value. It should be {{ num_visits + 1 }} and the value retreived was {{ fact_cake_num_visits }}" + when: django_num_visits.content|int != (num_visits|int + 1)