mirror of
https://github.com/ansible-collections/community.mysql.git
synced 2025-04-27 04:41:28 -07:00
Add unique test names
This commit is contained in:
parent
a646e76e87
commit
91e76d190e
2 changed files with 90 additions and 77 deletions
|
@ -1,3 +1,4 @@
|
|||
---
|
||||
# Copyright: (c) 2019, Andrew Klychkov (@Andersson007) <aaklychkov@mail.ru>
|
||||
# GNU General Public License v3.0+ (see COPYING or https://www.gnu.org/licenses/gpl-3.0.txt)
|
||||
|
||||
|
@ -85,7 +86,8 @@
|
|||
mode: getprimary
|
||||
register: mysql_primary_status
|
||||
|
||||
- assert:
|
||||
- name: Assert that primary is in expected state
|
||||
assert:
|
||||
that:
|
||||
- mysql_primary_status.Is_Primary == true
|
||||
- mysql_primary_status.Position != 0
|
||||
|
@ -102,9 +104,10 @@
|
|||
register: result
|
||||
ignore_errors: yes
|
||||
|
||||
- assert:
|
||||
- name: Assert that startreplica is failed
|
||||
assert:
|
||||
that:
|
||||
- result is failed
|
||||
- result is failed
|
||||
|
||||
# Test startreplica doesn't fail if fail_on_error: no
|
||||
- name: Start replica and fail without propagating it to ansible as we were asked not to
|
||||
|
@ -115,9 +118,10 @@
|
|||
fail_on_error: no
|
||||
register: result
|
||||
|
||||
- assert:
|
||||
- name: Assert that startreplica succeeded
|
||||
assert:
|
||||
that:
|
||||
- result is not failed
|
||||
- result is not failed
|
||||
|
||||
# Test startreplica doesn't fail if there is no fail_on_error.
|
||||
# This is suboptimal because nothing happens, but it's the old behavior.
|
||||
|
@ -128,9 +132,10 @@
|
|||
mode: startreplica
|
||||
register: result
|
||||
|
||||
- assert:
|
||||
- name: Assert that start replica succeeded again
|
||||
assert:
|
||||
that:
|
||||
- result is not failed
|
||||
- result is not failed
|
||||
|
||||
# Test changeprimary mode:
|
||||
# primary_ssl_ca will be set as '' to check the module's behaviour for #23976,
|
||||
|
@ -150,10 +155,11 @@
|
|||
primary_ssl: no
|
||||
register: result
|
||||
|
||||
- assert:
|
||||
- name: Assert that changeprimmary is changed and return expected query
|
||||
assert:
|
||||
that:
|
||||
- result is changed
|
||||
- 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=''"]
|
||||
- result is changed
|
||||
- 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=''"]
|
||||
|
||||
# Test startreplica mode:
|
||||
- name: Start replica
|
||||
|
@ -163,10 +169,11 @@
|
|||
mode: startreplica
|
||||
register: result
|
||||
|
||||
- assert:
|
||||
- name: Assert that startreplica is changed and returns expected query
|
||||
assert:
|
||||
that:
|
||||
- result is changed
|
||||
- result.queries == ["START SLAVE"] or result.queries == ["START REPLICA"]
|
||||
- result is changed
|
||||
- result.queries == ["START SLAVE"] or result.queries == ["START REPLICA"]
|
||||
|
||||
# Test getreplica mode:
|
||||
- name: Get replica status
|
||||
|
@ -176,26 +183,28 @@
|
|||
mode: getreplica
|
||||
register: replica_status
|
||||
|
||||
- assert:
|
||||
- name: Assert that getreplica returns expected values for MySQL older than 8.0.22 and Mariadb
|
||||
assert:
|
||||
that:
|
||||
- replica_status.Is_Replica == true
|
||||
- replica_status.Master_Host == '{{ mysql_host }}'
|
||||
- replica_status.Exec_Master_Log_Pos == mysql_primary_status.Position
|
||||
- replica_status.Master_Port == {{ mysql_primary_port }}
|
||||
- replica_status.Last_IO_Errno == 0
|
||||
- replica_status.Last_IO_Error == ''
|
||||
- replica_status is not changed
|
||||
- replica_status.Is_Replica == true
|
||||
- replica_status.Master_Host == '{{ mysql_host }}'
|
||||
- replica_status.Exec_Master_Log_Pos == mysql_primary_status.Position
|
||||
- replica_status.Master_Port == {{ mysql_primary_port }}
|
||||
- replica_status.Last_IO_Errno == 0
|
||||
- replica_status.Last_IO_Error == ''
|
||||
- replica_status is not changed
|
||||
when: mysql8022_and_higher == false
|
||||
|
||||
- assert:
|
||||
- name: Assert that getreplica returns expected values for MySQL newer than 8.0.22
|
||||
assert:
|
||||
that:
|
||||
- replica_status.Is_Replica == true
|
||||
- replica_status.Source_Host == '{{ mysql_host }}'
|
||||
- replica_status.Exec_Source_Log_Pos == mysql_primary_status.Position
|
||||
- replica_status.Source_Port == {{ mysql_primary_port }}
|
||||
- replica_status.Last_IO_Errno == 0
|
||||
- replica_status.Last_IO_Error == ''
|
||||
- replica_status is not changed
|
||||
- replica_status.Is_Replica == true
|
||||
- replica_status.Source_Host == '{{ mysql_host }}'
|
||||
- replica_status.Exec_Source_Log_Pos == mysql_primary_status.Position
|
||||
- replica_status.Source_Port == {{ mysql_primary_port }}
|
||||
- replica_status.Last_IO_Errno == 0
|
||||
- replica_status.Last_IO_Error == ''
|
||||
- replica_status is not changed
|
||||
when: mysql8022_and_higher == true
|
||||
|
||||
# Create test table and add data to it:
|
||||
|
@ -219,19 +228,18 @@
|
|||
|
||||
# mysql_primary_status.Position is not actual and it has been changed by the prev step,
|
||||
# so replica_status.Exec_Master_Log_Pos must be different:
|
||||
- assert:
|
||||
- name: Assert that getreplica Log_Pos is different for MySQL older than 8.0.22 and MariaDB
|
||||
assert:
|
||||
that:
|
||||
- replica_status.Exec_Master_Log_Pos != mysql_primary_status.Position
|
||||
- replica_status.Exec_Master_Log_Pos != mysql_primary_status.Position
|
||||
when: mysql8022_and_higher == false
|
||||
|
||||
- assert:
|
||||
- name: Assert that getreplica Log_Pos is different for MySQL newer than 8.0.22
|
||||
assert:
|
||||
that:
|
||||
- replica_status.Exec_Source_Log_Pos != mysql_primary_status.Position
|
||||
- replica_status.Exec_Source_Log_Pos != mysql_primary_status.Position
|
||||
when: mysql8022_and_higher == true
|
||||
|
||||
- shell: pip show pymysql | awk '/Version/ {print $2}'
|
||||
register: pymysql_version
|
||||
|
||||
- name: Start replica that is already running
|
||||
mysql_replication:
|
||||
<<: *mysql_params
|
||||
|
@ -241,7 +249,8 @@
|
|||
register: result
|
||||
|
||||
# mysqlclient 2.0.1 always return "changed"
|
||||
- assert:
|
||||
- name: Assert that startreplica is not changed
|
||||
assert:
|
||||
that:
|
||||
- result is not changed
|
||||
when:
|
||||
|
@ -255,10 +264,11 @@
|
|||
mode: stopreplica
|
||||
register: result
|
||||
|
||||
- assert:
|
||||
- name: Assert that stopreplica is changed and returns expected query
|
||||
assert:
|
||||
that:
|
||||
- result is changed
|
||||
- result.queries == ["STOP SLAVE"] or result.queries == ["STOP REPLICA"]
|
||||
- result is changed
|
||||
- result.queries == ["STOP SLAVE"] or result.queries == ["STOP REPLICA"]
|
||||
|
||||
- name: Pause for 2 seconds to let the replication stop
|
||||
ansible.builtin.wait_for:
|
||||
|
@ -274,7 +284,8 @@
|
|||
fail_on_error: true
|
||||
register: result
|
||||
|
||||
- assert:
|
||||
- name: Assert that stopreplica is not changed
|
||||
assert:
|
||||
that:
|
||||
- result is not changed
|
||||
when:
|
||||
|
@ -291,7 +302,8 @@
|
|||
register: result
|
||||
ignore_errors: yes
|
||||
|
||||
- assert:
|
||||
- name: Assert that stopslave returns expected error message
|
||||
assert:
|
||||
that:
|
||||
- result.msg == "value of mode must be one of{{ ":" }} getprimary, getreplica, changeprimary, stopreplica, startreplica, resetprimary, resetreplica, resetreplicaall, got{{ ":" }} stopslave"
|
||||
- result is failed
|
||||
- result.msg == "value of mode must be one of{{ ":" }} getprimary, getreplica, changeprimary, stopreplica, startreplica, resetprimary, resetreplica, resetreplicaall, got{{ ":" }} stopslave"
|
||||
- result is failed
|
||||
|
|
|
@ -1,3 +1,4 @@
|
|||
---
|
||||
# Test code for mysql_role module
|
||||
|
||||
- vars:
|
||||
|
@ -32,8 +33,8 @@
|
|||
when:
|
||||
- srv['version']['major'] < 8
|
||||
|
||||
# Skip unsupported versions
|
||||
- meta: end_play
|
||||
- name: Skip unsupported versions
|
||||
meta: end_play
|
||||
when: srv['version']['major'] < 8
|
||||
|
||||
#########
|
||||
|
@ -80,13 +81,13 @@
|
|||
name: '{{ role0 }}'
|
||||
state: present
|
||||
members:
|
||||
- '{{ user0 }}@{{ gateway_addr }}'
|
||||
- '{{ user0 }}@{{ gateway_addr }}'
|
||||
check_mode: yes
|
||||
|
||||
- name: Check
|
||||
- name: Assert that create role0 is changed
|
||||
assert:
|
||||
that:
|
||||
- result is changed
|
||||
- result is changed
|
||||
|
||||
- name: Check in DB
|
||||
<<: *task_params
|
||||
|
@ -94,13 +95,13 @@
|
|||
<<: *mysql_params
|
||||
query: "SELECT 1 FROM mysql.user WHERE User = '{{ role0 }}'"
|
||||
|
||||
- name: Check
|
||||
- name: Assert that user is not in mysql.user
|
||||
assert:
|
||||
that:
|
||||
- result.rowcount.0 == 0
|
||||
- result.rowcount.0 == 0
|
||||
|
||||
# It must fail because of check_mode
|
||||
- name: Check in DB, if not granted, the query will fail
|
||||
- name: Check in DB, if not granted, the query will fail (expect failure)
|
||||
<<: *task_params
|
||||
mysql_query:
|
||||
<<: *mysql_params
|
||||
|
@ -108,10 +109,10 @@
|
|||
ignore_errors: yes
|
||||
when: db_engine == 'mysql'
|
||||
|
||||
- name: Check
|
||||
- name: Assert that show grants is failed
|
||||
assert:
|
||||
that:
|
||||
- result is failed
|
||||
- result is failed
|
||||
when: db_engine == 'mysql'
|
||||
|
||||
- name: Check in DB (mariadb)
|
||||
|
@ -121,13 +122,13 @@
|
|||
query: "SELECT count(User) as user_roles FROM mysql.roles_mapping WHERE User = '{{ user0 }}' AND Host = '{{ gateway_addr }}' AND Role = '{{ role0 }}'"
|
||||
when: db_engine == 'mariadb'
|
||||
|
||||
- name: Check (mariadb)
|
||||
- name: Assert that user is not in mysql.roles_mapping (mariadb)
|
||||
assert:
|
||||
that:
|
||||
- result.query_result.0.0['user_roles'] == 0
|
||||
- result.query_result.0.0['user_roles'] == 0
|
||||
when: db_engine == 'mariadb'
|
||||
|
||||
#=====================
|
||||
# =====================
|
||||
|
||||
- name: Check that the user have no active roles
|
||||
<<: *task_params
|
||||
|
@ -138,10 +139,10 @@
|
|||
login_port: '{{ mysql_primary_port }}'
|
||||
query: 'SELECT COALESCE(current_role(), "NONE") as "current_role()"'
|
||||
|
||||
- name: Check
|
||||
- name: Assert that the user have no active roles
|
||||
assert:
|
||||
that:
|
||||
- result.query_result.0.0["current_role()"] == "NONE"
|
||||
- result.query_result.0.0["current_role()"] == "NONE"
|
||||
|
||||
- name: Create role {{ role0 }}
|
||||
<<: *task_params
|
||||
|
@ -150,12 +151,12 @@
|
|||
name: '{{ role0 }}'
|
||||
state: present
|
||||
members:
|
||||
- '{{ user0 }}@{{ gateway_addr }}'
|
||||
- '{{ user0 }}@{{ gateway_addr }}'
|
||||
|
||||
- name: Check
|
||||
- name: Assert that create role is changed
|
||||
assert:
|
||||
that:
|
||||
- result is changed
|
||||
- result is changed
|
||||
|
||||
- name: Check in DB
|
||||
<<: *task_params
|
||||
|
@ -163,10 +164,10 @@
|
|||
<<: *mysql_params
|
||||
query: "SELECT 1 FROM mysql.user WHERE User = '{{ role0 }}'"
|
||||
|
||||
- name: Check
|
||||
- name: Assert that tu role is in mysql.user
|
||||
assert:
|
||||
that:
|
||||
- result.rowcount.0 == 1
|
||||
- result.rowcount.0 == 1
|
||||
|
||||
- name: Check in DB, if not granted, the query will fail
|
||||
<<: *task_params
|
||||
|
@ -175,10 +176,10 @@
|
|||
query: "SHOW GRANTS FOR {{ user0 }}@{{ gateway_addr }} USING '{{ role0 }}'"
|
||||
when: db_engine == 'mysql'
|
||||
|
||||
- name: Check
|
||||
- name: Assert that show grants is succeeded (mysql)
|
||||
assert:
|
||||
that:
|
||||
- result is succeeded
|
||||
- result is succeeded
|
||||
when: db_engine == 'mysql'
|
||||
|
||||
- name: Check in DB (mariadb)
|
||||
|
@ -188,10 +189,10 @@
|
|||
query: "SELECT count(User) as user_roles FROM mysql.roles_mapping WHERE User = '{{ user0 }}' AND Host = '{{ gateway_addr }}' AND Role = '{{ role0 }}'"
|
||||
when: db_engine == 'mariadb'
|
||||
|
||||
- name: Check (mariadb)
|
||||
- name: Assert that role is in mysql.roles_mapping (mariadb)
|
||||
assert:
|
||||
that:
|
||||
- result.query_result.0.0['user_roles'] == 1
|
||||
- result.query_result.0.0['user_roles'] == 1
|
||||
when: db_engine == 'mariadb'
|
||||
|
||||
- name: Check that the role is active
|
||||
|
@ -204,10 +205,10 @@
|
|||
query: 'SELECT current_role()'
|
||||
when: db_engine == 'mysql'
|
||||
|
||||
- name: Check
|
||||
- name: Assert that current_role() returns role0
|
||||
assert:
|
||||
that:
|
||||
- "'{{ role0 }}' in result.query_result.0.0['current_role()']"
|
||||
- "'{{ role0 }}' in result.query_result.0.0['current_role()']"
|
||||
when: db_engine == 'mysql'
|
||||
|
||||
- name: Check that the role is active (mariadb)
|
||||
|
@ -222,13 +223,13 @@
|
|||
- 'SELECT current_role()'
|
||||
when: db_engine == 'mariadb'
|
||||
|
||||
- name: Check (mariadb)
|
||||
- name: Assert that role is active (mariadb)
|
||||
assert:
|
||||
that:
|
||||
- "'{{ role0 }}' in result.query_result.1.0['current_role()']"
|
||||
- "'{{ role0 }}' in result.query_result.1.0['current_role()']"
|
||||
when: db_engine == 'mariadb'
|
||||
|
||||
#========================
|
||||
# ========================
|
||||
|
||||
- name: Create role {{ role0 }} again in check_mode
|
||||
<<: *task_params
|
||||
|
@ -238,10 +239,10 @@
|
|||
state: present
|
||||
check_mode: yes
|
||||
|
||||
- name: Check
|
||||
- name: Assert that create role role0 again is not changed
|
||||
assert:
|
||||
that:
|
||||
- result is not changed
|
||||
- result is not changed
|
||||
|
||||
- name: Check in DB
|
||||
<<: *task_params
|
||||
|
@ -249,10 +250,10 @@
|
|||
<<: *mysql_params
|
||||
query: "SELECT 1 FROM mysql.user WHERE User = '{{ role0 }}'"
|
||||
|
||||
- name: Check
|
||||
- name: Assert that role role0 is present in the database
|
||||
assert:
|
||||
that:
|
||||
- result.rowcount.0 == 1
|
||||
- result.rowcount.0 == 1
|
||||
|
||||
- name: Check in DB, if not granted, the query will fail
|
||||
<<: *task_params
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue