forked from Azure/sap-automation-qa
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathprimary-node-kill.yml
More file actions
205 lines (188 loc) · 14 KB
/
primary-node-kill.yml
File metadata and controls
205 lines (188 loc) · 14 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
# Copyright (c) Microsoft Corporation.
# Licensed under the MIT License.
# /*---------------------------------------------------------------------------
# | Primary Node Kill |
# +--------------------------------------------------------------------------*/
- name: "Test Setup Tasks"
ansible.builtin.include_tasks: "roles/misc/tasks/test-case-setup.yml"
run_once: true
# /*---------------------------------------------------------------------------
# | Pre Validations |
# +--------------------------------------------------------------------------*/
- name: "Pre Validations: HANA DB Nodes"
ansible.builtin.include_tasks: "roles/misc/tasks/pre-validations-db.yml"
# /*---------------------------------------------------------------------------
# | Test Execution |
# +--------------------------------------------------------------------------*/
- name: "Test Execution: Primary Node Kill"
become: true
when:
- node_tier == "hana"
- pre_validations_status == "PASSED"
- saphanasr_provider | default('SAPHanaSR') == "SAPHanaSR-angi"
block:
- name: "Test Execution: Kill the primary node."
when: ansible_hostname == cluster_status_pre.primary_node
block:
- name: "Test Execution: Start timer"
ansible.builtin.set_fact:
test_execution_start: "{{ now(utc=true, fmt='%Y-%m-%d %H:%M:%S') }}"
test_execution_hostname: "{{ hostvars[cluster_status_pre.primary_node].ansible_hostname }}"
- name: "Test Execution: Kill the HANA DB"
become: true
become_user: "{{ db_sid | lower }}adm"
ansible.builtin.command: /usr/sap/{{ db_sid | upper }}/HDB{{ db_instance_number }}/HDB kill-9
register: hana_db_kill_results
changed_when: hana_db_kill_results == 0
failed_when: hana_db_kill_results.rc != 0
- name: "Test Execution: Validate HANA DB cluster status 1"
when: cluster_status_pre.AUTOMATED_REGISTER == "true"
get_cluster_status_db:
db_instance_number: "{{ db_instance_number }}"
operation_step: "test_execution"
database_sid: "{{ db_sid | lower }}"
saphanasr_provider: "{{ saphanasr_provider | default('SAPHanaSR') }}"
hana_clone_resource_name: "{{ hana_clone_resource_name | default('') }}"
hana_primitive_resource_name: "{{ hana_primitive_resource_name | default('') }}"
hana_topology: "{{ hana_topology | default('scale_up') }}"
register: cluster_status_test_execution
retries: "{{ default_retries }}"
delay: "{{ default_delay }}"
until: >
cluster_status_test_execution.primary_node != "" and
(
(hana_topology | default('scale_up') == 'scale_out_hsr' and
cluster_status_test_execution.primary_node in cluster_status_pre.secondary_site_nodes and
cluster_status_test_execution.primary_node != cluster_status_pre.primary_node and
cluster_status_test_execution.secondary_node != "")
or
(hana_topology | default('scale_up') != 'scale_out_hsr' and
cluster_status_test_execution.primary_node == cluster_status_pre.secondary_node and
cluster_status_test_execution.secondary_node == cluster_status_pre.primary_node)
)
- name: "Test Execution: Register Failed Resource when automated_register is false"
when: cluster_status_pre.AUTOMATED_REGISTER == "false"
block:
- name: "Test Execution: Validate HANA DB cluster status"
get_cluster_status_db:
db_instance_number: "{{ db_instance_number }}"
operation_step: "test_execution"
database_sid: "{{ db_sid | lower }}"
saphanasr_provider: "{{ saphanasr_provider | default('SAPHanaSR') }}"
hana_clone_resource_name: "{{ hana_clone_resource_name | default('') }}"
hana_primitive_resource_name: "{{ hana_primitive_resource_name | default('') }}"
hana_topology: "{{ hana_topology | default('scale_up') }}"
register: cluster_status_test_execution
retries: "{{ default_retries }}"
delay: "{{ default_delay }}"
until: >
cluster_status_test_execution.primary_node != "" and
(
(hana_topology | default('scale_up') == 'scale_out_hsr' and
cluster_status_test_execution.primary_node in cluster_status_pre.secondary_site_nodes and
cluster_status_test_execution.secondary_node == "")
or
(hana_topology | default('scale_up') != 'scale_out_hsr' and
cluster_status_test_execution.primary_node == cluster_status_pre.secondary_node and
cluster_status_test_execution.secondary_node == "")
)
- name: "Test Execution: Set facts for the failed resource"
ansible.builtin.set_fact:
replication_mode: "{{ cluster_status_pre.replication_mode }}"
primary_site_name: "{{ cluster_status_pre.primary_site_name }}"
operation_mode: "{{ cluster_status_pre.operation_mode }}"
- name: "Test Execution: Register the failed resource"
become: true
become_user: "{{ db_sid | lower }}adm"
ansible.builtin.shell: |
source /usr/sap/{{ db_sid | upper }}/HDB{{ db_instance_number | upper }}/HDBSettings.sh && \
/usr/sap/{{ db_sid | upper }}/HDB{{ db_instance_number }}/exe/hdbnsutil -sr_register \
--remoteHost={{ cluster_status_test_execution.primary_node }} \
--remoteInstance={{ db_instance_number }} \
--replicationMode={{ replication_mode }} \
--name={{ primary_site_name }} \
--operationMode={{ operation_mode }} --online
register: hana_db_register_failed_resource
args:
executable: /bin/bash
- name: "Test Execution: Stop timer"
ansible.builtin.set_fact:
test_execution_end: "{{ now(utc=true, fmt='%Y-%m-%d %H:%M:%S') }}"
- name: "Test Execution: CleanUp any failed resource"
ansible.builtin.command: "crm_resource --cleanup"
register: cleanup_failed_resource_post
changed_when: cleanup_failed_resource_post.rc == 0
ignore_errors: true
- name: "Test execution: Validate HANA DB cluster status 2"
get_cluster_status_db:
db_instance_number: "{{ db_instance_number }}"
operation_step: "post_failover"
database_sid: "{{ db_sid | lower }}"
saphanasr_provider: "{{ saphanasr_provider | default('SAPHanaSR') }}"
hana_clone_resource_name: "{{ hana_clone_resource_name | default('') }}"
hana_primitive_resource_name: "{{ hana_primitive_resource_name | default('') }}"
hana_topology: "{{ hana_topology | default('scale_up') }}"
register: cluster_status_post
retries: "{{ default_retries }}"
delay: "{{ default_delay }}"
until: >
cluster_status_post.primary_node != "" and
cluster_status_post.secondary_node != "" and
(
(hana_topology | default('scale_up') == 'scale_out_hsr' and
cluster_status_post.primary_node in cluster_status_pre.secondary_site_nodes and
cluster_status_post.primary_node != cluster_status_pre.primary_node)
or
(hana_topology | default('scale_up') != 'scale_out_hsr' and
cluster_status_post.primary_node == cluster_status_pre.secondary_node and
cluster_status_post.secondary_node == cluster_status_pre.primary_node)
)
- name: "Test Execution: Determine test execution status"
ansible.builtin.set_fact:
test_execution_status: "{{ 'PASSED' if (
(hana_topology | default('scale_up') == 'scale_out_hsr' and
cluster_status_post.primary_node in cluster_status_pre.secondary_site_nodes and
cluster_status_post.primary_node != cluster_status_pre.primary_node)
or
(hana_topology | default('scale_up') != 'scale_out_hsr' and
cluster_status_post.primary_node == cluster_status_pre.secondary_node and
cluster_status_post.secondary_node == cluster_status_pre.primary_node)
) else 'FAILED' }}"
- name: "Set test case message and details"
ansible.builtin.set_fact:
test_case_message_from_test_case: |
Old primary: {{ cluster_status_pre.primary_node }}
New primary: {{ cluster_status_post.primary_node }}
Old secondary: {{ cluster_status_pre.secondary_node }}
New secondary: {{ cluster_status_post.secondary_node }}
test_case_details_from_test_case: {
"Pre Validations: Remove any location_constraints": "{{ location_constraints_results }}",
"Pre Validations: Validate HANA DB cluster status": "{{ cluster_status_pre }}",
"Pre Validations: CleanUp any failed resource": "{{ cleanup_failed_resource_pre }}",
"Test Execution: Primary node crash": "{{ hana_db_kill_results }}",
"Post Validations: CleanUp any failed resource": "{{ cleanup_failed_resource_post }}",
"Post Validations: Validate HANA DB cluster status": "{{ cluster_status_post }}",
}
# /*---------------------------------------------------------------------------
# | Post Validations |
# +--------------------------------------------------------------------------*/
- name: "Post Validations Tasks"
ansible.builtin.include_tasks: "roles/misc/tasks/post-validations.yml"
rescue:
- name: "Rescue operation"
ansible.builtin.include_tasks: "roles/misc/tasks/rescue.yml"
- name: "Pre Validations: Test Case Skipped"
become: true
when: pre_validations_status == "FAILED"
block:
- name: "Set test case message and details"
ansible.builtin.set_fact:
test_case_message_from_test_case: "Pre Validations for HANA DB cluster status checks failed. Please check the details."
test_case_details_from_test_case: {
"Pre Validations: Remove any location_constraints": "{{ location_constraints_results }}",
"Pre Validations: Validate HANA DB cluster status": "{{ cluster_status_pre }}",
"Pre Validations: CleanUp any failed resource": "{{ cleanup_failed_resource_pre }}",
"Cluster Status": "{{ cluster_status_pre }}",
}
- name: "Post Validations Tasks"
ansible.builtin.include_tasks: "roles/misc/tasks/post-validations.yml"