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
|
@ -137,18 +137,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.
|
||||
#
|
||||
|
@ -161,10 +153,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):
|
||||
|
@ -424,8 +414,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)
|
||||
)
|
||||
|
@ -454,7 +444,7 @@ def main():
|
|||
" and doesn't need to be updated.")
|
||||
result['user'] = \
|
||||
proxysql_user.get_user_config(cursor)
|
||||
except MySQLdb.Error as e:
|
||||
except mysql_driver.Error as e:
|
||||
module.fail_json(
|
||||
msg="unable to modify user.. %s" % to_native(e)
|
||||
)
|
||||
|
@ -469,7 +459,7 @@ def main():
|
|||
result['changed'] = False
|
||||
result['msg'] = ("The user is already absent from the" +
|
||||
" mysql_users memory configuration")
|
||||
except MySQLdb.Error as e:
|
||||
except mysql_driver.Error as e:
|
||||
module.fail_json(
|
||||
msg="unable to remove user.. %s" % to_native(e)
|
||||
)
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue