From cbbfd14bc8668dcf78b095353dffd0c272fc021e Mon Sep 17 00:00:00 2001 From: Daniel Ziegenberg Date: Fri, 12 Mar 2021 14:56:23 +0100 Subject: [PATCH 1/8] change deprecated parameter pw to password --- plugins/module_utils/mysql.py | 19 ++++++++++++++++++- 1 file changed, 18 insertions(+), 1 deletion(-) diff --git a/plugins/module_utils/mysql.py b/plugins/module_utils/mysql.py index 5af9c202..2b8aec08 100644 --- a/plugins/module_utils/mysql.py +++ b/plugins/module_utils/mysql.py @@ -79,7 +79,24 @@ def mysql_connect(module, login_user=None, login_password=None, config_file='', if login_user is not None: config['user'] = login_user if login_password is not None: - config['passwd'] = login_password + if mysql_driver.__name__ == "pymysql": + # In case of PyMySQL driver: + version_tuple = (n for n in mysql_driver.__version__.split('.') if n != 'None') + if reduce(lambda x, y: int(x) * 100 + int(y), version_tuple) >= 607: + # pymysql >= 0.6.7 + config['password'] = login_password + else: + # NOTE: This check SHOULD be removed as soon as the minimum support version of PyMySQL for this collection reaches pymysql v0.6.7 + config['passwd'] = login_password + else: + # In case of MySQLdb driver + version_tuple = (n for n in mysql_driver.__version__.split('.') if n != 'None') + if reduce(lambda x, y: int(x) * 100 + int(y), version_tuple) >= 10308: + # mysqlclient >= 1.3.8 + config['password'] = login_password + else: + # NOTE: This check SHOULD be removed as soon as the minimum support version of MySQLdb for this collection reaches mysqlclient v1.3.8 + config['passwd'] = login_password if ssl_cert is not None: config['ssl']['cert'] = ssl_cert if ssl_key is not None: From 59b124ea5025ce75914800574f4990cf60c42ad5 Mon Sep 17 00:00:00 2001 From: Daniel Ziegenberg Date: Fri, 12 Mar 2021 15:01:28 +0100 Subject: [PATCH 2/8] change deprecated parameter db to database --- plugins/module_utils/mysql.py | 19 ++++++++++++++++++- 1 file changed, 18 insertions(+), 1 deletion(-) diff --git a/plugins/module_utils/mysql.py b/plugins/module_utils/mysql.py index 2b8aec08..58f5badf 100644 --- a/plugins/module_utils/mysql.py +++ b/plugins/module_utils/mysql.py @@ -104,7 +104,24 @@ def mysql_connect(module, login_user=None, login_password=None, config_file='', if ssl_ca is not None: config['ssl']['ca'] = ssl_ca if db is not None: - config['db'] = db + if mysql_driver.__name__ == "pymysql": + # In case of PyMySQL driver: + version_tuple = (n for n in mysql_driver.__version__.split('.') if n != 'None') + if reduce(lambda x, y: int(x) * 100 + int(y), version_tuple) >= 607: + # pymysql >= 0.6.7 + config['database'] = db + else: + # NOTE: This check SHOULD be removed as soon as the minimum support version of PyMySQL for this collection reaches pymysql v0.6.7 + config['db'] = db + else: + # In case of MySQLdb driver + version_tuple = (n for n in mysql_driver.__version__.split('.') if n != 'None') + if reduce(lambda x, y: int(x) * 100 + int(y), version_tuple) >= 10308: + # mysqlclient >= 1.3.8 + config['database'] = login_password + else: + # NOTE: This check SHOULD be removed as soon as the minimum support version of MySQLdb for this collection reaches mysqlclient v1.3.8 + config['db'] = db if connect_timeout is not None: config['connect_timeout'] = connect_timeout if check_hostname is not None: From 34bcbce4bdf759e21642972df26d8c554f08dca4 Mon Sep 17 00:00:00 2001 From: Daniel Ziegenberg Date: Fri, 12 Mar 2021 16:43:16 +0100 Subject: [PATCH 3/8] add changelog fragment --- .../fragments/177-change_deprecated_connection_parameters.yml | 2 ++ 1 file changed, 2 insertions(+) create mode 100644 changelogs/fragments/177-change_deprecated_connection_parameters.yml diff --git a/changelogs/fragments/177-change_deprecated_connection_parameters.yml b/changelogs/fragments/177-change_deprecated_connection_parameters.yml new file mode 100644 index 00000000..3c9e0884 --- /dev/null +++ b/changelogs/fragments/177-change_deprecated_connection_parameters.yml @@ -0,0 +1,2 @@ +minor_changes: +- mysql module utils - change deprecated connection parameters ``passwd`` and ``db`` to ``password`` and ``database`` (https://github.com/ansible-collections/community.mysql/pull/177). \ No newline at end of file From 4ca142a37689780cabb2e1c198c8027aa0627650 Mon Sep 17 00:00:00 2001 From: Jorge-Rodriguez Date: Sun, 22 Jan 2023 08:41:38 +0200 Subject: [PATCH 4/8] Old plugin versions are no longer supported --- plugins/module_utils/mysql.py | 38 ++--------------------------------- 1 file changed, 2 insertions(+), 36 deletions(-) diff --git a/plugins/module_utils/mysql.py b/plugins/module_utils/mysql.py index 58f5badf..67e00331 100644 --- a/plugins/module_utils/mysql.py +++ b/plugins/module_utils/mysql.py @@ -79,24 +79,7 @@ def mysql_connect(module, login_user=None, login_password=None, config_file='', if login_user is not None: config['user'] = login_user if login_password is not None: - if mysql_driver.__name__ == "pymysql": - # In case of PyMySQL driver: - version_tuple = (n for n in mysql_driver.__version__.split('.') if n != 'None') - if reduce(lambda x, y: int(x) * 100 + int(y), version_tuple) >= 607: - # pymysql >= 0.6.7 - config['password'] = login_password - else: - # NOTE: This check SHOULD be removed as soon as the minimum support version of PyMySQL for this collection reaches pymysql v0.6.7 - config['passwd'] = login_password - else: - # In case of MySQLdb driver - version_tuple = (n for n in mysql_driver.__version__.split('.') if n != 'None') - if reduce(lambda x, y: int(x) * 100 + int(y), version_tuple) >= 10308: - # mysqlclient >= 1.3.8 - config['password'] = login_password - else: - # NOTE: This check SHOULD be removed as soon as the minimum support version of MySQLdb for this collection reaches mysqlclient v1.3.8 - config['passwd'] = login_password + config['password'] = login_password if ssl_cert is not None: config['ssl']['cert'] = ssl_cert if ssl_key is not None: @@ -104,24 +87,7 @@ def mysql_connect(module, login_user=None, login_password=None, config_file='', if ssl_ca is not None: config['ssl']['ca'] = ssl_ca if db is not None: - if mysql_driver.__name__ == "pymysql": - # In case of PyMySQL driver: - version_tuple = (n for n in mysql_driver.__version__.split('.') if n != 'None') - if reduce(lambda x, y: int(x) * 100 + int(y), version_tuple) >= 607: - # pymysql >= 0.6.7 - config['database'] = db - else: - # NOTE: This check SHOULD be removed as soon as the minimum support version of PyMySQL for this collection reaches pymysql v0.6.7 - config['db'] = db - else: - # In case of MySQLdb driver - version_tuple = (n for n in mysql_driver.__version__.split('.') if n != 'None') - if reduce(lambda x, y: int(x) * 100 + int(y), version_tuple) >= 10308: - # mysqlclient >= 1.3.8 - config['database'] = login_password - else: - # NOTE: This check SHOULD be removed as soon as the minimum support version of MySQLdb for this collection reaches mysqlclient v1.3.8 - config['db'] = db + config['database'] = db if connect_timeout is not None: config['connect_timeout'] = connect_timeout if check_hostname is not None: From 14380349dbf4d52684f9028a9cb63f06896f845e Mon Sep 17 00:00:00 2001 From: Jorge-Rodriguez Date: Sun, 22 Jan 2023 08:46:08 +0200 Subject: [PATCH 5/8] Use packaging version checking. --- plugins/module_utils/mysql.py | 5 ++--- 1 file changed, 2 insertions(+), 3 deletions(-) diff --git a/plugins/module_utils/mysql.py b/plugins/module_utils/mysql.py index 67e00331..b3fbab36 100644 --- a/plugins/module_utils/mysql.py +++ b/plugins/module_utils/mysql.py @@ -10,7 +10,7 @@ # Simplified BSD License (see licenses/simplified_bsd.txt or https://opensource.org/licenses/BSD-2-Clause) from __future__ import (absolute_import, division, print_function) -from functools import reduce +from packaging import version __metaclass__ = type import os @@ -92,8 +92,7 @@ def mysql_connect(module, login_user=None, login_password=None, config_file='', config['connect_timeout'] = connect_timeout if check_hostname is not None: if mysql_driver.__name__ == "pymysql": - version_tuple = (n for n in mysql_driver.__version__.split('.') if n != 'None') - if reduce(lambda x, y: int(x) * 100 + int(y), version_tuple) >= 711: + if version.parse(mysql_driver.__version__) >= "0.7.11": config['ssl']['check_hostname'] = check_hostname else: module.fail_json(msg='To use check_hostname, pymysql >= 0.7.11 is required on the target host') From 9ad771bdd635a7490f561d28edb426f923a068e0 Mon Sep 17 00:00:00 2001 From: Jorge-Rodriguez Date: Sun, 22 Jan 2023 21:55:49 +0200 Subject: [PATCH 6/8] Use stdlib version comparison --- plugins/module_utils/mysql.py | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/plugins/module_utils/mysql.py b/plugins/module_utils/mysql.py index b3fbab36..c60e8278 100644 --- a/plugins/module_utils/mysql.py +++ b/plugins/module_utils/mysql.py @@ -10,7 +10,7 @@ # Simplified BSD License (see licenses/simplified_bsd.txt or https://opensource.org/licenses/BSD-2-Clause) from __future__ import (absolute_import, division, print_function) -from packaging import version +from distutils.version import LooseVersion __metaclass__ = type import os @@ -92,7 +92,7 @@ def mysql_connect(module, login_user=None, login_password=None, config_file='', config['connect_timeout'] = connect_timeout if check_hostname is not None: if mysql_driver.__name__ == "pymysql": - if version.parse(mysql_driver.__version__) >= "0.7.11": + if LooseVersion(mysql_driver.__version__) >= LooseVersion("0.7.11"): config['ssl']['check_hostname'] = check_hostname else: module.fail_json(msg='To use check_hostname, pymysql >= 0.7.11 is required on the target host') From 8a96baf4d4916475035ab95ff66339e6a56b6bfb Mon Sep 17 00:00:00 2001 From: Jorge-Rodriguez Date: Sun, 22 Jan 2023 22:20:32 +0200 Subject: [PATCH 7/8] Use parse_version from setuptools --- plugins/module_utils/mysql.py | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/plugins/module_utils/mysql.py b/plugins/module_utils/mysql.py index c60e8278..22c00ed9 100644 --- a/plugins/module_utils/mysql.py +++ b/plugins/module_utils/mysql.py @@ -10,7 +10,7 @@ # Simplified BSD License (see licenses/simplified_bsd.txt or https://opensource.org/licenses/BSD-2-Clause) from __future__ import (absolute_import, division, print_function) -from distutils.version import LooseVersion +from pkg_resources import parse_version __metaclass__ = type import os @@ -92,7 +92,7 @@ def mysql_connect(module, login_user=None, login_password=None, config_file='', config['connect_timeout'] = connect_timeout if check_hostname is not None: if mysql_driver.__name__ == "pymysql": - if LooseVersion(mysql_driver.__version__) >= LooseVersion("0.7.11"): + if parse_version(mysql_driver.__version__) >= parse_version("0.7.11"): config['ssl']['check_hostname'] = check_hostname else: module.fail_json(msg='To use check_hostname, pymysql >= 0.7.11 is required on the target host') From 19d971d8a9f7b9d2c9efddd465b81173c1eb057f Mon Sep 17 00:00:00 2001 From: Jorge-Rodriguez Date: Mon, 23 Jan 2023 12:17:51 +0200 Subject: [PATCH 8/8] Revert to tuple/reduce version check --- plugins/module_utils/mysql.py | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/plugins/module_utils/mysql.py b/plugins/module_utils/mysql.py index 22c00ed9..67e00331 100644 --- a/plugins/module_utils/mysql.py +++ b/plugins/module_utils/mysql.py @@ -10,7 +10,7 @@ # Simplified BSD License (see licenses/simplified_bsd.txt or https://opensource.org/licenses/BSD-2-Clause) from __future__ import (absolute_import, division, print_function) -from pkg_resources import parse_version +from functools import reduce __metaclass__ = type import os @@ -92,7 +92,8 @@ def mysql_connect(module, login_user=None, login_password=None, config_file='', config['connect_timeout'] = connect_timeout if check_hostname is not None: if mysql_driver.__name__ == "pymysql": - if parse_version(mysql_driver.__version__) >= parse_version("0.7.11"): + version_tuple = (n for n in mysql_driver.__version__.split('.') if n != 'None') + if reduce(lambda x, y: int(x) * 100 + int(y), version_tuple) >= 711: config['ssl']['check_hostname'] = check_hostname else: module.fail_json(msg='To use check_hostname, pymysql >= 0.7.11 is required on the target host')