mysql_user: when grant select on columns, the module always report the state has changed (#100)

* mysql_user: fix the module is not idempotent when there is SELECT on columns granted

* add changelog fragment

* fix

* Add unit tests for has_select_on_col function

* Add unit tests for sort_column_order function

* Add unit tests for handle_select_on_col function

* Update a comment
This commit is contained in:
Andrew Klychkov 2021-03-03 10:58:57 +01:00 committed by GitHub
commit 2694464ffb
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
4 changed files with 232 additions and 3 deletions

View file

@ -16,6 +16,7 @@
loop:
- data1
- data2
- data3
- name: Create user with privileges
mysql_user:
@ -37,6 +38,61 @@
- "'GRANT SELECT ON `data1`.*' in result.stdout"
- "'GRANT SELECT ON `data2`.*' in result.stdout"
# Issue https://github.com/ansible-collections/community.mysql/issues/99
- name: Create test table test_table_issue99
mysql_query:
<<: *mysql_params
query: "CREATE TABLE IF NOT EXISTS data3.test_table_issue99 (a INT, b INT, c INT)"
- name: Grant select on a column
mysql_user:
<<: *mysql_params
name: '{{ user_name_3 }}'
priv:
'data3.test_table_issue99': 'SELECT (a)'
register: result
- assert:
that:
- result is changed
- name: Grant select on the column again
mysql_user:
<<: *mysql_params
name: '{{ user_name_3 }}'
priv:
'data3.test_table_issue99': 'SELECT (a)'
register: result
- assert:
that:
- result is not changed
- name: Grant select on columns
mysql_user:
<<: *mysql_params
name: '{{ user_name_3 }}'
priv:
'data3.test_table_issue99': 'SELECT (a, b),INSERT'
register: result
- assert:
that:
- result is changed
- name: Grant select on columns again
mysql_user:
<<: *mysql_params
name: '{{ user_name_3 }}'
priv:
'data3.test_table_issue99': 'SELECT (a, b),INSERT'
register: result
- assert:
that:
- result is not changed
##########
# Clean up
- name: Drop test databases
@ -47,6 +103,7 @@
loop:
- data1
- data2
- data3
- name: Drop test user
mysql_user: