-
Notifications
You must be signed in to change notification settings - Fork 91
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Using show all slaves status
when using MariaDB to be consistent with MySQL
#602
Changes from 16 commits
a7de8f8
b2072a2
db4c50e
2de02bd
ed93655
6eec740
4c5e8f8
c66a5ac
3ef93e8
10660cf
fff53b4
690ac6f
aa7c5be
4a2a638
d61bb70
93e42bc
6ac515b
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,2 @@ | ||
bugfixes: | ||
- mysql_info - the ``slave_status`` filter was returning an empty list on MariaDB with multiple replication channels. It now returns all channels by running ``SHOW ALL SLAVES STATUS`` for MariaDB servers (https://github.com/ansible-collections/community.mysql/issues/603). |
Original file line number | Diff line number | Diff line change | ||||
---|---|---|---|---|---|---|
|
@@ -5,6 +5,7 @@ | |||||
# GNU General Public License v3.0+ (see COPYING or https://www.gnu.org/licenses/gpl-3.0.txt) | ||||||
|
||||||
from __future__ import absolute_import, division, print_function | ||||||
|
||||||
__metaclass__ = type | ||||||
|
||||||
DOCUMENTATION = r''' | ||||||
|
@@ -292,6 +293,8 @@ | |||||
mysql_driver_fail_msg, | ||||||
get_connector_name, | ||||||
get_connector_version, | ||||||
get_server_implementation, | ||||||
is_mariadb, | ||||||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
Suggested change
|
||||||
) | ||||||
|
||||||
from ansible_collections.community.mysql.plugins.module_utils.user import ( | ||||||
|
@@ -325,9 +328,10 @@ class MySQL_Info(object): | |||||
5. add info about the new subset with an example to RETURN block | ||||||
""" | ||||||
|
||||||
def __init__(self, module, cursor): | ||||||
def __init__(self, module, cursor, server_implementation): | ||||||
self.module = module | ||||||
self.cursor = cursor | ||||||
self.server_implementation = server_implementation | ||||||
self.info = { | ||||||
'version': {}, | ||||||
'databases': {}, | ||||||
|
@@ -497,7 +501,10 @@ def __get_master_status(self): | |||||
|
||||||
def __get_slave_status(self): | ||||||
"""Get slave status if the instance is a slave.""" | ||||||
res = self.__exec_sql('SHOW SLAVE STATUS') | ||||||
if is_mariadb(self.server_implementation): | ||||||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
Suggested change
|
||||||
res = self.__exec_sql('SHOW ALL SLAVES STATUS') | ||||||
else: | ||||||
res = self.__exec_sql('SHOW SLAVE STATUS') | ||||||
if res: | ||||||
for line in res: | ||||||
host = line['Master_Host'] | ||||||
|
@@ -738,10 +745,12 @@ def main(): | |||||
'Exception message: %s' % (connector_name, connector_version, config_file, to_native(e))) | ||||||
module.fail_json(msg) | ||||||
|
||||||
server_implementation = get_server_implementation(cursor) | ||||||
|
||||||
############################### | ||||||
# Create object and do main job | ||||||
|
||||||
mysql = MySQL_Info(module, cursor) | ||||||
mysql = MySQL_Info(module, cursor, server_implementation) | ||||||
|
||||||
module.exit_json(changed=False, | ||||||
connector_name=connector_name, | ||||||
|
Original file line number | Diff line number | Diff line change | ||||||||||||||||||||||||||||||
---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
@@ -1,9 +1,10 @@ | ||||||||||||||||||||||||||||||||
from __future__ import (absolute_import, division, print_function) | ||||||||||||||||||||||||||||||||
|
||||||||||||||||||||||||||||||||
__metaclass__ = type | ||||||||||||||||||||||||||||||||
|
||||||||||||||||||||||||||||||||
import pytest | ||||||||||||||||||||||||||||||||
|
||||||||||||||||||||||||||||||||
from ansible_collections.community.mysql.plugins.module_utils.mysql import get_server_version | ||||||||||||||||||||||||||||||||
from ansible_collections.community.mysql.plugins.module_utils.mysql import get_server_version, get_server_implementation, is_mariadb, is_mysql | ||||||||||||||||||||||||||||||||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
Suggested change
|
||||||||||||||||||||||||||||||||
from ..utils import dummy_cursor_class | ||||||||||||||||||||||||||||||||
|
||||||||||||||||||||||||||||||||
|
||||||||||||||||||||||||||||||||
|
@@ -22,3 +23,37 @@ def test_get_server_version(cursor_return_version, cursor_return_type): | |||||||||||||||||||||||||||||||
""" | ||||||||||||||||||||||||||||||||
cursor = dummy_cursor_class(cursor_return_version, cursor_return_type) | ||||||||||||||||||||||||||||||||
assert get_server_version(cursor) == cursor_return_version | ||||||||||||||||||||||||||||||||
|
||||||||||||||||||||||||||||||||
|
||||||||||||||||||||||||||||||||
@pytest.mark.parametrize( | ||||||||||||||||||||||||||||||||
'cursor_return_version,cursor_return_type,server_implementation', | ||||||||||||||||||||||||||||||||
[ | ||||||||||||||||||||||||||||||||
('5.7.0-mysql', 'dict', 'mysql'), | ||||||||||||||||||||||||||||||||
('8.0.0-mysql', 'list', 'mysql'), | ||||||||||||||||||||||||||||||||
('10.5.0-mariadb', 'dict', 'mariadb'), | ||||||||||||||||||||||||||||||||
('10.5.1-mariadb', 'list', 'mariadb'), | ||||||||||||||||||||||||||||||||
] | ||||||||||||||||||||||||||||||||
) | ||||||||||||||||||||||||||||||||
def test_get_server_implamentation(cursor_return_version, cursor_return_type, server_implementation): | ||||||||||||||||||||||||||||||||
""" | ||||||||||||||||||||||||||||||||
Test that server implementation are handled properly by get_server_implementation() whether the server version returned as a list or dict. | ||||||||||||||||||||||||||||||||
""" | ||||||||||||||||||||||||||||||||
cursor = dummy_cursor_class(cursor_return_version, cursor_return_type) | ||||||||||||||||||||||||||||||||
|
||||||||||||||||||||||||||||||||
assert get_server_implementation(cursor) == server_implementation | ||||||||||||||||||||||||||||||||
|
||||||||||||||||||||||||||||||||
|
||||||||||||||||||||||||||||||||
def test_is_mysql(): | ||||||||||||||||||||||||||||||||
""" | ||||||||||||||||||||||||||||||||
Test that server is_mysql return expect results | ||||||||||||||||||||||||||||||||
""" | ||||||||||||||||||||||||||||||||
assert is_mysql("mysql") is True | ||||||||||||||||||||||||||||||||
assert is_mysql("mariadb") is False | ||||||||||||||||||||||||||||||||
|
||||||||||||||||||||||||||||||||
|
||||||||||||||||||||||||||||||||
def test_is_mariadb(): | ||||||||||||||||||||||||||||||||
""" | ||||||||||||||||||||||||||||||||
Test that server is_mariadb return expect results | ||||||||||||||||||||||||||||||||
""" | ||||||||||||||||||||||||||||||||
assert is_mariadb("mariadb") is True | ||||||||||||||||||||||||||||||||
assert is_mariadb("mysql") is False | ||||||||||||||||||||||||||||||||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
Suggested change
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.