mirror of
https://github.com/ansible-collections/community.mysql.git
synced 2025-07-22 04:40:23 -07:00
mysql_replication: fix crashes caused by deprecated terminology (#71)
* mysql_replication: fix crashes caused by deprecated terminology * Fix unrelated sanity errors * Tests: mysql 8.0.21 -> 8.022 * Adjust integration tests * Add version check to the tests * Add debug statement * Adjust mysql version * Fix tests * Add unit tests * Add changelog fragment * Improve code and coverage * Get rid of extra blank line * Improve coverage * Change suggested
This commit is contained in:
parent
b7e828a092
commit
ebe503823a
8 changed files with 194 additions and 29 deletions
|
@ -7,7 +7,7 @@ percona_client_version: 5.7
|
|||
|
||||
mariadb_install: false
|
||||
|
||||
mysql_version: 8.0.21
|
||||
mysql_version: 8.0.22
|
||||
mariadb_version: 10.5.4
|
||||
|
||||
mysql_base_port: 3306
|
||||
|
|
|
@ -48,7 +48,7 @@
|
|||
- assert:
|
||||
that:
|
||||
- result is changed
|
||||
- result.queries == ["START SLAVE FOR CHANNEL '{{ test_channel }}'"]
|
||||
- result.queries == ["START SLAVE FOR CHANNEL '{{ test_channel }}'"] or result.queries == ["START REPLICA FOR CHANNEL '{{ test_channel }}'"]
|
||||
|
||||
# Test getslave mode:
|
||||
- name: Get standby status with channel
|
||||
|
@ -69,6 +69,20 @@
|
|||
- slave_status.Last_IO_Error == ''
|
||||
- slave_status.Channel_Name == '{{ test_channel }}'
|
||||
- slave_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
|
||||
when: mysql8022_and_higher == true
|
||||
|
||||
|
||||
# Test stopslave mode:
|
||||
- name: Stop slave with channel
|
||||
|
@ -82,7 +96,7 @@
|
|||
- assert:
|
||||
that:
|
||||
- result is changed
|
||||
- result.queries == ["STOP SLAVE FOR CHANNEL '{{ test_channel }}'"]
|
||||
- result.queries == ["STOP SLAVE FOR CHANNEL '{{ test_channel }}'"] or result.queries == ["STOP REPLICA FOR CHANNEL '{{ test_channel }}'"]
|
||||
|
||||
# Test reset
|
||||
- name: Reset slave with channel
|
||||
|
@ -96,7 +110,7 @@
|
|||
- assert:
|
||||
that:
|
||||
- result is changed
|
||||
- result.queries == ["RESET SLAVE FOR CHANNEL '{{ test_channel }}'"]
|
||||
- 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
|
||||
|
@ -110,4 +124,4 @@
|
|||
- assert:
|
||||
that:
|
||||
- result is changed
|
||||
- result.queries == ["RESET SLAVE ALL FOR CHANNEL '{{ test_channel }}'"]
|
||||
- result.queries == ["RESET SLAVE ALL FOR CHANNEL '{{ test_channel }}'"] or result.queries == ["RESET REPLICA ALL FOR CHANNEL '{{ test_channel }}'"]
|
||||
|
|
|
@ -8,6 +8,22 @@
|
|||
login_host: 127.0.0.1
|
||||
|
||||
block:
|
||||
- name: find out the database version
|
||||
mysql_info:
|
||||
<<: *mysql_params
|
||||
login_port: '{{ mysql_primary_port }}'
|
||||
filter: version
|
||||
register: db
|
||||
|
||||
- name: Set mysql8022_and_higher
|
||||
set_fact:
|
||||
mysql8022_and_higher: false
|
||||
|
||||
- name: Set mysql8022_and_higher
|
||||
set_fact:
|
||||
mysql8022_and_higher: true
|
||||
when:
|
||||
- db.version.major > 8 or (db.version.major == 8 and db.version.minor > 0) or (db.version.major == 8 and db.version.minor == 0 and db.version.release >= 22)
|
||||
|
||||
- name: alias mysql command to include default options
|
||||
set_fact:
|
||||
|
@ -120,7 +136,7 @@
|
|||
- assert:
|
||||
that:
|
||||
- result is changed
|
||||
- result.queries == ["START SLAVE"]
|
||||
- result.queries == ["START SLAVE"] or result.queries == ["START REPLICA"]
|
||||
|
||||
# Test getslave mode:
|
||||
- name: Get standby status
|
||||
|
@ -139,6 +155,18 @@
|
|||
- slave_status.Last_IO_Errno == 0
|
||||
- slave_status.Last_IO_Error == ''
|
||||
- slave_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
|
||||
when: mysql8022_and_higher == true
|
||||
|
||||
# Create test table and add data to it:
|
||||
- name: Create test table
|
||||
|
@ -164,6 +192,12 @@
|
|||
- assert:
|
||||
that:
|
||||
- slave_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
|
||||
when: mysql8022_and_higher == true
|
||||
|
||||
- shell: pip show pymysql | awk '/Version/ {print $2}'
|
||||
register: pymysql_version
|
||||
|
@ -192,7 +226,7 @@
|
|||
- assert:
|
||||
that:
|
||||
- result is changed
|
||||
- result.queries == ["STOP SLAVE"]
|
||||
- result.queries == ["STOP SLAVE"] or result.queries == ["STOP REPLICA"]
|
||||
|
||||
# Test stopslave mode:
|
||||
- name: Stop slave that is no longer running
|
||||
|
|
0
tests/unit/plugins/modules/__init__.py
Normal file
0
tests/unit/plugins/modules/__init__.py
Normal file
47
tests/unit/plugins/modules/test_mysql_replication.py
Normal file
47
tests/unit/plugins/modules/test_mysql_replication.py
Normal file
|
@ -0,0 +1,47 @@
|
|||
# -*- coding: utf-8 -*-
|
||||
# Copyright: (c) 2020, Andrew Klychkov (@Andersson007) <aaklychkov@mail.ru>
|
||||
|
||||
from __future__ import (absolute_import, division, print_function)
|
||||
__metaclass__ = type
|
||||
|
||||
import pytest
|
||||
|
||||
from ansible_collections.community.mysql.plugins.modules.mysql_replication import uses_replica_terminology
|
||||
|
||||
|
||||
class dummy_cursor_class():
|
||||
def __init__(self, output, ret_val_type='dict'):
|
||||
self.output = output
|
||||
self.ret_val_type = ret_val_type
|
||||
|
||||
def execute(self, query):
|
||||
pass
|
||||
|
||||
def fetchone(self):
|
||||
if self.ret_val_type == 'dict':
|
||||
return {'version': self.output}
|
||||
|
||||
elif self.ret_val_type == 'list':
|
||||
return [self.output]
|
||||
|
||||
|
||||
@pytest.mark.parametrize(
|
||||
'f_output,c_output,c_ret_type',
|
||||
[
|
||||
(False, '5.5.1-mysql', 'list'),
|
||||
(False, '5.7.0-mysql', 'dict'),
|
||||
(False, '8.0.0-mysql', 'list'),
|
||||
(False, '8.0.11-mysql', 'dict'),
|
||||
(False, '8.0.21-mysql', 'list'),
|
||||
(False, '10.5.0-mariadb', 'dict'),
|
||||
(True, '8.0.22-mysql', 'list'),
|
||||
(True, '8.1.2-mysql', 'dict'),
|
||||
(True, '9.0.0-mysql', 'list'),
|
||||
(True, '10.5.1-mariadb', 'dict'),
|
||||
(True, '10.6.0-mariadb', 'dict'),
|
||||
(True, '11.5.1-mariadb', 'dict'),
|
||||
]
|
||||
)
|
||||
def test_uses_replica_terminology(f_output, c_output, c_ret_type):
|
||||
cursor = dummy_cursor_class(c_output, c_ret_type)
|
||||
assert uses_replica_terminology(cursor) == f_output
|
Loading…
Add table
Add a link
Reference in a new issue