Replace privileges_equal() by a comparison

This commit is contained in:
R. Sicart 2022-09-08 10:35:37 +02:00
commit b195e71e7c
2 changed files with 2 additions and 46 deletions

View file

@ -387,10 +387,8 @@ def user_mod(cursor, user, host, host_all, password, encrypted,
privileges_grant(cursor, user, host, db_table, grant_privs, tls_requires, maria_role)
# after privilege manipulation, compare privileges from before and now
changed = changed or not privileges_equal(
curr_priv,
privileges_get(cursor, user, host, maria_role)
)
after_priv = privileges_get(cursor, user, host, maria_role)
changed = changed or not (curr_priv == after_priv)
if role:
continue
@ -885,15 +883,3 @@ def get_impl(cursor):
else:
from ansible_collections.community.mysql.plugins.module_utils.implementations.mysql import user as mysqluser
impl = mysqluser
def privileges_equal(before_privs, after_privs):
"""Compare 2 priv dicts
Args:
before_privs (dict): contains privileges, built with privileges_get()
after_privs (dict): contains privileges, built with privileges_get()
Returns: True, if equal, False otherwise.
"""
return before_privs == after_privs

View file

@ -98,33 +98,3 @@ def test_handle_grant_on_col(privileges, start, end, output):
def test_normalize_col_grants(input_, expected):
"""Tests normalize_col_grants function."""
assert normalize_col_grants(input_) == expected
@pytest.mark.parametrize(
'before_privileges,after_privileges,output',
[
(
{'*.*': ['INSERT', 'UPDATE', 'GRANT'], '`mysql`.*': ['SELECT']},
{'*.*': ['INSERT', 'UPDATE', 'GRANT'], '`mysql`.*': ['SELECT']},
True
),
(
{'`mysql`.*': ['SELECT'], '`sys`.*': ['SELECT']},
{'`mysql`.*': ['SELECT'], '`sys`.*': ['SELECT']},
True
),
(
{'`sys`.*': ['SELECT'], '`mysql`.*': ['SELECT']},
{'`mysql`.*': ['SELECT'], '`sys`.*': ['SELECT']},
True
),
(
{'`mysql`.*': ['UPDATE'], '`sys`.*': ['SELECT']},
{'`mysql`.*': ['SELECT'], '`sys`.*': ['SELECT']},
False
),
]
)
def test_privileges_equal(before_privileges, after_privileges, output):
"""Tests privileges_equal function."""
assert privileges_equal(before_privileges, after_privileges) == output