Skip to content

Commit 81ab18d

Browse files
chore: fix conditional statements should not include jinja 2 templating (#599)
Thanks to @tompal3 for your contribution
1 parent 8dfab12 commit 81ab18d

File tree

5 files changed

+87
-45
lines changed

5 files changed

+87
-45
lines changed

tests/integration/targets/setup_controller/tasks/verify.yml

Lines changed: 9 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -19,8 +19,11 @@
1919
- name: Assert that test container runs the expected MySQL/MariaDB version
2020
assert:
2121
that:
22-
- "'{{ primary_info.version.major }}.{{ primary_info.version.minor }}\
23-
.{{ primary_info.version.release }}' == '{{ db_version }}'"
22+
- registred_db_version == db_version
23+
vars:
24+
registred_db_version:
25+
"{{ primary_info.version.major }}.{{ primary_info.version.minor }}\
26+
.{{ primary_info.version.release }}"
2427

2528
- name: Assert that mysql_info module used the expected version of pymysql
2629
assert:
@@ -52,8 +55,9 @@
5255
- name: Assert that we run the expected ansible version
5356
assert:
5457
that:
55-
- >
56-
"{{ ansible_version.major }}.{{ ansible_version.minor }}"
57-
is version(test_ansible_version, '==')
58+
- ansible_running_version == test_ansible_version
59+
vars:
60+
ansible_running_version:
61+
"{{ ansible_version.major }}.{{ ansible_version.minor }}"
5862
when:
5963
- test_ansible_version != 'devel' # Devel will change overtime

tests/integration/targets/test_mysql_db/tasks/state_dump_import.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -339,7 +339,7 @@
339339
assert:
340340
that:
341341
- result is changed
342-
- "result.db =='{{ db_name }}'"
342+
- result.db == db_name
343343

344344
# - name: Dump and Import | Assert database was backed up successfully
345345
# command: "file {{ db_file_name }}"

tests/integration/targets/test_mysql_replication/tasks/mysql_replication_channel.yml

Lines changed: 52 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -34,8 +34,14 @@
3434

3535
- assert:
3636
that:
37-
- result is changed
38-
- result.queries == ["CHANGE MASTER TO MASTER_HOST='{{ mysql_host }}',MASTER_USER='{{ replication_user }}',MASTER_PASSWORD='********',MASTER_PORT={{ mysql_primary_port }},MASTER_LOG_FILE='{{ mysql_primary_status.File }}',MASTER_LOG_POS={{ mysql_primary_status.Position }} FOR CHANNEL '{{ test_channel }}'"]
37+
- result is changed
38+
- result.queries == result_query
39+
vars:
40+
result_query: ["CHANGE MASTER TO MASTER_HOST='{{ mysql_host }}',\
41+
MASTER_USER='{{ replication_user }}',MASTER_PASSWORD='********',\
42+
MASTER_PORT={{ mysql_primary_port }},MASTER_LOG_FILE=\
43+
'{{ mysql_primary_status.File }}',MASTER_LOG_POS=\
44+
{{ mysql_primary_status.Position }} FOR CHANNEL '{{ test_channel }}'"]
3945

4046
# Test startreplica mode:
4147
- name: Start replica with channel
@@ -48,8 +54,11 @@
4854

4955
- assert:
5056
that:
51-
- result is changed
52-
- result.queries == ["START SLAVE FOR CHANNEL '{{ test_channel }}'"] or result.queries == ["START REPLICA FOR CHANNEL '{{ test_channel }}'"]
57+
- result is changed
58+
- result.queries == result_query or result_query2
59+
vars:
60+
result_query: ["START SLAVE FOR CHANNEL '{{ test_channel }}'"]
61+
result_query2: ["START REPLICA FOR CHANNEL '{{ test_channel }}'"]
5362

5463
# Test getreplica mode:
5564
- name: Get standby status with channel
@@ -62,26 +71,34 @@
6271

6372
- assert:
6473
that:
65-
- replica_status.Is_Replica == true
66-
- replica_status.Master_Host == '{{ mysql_host }}'
67-
- replica_status.Exec_Master_Log_Pos == mysql_primary_status.Position
68-
- replica_status.Master_Port == {{ mysql_primary_port }}
69-
- replica_status.Last_IO_Errno == 0
70-
- replica_status.Last_IO_Error == ''
71-
- replica_status.Channel_Name == '{{ test_channel }}'
72-
- replica_status is not changed
74+
- replica_status.Is_Replica is truthy(convert_bool=True)
75+
- replica_status.Master_Host == mysql_host_value
76+
- replica_status.Exec_Master_Log_Pos == mysql_primary_status.Position
77+
- replica_status.Master_Port == mysql_primary_port_value
78+
- replica_status.Last_IO_Errno == 0
79+
- replica_status.Last_IO_Error == ''
80+
- replica_status.Channel_Name == test_channel_value
81+
- replica_status is not changed
82+
vars:
83+
mysql_host_value: '{{ mysql_host }}'
84+
mysql_primary_port_value: '{{ mysql_primary_port }}'
85+
test_channel_value: '{{ test_channel }}'
7386
when: mysql8022_and_higher == false
7487

7588
- assert:
7689
that:
77-
- replica_status.Is_Replica == true
78-
- replica_status.Source_Host == '{{ mysql_host }}'
79-
- replica_status.Exec_Source_Log_Pos == mysql_primary_status.Position
80-
- replica_status.Source_Port == {{ mysql_primary_port }}
81-
- replica_status.Last_IO_Errno == 0
82-
- replica_status.Last_IO_Error == ''
83-
- replica_status.Channel_Name == '{{ test_channel }}'
84-
- replica_status is not changed
90+
- replica_status.Is_Replica is truthy(convert_bool=True)
91+
- replica_status.Source_Host == mysql_host_value
92+
- replica_status.Exec_Source_Log_Pos == mysql_primary_status.Position
93+
- replica_status.Source_Port == mysql_primary_port_value
94+
- replica_status.Last_IO_Errno == 0
95+
- replica_status.Last_IO_Error == ''
96+
- replica_status.Channel_Name == test_channel_value
97+
- replica_status is not changed
98+
vars:
99+
mysql_host_value: '{{ mysql_host }}'
100+
mysql_primary_port_value: '{{ mysql_primary_port }}'
101+
test_channel_value: '{{ test_channel }}'
85102
when: mysql8022_and_higher == true
86103

87104

@@ -96,8 +113,11 @@
96113

97114
- assert:
98115
that:
99-
- result is changed
100-
- result.queries == ["STOP SLAVE FOR CHANNEL '{{ test_channel }}'"] or result.queries == ["STOP REPLICA FOR CHANNEL '{{ test_channel }}'"]
116+
- result is changed
117+
- result.queries == result_query or result.queries == result_query2
118+
vars:
119+
result_query: ["STOP SLAVE FOR CHANNEL '{{ test_channel }}'"]
120+
result_query2: ["STOP REPLICA FOR CHANNEL '{{ test_channel }}'"]
101121

102122
# Test reset
103123
- name: Reset replica with channel
@@ -110,8 +130,11 @@
110130

111131
- assert:
112132
that:
113-
- result is changed
114-
- result.queries == ["RESET SLAVE FOR CHANNEL '{{ test_channel }}'"] or result.queries == ["RESET REPLICA FOR CHANNEL '{{ test_channel }}'"]
133+
- result is changed
134+
- result.queries == result_query or result.queries == result_query2
135+
vars:
136+
result_query: ["RESET SLAVE FOR CHANNEL '{{ test_channel }}'"]
137+
result_query2: ["RESET REPLICA FOR CHANNEL '{{ test_channel }}'"]
115138

116139
# Test reset all
117140
- name: Reset replica all with channel
@@ -124,5 +147,8 @@
124147

125148
- assert:
126149
that:
127-
- result is changed
128-
- result.queries == ["RESET SLAVE ALL FOR CHANNEL '{{ test_channel }}'"] or result.queries == ["RESET REPLICA ALL FOR CHANNEL '{{ test_channel }}'"]
150+
- result is changed
151+
- result.queries == result_query or result.queries == result_query2
152+
vars:
153+
result_query: ["RESET SLAVE ALL FOR CHANNEL '{{ test_channel }}'"]
154+
result_query2: ["RESET REPLICA ALL FOR CHANNEL '{{ test_channel }}'"]

tests/integration/targets/test_mysql_replication/tasks/mysql_replication_initial.yml

Lines changed: 21 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -158,7 +158,13 @@
158158
assert:
159159
that:
160160
- result is changed
161-
- result.queries == ["CHANGE MASTER TO MASTER_HOST='{{ mysql_host }}',MASTER_USER='{{ replication_user }}',MASTER_PASSWORD='********',MASTER_PORT={{ mysql_primary_port }},MASTER_LOG_FILE='{{ mysql_primary_status.File }}',MASTER_LOG_POS={{ mysql_primary_status.Position }},MASTER_SSL=0,MASTER_SSL_CA=''"]
161+
- result.queries == expected_queries
162+
vars:
163+
expected_queries: ["CHANGE MASTER TO MASTER_HOST='{{ mysql_host }}',\
164+
MASTER_USER='{{ replication_user }}',MASTER_PASSWORD='********',\
165+
MASTER_PORT={{ mysql_primary_port }},MASTER_LOG_FILE=\
166+
'{{ mysql_primary_status.File }}',MASTER_LOG_POS=\
167+
{{ mysql_primary_status.Position }},MASTER_SSL=0,MASTER_SSL_CA=''"]
162168

163169
# Test startreplica mode:
164170
- name: Start replica
@@ -185,26 +191,32 @@
185191
- name: Assert that getreplica returns expected values for MySQL older than 8.0.22 and Mariadb
186192
assert:
187193
that:
188-
- replica_status.Is_Replica == true
189-
- replica_status.Master_Host == '{{ mysql_host }}'
194+
- replica_status.Is_Replica is truthy(convert_bool=True)
195+
- replica_status.Master_Host == mysql_host_value
190196
- replica_status.Exec_Master_Log_Pos == mysql_primary_status.Position
191-
- replica_status.Master_Port == {{ mysql_primary_port }}
197+
- replica_status.Master_Port == mysql_primary_port_value
192198
- replica_status.Last_IO_Errno == 0
193199
- replica_status.Last_IO_Error == ''
194200
- replica_status is not changed
195-
when: mysql8022_and_higher == false
201+
vars:
202+
mysql_host_value: "{{ mysql_host }}"
203+
mysql_primary_port_value: "{{ mysql_primary_port }}"
204+
when: mysql8022_and_higher is falsy(convert_bool=True)
196205

197206
- name: Assert that getreplica returns expected values for MySQL newer than 8.0.22
198207
assert:
199208
that:
200-
- replica_status.Is_Replica == true
201-
- replica_status.Source_Host == '{{ mysql_host }}'
209+
- replica_status.Is_Replica is truthy(convert_bool=True)
210+
- replica_status.Source_Host == mysql_host_value
202211
- replica_status.Exec_Source_Log_Pos == mysql_primary_status.Position
203-
- replica_status.Source_Port == {{ mysql_primary_port }}
212+
- replica_status.Source_Port == mysql_primary_port_value
204213
- replica_status.Last_IO_Errno == 0
205214
- replica_status.Last_IO_Error == ''
206215
- replica_status is not changed
207-
when: mysql8022_and_higher == true
216+
vars:
217+
mysql_host_value: "{{ mysql_host }}"
218+
mysql_primary_port_value: "{{ mysql_primary_port }}"
219+
when: mysql8022_and_higher is truthy(convert_bool=True)
208220

209221
# Create test table and add data to it:
210222
- name: Create test table

tests/integration/targets/test_mysql_user/tasks/main.yml

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -117,8 +117,8 @@
117117
- name: Assert grant access for user1 on multiple database
118118
assert:
119119
that:
120-
- "'{{ item }}' in result.stdout"
121-
with_items: "{{ db_names }}"
120+
- item in result.stdout
121+
loop: "{{ db_names }}"
122122

123123
- name: Show grants access for user2 on multiple database
124124
command: "{{ mysql_command }} -e \"SHOW GRANTS FOR '{{ user_name_2 }}'@'localhost'\""
@@ -127,8 +127,8 @@
127127
- name: Assert grant access for user2 on multiple database
128128
assert:
129129
that:
130-
- "'{{ item }}' in result.stdout"
131-
with_items: "{{db_names}}"
130+
- item in result.stdout
131+
loop: "{{db_names}}"
132132

133133
- include_tasks: utils/remove_user.yml
134134
vars:

0 commit comments

Comments
 (0)