diff options
author | Rhys <rhys.james.campbell@googlemail.com> | 2021-03-08 10:13:09 +0100 |
---|---|---|
committer | GitHub <noreply@github.com> | 2021-03-08 03:13:09 -0600 |
commit | d0703a8c7dde4f78cf5043b2f9940cecad9efcb1 (patch) | |
tree | fcabbb40390d416f124d33336abb016230d23bbb | |
parent | fc1f44e7944cd41dfe69df9511af082db76a1d9c (diff) | |
download | ansible-d0703a8c7dde4f78cf5043b2f9940cecad9efcb1.tar.gz |
Update mongodb replicaset check_compatibility function (#72299)
* Update check_compatibility function
4 files changed, 35 insertions, 16 deletions
diff --git a/changelogs/fragments/72299-fix-check-compatibility.yaml b/changelogs/fragments/72299-fix-check-compatibility.yaml new file mode 100644 index 0000000000..3cd8bf333c --- /dev/null +++ b/changelogs/fragments/72299-fix-check-compatibility.yaml @@ -0,0 +1,3 @@ +--- +bugfixes: + - mongodb_replicaset - fixes check_compatibility function (https://github.com/ansible-collections/community.mongodb/issues/230). diff --git a/lib/ansible/modules/database/mongodb/mongodb_replicaset.py b/lib/ansible/modules/database/mongodb/mongodb_replicaset.py index b4eeb67425..89e60f1d2a 100644 --- a/lib/ansible/modules/database/mongodb/mongodb_replicaset.py +++ b/lib/ansible/modules/database/mongodb/mongodb_replicaset.py @@ -180,29 +180,43 @@ from ansible.module_utils._text import to_native # MongoDB module specific support methods. # -def check_compatibility(module, client): +def check_compatibility(module, srv_version, driver_version): """Check the compatibility between the driver and the database. - - See: https://docs.mongodb.com/ecosystem/drivers/driver-compatibility-reference/#python-driver-compatibility - + See: https://docs.mongodb.com/ecosystem/drivers/driver-compatibility-reference/#python-driver-compatibility Args: module: Ansible module. - client (cursor): Mongodb cursor on admin database. + srv_version (LooseVersion): MongoDB server version. + driver_version (LooseVersion): Pymongo version. """ - loose_srv_version = LooseVersion(client.server_info()['version']) - loose_driver_version = LooseVersion(PyMongoVersion) + msg = 'pymongo driver version and MongoDB version are incompatible: ' + + if srv_version >= LooseVersion('4.2') and driver_version < LooseVersion('3.9'): + msg += 'you must use pymongo 3.9+ with MongoDB >= 4.2' + module.fail_json(msg=msg) - if loose_srv_version >= LooseVersion('3.2') and loose_driver_version < LooseVersion('3.2'): - module.fail_json(msg=' (Note: you must use pymongo 3.2+ with MongoDB >= 3.2)') + elif srv_version >= LooseVersion('4.0') and driver_version < LooseVersion('3.7'): + msg += 'you must use pymongo 3.7+ with MongoDB >= 4.0' + module.fail_json(msg=msg) - elif loose_srv_version >= LooseVersion('3.0') and loose_driver_version <= LooseVersion('2.8'): - module.fail_json(msg=' (Note: you must use pymongo 2.8+ with MongoDB 3.0)') + elif srv_version >= LooseVersion('3.6') and driver_version < LooseVersion('3.6'): + msg += 'you must use pymongo 3.6+ with MongoDB >= 3.6' + module.fail_json(msg=msg) - elif loose_srv_version >= LooseVersion('2.6') and loose_driver_version <= LooseVersion('2.7'): - module.fail_json(msg=' (Note: you must use pymongo 2.7+ with MongoDB 2.6)') + elif srv_version >= LooseVersion('3.4') and driver_version < LooseVersion('3.4'): + msg += 'you must use pymongo 3.4+ with MongoDB >= 3.4' + module.fail_json(msg=msg) - elif LooseVersion(PyMongoVersion) <= LooseVersion('2.5'): - module.fail_json(msg=' (Note: you must be on mongodb 2.4+ and pymongo 2.5+ to use the roles param)') + elif srv_version >= LooseVersion('3.2') and driver_version < LooseVersion('3.2'): + msg += 'you must use pymongo 3.2+ with MongoDB >= 3.2' + module.fail_json(msg=msg) + + elif srv_version >= LooseVersion('3.0') and driver_version <= LooseVersion('2.8'): + msg += 'you must use pymongo 2.8+ with MongoDB 3.0' + module.fail_json(msg=msg) + + elif srv_version >= LooseVersion('2.6') and driver_version <= LooseVersion('2.7'): + msg += 'you must use pymongo 2.7+ with MongoDB 2.6' + module.fail_json(msg=msg) def replicaset_find(client): @@ -394,6 +408,7 @@ def main(): # Get driver version:: driver_version = LooseVersion(PyMongoVersion) # Check driver and server version compatibility: + check_compatibility(module, srv_version, driver_version) except Exception as excep: module.fail_json(msg='Unable to authenticate with MongoDB: %s' % to_native(excep)) diff --git a/test/integration/targets/setup_mongodb/defaults/main.yml b/test/integration/targets/setup_mongodb/defaults/main.yml index b6d8dd6d42..367eb6c5fd 100644 --- a/test/integration/targets/setup_mongodb/defaults/main.yml +++ b/test/integration/targets/setup_mongodb/defaults/main.yml @@ -21,7 +21,7 @@ yum: baseurl: https://repo.mongodb.org/yum/redhat/$releasever/mongodb-org/{{mongodb_version}}/x86_64/ gpgcheck: 1 gpgkey: https://www.mongodb.org/static/pgp/server-{{mongodb_version}}.asc - redhat8url: https://repo.mongodb.org/yum/redhat/7/mongodb-org/{{mongodb_version}}/x86_64/ + redhat8url: https://repo.mongodb.org/yum/redhat/8/mongodb-org/{{mongodb_version}}/x86_64/ fedoraurl: https://repo.mongodb.org/yum/amazon/2013.03/mongodb-org/{{mongodb_version}}/x86_64/ debian_packages_py2: diff --git a/test/integration/targets/setup_mongodb/tasks/main.yml b/test/integration/targets/setup_mongodb/tasks/main.yml index 9400c8beda..c1593f960e 100644 --- a/test/integration/targets/setup_mongodb/tasks/main.yml +++ b/test/integration/targets/setup_mongodb/tasks/main.yml @@ -26,6 +26,7 @@ or ansible_os_family == "Suse" or ansible_distribution == 'Fedora' or (ansible_distribution == 'CentOS' and ansible_distribution_version == '7') + or (ansible_distribution == 'CentOS' and ansible_distribution_version == '8') # Ubuntu - name: Import MongoDB public GPG Key xenial |