Skip to content

Commit

Permalink
First CHANGE MASTER TO tests battery
Browse files Browse the repository at this point in the history
  • Loading branch information
Jorge-Rodriguez committed Jan 26, 2023
1 parent d60693c commit f07e389
Show file tree
Hide file tree
Showing 4 changed files with 118 additions and 10 deletions.
4 changes: 4 additions & 0 deletions plugins/module_utils/implementations/mysql/replication.py
Original file line number Diff line number Diff line change
Expand Up @@ -12,3 +12,7 @@
def uses_replica_terminology(cursor):
"""Checks if REPLICA must be used instead of SLAVE"""
return LooseVersion(get_server_version(cursor)) >= LooseVersion('8.0.22')

def supports_gtid_only(cursor):
"""The GTID_ONLY option is supported since MySQL 8.0.27"""
return LooseVersion(get_server_version(cursor)) >= LooseVersion('8.0.27')
20 changes: 10 additions & 10 deletions plugins/modules/mysql_replication.py
Original file line number Diff line number Diff line change
Expand Up @@ -604,12 +604,12 @@ def main():
do_domain_ids=dict(type='list', elements="str"),
ignore_domain_ids=dict(type='list', elements="str"),
primary_delay=dict(type='int', aliases=['master_delay']),
gtid_only=dict(type='bool', default=False)
gtid_only=dict(type='bool', default=False),
connection_name=dict(type='str'),
privilege_checks_user=dict(type='str', choices=['account']),
require_row_format=dict(type='bool', default=False),
require_table_primary_key_check=dict(type='str', choices=['stream', 'on', 'off']),
assign_gtids_to_anonymous_transactions=dict(type='str')
assign_gtids_to_anonymous_transactions=dict(type='str'),
source_connection_auto_failover=dict(type='bool', default=False),
network_namespace=dict(type='str'),
channel=dict(type='str'),
Expand Down Expand Up @@ -657,7 +657,7 @@ def main():
require_row_format = module.params["require_row_format"]
require_table_primary_key_check = module.params["require_table_primary_key_check"]
assign_gtids_to_anonymous_transactions = module.params["assign_gtids_to_anonymous_transactions"]
if re.fullmatch(r'^(?:[0-9A-F]{8}-[0-9A-F]{4}-[1-5][0-9A-F]{3}-[89AB][0-9A-F]{3}-[0-9A-F]{12}|off|local)$', assign_gtids_to_anonymous_transactions, re.I) is None:
if assign_gtids_to_anonymous_transactions is not None and re.fullmatch(r'^(?:[0-9A-F]{8}-[0-9A-F]{4}-[1-5][0-9A-F]{3}-[89AB][0-9A-F]{3}-[0-9A-F]{12}|off|local)$', assign_gtids_to_anonymous_transactions, re.I) is None:
module.fail_json(msg="assign_gtids_to_anonymous_transactions must be a UUID, 'OFF' or 'LOCAL'")
source_connection_auto_failover = module.params["source_connection_auto_failover"]
network_namespace = module.params["network_namespace"]
Expand Down Expand Up @@ -745,11 +745,11 @@ def main():
if primary_port is not None:
chm.append("MASTER_PORT=%s" % primary_port)
if primary_heartbeat_period is not None:
chm.append("MASTER_HEARTBEAT_PERIOD='%s'" % primary_heartbeat_period)
chm.append("MASTER_HEARTBEAT_PERIOD=%s" % primary_heartbeat_period)
if primary_connect_retry is not None:
chm.append("MASTER_CONNECT_RETRY=%s" % primary_connect_retry)
if primary_retry_count is not None:
chm.append("MASTER_RETRY_COUNT='%s'" % primary_retry_count)
chm.append("MASTER_RETRY_COUNT=%s" % primary_retry_count)
if primary_log_file is not None:
chm.append("MASTER_LOG_FILE='%s'" % primary_log_file)
if primary_log_pos is not None:
Expand Down Expand Up @@ -784,7 +784,7 @@ def main():
if primary_compression_algorithms is not None:
chm.append("MASTER_COMPRESSION_ALGORITHMS='%s'" % primary_compression_algorithms)
if primary_zstd_compression_level is not None:
chm.append("MASTER_ZSTD_COMPRESSION_LEVEL='%s'" % primary_zstd_compression_level)
chm.append("MASTER_ZSTD_COMPRESSION_LEVEL=%s" % primary_zstd_compression_level)
if primary_tls_ciphersuites is not None:
chm.append("MASTER_TLS_CIPHERSUITES='%s'" % primary_tls_ciphersuites)
if primary_public_key_path is not None:
Expand All @@ -798,11 +798,11 @@ def main():
if primary_use_gtid is not None:
chm.append("MASTER_USE_GTID=%s" % primary_use_gtid)
if ignore_server_ids:
chm.append("IGNORE_SERVER_IDS='%s'" % ','.join(ignore_server_ids))
chm.append("IGNORE_SERVER_IDS=(%s)" % ','.join(ignore_server_ids))
if do_domain_ids:
chm.append("DO_DOMAIN_IDS='%s'" % ','.join(do_domain_ids))
chm.append("DO_DOMAIN_IDS=(%s)" % ','.join(do_domain_ids))
if ignore_domain_ids:
chm.append("IGNORE_DOMAIN_IDS='%s'" % ','.join(ignore_domain_ids))
chm.append("IGNORE_DOMAIN_IDS=(%s)" % ','.join(ignore_domain_ids))
if privilege_checks_user is not None:
chm.append("PRIVILEGE_CHECKS_USER='%s'" % privilege_checks_user)
if require_row_format:
Expand All @@ -815,7 +815,7 @@ def main():
chm.append("SOURCE_CONNECTION_AUTO_FAILOVER=1")
if network_namespace is not None:
chm.append("NETWORK_NAMESPACE='%s'" % network_namespace)
if gtid_only is not None:
if gtid_only is not None and impl.supports_gtid_only(cursor):
if gtid_only:
chm.append("GTID_ONLY=1")
else:
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,9 @@
# Tests of primary_delay parameter:
- import_tasks: mysql_replication_primary_delay.yml

# Tests of CHANGE MASTER TO options
- include: mysql_replication_changeprimary_options.yml

# Tests of channel parameter:
- import_tasks: mysql_replication_channel.yml
when:
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,101 @@
# Copyright: (c) 2023, Jorge Rodriguez (@Jorge-Rodriguez) <[email protected]>
# 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:
# Auxiliary step:
- name: Stop Replica
mysql_replication:
<<: *mysql_params
login_port: '{{ mysql_replica1_port }}'
mode: stopreplica

- name: Test CHANGE MASTER TO options
mysql_replication:
<<: *mysql_params
login_port: '{{ mysql_replica1_port }}'
mode: changeprimary
primary_bind: 127.0.0.1
primary_retry_count: 12
primary_ssl_crl: bogus_crl
primary_ssl_crlpath: bogus_crl_path
primary_tls_version: TLSv1.3
primary_public_key_path: bogus_pub_key_path
get_primary_public_key: yes
ignore_server_ids: '123456789'
network_namespace: 'test_net_namespace'
primary_heartbeat_period: 15
primary_compression_algorithms: 'zstd'
primary_zstd_compression_level: 15
register: result

- assert:
that:
- result is changed
- result.queries == ["CHANGE MASTER TO MASTER_BIND='127.0.0.1',MASTER_HEARTBEAT_PERIOD=15,MASTER_RETRY_COUNT=12,MASTER_SSL_CRL='bogus_crl',MASTER_SSL_CRLPATH='bogus_crl_path',MASTER_TLS_VERSION='TLSv1.3',MASTER_COMPRESSION_ALGORITHMS='zstd',MASTER_ZSTD_COMPRESSION_LEVEL=15,MASTER_PUBLIC_KEY_PATH='bogus_pub_key_path',GET_MASTER_PUBLIC_KEY=1,IGNORE_SERVER_IDS=(123456789),NETWORK_NAMESPACE='test_net_namespace'"]

# Auxiliary step:
- name: Start replica
mysql_replication:
<<: *mysql_params
login_port: '{{ mysql_replica1_port }}'
mode: startreplica

# Check primary_bind:
- name: Get standby status
mysql_replication:
<<: *mysql_params
login_port: '{{ mysql_replica1_port }}'
mode: getreplica
register: replica_status

- assert:
that:
- replica_status.Source_Bind == '127.0.0.1'
- replica_status.Source_Retry_Count == 12
- replica_status.Source_SSL_Crl == 'bogus_crl'
- replica_status.Source_SSL_Crlpath == 'bogus_crl_path'
- replica_status.Source_TLS_Version == 'TLSv1.3'
- replica_status.Source_public_key_path == 'bogus_pub_key_path'
- replica_status.Get_Source_public_key == 1
- replica_status.Replicate_Ignore_Server_Ids == '123456789'
- replica_status.Network_Namespace == 'test_net_namespace'
- replica_status is not changed

- name: Test Results
mysql_query:
<<: *mysql_params
login_port: '{{ mysql_replica1_port }}'
query: SELECT HEARTBEAT_INTERVAL, COMPRESSION_ALGORITHM, ZSTD_COMPRESSION_LEVEL FROM performance_schema.replication_connection_configuration
register: result

- assert:
that:
- result.query_result[0][0]['COMPRESSION_ALGORITHM'] == 'zstd'
- result.query_result[0][0]['HEARTBEAT_INTERVAL'] == 15.0
- result.query_result[0][0]['ZSTD_COMPRESSION_LEVEL'] == 15

# Missing TESTS
# - privilege_checks_user
# - require_row_format
# - require_table_primary_key_check
# - assign_gtids_To anonymous_transactions
# - GTID_ONLY availabe on MySQL 8.0.27
# - ztsd_compression_level out of bounds
# - source_connection_auto_failover -> only possible when GTID_MODE = on
# - primary_tls_ciphersuites -> requires SSL enabled

# - name: Test Results
# mysql_query:
# <<: *mysql_params
# login_port: '{{ mysql_replica1_port }}'
# query: SHOW VARIABLES LIKE '%tls_ciphersuites%'
# register: result

# - debug:
# var: result

0 comments on commit f07e389

Please sign in to comment.