Browse Source

Missing required lib (#50)

* use missing_required_lib

* remove another import

* update docs (drop MySQL-Python, add mysqlclient)

* fix var name

* remove MySQL-python from error message and replace with mysqlclient

* add changelog fragment

* pymysql or MySQLdb

* use library

* Update changelogs/fragments/50-refactor-connectors.yaml

Co-authored-by: Andrew Klychkov <aaklychkov@mail.ru>

Co-authored-by: Andrew Klychkov <aaklychkov@mail.ru>
local_integrationtest
Markus Bergholz 1 year ago committed by GitHub
parent
commit
df5ede0077
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
  1. 3
      changelogs/fragments/50-refactor-connectors.yaml
  2. 4
      plugins/doc_fragments/proxysql.py
  3. 11
      plugins/module_utils/mysql.py
  4. 5
      plugins/modules/proxysql_backend_servers.py
  5. 5
      plugins/modules/proxysql_global_variables.py
  6. 5
      plugins/modules/proxysql_manage_config.py
  7. 5
      plugins/modules/proxysql_mysql_users.py
  8. 5
      plugins/modules/proxysql_query_rules.py
  9. 5
      plugins/modules/proxysql_query_rules_fast_routing.py
  10. 5
      plugins/modules/proxysql_replication_hostgroups.py
  11. 5
      plugins/modules/proxysql_scheduler.py

3
changelogs/fragments/50-refactor-connectors.yaml

@ -0,0 +1,3 @@
minor_changes:
- Refactoring of connector presence checking (https://github.com/ansible-collections/community.proxysql/pull/50).
- Replace MySQL-Python with mysqlclient in the import error message (https://github.com/ansible-collections/community.proxysql/pull/50).

4
plugins/doc_fragments/proxysql.py

@ -41,8 +41,8 @@ options:
type: path
default: ''
requirements:
- PyMySQL (Python 2.7 and Python 3.X), or
- MySQLdb (Python 2.x)
- PyMySQL
- mysqlclient
'''
# Documentation fragment for managing ProxySQL configuration

11
plugins/module_utils/mysql.py

@ -15,20 +15,24 @@ __metaclass__ = type
import os
from ansible.module_utils.six.moves import configparser
from ansible.module_utils.basic import missing_required_lib
MYSQL_IMP_ERR = None
try:
import pymysql as mysql_driver
_mysql_cursor_param = 'cursor'
HAS_MYSQL_PACKAGE = True
except ImportError:
try:
import MySQLdb as mysql_driver
import MySQLdb.cursors
_mysql_cursor_param = 'cursorclass'
HAS_MYSQL_PACKAGE = True
except ImportError:
MYSQL_IMP_ERR = 'Cannot find PyMySQL or mysqlclient library.'
HAS_MYSQL_PACKAGE = False
mysql_driver = None
mysql_driver_fail_msg = 'The PyMySQL (Python 2.7 and Python 3.X) or MySQL-python (Python 2.X) module is required.'
def parse_from_mysql_config_file(cnf):
cp = configparser.ConfigParser()
@ -41,6 +45,9 @@ def mysql_connect(module, login_user=None, login_password=None, config_file='',
connect_timeout=30, autocommit=False, config_overrides_defaults=False):
config = {}
if not HAS_MYSQL_PACKAGE:
module.fail_json(msg=missing_required_lib("pymysql or MySQLdb"), exception=MYSQL_IMP_ERR)
if config_file and os.path.exists(config_file):
config['read_default_file'] = config_file
cp = parse_from_mysql_config_file(config_file)

5
plugins/modules/proxysql_backend_servers.py

@ -159,7 +159,7 @@ stdout:
'''
from ansible.module_utils.basic import AnsibleModule
from ansible_collections.community.proxysql.plugins.module_utils.mysql import mysql_connect, mysql_driver, mysql_driver_fail_msg
from ansible_collections.community.proxysql.plugins.module_utils.mysql import mysql_connect, mysql_driver
from ansible.module_utils.six import iteritems
from ansible.module_utils._text import to_native
@ -195,9 +195,6 @@ def perform_checks(module):
msg="max_replication_lag must be set between 0 and 102400"
)
if mysql_driver is None:
module.fail_json(msg=mysql_driver_fail_msg)
def save_config_to_disk(cursor):
cursor.execute("SAVE MYSQL SERVERS TO DISK")

5
plugins/modules/proxysql_global_variables.py

@ -73,7 +73,7 @@ stdout:
'''
from ansible.module_utils.basic import AnsibleModule
from ansible_collections.community.proxysql.plugins.module_utils.mysql import mysql_connect, mysql_driver, mysql_driver_fail_msg
from ansible_collections.community.proxysql.plugins.module_utils.mysql import mysql_connect, mysql_driver
from ansible.module_utils._text import to_native
# ===========================================
@ -88,9 +88,6 @@ def perform_checks(module):
msg="login_port must be a valid unix port number (0-65535)"
)
if mysql_driver is None:
module.fail_json(msg=mysql_driver_fail_msg)
def save_config_to_disk(variable, cursor):
if variable.startswith("admin"):

5
plugins/modules/proxysql_manage_config.py

@ -98,7 +98,7 @@ stdout:
'''
from ansible.module_utils.basic import AnsibleModule
from ansible_collections.community.proxysql.plugins.module_utils.mysql import mysql_connect, mysql_driver, mysql_driver_fail_msg
from ansible_collections.community.proxysql.plugins.module_utils.mysql import mysql_connect, mysql_driver
from ansible.module_utils._text import to_native
# ===========================================
@ -135,9 +135,6 @@ def perform_checks(module):
" with the CONFIG config_layer")
module.fail_json(msg=msg_string % module.params["direction"])
if mysql_driver is None:
module.fail_json(msg=mysql_driver_fail_msg)
def manage_config(manage_config_settings, cursor):

5
plugins/modules/proxysql_mysql_users.py

@ -160,7 +160,7 @@ stdout:
'''
from ansible.module_utils.basic import AnsibleModule
from ansible_collections.community.proxysql.plugins.module_utils.mysql import mysql_connect, mysql_driver, mysql_driver_fail_msg
from ansible_collections.community.proxysql.plugins.module_utils.mysql import mysql_connect, mysql_driver
from ansible.module_utils.six import iteritems
from ansible.module_utils._text import to_native, to_bytes
from hashlib import sha1
@ -177,9 +177,6 @@ def perform_checks(module):
msg="login_port must be a valid unix port number (0-65535)"
)
if mysql_driver is None:
module.fail_json(msg=mysql_driver_fail_msg)
def save_config_to_disk(cursor):
cursor.execute("SAVE MYSQL USERS TO DISK")

5
plugins/modules/proxysql_query_rules.py

@ -312,7 +312,7 @@ stdout:
'''
from ansible.module_utils.basic import AnsibleModule
from ansible_collections.community.proxysql.plugins.module_utils.mysql import mysql_connect, mysql_driver, mysql_driver_fail_msg
from ansible_collections.community.proxysql.plugins.module_utils.mysql import mysql_connect, mysql_driver
from ansible.module_utils.six import iteritems
from ansible.module_utils._text import to_native
@ -328,9 +328,6 @@ def perform_checks(module):
msg="login_port must be a valid unix port number (0-65535)"
)
if mysql_driver is None:
module.fail_json(msg=mysql_driver_fail_msg)
def save_config_to_disk(cursor):
cursor.execute("SAVE MYSQL QUERY RULES TO DISK")

5
plugins/modules/proxysql_query_rules_fast_routing.py

@ -106,7 +106,7 @@ stdout:
'''
from ansible.module_utils.basic import AnsibleModule
from ansible_collections.community.proxysql.plugins.module_utils.mysql import mysql_connect, mysql_driver, mysql_driver_fail_msg
from ansible_collections.community.proxysql.plugins.module_utils.mysql import mysql_connect, mysql_driver
from ansible.module_utils.six import iteritems
from ansible.module_utils._text import to_native
@ -119,9 +119,6 @@ def perform_checks(module):
if module.params["login_port"] < 0 or module.params["login_port"] > 65535:
module.fail_json(msg="login_port must be a valid unix port number (0-65535)")
if mysql_driver is None:
module.fail_json(msg=mysql_driver_fail_msg)
def save_config_to_disk(cursor):
cursor.execute("SAVE MYSQL QUERY RULES TO DISK")

5
plugins/modules/proxysql_replication_hostgroups.py

@ -97,7 +97,7 @@ stdout:
'''
from ansible.module_utils.basic import AnsibleModule
from ansible_collections.community.proxysql.plugins.module_utils.mysql import mysql_connect, mysql_driver, mysql_driver_fail_msg
from ansible_collections.community.proxysql.plugins.module_utils.mysql import mysql_connect, mysql_driver
from ansible.module_utils._text import to_native
# ===========================================
@ -129,9 +129,6 @@ def perform_checks(module):
msg="reader_hostgroup cannot equal writer_hostgroup"
)
if mysql_driver is None:
module.fail_json(msg=mysql_driver_fail_msg)
def save_config_to_disk(cursor):
cursor.execute("SAVE MYSQL SERVERS TO DISK")

5
plugins/modules/proxysql_scheduler.py

@ -135,7 +135,7 @@ stdout:
'''
from ansible.module_utils.basic import AnsibleModule
from ansible_collections.community.proxysql.plugins.module_utils.mysql import mysql_connect, mysql_driver, mysql_driver_fail_msg
from ansible_collections.community.proxysql.plugins.module_utils.mysql import mysql_connect, mysql_driver
from ansible.module_utils.six import iteritems
from ansible.module_utils._text import to_native
@ -157,9 +157,6 @@ def perform_checks(module):
msg="interval_ms must between 100ms & 100000000ms"
)
if mysql_driver is None:
module.fail_json(msg=mysql_driver_fail_msg)
def save_config_to_disk(cursor):
cursor.execute("SAVE SCHEDULER TO DISK")

Loading…
Cancel
Save