From 2d2e56d13ad5238be9d055dd0aea625c966aa378 Mon Sep 17 00:00:00 2001 From: Laurent Indermuehle Date: Fri, 6 Oct 2023 14:09:28 +0200 Subject: [PATCH] fix warning to be displayed only when option is not set by the user --- plugins/modules/mysql_role.py | 12 ++++++------ plugins/modules/mysql_user.py | 11 ++++++----- .../tasks/test_column_case_sensitive.yml | 2 +- 3 files changed, 13 insertions(+), 12 deletions(-) diff --git a/plugins/modules/mysql_role.py b/plugins/modules/mysql_role.py index f588374..4667fa9 100644 --- a/plugins/modules/mysql_role.py +++ b/plugins/modules/mysql_role.py @@ -128,7 +128,6 @@ options: feature was introduced but since MySQL/MariaDB is case sensitive you should set this to C(true) in most cases. type: bool - default: false version_added: '3.8.0' notes: @@ -970,7 +969,7 @@ def main(): check_implicit_admin=dict(type='bool', default=False), set_default_role_all=dict(type='bool', default=True), members_must_exist=dict(type='bool', default=True), - column_case_sensitive=dict(type='bool', default=False), + column_case_sensitive=dict(type='bool', default=None), # TODO 4.0.0 add default=True ) module = AnsibleModule( argument_spec=argument_spec, @@ -1018,6 +1017,11 @@ def main(): if mysql_driver is None: module.fail_json(msg=mysql_driver_fail_msg) + # TODO Release 4.0.0 : Remove this test and variable assignation + if column_case_sensitive is None: + column_case_sensitive = False + module.warn("Option column_case_sensitive not provided, column's name will be uppercased") + cursor = None try: if check_implicit_admin: @@ -1087,10 +1091,6 @@ def main(): try: if state == 'present': if not role.exists: - # TODO Release 4.0.0 : Remove this warning or change the message. - if not column_case_sensitive and "(" in str(priv): - module.warn("column_case_sensitive set to False, column's name will be uppercased") - if subtract_privs: priv = None # avoid granting unwanted privileges if detach_members: diff --git a/plugins/modules/mysql_user.py b/plugins/modules/mysql_user.py index 9a0c349..80c02a1 100644 --- a/plugins/modules/mysql_user.py +++ b/plugins/modules/mysql_user.py @@ -163,7 +163,6 @@ options: - This feature was introduced because MySQL 8 and above uses case sensitive fields names in privileges. type: bool - default: false version_added: '3.8.0' notes: @@ -414,7 +413,7 @@ def main(): resource_limits=dict(type='dict'), force_context=dict(type='bool', default=False), session_vars=dict(type='dict'), - column_case_sensitive=dict(type='bool', default=False) + column_case_sensitive=dict(type='bool', default=None), # TODO 4.0.0 add default=True ) module = AnsibleModule( argument_spec=argument_spec, @@ -477,6 +476,11 @@ def main(): module.fail_json(msg="unable to connect to database, check login_user and login_password are correct or %s has the credentials. " "Exception message: %s" % (config_file, to_native(e))) + # TODO Release 4.0.0 : Remove this test and variable assignation + if column_case_sensitive is None: + column_case_sensitive = False + module.warn("Option column_case_sensitive not provided, column's name will be uppercased") + if not sql_log_bin: cursor.execute("SET SQL_LOG_BIN=0;") @@ -491,9 +495,6 @@ def main(): except Exception as e: module.fail_json(msg=to_native(e)) - # TODO Release 4.0.0 : Remove this warning or change the message. - if not column_case_sensitive and "(" in str(priv): - module.warn("column_case_sensitive set to False, column's name will be uppercased") priv = privileges_unpack(priv, mode, column_case_sensitive, ensure_usage=not subtract_privs) password_changed = False if state == "present": diff --git a/tests/integration/targets/test_mysql_user/tasks/test_column_case_sensitive.yml b/tests/integration/targets/test_mysql_user/tasks/test_column_case_sensitive.yml index 73c8ae1..68e95aa 100644 --- a/tests/integration/targets/test_mysql_user/tasks/test_column_case_sensitive.yml +++ b/tests/integration/targets/test_mysql_user/tasks/test_column_case_sensitive.yml @@ -25,7 +25,7 @@ # ================= Reproduce failure ===================================== - - name: Mysql_user Column case sensitive | Create users + - name: Mysql_user Column case sensitive | Create test user community.mysql.mysql_user: <<: *mysql_params name: column_case_sensitive