From 70efd0f43cca12e03d13f1ba24dd570c55ef00c0 Mon Sep 17 00:00:00 2001 From: bizmate Date: Thu, 1 Dec 2022 10:50:42 +0400 Subject: [PATCH] Adding params in exception output and check exception message with is search instead of find expression (#465) --- plugins/module_utils/user.py | 3 ++- .../targets/test_mysql_user/tasks/test_privs_issue_465.yml | 6 ++++-- 2 files changed, 6 insertions(+), 3 deletions(-) diff --git a/plugins/module_utils/user.py b/plugins/module_utils/user.py index 5c0e0c5..e80bccf 100644 --- a/plugins/module_utils/user.py +++ b/plugins/module_utils/user.py @@ -725,7 +725,8 @@ def privileges_grant(cursor, user, host, db_table, priv, tls_requires, maria_rol try: cursor.execute(query, params) except (mysql_driver.ProgrammingError, mysql_driver.OperationalError, mysql_driver.InternalError) as e: - raise InvalidPrivsError("Error granting privileges, invalid priv string: %s , query: %s , exception: %s." % (priv_string, query, str(e))) + raise InvalidPrivsError("Error granting privileges, invalid priv string: %s , params: %s, query: %s ," + " exception: %s." % (priv_string, str(params), query, str(e))) def convert_priv_dict_to_str(priv): diff --git a/tests/integration/targets/test_mysql_user/tasks/test_privs_issue_465.yml b/tests/integration/targets/test_mysql_user/tasks/test_privs_issue_465.yml index b769c6d..9b6acfc 100644 --- a/tests/integration/targets/test_mysql_user/tasks/test_privs_issue_465.yml +++ b/tests/integration/targets/test_mysql_user/tasks/test_privs_issue_465.yml @@ -40,5 +40,7 @@ assert: that: - result is failed - - result.msg.find('exception') != -1 - fail_msg: "Error granting privileges, invalid priv string: SELECT , query: GRANT SELECT ON *.`data` TO %s@%s , exception: (1064, \"You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near '`data` TO 'db_user2'@'localhost'' at line 1\")." + - result.msg is search('invalid priv string') + - result.msg is search('params') + - result.msg is search('query') + - result.msg is search('exception')