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
parent c255d7ece2
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

@ -56,7 +56,8 @@ jobs:
fail-fast: false
matrix:
mysql:
- 8.0.20
- 5.7.31
- 8.0.21
ansible:
- stable-2.9
- stable-2.10

View file

@ -1,8 +0,0 @@
destructive
shippable/posix/group4
# Make sure that this test runs in a different group than mariadb_replication!
skip/aix
skip/osx
skip/freebsd
skip/rhel
needs/root

View file

@ -1,3 +0,0 @@
---
dependencies:
- setup_mysql_replication

View file

@ -1,119 +0,0 @@
# 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)
# Needs for further tests:
- name: Stop slave
mysql_replication:
login_host: 127.0.0.1
login_port: "{{ standby_port }}"
mode: stopslave
- name: Reset slave all
mysql_replication:
login_host: 127.0.0.1
login_port: "{{ standby_port }}"
mode: resetslaveall
# Get master log file and log pos:
- name: Get master status
mysql_replication:
login_host: 127.0.0.1
login_port: "{{ master_port }}"
mode: getmaster
register: master_status
# Test changemaster mode:
- name: Run replication with channel
mysql_replication:
login_host: 127.0.0.1
login_port: "{{ standby_port }}"
mode: changemaster
master_host: 127.0.0.1
master_port: "{{ master_port }}"
master_user: "{{ replication_user }}"
master_password: "{{ replication_pass }}"
master_log_file: "{{ master_status.File }}"
master_log_pos: "{{ master_status.Position }}"
channel: "{{ test_channel }}"
register: result
- assert:
that:
- result is changed
- result.queries == ["CHANGE MASTER TO MASTER_HOST='127.0.0.1',MASTER_USER='replication_user',MASTER_PASSWORD='********',MASTER_PORT=3306,MASTER_LOG_FILE='{{ master_status.File }}',MASTER_LOG_POS={{ master_status.Position }} FOR CHANNEL '{{ test_channel }}'"]
# Test startslave mode:
- name: Start slave with channel
mysql_replication:
login_host: 127.0.0.1
login_port: "{{ standby_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:
login_host: 127.0.0.1
login_port: "{{ standby_port }}"
mode: getslave
channel: '{{ test_channel }}'
register: slave_status
- assert:
that:
- slave_status.Is_Slave == true
- slave_status.Master_Host == '127.0.0.1'
- slave_status.Exec_Master_Log_Pos == master_status.Position
- slave_status.Master_Port == {{ master_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:
login_host: 127.0.0.1
login_port: "{{ standby_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:
login_host: 127.0.0.1
login_port: "{{ standby_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:
login_host: 127.0.0.1
login_port: "{{ standby_port }}"
mode: resetslaveall
channel: '{{ test_channel }}'
register: result
- assert:
that:
- result is changed
- result.queries == ["RESET SLAVE ALL FOR CHANNEL '{{ test_channel }}'"]

View file

@ -1,191 +0,0 @@
# 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)
# Preparation:
- name: Create user for replication
shell: "echo \"GRANT REPLICATION SLAVE ON *.* TO '{{ replication_user }}'@'localhost' IDENTIFIED BY '{{ replication_pass }}'; FLUSH PRIVILEGES;\" | mysql -P {{ master_port }} -h 127.0.0.1"
- name: Create test database
mysql_db:
login_host: 127.0.0.1
login_port: '{{ master_port }}'
state: present
name: '{{ test_db }}'
- name: Dump all databases from the master
shell: 'mysqldump -P {{ master_port }} -h 127.0.0.1 --all-databases --master-data=2 > {{ dump_path }}'
- name: Restore the dump to the standby
shell: 'mysql -P {{ standby_port }} -h 127.0.0.1 < {{ dump_path }}'
# Test getmaster mode:
- name: Get master status
mysql_replication:
login_host: 127.0.0.1
login_port: "{{ master_port }}"
mode: getmaster
register: master_status
- assert:
that:
- master_status.Is_Master == true
- master_status.Position != 0
- master_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:
login_host: 127.0.0.1
login_port: "{{ standby_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:
login_host: 127.0.0.1
login_port: "{{ standby_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:
login_host: 127.0.0.1
login_port: "{{ standby_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:
login_host: 127.0.0.1
login_port: "{{ standby_port }}"
mode: changemaster
master_host: 127.0.0.1
master_port: "{{ master_port }}"
master_user: "{{ replication_user }}"
master_password: "{{ replication_pass }}"
master_log_file: "{{ master_status.File }}"
master_log_pos: "{{ master_status.Position }}"
master_ssl_ca: ''
register: result
- assert:
that:
- result is changed
- result.queries == ["CHANGE MASTER TO MASTER_HOST='127.0.0.1',MASTER_USER='replication_user',MASTER_PASSWORD='********',MASTER_PORT=3306,MASTER_LOG_FILE='{{ master_status.File }}',MASTER_LOG_POS={{ master_status.Position }},MASTER_SSL_CA=''"]
# Test startslave mode:
- name: Start slave
mysql_replication:
login_host: 127.0.0.1
login_port: "{{ standby_port }}"
mode: startslave
register: result
- assert:
that:
- result is changed
- result.queries == ["START SLAVE"]
# Test getslave mode:
- name: Get standby status
mysql_replication:
login_host: 127.0.0.1
login_port: "{{ standby_port }}"
mode: getslave
register: slave_status
- assert:
that:
- slave_status.Is_Slave == true
- slave_status.Master_Host == '127.0.0.1'
- slave_status.Exec_Master_Log_Pos == master_status.Position
- slave_status.Master_Port == {{ master_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 -P {{ master_port }} -h 127.0.0.1 {{ test_db }}"
- name: Insert data
shell: >
echo "INSERT INTO {{ test_table }} (id) VALUES (1), (2), (3); FLUSH LOGS;" |
mysql -P {{ master_port }} -h 127.0.0.1 {{ 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:
login_host: 127.0.0.1
login_port: "{{ standby_port }}"
mode: getslave
register: slave_status
# master_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 != master_status.Position
- name: Start slave that is already running
mysql_replication:
login_host: 127.0.0.1
login_port: "{{ standby_port }}"
mode: startslave
fail_on_error: true
register: result
- assert:
that:
- result is not changed
# Test stopslave mode:
- name: Stop slave
mysql_replication:
login_host: 127.0.0.1
login_port: "{{ standby_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:
login_host: 127.0.0.1
login_port: "{{ standby_port }}"
mode: stopslave
fail_on_error: true
register: result
- assert:
that:
- result is not changed

View file

@ -1,44 +0,0 @@
# 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)
# Test master_delay mode:
- name: Run replication
mysql_replication:
login_host: 127.0.0.1
login_port: "{{ standby_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:
login_host: 127.0.0.1
login_port: "{{ standby_port }}"
mode: startslave
register: result
# Check master_delay:
- name: Get standby status
mysql_replication:
login_host: 127.0.0.1
login_port: "{{ standby_port }}"
mode: getslave
register: slave_status
- assert:
that:
- slave_status.SQL_Delay == {{ test_master_delay }}
- slave_status is not changed
# Stop standby for further tests:
- name: Stop slave
mysql_replication:
login_host: 127.0.0.1
login_port: "{{ standby_port }}"
mode: stopslave

View file

@ -1,48 +0,0 @@
# 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)
# Needs for further tests:
- name: Stop slave
mysql_replication:
login_host: 127.0.0.1
login_port: "{{ standby_port }}"
mode: stopslave
- name: Reset slave all
mysql_replication:
login_host: 127.0.0.1
login_port: "{{ standby_port }}"
mode: resetslaveall
# Get master initial status:
- name: Get master status
mysql_replication:
login_host: 127.0.0.1
login_port: "{{ master_port }}"
mode: getmaster
register: master_initial_status
# Test resetmaster mode:
- name: Reset master
mysql_replication:
login_host: 127.0.0.1
login_port: "{{ master_port }}"
mode: resetmaster
register: result
- assert:
that:
- result is changed
- result.queries == ["RESET MASTER"]
# Get master final status:
- name: Get master status
mysql_replication:
login_host: 127.0.0.1
login_port: "{{ master_port }}"
mode: getmaster
register: master_final_status
- assert:
that:
- master_initial_status.File != master_final_status.File

View file

@ -7,7 +7,7 @@ percona_client_version: 5.7
mariadb_install: false
mysql_version: 8.0.20
mysql_version: 8.0.21
mariadb_version: 10.5.4
mysql_base_port: 3306

View file

@ -11,5 +11,5 @@
- name: "{{ role_name }} | config | setup replication topology"
shell:
cmd: "dbdeployer deploy multiple {{ install_version }} --base-port {{ mysql_base_port }}"
cmd: "dbdeployer deploy multiple {{ install_version }} --base-port {{ mysql_base_port }} --my-cnf-options=\"master_info_repository='TABLE'\" --my-cnf-options=\"relay_log_info_repository='TABLE'\""
creates: "{{ dbdeployer_sandbox_home_dir }}/multi_msb_{{ install_version|replace('.','_') }}"

View file

@ -1,5 +1,10 @@
master_port: 3306
standby_port: 3307
mysql_user: root
mysql_password: msandbox
mysql_host: 127.0.0.1
mysql_primary_port: 3307
mysql_replica1_port: 3308
mysql_replica2_port: 3309
test_db: test_db
test_table: test_table
test_master_delay: 60

View file

@ -0,0 +1,3 @@
---
dependencies:
- setup_mysql

View file

@ -3,24 +3,12 @@
# Initial CI tests of mysql_replication module:
- import_tasks: mysql_replication_initial.yml
when:
- ansible_facts.distribution == 'CentOS'
- ansible_facts.distribution_major_version is version('7', '==')
# Tests of master_delay parameter:
- import_tasks: mysql_replication_master_delay.yml
when:
- ansible_facts.distribution == 'CentOS'
- ansible_facts.distribution_major_version is version('7', '==')
# Tests of channel parameter:
- import_tasks: mysql_replication_channel.yml
when:
- ansible_facts.distribution == 'CentOS'
- ansible_facts.distribution_major_version is version('7', '==')
# Tests of resetmaster mode:
- import_tasks: mysql_replication_resetmaster_mode.yml
when:
- ansible_facts.distribution == 'CentOS'
- ansible_facts.distribution_major_version is version('7', '==')

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

View file

@ -279,79 +279,83 @@
- include: assert_fail_msg.yml output={{ result }} msg='unable to connect to database'
#=========================================
# Check mode 'persist' and 'persist_only':
#
- name: update mysql variable value (expect changed=true) in persist mode
mysql_variables:
<<: *mysql_params
variable: '{{ set_name }}'
value: '{{ set_value }}'
mode: persist
register: result
- block:
- assert:
that:
- result.queries == ["SET PERSIST `{{ set_name }}` = {{ set_value }}"]
#=========================================
# Check mode 'persist' and 'persist_only':
#
- name: update mysql variable value (expect changed=true) in persist mode
mysql_variables:
<<: *mysql_params
variable: '{{ set_name }}'
value: '{{ set_value }}'
mode: persist
register: result
- include: assert_var.yml changed=true output={{ result }} var_name={{ set_name }} var_value='{{ set_value }}'
- assert:
that:
- result.queries == ["SET PERSIST `{{ set_name }}` = {{ set_value }}"]
- name: try to update mysql variable value (expect changed=false) in persist mode again
mysql_variables:
<<: *mysql_params
variable: '{{ set_name }}'
value: '{{ set_value }}'
mode: persist
register: result
- include: assert_var.yml changed=true output={{ result }} var_name={{ set_name }} var_value='{{ set_value }}'
- include: assert_var.yml changed=false output={{ result }} var_name={{ set_name }} var_value='{{ set_value }}'
- name: try to update mysql variable value (expect changed=false) in persist mode again
mysql_variables:
<<: *mysql_params
variable: '{{ set_name }}'
value: '{{ set_value }}'
mode: persist
register: result
- name: set mysql variable to a temp value
mysql_variables:
<<: *mysql_params
variable: '{{ set_name }}'
value: '200'
mode: persist
- include: assert_var.yml changed=false output={{ result }} var_name={{ set_name }} var_value='{{ set_value }}'
- name: update mysql variable value (expect changed=true) in persist_only mode
mysql_variables:
<<: *mysql_params
variable: '{{ set_name }}'
value: '{{ set_value }}'
mode: persist_only
register: result
- name: set mysql variable to a temp value
mysql_variables:
<<: *mysql_params
variable: '{{ set_name }}'
value: '200'
mode: persist
- assert:
that:
- result is changed
- result.queries == ["SET PERSIST_ONLY `{{ set_name }}` = {{ set_value }}"]
- name: update mysql variable value (expect changed=true) in persist_only mode
mysql_variables:
<<: *mysql_params
variable: '{{ set_name }}'
value: '{{ set_value }}'
mode: persist_only
register: result
- name: try to update mysql variable value (expect changed=false) in persist_only mode again
mysql_variables:
<<: *mysql_params
variable: '{{ set_name }}'
value: '{{ set_value }}'
mode: persist_only
register: result
- assert:
that:
- result is changed
- result.queries == ["SET PERSIST_ONLY `{{ set_name }}` = {{ set_value }}"]
- assert:
that:
- result is not changed
- name: try to update mysql variable value (expect changed=false) in persist_only mode again
mysql_variables:
<<: *mysql_params
variable: '{{ set_name }}'
value: '{{ set_value }}'
mode: persist_only
register: result
- set_fact:
set_name: max_connections
set_value: 105
def_val: 151
- assert:
that:
- result is not changed
- name: update mysql variable value (expect changed=true) in persist_only mode
mysql_variables:
<<: *mysql_params
variable: '{{ set_name }}'
value: '{{ set_value }}'
mode: persist_only
register: result
- set_fact:
set_name: max_connections
set_value: 105
def_val: 151
- include: assert_var.yml changed=true output={{ result }} var_name={{ set_name }} var_value='{{ def_val }}'
- name: update mysql variable value (expect changed=true) in persist_only mode
mysql_variables:
<<: *mysql_params
variable: '{{ set_name }}'
value: '{{ set_value }}'
mode: persist_only
register: result
- include: assert_var.yml changed=true output={{ result }} var_name={{ set_name }} var_value='{{ def_val }}'
when: mysql_version is not version('8.0', '<')
# Bugfix of https://github.com/ansible/ansible/issues/54239
# - name: set variable containing dot