mirror of
https://github.com/ansible-collections/community.mysql.git
synced 2025-07-22 12:50:24 -07:00
Fix deprecated options from MySQL 8.2 (#662)
* Fix show master status for MySQL 8.2+ * Fix mysqldump option form --master-data to --source-data * Fix incompatibility between mysqldump 8.0 and MySQL 8.4 Installing the same version between the client and the server makes sense anyway. The incompatibility arise when you use mysqldump with --source-data. The the tool tries to perform a SHOW MASTER STATUS which is deprecated in MySQL 8.2+. * Fix missing condition * Fix unit tests * Add a query resolver depending on implementation and version * Sanity * Fix SHOW REPLICA STATUS queries * Fix mariadb's SHOW REPLICA HOSTS query * Fix CHANGE MASTER for MySQL 8.0.23+ * Fix integration test for CHANGE MASTER * Fix integration test for CHANGE MASTER * Fix replication queries for MySQL 8.0.23+ and 8.4+ * Revert file edited by mistake * Enhance tests format
This commit is contained in:
parent
c503dc5b6b
commit
cd9f4fcf57
14 changed files with 503 additions and 94 deletions
39
tests/unit/plugins/module_utils/test_command_resolver.py
Normal file
39
tests/unit/plugins/module_utils/test_command_resolver.py
Normal file
|
@ -0,0 +1,39 @@
|
|||
# -*- coding: utf-8 -*-
|
||||
|
||||
from __future__ import (absolute_import, division, print_function)
|
||||
__metaclass__ = type
|
||||
|
||||
import pytest
|
||||
|
||||
from ansible_collections.community.mysql.plugins.module_utils.command_resolver import (
|
||||
CommandResolver,
|
||||
)
|
||||
|
||||
|
||||
@pytest.mark.parametrize(
|
||||
'server_implementation,server_version,command,expected_output,expected_exception,expected_message',
|
||||
[
|
||||
('mysql', '1.0.0', 'SHOW NOTHING', '', ValueError, 'Unsupported command: SHOW NOTHING'),
|
||||
('mysql', '8.0.20', 'SHOW MASTER STATUS', 'SHOW MASTER STATUS', None, None), # Case insensitive
|
||||
('mysql', '8.0.20', 'show master status', 'SHOW MASTER STATUS', None, None), # Case insensitive
|
||||
('mysql', '8.0.20', 'SHOW master STATUS', 'SHOW MASTER STATUS', None, None), # Case insensitive
|
||||
('mysql', '8.2.0', 'SHOW MASTER STATUS', 'SHOW BINARY LOG STATUS', None, None),
|
||||
('mysql', '9.0.0', 'SHOW MASTER STATUS', 'SHOW BINARY LOG STATUS', None, None),
|
||||
('mariadb', '10.4.23', 'SHOW MASTER STATUS', 'SHOW MASTER STATUS', None, None), # Default
|
||||
('mariadb', '10.5.1', 'SHOW MASTER STATUS', 'SHOW MASTER STATUS', None, None), # Default
|
||||
('mariadb', '10.5.2', 'SHOW MASTER STATUS', 'SHOW BINLOG STATUS', None, None),
|
||||
('mariadb', '10.6.17', 'SHOW MASTER STATUS', 'SHOW BINLOG STATUS', None, None),
|
||||
('mysql', '8.4.1', 'CHANGE MASTER', 'CHANGE REPLICATION SOURCE', None, None),
|
||||
]
|
||||
)
|
||||
def test_resolve_command(server_implementation, server_version, command, expected_output, expected_exception, expected_message):
|
||||
"""
|
||||
Tests that the CommandResolver method resolve_command return the correct query.
|
||||
"""
|
||||
resolver = CommandResolver(server_implementation, server_version)
|
||||
if expected_exception:
|
||||
with pytest.raises(expected_exception) as excinfo:
|
||||
resolver.resolve_command(command)
|
||||
assert str(excinfo.value) == expected_message
|
||||
else:
|
||||
assert resolver.resolve_command(command) == expected_output
|
|
@ -14,15 +14,15 @@ from ansible_collections.community.mysql.plugins.modules.mysql_info import MySQL
|
|||
|
||||
|
||||
@pytest.mark.parametrize(
|
||||
'suffix,cursor_output,server_implementation,user_implementation',
|
||||
'suffix,cursor_output,server_implementation,server_version,user_implementation',
|
||||
[
|
||||
('mysql', '5.5.1-mysql', 'mysql', 'mysql'),
|
||||
('log', '5.7.31-log', 'mysql', 'mysql'),
|
||||
('mariadb', '10.5.0-mariadb', 'mariadb', 'mariadb'),
|
||||
('', '8.0.22', 'mysql', 'mysql'),
|
||||
('mysql', '5.5.1-mysql', 'mysql', '5.5.1', 'mysql'),
|
||||
('log', '5.7.31-log', 'mysql', '5.7.31', 'mysql'),
|
||||
('mariadb', '10.5.0-mariadb', 'mariadb', '10.5.0', 'mariadb'),
|
||||
('', '8.0.22', 'mysql', '8.0.22', 'mysql'),
|
||||
]
|
||||
)
|
||||
def test_get_info_suffix(suffix, cursor_output, server_implementation, user_implementation):
|
||||
def test_get_info_suffix(suffix, cursor_output, server_implementation, server_version, user_implementation):
|
||||
def __cursor_return_value(input_parameter):
|
||||
if input_parameter == "SHOW GLOBAL VARIABLES":
|
||||
cursor.fetchall.return_value = [{"Variable_name": "version", "Value": cursor_output}]
|
||||
|
@ -32,6 +32,6 @@ def test_get_info_suffix(suffix, cursor_output, server_implementation, user_impl
|
|||
cursor = MagicMock()
|
||||
cursor.execute.side_effect = __cursor_return_value
|
||||
|
||||
info = MySQL_Info(MagicMock(), cursor, server_implementation, user_implementation)
|
||||
info = MySQL_Info(MagicMock(), cursor, server_implementation, server_version, user_implementation)
|
||||
|
||||
assert info.get_info([], [], False)['version']['suffix'] == suffix
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue