mirror of
https://github.com/ansible-collections/community.general.git
synced 2025-04-24 11:21:25 -07:00
Migrate from MySQLdb to PyMySQL (#40123)
* Migrate from MySQLdb to PyMySQL * Deduplicate driver loading and failure message * Explain requirements * Apply requirements docs change to proxysql too * Add changelog
This commit is contained in:
parent
205693a3f9
commit
d34cf93f1a
20 changed files with 92 additions and 179 deletions
|
@ -221,18 +221,10 @@ ANSIBLE_METADATA = {'metadata_version': '1.1',
|
|||
|
||||
|
||||
from ansible.module_utils.basic import AnsibleModule
|
||||
from ansible.module_utils.mysql import mysql_connect
|
||||
from ansible.module_utils.mysql import mysql_connect, mysql_driver, mysql_driver_fail_msg
|
||||
from ansible.module_utils.six import iteritems
|
||||
from ansible.module_utils._text import to_native
|
||||
|
||||
try:
|
||||
import MySQLdb
|
||||
import MySQLdb.cursors
|
||||
except ImportError:
|
||||
MYSQLDB_FOUND = False
|
||||
else:
|
||||
MYSQLDB_FOUND = True
|
||||
|
||||
# ===========================================
|
||||
# proxysql module specific support methods.
|
||||
#
|
||||
|
@ -245,10 +237,8 @@ def perform_checks(module):
|
|||
msg="login_port must be a valid unix port number (0-65535)"
|
||||
)
|
||||
|
||||
if not MYSQLDB_FOUND:
|
||||
module.fail_json(
|
||||
msg="the python mysqldb module is required"
|
||||
)
|
||||
if mysql_driver is None:
|
||||
module.fail_json(msg=mysql_driver_fail_msg)
|
||||
|
||||
|
||||
def save_config_to_disk(cursor):
|
||||
|
@ -552,8 +542,8 @@ def main():
|
|||
login_user,
|
||||
login_password,
|
||||
config_file,
|
||||
cursor_class=MySQLdb.cursors.DictCursor)
|
||||
except MySQLdb.Error as e:
|
||||
cursor_class=mysql_driver.cursors.DictCursor)
|
||||
except mysql_driver.Error as e:
|
||||
module.fail_json(
|
||||
msg="unable to connect to ProxySQL Admin Module.. %s" % to_native(e)
|
||||
)
|
||||
|
@ -583,7 +573,7 @@ def main():
|
|||
result['rules'] = \
|
||||
proxysql_query_rule.get_rule_config(cursor)
|
||||
|
||||
except MySQLdb.Error as e:
|
||||
except mysql_driver.Error as e:
|
||||
module.fail_json(
|
||||
msg="unable to modify rule.. %s" % to_native(e)
|
||||
)
|
||||
|
@ -606,7 +596,7 @@ def main():
|
|||
result['changed'] = False
|
||||
result['msg'] = ("The rule is already absent from the" +
|
||||
" mysql_query_rules memory configuration")
|
||||
except MySQLdb.Error as e:
|
||||
except mysql_driver.Error as e:
|
||||
module.fail_json(
|
||||
msg="unable to remove rule.. %s" % to_native(e)
|
||||
)
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue