Add support for MariaDB 11.4 (#703)

* fix missing symlink to mysql binaries for MariaDB 11+

* update tested version of MariaDB 11.4 instead of 10.5

* add changelog fragment

* [CI] add way to trigger workflow manually

Useful in the case we don't modifiy any files in the paths: sections of the push event.

* add version check for mariadb < 10.4.6 without mariadb* binaries

* Use same concatenation method between functions to avoid future confusion

I didn't notice that db_dump and db_import were different, thus I introduced a bug with the initialization of the variable cmd. This commit fixes that.
This commit is contained in:
Laurent Indermühle 2025-03-10 18:55:42 +01:00 committed by GitHub
parent e9845b0a1c
commit dd7e297d50
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
7 changed files with 84 additions and 49 deletions

View file

@ -386,67 +386,75 @@ def db_dump(module, host, user, password, db_name, target, all_databases, port,
encoding=None, force=False, master_data=0, skip_lock_tables=False,
dump_extra_args=None, unsafe_password=False, restrict_config_file=False,
check_implicit_admin=False, pipefail=False):
cmd = module.get_bin_path('mysqldump', True)
cmd_str = 'mysqldump'
if server_implementation == 'mariadb' and LooseVersion(server_version) >= LooseVersion("10.4.6"):
cmd_str = 'mariadb-dump'
try:
cmd = [module.get_bin_path(cmd_str, True)]
except Exception as e:
return 1, "", "Error determining dump command: %s" % str(e)
# If defined, mysqldump demands --defaults-extra-file be the first option
if config_file:
if restrict_config_file:
cmd += " --defaults-file=%s" % shlex_quote(config_file)
cmd.append("--defaults-file=%s" % shlex_quote(config_file))
else:
cmd += " --defaults-extra-file=%s" % shlex_quote(config_file)
cmd.append("--defaults-extra-file=%s" % shlex_quote(config_file))
if check_implicit_admin:
cmd += " --user=root --password=''"
cmd.append("--user=root --password=''")
else:
if user is not None:
cmd += " --user=%s" % shlex_quote(user)
cmd.append("--user=%s" % shlex_quote(user))
if password is not None:
if not unsafe_password:
cmd += " --password=%s" % shlex_quote(password)
cmd.append("--password=%s" % shlex_quote(password))
else:
cmd += " --password=%s" % password
cmd.append("--password=%s" % password)
if ssl_cert is not None:
cmd += " --ssl-cert=%s" % shlex_quote(ssl_cert)
cmd.append("--ssl-cert=%s" % shlex_quote(ssl_cert))
if ssl_key is not None:
cmd += " --ssl-key=%s" % shlex_quote(ssl_key)
cmd.append("--ssl-key=%s" % shlex_quote(ssl_key))
if ssl_ca is not None:
cmd += " --ssl-ca=%s" % shlex_quote(ssl_ca)
cmd.append("--ssl-ca=%s" % shlex_quote(ssl_ca))
if force:
cmd += " --force"
cmd.append("--force")
if socket is not None:
cmd += " --socket=%s" % shlex_quote(socket)
cmd.append("--socket=%s" % shlex_quote(socket))
else:
cmd += " --host=%s --port=%i" % (shlex_quote(host), port)
cmd.append("--host=%s --port=%i" % (shlex_quote(host), port))
if all_databases:
cmd += " --all-databases"
cmd.append("--all-databases")
elif len(db_name) > 1:
cmd += " --databases {0}".format(' '.join(db_name))
cmd.append("--databases {0}".format(' '.join(db_name)))
else:
cmd += " %s" % shlex_quote(' '.join(db_name))
cmd.append("%s" % shlex_quote(' '.join(db_name)))
if skip_lock_tables:
cmd += " --skip-lock-tables"
cmd.append("--skip-lock-tables")
if (encoding is not None) and (encoding != ""):
cmd += " --default-character-set=%s" % shlex_quote(encoding)
cmd.append("--default-character-set=%s" % shlex_quote(encoding))
if single_transaction:
cmd += " --single-transaction=true"
cmd.append("--single-transaction=true")
if quick:
cmd += " --quick"
cmd.append("--quick")
if ignore_tables:
for an_ignored_table in ignore_tables:
cmd += " --ignore-table={0}".format(an_ignored_table)
cmd.append("--ignore-table={0}".format(an_ignored_table))
if hex_blob:
cmd += " --hex-blob"
cmd.append("--hex-blob")
if master_data:
if (server_implementation == 'mysql' and
LooseVersion(server_version) >= LooseVersion("8.2.0")):
cmd += " --source-data=%s" % master_data
cmd.append("--source-data=%s" % master_data)
else:
cmd += " --master-data=%s" % master_data
cmd.append("--master-data=%s" % master_data)
if dump_extra_args is not None:
cmd += " " + dump_extra_args
cmd.append(dump_extra_args)
path = None
if os.path.splitext(target)[-1] == '.gz':
@ -458,6 +466,8 @@ def db_dump(module, host, user, password, db_name, target, all_databases, port,
elif os.path.splitext(target)[-1] == '.zst':
path = module.get_bin_path('zstd', True)
cmd = ' '.join(cmd)
if path:
cmd = '%s | %s > %s' % (cmd, path, shlex_quote(target))
if pipefail:
@ -476,13 +486,21 @@ def db_dump(module, host, user, password, db_name, target, all_databases, port,
def db_import(module, host, user, password, db_name, target, all_databases, port, config_file,
socket=None, ssl_cert=None, ssl_key=None, ssl_ca=None, encoding=None, force=False,
server_implementation, server_version, socket=None, ssl_cert=None, ssl_key=None, ssl_ca=None,
encoding=None, force=False,
use_shell=False, unsafe_password=False, restrict_config_file=False,
check_implicit_admin=False):
if not os.path.exists(target):
return module.fail_json(msg="target %s does not exist on the host" % target)
cmd = [module.get_bin_path('mysql', True)]
cmd_str = 'mysql'
if server_implementation == 'mariadb' and LooseVersion(server_version) >= LooseVersion("10.4.6"):
cmd_str = 'mariadb'
try:
cmd = [module.get_bin_path(cmd_str, True)]
except Exception as e:
return 1, "", "Error determining mysql/mariadb command: %s" % str(e)
# --defaults-file must go first, or errors out
if config_file:
if restrict_config_file:
@ -772,8 +790,8 @@ def main():
rc, stdout, stderr = db_import(module, login_host, login_user,
login_password, db, target,
all_databases,
login_port, config_file,
socket, ssl_cert, ssl_key, ssl_ca,
login_port, config_file, server_implementation,
server_version, socket, ssl_cert, ssl_key, ssl_ca,
encoding, force, use_shell, unsafe_login_password,
restrict_config_file, check_implicit_admin)
if rc != 0: