mirror of
https://github.com/ansible-collections/community.mysql.git
synced 2025-06-03 06:49:12 -07:00
initial commit (#1)
* initial commit * removed remaining references to community.general * enabled integration pipeline * switched from preconfigured replication topology to simple multinode install * updated version from 1.0.0 to 0.1.0
This commit is contained in:
parent
9fcbbaad81
commit
c26bc095ad
89 changed files with 8774 additions and 135 deletions
21
tests/integration/old_mariadb_replication/tasks/main.yml
Normal file
21
tests/integration/old_mariadb_replication/tasks/main.yml
Normal file
|
@ -0,0 +1,21 @@
|
|||
# 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: mariadb_replication_initial.yml
|
||||
when:
|
||||
- ansible_facts.distribution == 'CentOS'
|
||||
- ansible_facts.distribution_major_version is version('7', '>=')
|
||||
|
||||
# Tests of master_use_gtid parameter
|
||||
# https://github.com/ansible/ansible/pull/62648
|
||||
- import_tasks: mariadb_master_use_gtid.yml
|
||||
when:
|
||||
- ansible_facts.distribution == 'CentOS'
|
||||
- ansible_facts.distribution_major_version is version('7', '>=')
|
||||
|
||||
# Tests of connection_name parameter
|
||||
- import_tasks: mariadb_replication_connection_name.yml
|
||||
when:
|
||||
- ansible_facts.distribution == 'CentOS'
|
||||
- ansible_facts.distribution_major_version is version('7', '>=')
|
|
@ -0,0 +1,173 @@
|
|||
# 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)
|
||||
|
||||
# Tests for master_use_gtid parameter.
|
||||
# https://github.com/ansible/ansible/pull/62648
|
||||
|
||||
#############################
|
||||
# master_use_gtid: "disabled"
|
||||
#############################
|
||||
|
||||
# Auxiliary step:
|
||||
- name: Get master status
|
||||
mysql_replication:
|
||||
login_host: 127.0.0.1
|
||||
login_port: "{{ primary_db.port }}"
|
||||
mode: getmaster
|
||||
register: primary_status
|
||||
|
||||
# Set master_use_gtid disabled:
|
||||
- name: Run replication
|
||||
mysql_replication:
|
||||
login_host: 127.0.0.1
|
||||
login_port: "{{ replica_db.port }}"
|
||||
mode: changemaster
|
||||
master_host: 127.0.0.1
|
||||
master_port: "{{ primary_db.port }}"
|
||||
master_user: "{{ replication_user }}"
|
||||
master_password: "{{ replication_pass }}"
|
||||
master_log_file: mysql-bin.000001
|
||||
master_log_pos: '{{ primary_status.Position }}'
|
||||
master_use_gtid: disabled
|
||||
register: result
|
||||
|
||||
- assert:
|
||||
that:
|
||||
- result is changed
|
||||
|
||||
# Start standby for further tests:
|
||||
- name: Start standby
|
||||
mysql_replication:
|
||||
login_host: 127.0.0.1
|
||||
login_port: "{{ primary_db.port }}"
|
||||
mode: startslave
|
||||
|
||||
- name: Get standby status
|
||||
mysql_replication:
|
||||
login_host: 127.0.0.1
|
||||
login_port: "{{ replica_db.port }}"
|
||||
mode: getslave
|
||||
register: slave_status
|
||||
|
||||
- assert:
|
||||
that:
|
||||
- slave_status.Using_Gtid == 'No'
|
||||
|
||||
# Stop standby for further tests:
|
||||
- name: Stop standby
|
||||
mysql_replication:
|
||||
login_host: 127.0.0.1
|
||||
login_port: "{{ replica_db.port }}"
|
||||
mode: stopslave
|
||||
|
||||
################################
|
||||
# master_use_gtid: "current_pos"
|
||||
################################
|
||||
|
||||
# Auxiliary step:
|
||||
- name: Get master status
|
||||
mysql_replication:
|
||||
login_host: 127.0.0.1
|
||||
login_port: "{{ primary_db.port }}"
|
||||
mode: getmaster
|
||||
register: primary_status
|
||||
|
||||
# Set master_use_gtid current_pos:
|
||||
- name: Run replication
|
||||
mysql_replication:
|
||||
login_host: 127.0.0.1
|
||||
login_port: "{{ replica_db.port }}"
|
||||
mode: changemaster
|
||||
master_host: 127.0.0.1
|
||||
master_port: "{{ primary_db.port }}"
|
||||
master_user: "{{ replication_user }}"
|
||||
master_password: "{{ replication_pass }}"
|
||||
master_log_file: mysql-bin.000001
|
||||
master_log_pos: '{{ primary_status.Position }}'
|
||||
master_use_gtid: current_pos
|
||||
register: result
|
||||
|
||||
- assert:
|
||||
that:
|
||||
- result is changed
|
||||
|
||||
# Start standby for further tests:
|
||||
- name: Start standby
|
||||
mysql_replication:
|
||||
login_host: 127.0.0.1
|
||||
login_port: "{{ primary_db.port }}"
|
||||
mode: startslave
|
||||
|
||||
- name: Get standby status
|
||||
mysql_replication:
|
||||
login_host: 127.0.0.1
|
||||
login_port: "{{ replica_db.port }}"
|
||||
mode: getslave
|
||||
register: slave_status
|
||||
|
||||
- assert:
|
||||
that:
|
||||
- slave_status.Using_Gtid == 'Current_Pos'
|
||||
|
||||
# Stop standby for further tests:
|
||||
- name: Stop standby
|
||||
mysql_replication:
|
||||
login_host: 127.0.0.1
|
||||
login_port: "{{ replica_db.port }}"
|
||||
mode: stopslave
|
||||
|
||||
##############################
|
||||
# master_use_gtid: "slave_pos"
|
||||
##############################
|
||||
|
||||
# Auxiliary step:
|
||||
- name: Get master status
|
||||
mysql_replication:
|
||||
login_host: 127.0.0.1
|
||||
login_port: "{{ primary_db.port }}"
|
||||
mode: getmaster
|
||||
register: primary_status
|
||||
|
||||
# Set master_use_gtid slave_pos:
|
||||
- name: Run replication
|
||||
mysql_replication:
|
||||
login_host: 127.0.0.1
|
||||
login_port: "{{ replica_db.port }}"
|
||||
mode: changemaster
|
||||
master_host: 127.0.0.1
|
||||
master_port: "{{ primary_db.port }}"
|
||||
master_user: "{{ replication_user }}"
|
||||
master_password: "{{ replication_pass }}"
|
||||
master_log_file: mysql-bin.000001
|
||||
master_log_pos: '{{ primary_status.Position }}'
|
||||
master_use_gtid: slave_pos
|
||||
register: result
|
||||
|
||||
- assert:
|
||||
that:
|
||||
- result is changed
|
||||
|
||||
# Start standby for further tests:
|
||||
- name: Start standby
|
||||
mysql_replication:
|
||||
login_host: 127.0.0.1
|
||||
login_port: "{{ primary_db.port }}"
|
||||
mode: startslave
|
||||
|
||||
- name: Get standby status
|
||||
mysql_replication:
|
||||
login_host: 127.0.0.1
|
||||
login_port: "{{ replica_db.port }}"
|
||||
mode: getslave
|
||||
register: slave_status
|
||||
|
||||
- assert:
|
||||
that:
|
||||
- slave_status.Using_Gtid == 'Slave_Pos'
|
||||
|
||||
# Stop standby for further tests:
|
||||
- name: Stop standby
|
||||
mysql_replication:
|
||||
login_host: 127.0.0.1
|
||||
login_port: "{{ replica_db.port }}"
|
||||
mode: stopslave
|
|
@ -0,0 +1,118 @@
|
|||
# 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: "{{ replica_db.port }}"
|
||||
mode: stopslave
|
||||
|
||||
- name: Reset slave all
|
||||
mysql_replication:
|
||||
login_host: 127.0.0.1
|
||||
login_port: "{{ replica_db.port }}"
|
||||
mode: resetslaveall
|
||||
|
||||
# Get master log pos:
|
||||
- name: Get master status
|
||||
mysql_replication:
|
||||
login_host: 127.0.0.1
|
||||
login_port: "{{ primary_db.port }}"
|
||||
mode: getmaster
|
||||
register: primary_status
|
||||
|
||||
# Test changemaster mode:
|
||||
- name: Run replication with connection_name
|
||||
mysql_replication:
|
||||
login_host: 127.0.0.1
|
||||
login_port: "{{ replica_db.port }}"
|
||||
mode: changemaster
|
||||
master_host: 127.0.0.1
|
||||
master_port: "{{ primary_db.port }}"
|
||||
master_user: "{{ replication_user }}"
|
||||
master_password: "{{ replication_pass }}"
|
||||
master_log_file: mysql-bin.000001
|
||||
master_log_pos: '{{ primary_status.Position }}'
|
||||
connection_name: '{{ conn_name }}'
|
||||
register: result
|
||||
|
||||
- assert:
|
||||
that:
|
||||
- result is changed
|
||||
- result.queries[0] is match("CHANGE MASTER ('\S+' )?TO MASTER_HOST='[0-9.]+',MASTER_USER='\w+',MASTER_PASSWORD='[*]{8}',MASTER_PORT=\d+,MASTER_LOG_FILE='mysql-bin.000001',MASTER_LOG_POS=\d+")
|
||||
|
||||
# Test startslave mode:
|
||||
- name: Start slave with connection_name
|
||||
mysql_replication:
|
||||
login_host: 127.0.0.1
|
||||
login_port: "{{ replica_db.port }}"
|
||||
mode: startslave
|
||||
connection_name: "{{ conn_name }}"
|
||||
register: result
|
||||
|
||||
- assert:
|
||||
that:
|
||||
- result is changed
|
||||
- result.queries == ["START SLAVE \'{{ conn_name }}\'"]
|
||||
|
||||
# Test getslave mode:
|
||||
- name: Get standby statu with connection_name
|
||||
mysql_replication:
|
||||
login_host: 127.0.0.1
|
||||
login_port: "{{ replica_db.port }}"
|
||||
mode: getslave
|
||||
connection_name: "{{ conn_name }}"
|
||||
register: slave_status
|
||||
|
||||
- assert:
|
||||
that:
|
||||
- slave_status.Is_Slave == true
|
||||
- slave_status.Master_Host == '127.0.0.1'
|
||||
- slave_status.Exec_Master_Log_Pos == primary_status.Position
|
||||
- slave_status.Master_Port == {{ primary_db.port }}
|
||||
- slave_status.Last_IO_Errno == 0
|
||||
- slave_status.Last_IO_Error == ''
|
||||
- slave_status is not changed
|
||||
|
||||
# Test stopslave mode:
|
||||
- name: Stop slave with connection_name
|
||||
mysql_replication:
|
||||
login_host: 127.0.0.1
|
||||
login_port: "{{ replica_db.port }}"
|
||||
mode: stopslave
|
||||
connection_name: "{{ conn_name }}"
|
||||
register: result
|
||||
|
||||
- assert:
|
||||
that:
|
||||
- result is changed
|
||||
- result.queries == ["STOP SLAVE \'{{ conn_name }}\'"]
|
||||
|
||||
# Test reset
|
||||
- name: Reset slave with connection_name
|
||||
mysql_replication:
|
||||
login_host: 127.0.0.1
|
||||
login_port: "{{ replica_db.port }}"
|
||||
mode: resetslave
|
||||
connection_name: "{{ conn_name }}"
|
||||
register: result
|
||||
|
||||
- assert:
|
||||
that:
|
||||
- result is changed
|
||||
- result.queries == ["RESET SLAVE \'{{ conn_name }}\'"]
|
||||
|
||||
# Test reset all
|
||||
- name: Reset slave all with connection_name
|
||||
mysql_replication:
|
||||
login_host: 127.0.0.1
|
||||
login_port: "{{ replica_db.port }}"
|
||||
mode: resetslaveall
|
||||
connection_name: "{{ conn_name }}"
|
||||
register: result
|
||||
|
||||
- assert:
|
||||
that:
|
||||
- result is changed
|
||||
- result.queries == ["RESET SLAVE \'{{ conn_name }}\' ALL"]
|
|
@ -0,0 +1,96 @@
|
|||
# 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 {{ primary_db.port }} -h 127.0.0.1"
|
||||
|
||||
- name: Create test database
|
||||
mysql_db:
|
||||
login_host: 127.0.0.1
|
||||
login_port: '{{ primary_db.port }}'
|
||||
state: present
|
||||
name: '{{ test_db }}'
|
||||
|
||||
- name: Dump all databases from the master
|
||||
shell: 'mysqldump -P {{ primary_db.port }} -h 127.0.01 --all-databases --master-data=2 > {{ dump_path }}'
|
||||
|
||||
- name: Restore the dump to the replica
|
||||
shell: 'mysql -P {{ replica_db.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: "{{ primary_db.port }}"
|
||||
mode: getmaster
|
||||
register: master_status
|
||||
|
||||
- assert:
|
||||
that:
|
||||
- master_status.Is_Master == true
|
||||
- master_status.Position != 0
|
||||
- master_status is not changed
|
||||
|
||||
# Test changemaster mode:
|
||||
- name: Run replication
|
||||
mysql_replication:
|
||||
login_host: 127.0.0.1
|
||||
login_port: "{{ replica_db.port }}"
|
||||
mode: changemaster
|
||||
master_host: 127.0.0.1
|
||||
master_port: "{{ primary_db.port }}"
|
||||
master_user: "{{ replication_user }}"
|
||||
master_password: "{{ replication_pass }}"
|
||||
master_log_file: mysql-bin.000001
|
||||
master_log_pos: '{{ master_status.Position }}'
|
||||
register: result
|
||||
|
||||
- assert:
|
||||
that:
|
||||
- result is changed
|
||||
- result.queries[0] is match("CHANGE MASTER ('\S+' )?TO MASTER_HOST='[0-9.]+',MASTER_USER='\w+',MASTER_PASSWORD='[*]{8}',MASTER_PORT=\d+,MASTER_LOG_FILE='mysql-bin.000001',MASTER_LOG_POS=\d+")
|
||||
|
||||
# Test startslave mode:
|
||||
- name: Start slave
|
||||
mysql_replication:
|
||||
login_host: 127.0.0.1
|
||||
login_port: "{{ replica_db.port }}"
|
||||
mode: startslave
|
||||
register: result
|
||||
|
||||
- assert:
|
||||
that:
|
||||
- result is changed
|
||||
- result.queries == ["START SLAVE"]
|
||||
|
||||
# Test getslave mode:
|
||||
- name: Get replica status
|
||||
mysql_replication:
|
||||
login_host: 127.0.0.1
|
||||
login_port: "{{ replica_db.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 == {{ primary_db.port }}
|
||||
- slave_status.Last_IO_Errno == 0
|
||||
- slave_status.Last_IO_Error == ''
|
||||
- slave_status is not changed
|
||||
|
||||
# Test stopslave mode:
|
||||
- name: Stop slave
|
||||
mysql_replication:
|
||||
login_host: 127.0.0.1
|
||||
login_port: "{{ replica_db.port }}"
|
||||
mode: stopslave
|
||||
register: result
|
||||
|
||||
- assert:
|
||||
that:
|
||||
- result is changed
|
||||
- result.queries == ["STOP SLAVE"]
|
Loading…
Add table
Add a link
Reference in a new issue