Move version check for resource_limits to implementations

This commit is contained in:
Maximilian Stinsky 2023-03-31 09:26:24 +02:00
parent 424b33d1f8
commit 97604477c6
No known key found for this signature in database
GPG key ID: 46D3BABABE00D5E6
3 changed files with 13 additions and 28 deletions

View file

@ -17,3 +17,9 @@ def use_old_user_mgmt(cursor):
def supports_identified_by_password(cursor):
return True
def server_supports_alter_user(cursor):
version = get_server_version(cursor)
return LooseVersion(version) >= LooseVersion("10.2")

View file

@ -18,3 +18,9 @@ def use_old_user_mgmt(cursor):
def supports_identified_by_password(cursor):
version = get_server_version(cursor)
return LooseVersion(version) < LooseVersion("8")
def server_supports_alter_user(cursor):
version = get_server_version(cursor)
return LooseVersion(version) >= LooseVersion("5.6")

View file

@ -753,33 +753,6 @@ def convert_priv_dict_to_str(priv):
return '/'.join(priv_list)
# Alter user is supported since MySQL 5.6 and MariaDB 10.2.0
def server_supports_alter_user(cursor):
"""Check if the server supports ALTER USER statement or doesn't.
Args:
cursor (cursor): DB driver cursor object.
Returns: True if supports, False otherwise.
"""
cursor.execute("SELECT VERSION()")
version_str = cursor.fetchone()[0]
version = version_str.split('.')
if 'mariadb' in version_str.lower():
# MariaDB 10.2 and later
if int(version[0]) * 1000 + int(version[1]) >= 10002:
return True
else:
return False
else:
# MySQL 5.6 and later
if int(version[0]) * 1000 + int(version[1]) >= 5006:
return True
else:
return False
def get_resource_limits(cursor, user, host):
"""Get user resource limits.
@ -869,7 +842,7 @@ def limit_resources(module, cursor, user, host, resource_limits, check_mode):
Returns: True, if changed, False otherwise.
"""
if not server_supports_alter_user(cursor):
if not impl.server_supports_alter_user(cursor):
module.fail_json(msg="The server version does not match the requirements "
"for resource_limits parameter. See module's documentation.")