updated replication integration tests, added testing for mysql 5.7 (#7)

Co-authored-by: Ben Mildren <bmildren@digitalocean.com>
This commit is contained in:
Ben Mildren 2020-07-14 14:13:16 +01:00 committed by GitHub
commit ac79b437c8
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
17 changed files with 497 additions and 491 deletions

View file

@ -0,0 +1,14 @@
# 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)
# Initial CI tests of mysql_replication module:
- import_tasks: mysql_replication_initial.yml
# Tests of master_delay parameter:
- import_tasks: mysql_replication_master_delay.yml
# Tests of channel parameter:
- import_tasks: mysql_replication_channel.yml
# Tests of resetmaster mode:
- import_tasks: mysql_replication_resetmaster_mode.yml

View file

@ -0,0 +1,113 @@
# 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)
- vars:
mysql_params: &mysql_params
login_user: '{{ mysql_user }}'
login_password: '{{ mysql_password }}'
login_host: 127.0.0.1
block:
# Get master log file and log pos:
- name: Get master status
mysql_replication:
<<: *mysql_params
login_port: '{{ mysql_primary_port }}'
mode: getmaster
register: mysql_primary_status
# Test changemaster mode:
- name: Run replication with channel
mysql_replication:
<<: *mysql_params
login_port: '{{ mysql_replica2_port }}'
mode: changemaster
master_host: '{{ mysql_host }}'
master_port: '{{ mysql_primary_port }}'
master_user: '{{ replication_user }}'
master_password: '{{ replication_pass }}'
master_log_file: '{{ mysql_primary_status.File }}'
master_log_pos: '{{ mysql_primary_status.Position }}'
channel: '{{ test_channel }}'
register: result
- 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 }} FOR CHANNEL '{{ test_channel }}'"]
# Test startslave mode:
- name: Start slave with channel
mysql_replication:
<<: *mysql_params
login_port: '{{ mysql_replica2_port }}'
mode: startslave
channel: '{{ test_channel }}'
register: result
- assert:
that:
- result is changed
- result.queries == ["START SLAVE FOR CHANNEL '{{ test_channel }}'"]
# Test getslave mode:
- name: Get standby status with channel
mysql_replication:
<<: *mysql_params
login_port: '{{ mysql_replica2_port }}'
mode: getslave
channel: '{{ test_channel }}'
register: slave_status
- assert:
that:
- slave_status.Is_Slave == true
- slave_status.Master_Host == '{{ mysql_host }}'
- slave_status.Exec_Master_Log_Pos == mysql_primary_status.Position
- slave_status.Master_Port == {{ mysql_primary_port }}
- slave_status.Last_IO_Errno == 0
- slave_status.Last_IO_Error == ''
- slave_status.Channel_Name == '{{ test_channel }}'
- slave_status is not changed
# Test stopslave mode:
- name: Stop slave with channel
mysql_replication:
<<: *mysql_params
login_port: '{{ mysql_replica2_port }}'
mode: stopslave
channel: '{{ test_channel }}'
register: result
- assert:
that:
- result is changed
- result.queries == ["STOP SLAVE FOR CHANNEL '{{ test_channel }}'"]
# Test reset
- name: Reset slave with channel
mysql_replication:
<<: *mysql_params
login_port: '{{ mysql_replica2_port }}'
mode: resetslave
channel: '{{ test_channel }}'
register: result
- assert:
that:
- result is changed
- result.queries == ["RESET SLAVE FOR CHANNEL '{{ test_channel }}'"]
# Test reset all
- name: Reset slave all with channel
mysql_replication:
<<: *mysql_params
login_port: '{{ mysql_replica2_port }}'
mode: resetslaveall
channel: '{{ test_channel }}'
register: result
- assert:
that:
- result is changed
- result.queries == ["RESET SLAVE ALL FOR CHANNEL '{{ test_channel }}'"]

View file

@ -0,0 +1,204 @@
# 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)
- vars:
mysql_params: &mysql_params
login_user: '{{ mysql_user }}'
login_password: '{{ mysql_password }}'
login_host: 127.0.0.1
block:
- name: alias mysql command to include default options
set_fact:
mysql_command: "mysql -u{{ mysql_user }} -p{{ mysql_password }} --protocol=tcp"
# Preparation:
- name: Create user for replication
shell: "echo \"CREATE USER '{{ replication_user }}'@'localhost' IDENTIFIED WITH mysql_native_password BY '{{ replication_pass }}'; GRANT REPLICATION SLAVE ON *.* TO '{{ replication_user }}'@'localhost';\" | {{ mysql_command }} -P{{ mysql_primary_port }}"
- name: Create test database
mysql_db:
<<: *mysql_params
login_port: '{{ mysql_primary_port }}'
state: present
name: '{{ test_db }}'
- name: Dump all databases from the primary
shell: 'mysqldump -u{{ mysql_user }} -p{{ mysql_password }} -h{{ mysql_host }} --protocol=tcp -P{{ mysql_primary_port }} --all-databases --ignore-table=mysql.innodb_index_stats --ignore-table=mysql.innodb_table_stats --master-data=2 > {{ dump_path }}'
- name: Restore the dump to replica1
shell: '{{ mysql_command }} -P{{ mysql_replica1_port }} < {{ dump_path }}'
- name: Restore the dump to replica2
shell: '{{ mysql_command }} -P{{ mysql_replica2_port }} < {{ dump_path }}'
# Test getmaster mode:
- name: Get master status
mysql_replication:
<<: *mysql_params
login_port: '{{ mysql_primary_port }}'
mode: getmaster
register: mysql_primary_status
- assert:
that:
- mysql_primary_status.Is_Master == true
- mysql_primary_status.Position != 0
- mysql_primary_status is not changed
# Test startslave fails without changemaster first. This needs fail_on_error
- name: Start slave and fail because master is not specified; failing on error as requested
mysql_replication:
<<: *mysql_params
login_port: '{{ mysql_replica1_port }}'
mode: startslave
fail_on_error: yes
register: result
ignore_errors: yes
- assert:
that:
- result is failed
# Test startslave doesn't fail if fail_on_error: no
- name: Start slave and fail without propagating it to ansible as we were asked not to
mysql_replication:
<<: *mysql_params
login_port: '{{ mysql_replica1_port }}'
mode: startslave
fail_on_error: no
register: result
- assert:
that:
- result is not failed
# Test startslave doesn't fail if there is no fail_on_error.
# This is suboptimal because nothing happens, but it's the old behavior.
- name: Start slave and fail without propagating it to ansible as previous versions did not fail on error
mysql_replication:
<<: *mysql_params
login_port: '{{ mysql_replica1_port }}'
mode: startslave
register: result
- assert:
that:
- result is not failed
# Test changemaster mode:
# master_ssl_ca will be set as '' to check the module's behaviour for #23976,
# must be converted to an empty string
- name: Run replication
mysql_replication:
<<: *mysql_params
login_port: '{{ mysql_replica1_port }}'
mode: changemaster
master_host: '{{ mysql_host }}'
master_port: '{{ mysql_primary_port }}'
master_user: '{{ replication_user }}'
master_password: '{{ replication_pass }}'
master_log_file: '{{ mysql_primary_status.File }}'
master_log_pos: '{{ mysql_primary_status.Position }}'
master_ssl_ca: ''
register: result
- 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_CA=''"]
# Test startslave mode:
- name: Start slave
mysql_replication:
<<: *mysql_params
login_port: '{{ mysql_replica1_port }}'
mode: startslave
register: result
- assert:
that:
- result is changed
- result.queries == ["START SLAVE"]
# Test getslave mode:
- name: Get standby status
mysql_replication:
<<: *mysql_params
login_port: '{{ mysql_replica1_port }}'
mode: getslave
register: slave_status
- assert:
that:
- slave_status.Is_Slave == true
- slave_status.Master_Host == '{{ mysql_host }}'
- slave_status.Exec_Master_Log_Pos == mysql_primary_status.Position
- slave_status.Master_Port == {{ mysql_primary_port }}
- slave_status.Last_IO_Errno == 0
- slave_status.Last_IO_Error == ''
- slave_status is not changed
# Create test table and add data to it:
- name: Create test table
shell: "echo \"CREATE TABLE {{ test_table }} (id int);\" | {{ mysql_command }} -P{{ mysql_primary_port }} {{ test_db }}"
- name: Insert data
shell: "echo \"INSERT INTO {{ test_table }} (id) VALUES (1), (2), (3); FLUSH LOGS;\" | {{ mysql_command }} -P{{ mysql_primary_port }} {{ test_db }}"
- name: Small pause to be sure the bin log, which was flushed previously, reached the slave
pause:
seconds: 2
# Test master log pos has been changed:
- name: Get standby status
mysql_replication:
<<: *mysql_params
login_port: '{{ mysql_replica1_port }}'
mode: getslave
register: slave_status
# mysql_primary_status.Position is not actual and it has been changed by the prev step,
# so slave_status.Exec_Master_Log_Pos must be different:
- assert:
that:
- slave_status.Exec_Master_Log_Pos != mysql_primary_status.Position
- name: Start slave that is already running
mysql_replication:
<<: *mysql_params
login_port: '{{ mysql_replica1_port }}'
mode: startslave
fail_on_error: true
register: result
- assert:
that:
- result is not changed
# Test stopslave mode:
- name: Stop slave
mysql_replication:
<<: *mysql_params
login_port: '{{ mysql_replica1_port }}'
mode: stopslave
register: result
- assert:
that:
- result is changed
- result.queries == ["STOP SLAVE"]
# Test stopslave mode:
- name: Stop slave that is no longer running
mysql_replication:
<<: *mysql_params
login_port: '{{ mysql_replica1_port }}'
mode: stopslave
fail_on_error: true
register: result
- assert:
that:
- result is not changed

View file

@ -0,0 +1,45 @@
# 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)
- vars:
mysql_params: &mysql_params
login_user: '{{ mysql_user }}'
login_password: '{{ mysql_password }}'
login_host: 127.0.0.1
block:
# Test master_delay mode:
- name: Run replication
mysql_replication:
<<: *mysql_params
login_port: '{{ mysql_replica1_port }}'
mode: changemaster
master_delay: '{{ test_master_delay }}'
register: result
- assert:
that:
- result is changed
- result.queries == ["CHANGE MASTER TO MASTER_DELAY=60"]
# Auxiliary step:
- name: Start slave
mysql_replication:
<<: *mysql_params
login_port: '{{ mysql_replica1_port }}'
mode: startslave
register: result
# Check master_delay:
- name: Get standby status
mysql_replication:
<<: *mysql_params
login_port: '{{ mysql_replica1_port }}'
mode: getslave
register: slave_status
- assert:
that:
- slave_status.SQL_Delay == {{ test_master_delay }}
- slave_status is not changed

View file

@ -0,0 +1,56 @@
# 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)
- vars:
mysql_params: &mysql_params
login_user: '{{ mysql_user }}'
login_password: '{{ mysql_password }}'
login_host: 127.0.0.1
block:
# Needs for further tests:
- name: Stop slave
mysql_replication:
<<: *mysql_params
login_port: '{{ mysql_replica1_port }}'
mode: stopslave
- name: Reset slave all
mysql_replication:
<<: *mysql_params
login_port: '{{ mysql_replica1_port }}'
mode: resetslaveall
# Get master initial status:
- name: Get master status
mysql_replication:
<<: *mysql_params
login_port: '{{ mysql_primary_port }}'
mode: getmaster
register: mysql_primary_initial_status
# Test resetmaster mode:
- name: Reset master
mysql_replication:
<<: *mysql_params
login_port: '{{ mysql_primary_port }}'
mode: resetmaster
register: result
- assert:
that:
- result is changed
- result.queries == ["RESET MASTER"]
# Get master final status:
- name: Get master status
mysql_replication:
<<: *mysql_params
login_port: '{{ mysql_primary_port }}'
mode: getmaster
register: mysql_primary_final_status
- assert:
that:
- mysql_primary_initial_status.File != mysql_primary_final_status.File