From f635ed6c2ed62feebd4af912c9c365c26959e8e0 Mon Sep 17 00:00:00 2001 From: Sergei Antipov Date: Thu, 20 Jul 2023 14:51:53 -0400 Subject: [PATCH] [PR #6980/796ad356 backport][stable-6] [proxmox] Use proxmoxer_version instead of server API version (#6984) * [proxmox] Use proxmoxer_version instead of server API version (#6980) * Use proxmoxer_version instead of server API version * Add changelog fragment (cherry picked from commit 796ad3565eab36a0146c3f3d084306969a5e51ee) * Update unit tests requirements file * Add python 2.6 constraint for tests --- changelogs/fragments/6980-proxmox-fix-token-auth.yml | 2 ++ plugins/module_utils/proxmox.py | 4 +++- tests/unit/plugins/modules/test_proxmox_snap.py | 7 +++++++ tests/unit/plugins/modules/test_proxmox_tasks_info.py | 7 +++++++ tests/unit/requirements.txt | 6 +++++- 5 files changed, 24 insertions(+), 2 deletions(-) create mode 100644 changelogs/fragments/6980-proxmox-fix-token-auth.yml diff --git a/changelogs/fragments/6980-proxmox-fix-token-auth.yml b/changelogs/fragments/6980-proxmox-fix-token-auth.yml new file mode 100644 index 0000000000..93545fff3e --- /dev/null +++ b/changelogs/fragments/6980-proxmox-fix-token-auth.yml @@ -0,0 +1,2 @@ +bugfixes: + - proxmox module utils - fix proxmoxer library version check (https://github.com/ansible-collections/community.general/issues/6974, https://github.com/ansible-collections/community.general/issues/6975, https://github.com/ansible-collections/community.general/pull/6980). diff --git a/plugins/module_utils/proxmox.py b/plugins/module_utils/proxmox.py index d07026c038..47117ada81 100644 --- a/plugins/module_utils/proxmox.py +++ b/plugins/module_utils/proxmox.py @@ -18,6 +18,7 @@ import traceback PROXMOXER_IMP_ERR = None try: from proxmoxer import ProxmoxAPI + from proxmoxer import __version__ as proxmoxer_version HAS_PROXMOXER = True except ImportError: HAS_PROXMOXER = False @@ -79,6 +80,7 @@ class ProxmoxAnsible(object): module.fail_json(msg=missing_required_lib('proxmoxer'), exception=PROXMOXER_IMP_ERR) self.module = module + self.proxmoxer_version = proxmoxer_version self.proxmox_api = self._connect() # Test token validity try: @@ -98,7 +100,7 @@ class ProxmoxAnsible(object): if api_password: auth_args['password'] = api_password else: - if self.version() < LooseVersion('1.1.0'): + if self.proxmoxer_version < LooseVersion('1.1.0'): self.module.fail_json('Using "token_name" and "token_value" require proxmoxer>=1.1.0') auth_args['token_name'] = api_token_id auth_args['token_value'] = api_token_secret diff --git a/tests/unit/plugins/modules/test_proxmox_snap.py b/tests/unit/plugins/modules/test_proxmox_snap.py index 4bdcaa8b77..52ac1ecc64 100644 --- a/tests/unit/plugins/modules/test_proxmox_snap.py +++ b/tests/unit/plugins/modules/test_proxmox_snap.py @@ -8,6 +8,13 @@ __metaclass__ = type import json import pytest +import sys + +proxmoxer = pytest.importorskip('proxmoxer') +mandatory_py_version = pytest.mark.skipif( + sys.version_info < (2, 7), + reason='The proxmoxer dependency requires python2.7 or higher' +) from ansible_collections.community.general.tests.unit.compat.mock import MagicMock, patch from ansible_collections.community.general.plugins.modules import proxmox_snap diff --git a/tests/unit/plugins/modules/test_proxmox_tasks_info.py b/tests/unit/plugins/modules/test_proxmox_tasks_info.py index 0d1b5a7bfb..8dbacf60d1 100644 --- a/tests/unit/plugins/modules/test_proxmox_tasks_info.py +++ b/tests/unit/plugins/modules/test_proxmox_tasks_info.py @@ -12,6 +12,13 @@ __metaclass__ = type import pytest import json +import sys + +proxmoxer = pytest.importorskip('proxmoxer') +mandatory_py_version = pytest.mark.skipif( + sys.version_info < (2, 7), + reason='The proxmoxer dependency requires python2.7 or higher' +) from ansible_collections.community.general.plugins.modules import proxmox_tasks_info import ansible_collections.community.general.plugins.module_utils.proxmox as proxmox_utils diff --git a/tests/unit/requirements.txt b/tests/unit/requirements.txt index 0aa7c1fc9f..be060a3dd3 100644 --- a/tests/unit/requirements.txt +++ b/tests/unit/requirements.txt @@ -43,4 +43,8 @@ dataclasses ; python_version == '3.6' elastic-apm ; python_version >= '3.6' # requirements for scaleway modules -passlib[argon2] \ No newline at end of file +passlib[argon2] + +# requirements for the proxmox modules +proxmoxer < 2.0.0 ; python_version >= '2.7' and python_version <= '3.6' +proxmoxer ; python_version > '3.6'