From 6ac89ca1f608d3c798410dcadf39cdc9c9b19996 Mon Sep 17 00:00:00 2001 From: Diego Gullo Date: Tue, 6 Dec 2022 16:12:01 +0400 Subject: [PATCH 1/3] Display a more informative error when InvalidPrivsError is raised (#465) (#466) MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit * Display a more informative error when InvalidPrivsError is raised (Issue #465) Co-authored-by: Laurent Indermühle --- ...re_informative_invalid_priv_exceptiion.yml | 5 +++ plugins/module_utils/user.py | 3 +- .../targets/setup_mysql/handlers/main.yml | 2 ++ .../targets/setup_mysql/tasks/main.yml | 10 ++++++ .../setup_remote_tmp_dir/handlers/main.yml | 4 +++ .../setup_remote_tmp_dir/tasks/main.yml | 4 +++ .../targets/test_mysql_user/tasks/main.yml | 4 +++ .../tasks/test_privs_issue_465.yml | 31 +++++++++++++++++++ 8 files changed, 62 insertions(+), 1 deletion(-) create mode 100644 changelogs/fragments/465-display_more_informative_invalid_priv_exceptiion.yml create mode 100644 tests/integration/targets/test_mysql_user/tasks/test_privs_issue_465.yml diff --git a/changelogs/fragments/465-display_more_informative_invalid_priv_exceptiion.yml b/changelogs/fragments/465-display_more_informative_invalid_priv_exceptiion.yml new file mode 100644 index 0000000..fc47d37 --- /dev/null +++ b/changelogs/fragments/465-display_more_informative_invalid_priv_exceptiion.yml @@ -0,0 +1,5 @@ +--- +minor_changes: + - mysql_user - display a more informative invalid privilege exception. + Changes the exception handling of the granting permission logic to show the query executed , params + and the exception message granting privileges fails` (https://github.com/ansible-collections/community.mysql/issues/465). \ No newline at end of file diff --git a/plugins/module_utils/user.py b/plugins/module_utils/user.py index 7def8c7..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" % priv_string) + 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/setup_mysql/handlers/main.yml b/tests/integration/targets/setup_mysql/handlers/main.yml index 090a5e7..8f751ee 100644 --- a/tests/integration/targets/setup_mysql/handlers/main.yml +++ b/tests/integration/targets/setup_mysql/handlers/main.yml @@ -4,3 +4,5 @@ src: installed_file.j2 dest: "{{ dbdeployer_installed_file }}" listen: create zookeeper installed file + tags: + - setup_mysql diff --git a/tests/integration/targets/setup_mysql/tasks/main.yml b/tests/integration/targets/setup_mysql/tasks/main.yml index c6a8348..47a5ee0 100644 --- a/tests/integration/targets/setup_mysql/tasks/main.yml +++ b/tests/integration/targets/setup_mysql/tasks/main.yml @@ -5,7 +5,17 @@ #################################################################### - import_tasks: setvars.yml + tags: + - setup_mysql - import_tasks: dir.yml + tags: + - setup_mysql - import_tasks: install.yml + tags: + - setup_mysql - import_tasks: config.yml + tags: + - setup_mysql - import_tasks: verify.yml + tags: + - setup_mysql diff --git a/tests/integration/targets/setup_remote_tmp_dir/handlers/main.yml b/tests/integration/targets/setup_remote_tmp_dir/handlers/main.yml index 229037c..39f3239 100644 --- a/tests/integration/targets/setup_remote_tmp_dir/handlers/main.yml +++ b/tests/integration/targets/setup_remote_tmp_dir/handlers/main.yml @@ -1,5 +1,9 @@ - name: delete temporary directory include_tasks: default-cleanup.yml + tags: + - setup_remote_tmp_dir - name: delete temporary directory (windows) include_tasks: windows-cleanup.yml + tags: + - setup_remote_tmp_dir diff --git a/tests/integration/targets/setup_remote_tmp_dir/tasks/main.yml b/tests/integration/targets/setup_remote_tmp_dir/tasks/main.yml index 93d786f..5d898ab 100644 --- a/tests/integration/targets/setup_remote_tmp_dir/tasks/main.yml +++ b/tests/integration/targets/setup_remote_tmp_dir/tasks/main.yml @@ -7,9 +7,13 @@ setup: gather_subset: distribution when: ansible_facts == {} + tags: + - setup_remote_tmp_dir - include_tasks: "{{ lookup('first_found', files)}}" vars: files: - "{{ ansible_os_family | lower }}.yml" - "default.yml" + tags: + - setup_remote_tmp_dir diff --git a/tests/integration/targets/test_mysql_user/tasks/main.yml b/tests/integration/targets/test_mysql_user/tasks/main.yml index db3304c..ef21c55 100644 --- a/tests/integration/targets/test_mysql_user/tasks/main.yml +++ b/tests/integration/targets/test_mysql_user/tasks/main.yml @@ -281,6 +281,10 @@ - include: test_priv_subtract.yml enable_check_mode=no - include: test_priv_subtract.yml enable_check_mode=yes + - import_tasks: test_privs_issue_465.yml + tags: + - issue_465 + # Tests for the TLS requires dictionary - include: tls_requirements.yml 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 new file mode 100644 index 0000000..edf4a0f --- /dev/null +++ b/tests/integration/targets/test_mysql_user/tasks/test_privs_issue_465.yml @@ -0,0 +1,31 @@ +--- +# test code for privileges for mysql_user module - issue 465 + +- vars: + mysql_parameters: &mysql_params + login_user: '{{ mysql_user }}' + login_password: '{{ mysql_password }}' + login_host: 127.0.0.1 + login_port: '{{ mysql_primary_port }}' + + block: + + # ============================================================ + - name: create a user with parameters that will always cause an exception + mysql_user: + <<: *mysql_params + name: user_issue_465 + password: a_test_password_465 + priv: '*.{{ db_name }}:SELECT' + state: present + ignore_errors: true + register: result + + - name: assert output message for current privileges + assert: + that: + - result is failed + - result.msg is search('invalid priv string') + - result.msg is search('params') + - result.msg is search('query') + - result.msg is search('exception') From 015f58ea5a11ac46c81de8b2de8f9910efaf5e3b Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Laurent=20Inderm=C3=BChle?= Date: Thu, 8 Dec 2022 19:32:22 +0100 Subject: [PATCH 2/3] Update CONTRIBUTORS --- CONTRIBUTORS | 1 + 1 file changed, 1 insertion(+) diff --git a/CONTRIBUTORS b/CONTRIBUTORS index cacb4ff..3acc8f3 100644 --- a/CONTRIBUTORS +++ b/CONTRIBUTORS @@ -33,6 +33,7 @@ baldpale banyek BarbzYHOOL Berbe +bizmate bjne bmalynovytch bmildren From eade7ec1f0aad6de6a6a94e5acb5e9b213c54c2b Mon Sep 17 00:00:00 2001 From: Andrew Klychkov Date: Fri, 9 Dec 2022 14:50:37 +0100 Subject: [PATCH 3/3] CI: add PR change detection (#473) --- .github/workflows/ansible-test-plugins.yml | 12 +++--------- 1 file changed, 3 insertions(+), 9 deletions(-) diff --git a/.github/workflows/ansible-test-plugins.yml b/.github/workflows/ansible-test-plugins.yml index e1957cf..27c657f 100644 --- a/.github/workflows/ansible-test-plugins.yml +++ b/.github/workflows/ansible-test-plugins.yml @@ -25,7 +25,6 @@ jobs: strategy: matrix: ansible: - - stable-2.11 - stable-2.12 - stable-2.13 - stable-2.14 @@ -36,6 +35,7 @@ jobs: with: ansible-core-version: ${{ matrix.ansible }} testing-type: sanity + pull-request-change-detection: true integration: name: "Integration (Python: ${{ matrix.python }}, Ansible: ${{ matrix.ansible }}, MySQL: ${{ matrix.db_engine_version }}, Connector: ${{ matrix.connector }})" @@ -51,7 +51,6 @@ jobs: # also change the "Set MariaDB URL sub dir" task - mariadb_10.8.3 ansible: - - stable-2.11 - stable-2.12 - stable-2.13 - stable-2.14 @@ -77,16 +76,12 @@ jobs: ansible: stable-2.14 - python: 3.6 ansible: devel - - python: 3.8 - ansible: stable-2.11 - python: 3.8 ansible: stable-2.13 - python: 3.8 ansible: stable-2.14 - python: 3.8 ansible: devel - - python: 3.9 - ansible: stable-2.11 - python: 3.9 ansible: stable-2.12 @@ -116,6 +111,7 @@ jobs: sed -i 's/^python_packages:.*/python_packages: [${{ matrix.connector }}]/' ${{ env.connector_version_file }} target-python-version: ${{ matrix.python }} testing-type: integration + pull-request-change-detection: true units: runs-on: ubuntu-20.04 @@ -126,7 +122,6 @@ jobs: fail-fast: true matrix: ansible: - - stable-2.11 - stable-2.12 - stable-2.13 - stable-2.14 @@ -141,8 +136,6 @@ jobs: ansible: stable-2.14 - python: 3.8 ansible: devel - - python: 3.9 - ansible: stable-2.11 - python: 3.9 ansible: stable-2.12 @@ -155,3 +148,4 @@ jobs: ansible-core-version: ${{ matrix.ansible }} target-python-version: ${{ matrix.python }} testing-type: units + pull-request-change-detection: true