mirror of
https://github.com/ansible-collections/community.mysql.git
synced 2025-04-05 18:20:31 -07:00
Fix the collection to work with mysqlclient connector (#293)
* Integration tests: restrict exclusion mysqlclient + MariaDB only when testing the mysql_role module * Fix * Fix underlying issue * Fix units * Add changelog fragment
This commit is contained in:
parent
71a628f82d
commit
f00f06df76
5 changed files with 11 additions and 9 deletions
.github/workflows
changelogs/fragments
plugins
tests/unit/plugins/modules
4
.github/workflows/ansible-test-plugins.yml
vendored
4
.github/workflows/ansible-test-plugins.yml
vendored
|
@ -78,10 +78,6 @@ jobs:
|
|||
connector: pymysql==0.7.10
|
||||
- db_engine_version: mariadb_10.5.9
|
||||
connector: pymysql==0.7.10
|
||||
- db_engine_version: mariadb_10.3.34
|
||||
connector: mysqlclient==2.0.1
|
||||
- db_engine_version: mariadb_10.5.9
|
||||
connector: mysqlclient==2.0.1
|
||||
- python: 3.8
|
||||
ansible: stable-2.9
|
||||
- python: 3.8
|
||||
|
|
2
changelogs/fragments/0-mysqlclient.yml
Normal file
2
changelogs/fragments/0-mysqlclient.yml
Normal file
|
@ -0,0 +1,2 @@
|
|||
bugfixes:
|
||||
- Collection core functions - fixes related to the mysqlclient Python connector (https://github.com/ansible-collections/community.mysql/issues/292).
|
|
@ -398,7 +398,7 @@ def privileges_get(cursor, user, host, maria_role=False):
|
|||
if not maria_role:
|
||||
cursor.execute("SHOW GRANTS FOR %s@%s", (user, host))
|
||||
else:
|
||||
cursor.execute("SHOW GRANTS FOR %s", (user))
|
||||
cursor.execute("SHOW GRANTS FOR %s", (user,))
|
||||
grants = cursor.fetchall()
|
||||
|
||||
def pick(x):
|
||||
|
@ -618,7 +618,7 @@ def privileges_revoke(cursor, user, host, db_table, priv, grant_option, maria_ro
|
|||
params = (user, host)
|
||||
else:
|
||||
query.append("FROM %s")
|
||||
params = (user)
|
||||
params = (user,)
|
||||
|
||||
query = ' '.join(query)
|
||||
cursor.execute(query, params)
|
||||
|
@ -644,6 +644,10 @@ def privileges_grant(cursor, user, host, db_table, priv, tls_requires, maria_rol
|
|||
if 'GRANT' in priv:
|
||||
query.append("WITH GRANT OPTION")
|
||||
query = ' '.join(query)
|
||||
|
||||
if isinstance(params, str):
|
||||
params = (params,)
|
||||
|
||||
try:
|
||||
cursor.execute(query, params)
|
||||
except (mysql_driver.ProgrammingError, mysql_driver.OperationalError, mysql_driver.InternalError) as e:
|
||||
|
|
|
@ -481,7 +481,7 @@ class MariaDBQueryBuilder():
|
|||
Returns:
|
||||
tuple: (query_string, tuple_containing_parameters).
|
||||
"""
|
||||
return "SELECT count(*) FROM mysql.user WHERE user = %s AND is_role = 'Y'", (self.name)
|
||||
return "SELECT count(*) FROM mysql.user WHERE user = %s AND is_role = 'Y'", (self.name,)
|
||||
|
||||
def role_grant(self, user):
|
||||
"""Return a query to grant a role to a user or role.
|
||||
|
|
|
@ -28,9 +28,9 @@ module = Module()
|
|||
@pytest.mark.parametrize(
|
||||
'builder,output',
|
||||
[
|
||||
(MariaDBQueryBuilder('role0'), ("SELECT count(*) FROM mysql.user WHERE user = %s AND is_role = 'Y'", ('role0'))),
|
||||
(MariaDBQueryBuilder('role0'), ("SELECT count(*) FROM mysql.user WHERE user = %s AND is_role = 'Y'", ('role0',))),
|
||||
(MySQLQueryBuilder('role0', '%'), ('SELECT count(*) FROM mysql.user WHERE user = %s AND host = %s', ('role0', '%'))),
|
||||
(MariaDBQueryBuilder('role1'), ("SELECT count(*) FROM mysql.user WHERE user = %s AND is_role = 'Y'", ('role1'))),
|
||||
(MariaDBQueryBuilder('role1'), ("SELECT count(*) FROM mysql.user WHERE user = %s AND is_role = 'Y'", ('role1',))),
|
||||
(MySQLQueryBuilder('role1', 'fake'), ('SELECT count(*) FROM mysql.user WHERE user = %s AND host = %s', ('role1', 'fake'))),
|
||||
]
|
||||
)
|
||||
|
|
Loading…
Add table
Reference in a new issue