From 3439a831c854419eebb7eb9a3bbc86880c7ba9a6 Mon Sep 17 00:00:00 2001 From: Andrew Klychkov Date: Sun, 14 Feb 2021 11:01:30 +0300 Subject: [PATCH 1/6] mysql_replication: deprecation of slave related options, adding alternatives --- plugins/modules/mysql_replication.py | 126 ++++++++++++++++++--------- 1 file changed, 84 insertions(+), 42 deletions(-) diff --git a/plugins/modules/mysql_replication.py b/plugins/modules/mysql_replication.py index 322a6a8c..1645a69f 100644 --- a/plugins/modules/mysql_replication.py +++ b/plugins/modules/mysql_replication.py @@ -15,7 +15,7 @@ module: mysql_replication short_description: Manage MySQL replication description: -- Manages MySQL server replication, slave, master status, get and change master host. +- Manages MySQL server replication, replica, master status, get and change master host. author: - Balazs Pocze (@banyek) - Andrew Klychkov (@Andersson007) @@ -25,23 +25,28 @@ - Module operating mode. Could be C(changemaster) (CHANGE MASTER TO), C(getmaster) (SHOW MASTER STATUS), - C(getslave) (SHOW SLAVE STATUS), - C(startslave) (START SLAVE), - C(stopslave) (STOP SLAVE), + C(getreplica | getslave) (SHOW REPLICA | SLAVE STATUS), + C(startreplica | startslave) (START REPLICA | SLAVE), + C(stopreplica | stopslave) (STOP REPLICA | SLAVE), C(resetmaster) (RESET MASTER) - supported since community.mysql 0.1.0, - C(resetslave) (RESET SLAVE), - C(resetslaveall) (RESET SLAVE ALL). + C(resetreplica, resetslave) (RESET REPLICA | SLAVE), + C(resetreplicaall, resetslave) (RESET REPLICA | SLAVE ALL). type: str choices: - changemaster - getmaster + - getreplica - getslave + - startreplica - startslave + - stopreplica - stopslave - resetmaster + - resetreplica - resetslave + - resetreplicaall - resetslaveall - default: getslave + default: getreplica master_host: description: - Same as mysql variable. @@ -110,12 +115,14 @@ default: false master_use_gtid: description: - - Configures the slave to use the MariaDB Global Transaction ID. + - Configures the replica to use the MariaDB Global Transaction ID. - C(disabled) equals MASTER_USE_GTID=no command. - To find information about available values see U(https://mariadb.com/kb/en/library/change-master-to/#master_use_gtid). - Available since MariaDB 10.0.2. - choices: [current_pos, slave_pos, disabled] + - C(replica_pos) has been introduced in MariaDB 10.5.1 and + it is an alias for C(slave_pos). + choices: [current_pos, replica_pos, slave_pos, disabled] type: str version_added: '0.1.0' master_delay: @@ -166,9 +173,9 @@ ''' EXAMPLES = r''' -- name: Stop mysql slave thread +- name: Stop mysql replica thread community.mysql.mysql_replication: - mode: stopslave + mode: stopreplica - name: Get master binlog file name and binlog position community.mysql.mysql_replication: @@ -181,9 +188,9 @@ master_log_file: mysql-bin.000009 master_log_pos: 4578 -- name: Check slave status using port 3308 +- name: Check replica status using port 3308 community.mysql.mysql_replication: - mode: getslave + mode: getreplica login_host: ansible.example.com login_port: 3308 @@ -198,14 +205,14 @@ master_host: 192.0.2.1 master_delay: 3600 -- name: Start MariaDB standby with connection name master-1 +- name: Start MariaDB replica with connection name master-1 community.mysql.mysql_replication: - mode: startslave + mode: startreplica connection_name: master-1 - name: Stop replication in channel master-1 community.mysql.mysql_replication: - mode: stopslave + mode: stopreplica channel: master-1 - name: > @@ -214,13 +221,13 @@ community.mysql.mysql_replication: mode: resetmaster -- name: Run start slave and fail the task on errors +- name: Run start replica and fail the task on errors community.mysql.mysql_replication: - mode: startslave + mode: startreplica connection_name: master-1 fail_on_error: yes -- name: Change master and fail on error (like when slave thread is running) +- name: Change master and fail on error (like when replica thread is running) community.mysql.mysql_replication: mode: changemaster fail_on_error: yes @@ -240,7 +247,12 @@ import warnings from ansible.module_utils.basic import AnsibleModule -from ansible_collections.community.mysql.plugins.module_utils.mysql import mysql_connect, mysql_driver, mysql_driver_fail_msg, mysql_common_argument_spec +from ansible_collections.community.mysql.plugins.module_utils.mysql import ( + mysql_connect, + mysql_driver, + mysql_driver_fail_msg, + mysql_common_argument_spec, +) from ansible.module_utils._text import to_native from distutils.version import LooseVersion @@ -271,7 +283,7 @@ def get_master_status(cursor): return masterstatus -def get_slave_status(cursor, connection_name='', channel='', term='REPLICA'): +def get_replica_status(cursor, connection_name='', channel='', term='REPLICA'): if connection_name: query = "SHOW %s '%s' STATUS" % (term, connection_name) else: @@ -281,11 +293,11 @@ def get_slave_status(cursor, connection_name='', channel='', term='REPLICA'): query += " FOR CHANNEL '%s'" % channel cursor.execute(query) - slavestatus = cursor.fetchone() - return slavestatus + replica_status = cursor.fetchone() + return replica_status -def stop_slave(module, cursor, connection_name='', channel='', fail_on_error=False, term='REPLICA'): +def stop_replica(module, cursor, connection_name='', channel='', fail_on_error=False, term='REPLICA'): if connection_name: query = "STOP %s '%s'" % (term, connection_name) else: @@ -307,7 +319,7 @@ def stop_slave(module, cursor, connection_name='', channel='', fail_on_error=Fal return stopped -def reset_slave(module, cursor, connection_name='', channel='', fail_on_error=False, term='REPLICA'): +def reset_replica(module, cursor, connection_name='', channel='', fail_on_error=False, term='REPLICA'): if connection_name: query = "RESET %s '%s'" % (term, connection_name) else: @@ -329,7 +341,7 @@ def reset_slave(module, cursor, connection_name='', channel='', fail_on_error=Fa return reset -def reset_slave_all(module, cursor, connection_name='', channel='', fail_on_error=False, term='REPLICA'): +def reset_replica_all(module, cursor, connection_name='', channel='', fail_on_error=False, term='REPLICA'): if connection_name: query = "RESET %s '%s' ALL" % (term, connection_name) else: @@ -366,7 +378,7 @@ def reset_master(module, cursor, fail_on_error=False): return reset -def start_slave(module, cursor, connection_name='', channel='', fail_on_error=False, term='REPLICA'): +def start_replica(module, cursor, connection_name='', channel='', fail_on_error=False, term='REPLICA'): if connection_name: query = "START %s '%s'" % (term, connection_name) else: @@ -404,9 +416,11 @@ def changemaster(cursor, chm, connection_name='', channel=''): def main(): argument_spec = mysql_common_argument_spec() argument_spec.update( - mode=dict(type='str', default='getslave', choices=[ - 'getmaster', 'getslave', 'changemaster', 'stopslave', - 'startslave', 'resetmaster', 'resetslave', 'resetslaveall']), + mode=dict(type='str', default='getreplica', choices=[ + 'getmaster', 'getreplica', 'getslave', 'changemaster', + 'stopreplica', 'stopslave', 'startreplica', 'startslave', + 'resetmaster', 'resetreplica', 'resetslave', + 'resetreplicaall', 'resetslaveall']), master_auto_position=dict(type='bool', default=False), master_host=dict(type='str'), master_user=dict(type='str'), @@ -423,7 +437,8 @@ def main(): master_ssl_cert=dict(type='str'), master_ssl_key=dict(type='str'), master_ssl_cipher=dict(type='str'), - master_use_gtid=dict(type='str', choices=['current_pos', 'slave_pos', 'disabled']), + master_use_gtid=dict(type='str', choices=[ + 'current_pos', 'replica_pos', 'slave_pos', 'disabled']), master_delay=dict(type='int'), connection_name=dict(type='str'), channel=dict(type='str'), @@ -481,7 +496,8 @@ def main(): connect_timeout=connect_timeout, check_hostname=check_hostname) except Exception as e: if os.path.exists(config_file): - module.fail_json(msg="unable to connect to database, check login_user and login_password are correct or %s has the credentials. " + module.fail_json(msg="unable to connect to database, check login_user and " + "login_password are correct or %s has the credentials. " "Exception message: %s" % (config_file, to_native(e))) else: module.fail_json(msg="unable to find %s. Exception message: %s" % (config_file, to_native(e))) @@ -490,8 +506,14 @@ def main(): # "REPLICA" must be used instead of "SLAVE" if uses_replica_terminology(cursor): replica_term = 'REPLICA' + if master_use_gtid == 'slave_pos': + module.warn('master_use_gtid "slave_pos" value is deprecated. ' + 'Please, use "replica_pos" instead.') + master_use_gtid = 'replica_pos' else: replica_term = 'SLAVE' + if master_use_gtid == 'replica_pos': + master_use_gtid = 'slave_pos' if mode in "getmaster": status = get_master_status(cursor) @@ -501,8 +523,12 @@ def main(): status['Is_Master'] = True module.exit_json(queries=executed_queries, **status) - elif mode in "getslave": - status = get_slave_status(cursor, connection_name, channel, replica_term) + elif mode in ("getreplica", "getslave"): + if mode == "getslave": + module.warn('"getslave" option is deprecated. ' + 'Please, use "getreplica" instead.') + + status = get_replica_status(cursor, connection_name, channel, replica_term) if not isinstance(status, dict): status = dict(Is_Slave=False, msg="Server is not configured as mysql slave") else: @@ -556,14 +582,22 @@ def main(): module.fail_json(msg='%s. Query == CHANGE MASTER TO %s' % (to_native(e), chm)) result['changed'] = True module.exit_json(queries=executed_queries, **result) - elif mode in "startslave": - started = start_slave(module, cursor, connection_name, channel, fail_on_error, replica_term) + elif mode in ("startreplica", "startslave"): + if mode == "startslave": + module.warn('"startslave" option is deprecated. ' + 'Please, use "startreplica" instead.') + + started = start_replica(module, cursor, connection_name, channel, fail_on_error, replica_term) if started is True: module.exit_json(msg="Slave started ", changed=True, queries=executed_queries) else: module.exit_json(msg="Slave already started (Or cannot be started)", changed=False, queries=executed_queries) - elif mode in "stopslave": - stopped = stop_slave(module, cursor, connection_name, channel, fail_on_error, replica_term) + elif mode in ("stopreplica", "stopslave"): + if mode == "stopslave": + module.warn('"stopslave" option is deprecated. ' + 'Please, use "stopreplica" instead.') + + stopped = stop_replica(module, cursor, connection_name, channel, fail_on_error, replica_term) if stopped is True: module.exit_json(msg="Slave stopped", changed=True, queries=executed_queries) else: @@ -574,14 +608,22 @@ def main(): module.exit_json(msg="Master reset", changed=True, queries=executed_queries) else: module.exit_json(msg="Master already reset", changed=False, queries=executed_queries) - elif mode in "resetslave": - reset = reset_slave(module, cursor, connection_name, channel, fail_on_error, replica_term) + elif mode in ("resetreplica", "resetslave"): + if mode == "resetslave": + module.warn('"resetslave" option is deprecated. ' + 'Please, use "resetreplica" instead.') + + reset = reset_replica(module, cursor, connection_name, channel, fail_on_error, replica_term) if reset is True: module.exit_json(msg="Slave reset", changed=True, queries=executed_queries) else: module.exit_json(msg="Slave already reset", changed=False, queries=executed_queries) - elif mode in "resetslaveall": - reset = reset_slave_all(module, cursor, connection_name, channel, fail_on_error, replica_term) + elif mode in ("resetreplicaall", "resetslaveall"): + if mode == "resetslaveall": + module.warn('"resetslaveall" option is deprecated. ' + 'Please, use "resetreplicaall" instead.') + + reset = reset_replica_all(module, cursor, connection_name, channel, fail_on_error, replica_term) if reset is True: module.exit_json(msg="Slave reset", changed=True, queries=executed_queries) else: From 3575ecc5289a4a6f8ce9fab58df54b2378e7b8cc Mon Sep 17 00:00:00 2001 From: Andrew Klychkov Date: Thu, 18 Feb 2021 11:15:51 +0300 Subject: [PATCH 2/6] Add changelog fragment --- .../97-mysql_replication_deprecate_offending_terminology.yml | 2 ++ 1 file changed, 2 insertions(+) create mode 100644 changelogs/fragments/97-mysql_replication_deprecate_offending_terminology.yml diff --git a/changelogs/fragments/97-mysql_replication_deprecate_offending_terminology.yml b/changelogs/fragments/97-mysql_replication_deprecate_offending_terminology.yml new file mode 100644 index 00000000..092a5e72 --- /dev/null +++ b/changelogs/fragments/97-mysql_replication_deprecate_offending_terminology.yml @@ -0,0 +1,2 @@ +minor_changes: +- mysql_replication - deprecate offending terminology, add alternative choices to the ``mode`` option (https://github.com/ansible-collections/community.mysql/issues/78). From ede3b32b432b3230716e3e9505f3702240f7ce8f Mon Sep 17 00:00:00 2001 From: Andrew Klychkov Date: Thu, 18 Feb 2021 11:48:19 +0300 Subject: [PATCH 3/6] Integration tests getslave -> getreplica --- .../tasks/mysql_replication_channel.yml | 4 ++-- .../tasks/mysql_replication_initial.yml | 6 +++--- .../tasks/mysql_replication_master_delay.yml | 2 +- 3 files changed, 6 insertions(+), 6 deletions(-) diff --git a/tests/integration/targets/test_mysql_replication/tasks/mysql_replication_channel.yml b/tests/integration/targets/test_mysql_replication/tasks/mysql_replication_channel.yml index cb6d23a9..94ecc832 100644 --- a/tests/integration/targets/test_mysql_replication/tasks/mysql_replication_channel.yml +++ b/tests/integration/targets/test_mysql_replication/tasks/mysql_replication_channel.yml @@ -50,12 +50,12 @@ - result is changed - result.queries == ["START SLAVE FOR CHANNEL '{{ test_channel }}'"] or result.queries == ["START REPLICA FOR CHANNEL '{{ test_channel }}'"] - # Test getslave mode: + # Test getreplica mode: - name: Get standby status with channel mysql_replication: <<: *mysql_params login_port: '{{ mysql_replica2_port }}' - mode: getslave + mode: getreplica channel: '{{ test_channel }}' register: slave_status diff --git a/tests/integration/targets/test_mysql_replication/tasks/mysql_replication_initial.yml b/tests/integration/targets/test_mysql_replication/tasks/mysql_replication_initial.yml index e26dcd23..d1102f47 100644 --- a/tests/integration/targets/test_mysql_replication/tasks/mysql_replication_initial.yml +++ b/tests/integration/targets/test_mysql_replication/tasks/mysql_replication_initial.yml @@ -138,12 +138,12 @@ - result is changed - result.queries == ["START SLAVE"] or result.queries == ["START REPLICA"] - # Test getslave mode: + # Test getreplica mode: - name: Get standby status mysql_replication: <<: *mysql_params login_port: '{{ mysql_replica1_port }}' - mode: getslave + mode: getreplica register: slave_status - assert: @@ -184,7 +184,7 @@ mysql_replication: <<: *mysql_params login_port: '{{ mysql_replica1_port }}' - mode: getslave + mode: getreplica register: slave_status # mysql_primary_status.Position is not actual and it has been changed by the prev step, diff --git a/tests/integration/targets/test_mysql_replication/tasks/mysql_replication_master_delay.yml b/tests/integration/targets/test_mysql_replication/tasks/mysql_replication_master_delay.yml index dcf977d1..7fef0913 100644 --- a/tests/integration/targets/test_mysql_replication/tasks/mysql_replication_master_delay.yml +++ b/tests/integration/targets/test_mysql_replication/tasks/mysql_replication_master_delay.yml @@ -36,7 +36,7 @@ mysql_replication: <<: *mysql_params login_port: '{{ mysql_replica1_port }}' - mode: getslave + mode: getreplica register: slave_status - assert: From 18b31a180f438a4255a01c8f2070f5e56a6ddce3 Mon Sep 17 00:00:00 2001 From: Andrew Klychkov Date: Thu, 18 Feb 2021 12:16:33 +0300 Subject: [PATCH 4/6] Change the rest of offending choices/comments --- .../tasks/mysql_replication_channel.yml | 54 ++++++------ .../tasks/mysql_replication_initial.yml | 82 +++++++++---------- .../tasks/mysql_replication_master_delay.yml | 10 +-- .../mysql_replication_resetmaster_mode.yml | 8 +- 4 files changed, 77 insertions(+), 77 deletions(-) diff --git a/tests/integration/targets/test_mysql_replication/tasks/mysql_replication_channel.yml b/tests/integration/targets/test_mysql_replication/tasks/mysql_replication_channel.yml index 94ecc832..1bbc1bca 100644 --- a/tests/integration/targets/test_mysql_replication/tasks/mysql_replication_channel.yml +++ b/tests/integration/targets/test_mysql_replication/tasks/mysql_replication_channel.yml @@ -36,12 +36,12 @@ - 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 + # Test startreplica mode: + - name: Start replica with channel mysql_replication: <<: *mysql_params login_port: '{{ mysql_replica2_port }}' - mode: startslave + mode: startreplica channel: '{{ test_channel }}' register: result @@ -57,39 +57,39 @@ login_port: '{{ mysql_replica2_port }}' mode: getreplica channel: '{{ test_channel }}' - register: slave_status + register: replica_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 + - replica_status.Is_Slave == 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.Channel_Name == '{{ test_channel }}' + - replica_status is not changed when: mysql8022_and_higher == false - assert: that: - - slave_status.Is_Slave == true - - slave_status.Source_Host == '{{ mysql_host }}' - - slave_status.Exec_Source_Log_Pos == mysql_primary_status.Position - - slave_status.Source_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 + - replica_status.Is_Slave == 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.Channel_Name == '{{ test_channel }}' + - replica_status is not changed when: mysql8022_and_higher == true - # Test stopslave mode: - - name: Stop slave with channel + # Test stopreplica mode: + - name: Stop replica with channel mysql_replication: <<: *mysql_params login_port: '{{ mysql_replica2_port }}' - mode: stopslave + mode: stopreplica channel: '{{ test_channel }}' register: result @@ -99,11 +99,11 @@ - result.queries == ["STOP SLAVE FOR CHANNEL '{{ test_channel }}'"] or result.queries == ["STOP REPLICA FOR CHANNEL '{{ test_channel }}'"] # Test reset - - name: Reset slave with channel + - name: Reset replica with channel mysql_replication: <<: *mysql_params login_port: '{{ mysql_replica2_port }}' - mode: resetslave + mode: resetreplica channel: '{{ test_channel }}' register: result @@ -113,11 +113,11 @@ - result.queries == ["RESET SLAVE FOR CHANNEL '{{ test_channel }}'"] or result.queries == ["RESET REPLICA FOR CHANNEL '{{ test_channel }}'"] # Test reset all - - name: Reset slave all with channel + - name: Reset replica all with channel mysql_replication: <<: *mysql_params login_port: '{{ mysql_replica2_port }}' - mode: resetslaveall + mode: resetreplicaall channel: '{{ test_channel }}' register: result diff --git a/tests/integration/targets/test_mysql_replication/tasks/mysql_replication_initial.yml b/tests/integration/targets/test_mysql_replication/tasks/mysql_replication_initial.yml index d1102f47..4e907070 100644 --- a/tests/integration/targets/test_mysql_replication/tasks/mysql_replication_initial.yml +++ b/tests/integration/targets/test_mysql_replication/tasks/mysql_replication_initial.yml @@ -63,8 +63,8 @@ - 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 + # Test startreplica fails without changemaster first. This needs fail_on_error + - name: Start replica (using deprecated startslave choice) and fail because master is not specified; failing on error as requested mysql_replication: <<: *mysql_params login_port: '{{ mysql_replica1_port }}' @@ -77,12 +77,12 @@ 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 + # 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 mysql_replication: <<: *mysql_params login_port: '{{ mysql_replica1_port }}' - mode: startslave + mode: startreplica fail_on_error: no register: result @@ -90,13 +90,13 @@ that: - result is not failed - # Test startslave doesn't fail if there is no fail_on_error. + # Test startreplica 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 + - name: Start replica 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 + mode: startreplica register: result - assert: @@ -125,12 +125,12 @@ - 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 + # Test startreplica mode: + - name: Start replica mysql_replication: <<: *mysql_params login_port: '{{ mysql_replica1_port }}' - mode: startslave + mode: startreplica register: result - assert: @@ -139,33 +139,33 @@ - result.queries == ["START SLAVE"] or result.queries == ["START REPLICA"] # Test getreplica mode: - - name: Get standby status + - name: Get replica status using deprecated getslave choice mysql_replication: <<: *mysql_params login_port: '{{ mysql_replica1_port }}' - mode: getreplica - register: slave_status + mode: getslave + register: replica_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 + - replica_status.Is_Slave == 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: that: - - slave_status.Is_Slave == true - - slave_status.Source_Host == '{{ mysql_host }}' - - slave_status.Exec_Source_Log_Pos == mysql_primary_status.Position - - slave_status.Source_Port == {{ mysql_primary_port }} - - slave_status.Last_IO_Errno == 0 - - slave_status.Last_IO_Error == '' - - slave_status is not changed + - replica_status.Is_Slave == 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: @@ -175,38 +175,38 @@ - 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 + - name: Small pause to be sure the bin log, which was flushed previously, reached the replica pause: seconds: 2 # Test master log pos has been changed: - - name: Get standby status + - name: Get replica status mysql_replication: <<: *mysql_params login_port: '{{ mysql_replica1_port }}' mode: getreplica - register: slave_status + register: replica_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: + # so replica_status.Exec_Master_Log_Pos must be different: - assert: that: - - slave_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: that: - - slave_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 slave that is already running + - name: Start replica that is already running mysql_replication: <<: *mysql_params login_port: '{{ mysql_replica1_port }}' - mode: startslave + mode: startreplica fail_on_error: true register: result @@ -215,8 +215,8 @@ - result is not changed when: (pymysql_version.stdout | default('1000', true)) is version('0.9.3', '<=') - # Test stopslave mode: - - name: Stop slave + # Test stopreplica mode: + - name: Stop replica using deprecated stopslave choice mysql_replication: <<: *mysql_params login_port: '{{ mysql_replica1_port }}' @@ -228,12 +228,12 @@ - result is changed - result.queries == ["STOP SLAVE"] or result.queries == ["STOP REPLICA"] - # Test stopslave mode: - - name: Stop slave that is no longer running + # Test stopreplica mode: + - name: Stop replica that is no longer running mysql_replication: <<: *mysql_params login_port: '{{ mysql_replica1_port }}' - mode: stopslave + mode: stopreplica fail_on_error: true register: result diff --git a/tests/integration/targets/test_mysql_replication/tasks/mysql_replication_master_delay.yml b/tests/integration/targets/test_mysql_replication/tasks/mysql_replication_master_delay.yml index 7fef0913..94a10b2a 100644 --- a/tests/integration/targets/test_mysql_replication/tasks/mysql_replication_master_delay.yml +++ b/tests/integration/targets/test_mysql_replication/tasks/mysql_replication_master_delay.yml @@ -24,11 +24,11 @@ - result.queries == ["CHANGE MASTER TO MASTER_DELAY=60"] # Auxiliary step: - - name: Start slave + - name: Start replica mysql_replication: <<: *mysql_params login_port: '{{ mysql_replica1_port }}' - mode: startslave + mode: startreplica register: result # Check master_delay: @@ -37,9 +37,9 @@ <<: *mysql_params login_port: '{{ mysql_replica1_port }}' mode: getreplica - register: slave_status + register: replica_status - assert: that: - - slave_status.SQL_Delay == {{ test_master_delay }} - - slave_status is not changed + - replica_status.SQL_Delay == {{ test_master_delay }} + - replica_status is not changed diff --git a/tests/integration/targets/test_mysql_replication/tasks/mysql_replication_resetmaster_mode.yml b/tests/integration/targets/test_mysql_replication/tasks/mysql_replication_resetmaster_mode.yml index 36ed47d5..223e3259 100644 --- a/tests/integration/targets/test_mysql_replication/tasks/mysql_replication_resetmaster_mode.yml +++ b/tests/integration/targets/test_mysql_replication/tasks/mysql_replication_resetmaster_mode.yml @@ -10,17 +10,17 @@ block: # Needs for further tests: - - name: Stop slave + - name: Stop replica mysql_replication: <<: *mysql_params login_port: '{{ mysql_replica1_port }}' - mode: stopslave + mode: stopreplica - - name: Reset slave all + - name: Reset replica all mysql_replication: <<: *mysql_params login_port: '{{ mysql_replica1_port }}' - mode: resetslaveall + mode: resetreplicaall # Get master initial status: - name: Get master status From 9d58a12cb016223abe0b81cb5b7827519b3cfb7c Mon Sep 17 00:00:00 2001 From: Andrew Klychkov Date: Thu, 18 Feb 2021 12:38:03 +0300 Subject: [PATCH 5/6] Add announcement about replacing SLAVE to REPLICA in messages --- .../97-mysql_replication_deprecate_offending_terminology.yml | 3 +++ 1 file changed, 3 insertions(+) diff --git a/changelogs/fragments/97-mysql_replication_deprecate_offending_terminology.yml b/changelogs/fragments/97-mysql_replication_deprecate_offending_terminology.yml index 092a5e72..a884274a 100644 --- a/changelogs/fragments/97-mysql_replication_deprecate_offending_terminology.yml +++ b/changelogs/fragments/97-mysql_replication_deprecate_offending_terminology.yml @@ -1,2 +1,5 @@ minor_changes: - mysql_replication - deprecate offending terminology, add alternative choices to the ``mode`` option (https://github.com/ansible-collections/community.mysql/issues/78). + +major_changes: +- mysql_replication - the word ``SLAVE`` in messages returned by the module will be changed to ``REPLICA`` in the next major release (https://github.com/ansible-collections/community.mysql/issues/98). From ce14680228c0a4796ff621d0696d4209ac3682cb Mon Sep 17 00:00:00 2001 From: Andrew Klychkov Date: Thu, 25 Feb 2021 15:16:29 +0300 Subject: [PATCH 6/6] Deprecate offending values --- ...cation_deprecate_offending_terminology.yml | 3 ++- plugins/modules/mysql_replication.py | 24 +++++++++---------- 2 files changed, 14 insertions(+), 13 deletions(-) diff --git a/changelogs/fragments/97-mysql_replication_deprecate_offending_terminology.yml b/changelogs/fragments/97-mysql_replication_deprecate_offending_terminology.yml index a884274a..7bf4da7d 100644 --- a/changelogs/fragments/97-mysql_replication_deprecate_offending_terminology.yml +++ b/changelogs/fragments/97-mysql_replication_deprecate_offending_terminology.yml @@ -2,4 +2,5 @@ minor_changes: - mysql_replication - deprecate offending terminology, add alternative choices to the ``mode`` option (https://github.com/ansible-collections/community.mysql/issues/78). major_changes: -- mysql_replication - the word ``SLAVE`` in messages returned by the module will be changed to ``REPLICA`` in the next major release (https://github.com/ansible-collections/community.mysql/issues/98). +- mysql_replication - the word ``SLAVE`` in messages returned by the module will be changed to ``REPLICA`` in ``community.mysql`` 2.0.0 (https://github.com/ansible-collections/community.mysql/issues/98). +- mysql_replication - the mode options values ``getslave``, ``startslave``, ``stopslave``, ``resetslave``, ``resetslaveall` and the master_use_gtid option ``slave_pos`` are deprecated (see the alternative values) and will be removed in ``community.mysql`` 3.0.0 (https://github.com/ansible-collections/community.mysql/pull/97). diff --git a/plugins/modules/mysql_replication.py b/plugins/modules/mysql_replication.py index 1645a69f..55ac725e 100644 --- a/plugins/modules/mysql_replication.py +++ b/plugins/modules/mysql_replication.py @@ -507,8 +507,8 @@ def main(): if uses_replica_terminology(cursor): replica_term = 'REPLICA' if master_use_gtid == 'slave_pos': - module.warn('master_use_gtid "slave_pos" value is deprecated. ' - 'Please, use "replica_pos" instead.') + module.deprecate('master_use_gtid "slave_pos" value is deprecated, use "replica_pos" instead.', + version='3.0.0', collection_name='community.mysql') master_use_gtid = 'replica_pos' else: replica_term = 'SLAVE' @@ -525,8 +525,8 @@ def main(): elif mode in ("getreplica", "getslave"): if mode == "getslave": - module.warn('"getslave" option is deprecated. ' - 'Please, use "getreplica" instead.') + module.deprecate('"getslave" option is deprecated, use "getreplica" instead.', + version='3.0.0', collection_name='community.mysql') status = get_replica_status(cursor, connection_name, channel, replica_term) if not isinstance(status, dict): @@ -584,8 +584,8 @@ def main(): module.exit_json(queries=executed_queries, **result) elif mode in ("startreplica", "startslave"): if mode == "startslave": - module.warn('"startslave" option is deprecated. ' - 'Please, use "startreplica" instead.') + module.deprecate('"startslave" option is deprecated, use "startreplica" instead.', + version='3.0.0', collection_name='community.mysql') started = start_replica(module, cursor, connection_name, channel, fail_on_error, replica_term) if started is True: @@ -594,8 +594,8 @@ def main(): module.exit_json(msg="Slave already started (Or cannot be started)", changed=False, queries=executed_queries) elif mode in ("stopreplica", "stopslave"): if mode == "stopslave": - module.warn('"stopslave" option is deprecated. ' - 'Please, use "stopreplica" instead.') + module.deprecate('"stopslave" option is deprecated, use "stopreplica" instead.', + version='3.0.0', collection_name='community.mysql') stopped = stop_replica(module, cursor, connection_name, channel, fail_on_error, replica_term) if stopped is True: @@ -610,8 +610,8 @@ def main(): module.exit_json(msg="Master already reset", changed=False, queries=executed_queries) elif mode in ("resetreplica", "resetslave"): if mode == "resetslave": - module.warn('"resetslave" option is deprecated. ' - 'Please, use "resetreplica" instead.') + module.deprecate('"resetslave" option is deprecated, use "resetreplica" instead.', + version='3.0.0', collection_name='community.mysql') reset = reset_replica(module, cursor, connection_name, channel, fail_on_error, replica_term) if reset is True: @@ -620,8 +620,8 @@ def main(): module.exit_json(msg="Slave already reset", changed=False, queries=executed_queries) elif mode in ("resetreplicaall", "resetslaveall"): if mode == "resetslaveall": - module.warn('"resetslaveall" option is deprecated. ' - 'Please, use "resetreplicaall" instead.') + module.deprecate('"resetslaveall" option is deprecated, use "resetreplicaall" instead.', + version='3.0.0', collection_name='community.mysql') reset = reset_replica_all(module, cursor, connection_name, channel, fail_on_error, replica_term) if reset is True: