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
|
@ -95,17 +95,9 @@ 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._text import to_native
|
||||
|
||||
try:
|
||||
import MySQLdb
|
||||
import MySQLdb.cursors
|
||||
except ImportError:
|
||||
MYSQLDB_FOUND = False
|
||||
else:
|
||||
MYSQLDB_FOUND = True
|
||||
|
||||
# ===========================================
|
||||
# proxysql module specific support methods.
|
||||
#
|
||||
|
@ -135,10 +127,8 @@ def perform_checks(module):
|
|||
msg="reader_hostgroup cannot equal writer_hostgroup"
|
||||
)
|
||||
|
||||
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):
|
||||
|
@ -328,8 +318,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)
|
||||
)
|
||||
|
@ -360,7 +350,7 @@ def main():
|
|||
result['repl_group'] = \
|
||||
proxysql_repl_group.get_repl_group_config(cursor)
|
||||
|
||||
except MySQLdb.Error as e:
|
||||
except mysql_driver.Error as e:
|
||||
module.fail_json(
|
||||
msg="unable to modify replication hostgroup.. %s" % to_native(e)
|
||||
)
|
||||
|
@ -378,7 +368,7 @@ def main():
|
|||
" mysql_replication_hostgroups memory" +
|
||||
" configuration")
|
||||
|
||||
except MySQLdb.Error as e:
|
||||
except mysql_driver.Error as e:
|
||||
module.fail_json(
|
||||
msg="unable to delete replication hostgroup.. %s" % to_native(e)
|
||||
)
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue