mirror of
https://github.com/ansible-collections/community.general.git
synced 2025-04-26 12:21:26 -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
|
@ -125,18 +125,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.
|
||||
#
|
||||
|
@ -155,10 +147,8 @@ def perform_checks(module):
|
|||
msg="interval_ms must between 100ms & 100000000ms"
|
||||
)
|
||||
|
||||
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):
|
||||
|
@ -366,8 +356,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)
|
||||
)
|
||||
|
@ -390,7 +380,7 @@ def main():
|
|||
" need to be updated.")
|
||||
result['schedules'] = \
|
||||
proxysql_schedule.get_schedule_config(cursor)
|
||||
except MySQLdb.Error as e:
|
||||
except mysql_driver.Error as e:
|
||||
module.fail_json(
|
||||
msg="unable to modify schedule.. %s" % to_native(e)
|
||||
)
|
||||
|
@ -413,7 +403,7 @@ def main():
|
|||
result['changed'] = False
|
||||
result['msg'] = ("The schedule is already absent from the" +
|
||||
" memory configuration")
|
||||
except MySQLdb.Error as e:
|
||||
except mysql_driver.Error as e:
|
||||
module.fail_json(
|
||||
msg="unable to remove schedule.. %s" % to_native(e)
|
||||
)
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue