Using show all slaves status whe using MariaDB to be consistent

with the MySQL behaviour.
This commit is contained in:
William Welter 2024-01-04 13:38:38 +00:00
parent 81ab18d56c
commit a7de8f89c4

View file

@ -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'''
@ -325,9 +326,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': {},
@ -387,6 +389,18 @@ class MySQL_Info(object):
self.__collect(exclude_fields, return_empty_dbs, set(self.info))
return self.info
def is_mariadb(self):
if self.server_implementation == "mariadb":
return True
else:
return False
def is_mysql(self):
if self.server_implementation == "mysql":
return True
else:
return False
def __collect(self, exclude_fields, return_empty_dbs, wanted):
"""Collect all possible subsets."""
if 'version' in wanted or 'settings' in wanted:
@ -497,7 +511,10 @@ class MySQL_Info(object):
def __get_slave_status(self):
"""Get slave status if the instance is a slave."""
res = self.__exec_sql('SHOW SLAVE STATUS')
if(self.is_mariadb()):
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 +755,16 @@ def main():
'Exception message: %s' % (connector_name, connector_version, config_file, to_native(e)))
module.fail_json(msg)
cursor.execute("SELECT VERSION()")
if 'mariadb' in cursor.fetchone()[0].lower():
server_implementation="mariadb"
else:
server_implementation="mysql"
###############################
# 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,