Skip to content

Commit 4c02ea6

Browse files
authored
Merge pull request #878 from moreati/ci-version-comparisons
ci: Fix version comparisons involving double digits
2 parents 9a66d3a + d9b8d50 commit 4c02ea6

23 files changed

+146
-79
lines changed

ansible_mitogen/loaders.py

Lines changed: 3 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -31,7 +31,8 @@
3131
"""
3232

3333
from __future__ import absolute_import
34-
import distutils.version
34+
35+
import ansible_mitogen.utils
3536

3637
__all__ = [
3738
'action_loader',
@@ -42,7 +43,6 @@
4243
'strategy_loader',
4344
]
4445

45-
import ansible
4646

4747
ANSIBLE_VERSION_MIN = (2, 10)
4848
ANSIBLE_VERSION_MAX = (2, 11)
@@ -68,10 +68,7 @@ def assert_supported_release():
6868
Throw AnsibleError with a descriptive message in case of being loaded into
6969
an unsupported Ansible release.
7070
"""
71-
v = ansible.__version__
72-
if not isinstance(v, tuple):
73-
v = tuple(distutils.version.LooseVersion(v).version)
74-
71+
v = ansible_mitogen.utils.ansible_version
7572
if v[:2] < ANSIBLE_VERSION_MIN:
7673
raise ansible.errors.AnsibleError(
7774
OLD_VERSION_MSG % (v, ANSIBLE_VERSION_MIN)

ansible_mitogen/mixins.py

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -53,6 +53,8 @@
5353
import ansible_mitogen.connection
5454
import ansible_mitogen.planner
5555
import ansible_mitogen.target
56+
import ansible_mitogen.utils
57+
5658
from ansible.module_utils._text import to_text
5759

5860
try:
@@ -226,7 +228,7 @@ def _remove_tmp_path(self, tmp_path):
226228
with a pipelined call to :func:`ansible_mitogen.target.prune_tree`.
227229
"""
228230
LOG.debug('_remove_tmp_path(%r)', tmp_path)
229-
if tmp_path is None and ansible.__version__ > '2.6':
231+
if tmp_path is None and ansible_mitogen.utils.ansible_version[:2] >= (2, 6):
230232
tmp_path = self._connection._shell.tmpdir # 06f73ad578d
231233
if tmp_path is not None:
232234
self._connection.get_chain().call_no_reply(
@@ -335,7 +337,7 @@ def get_task_timeout_secs(self):
335337
def _set_temp_file_args(self, module_args, wrap_async):
336338
# Ansible>2.5 module_utils reuses the action's temporary directory if
337339
# one exists. Older versions error if this key is present.
338-
if ansible.__version__ > '2.5':
340+
if ansible_mitogen.utils.ansible_version[:2] >= (2, 5):
339341
if wrap_async:
340342
# Sharing is not possible with async tasks, as in that case,
341343
# the directory must outlive the action plug-in.
@@ -346,7 +348,7 @@ def _set_temp_file_args(self, module_args, wrap_async):
346348
# If _ansible_tmpdir is unset, Ansible>2.6 module_utils will use
347349
# _ansible_remote_tmp as the location to create the module's temporary
348350
# directory. Older versions error if this key is present.
349-
if ansible.__version__ > '2.6':
351+
if ansible_mitogen.utils.ansible_version[:2] >= (2, 6):
350352
module_args['_ansible_remote_tmp'] = (
351353
self._connection.get_good_temp_dir()
352354
)
@@ -393,7 +395,7 @@ def _execute_module(self, module_name=None, module_args=None, tmp=None,
393395
)
394396
)
395397

396-
if tmp and ansible.__version__ < '2.5' and delete_remote_tmp:
398+
if tmp and delete_remote_tmp and ansible_mitogen.utils.ansible_version[:2] < (2, 5):
397399
# Built-in actions expected tmpdir to be cleaned up automatically
398400
# on _execute_module().
399401
self._remove_tmp_path(tmp)

ansible_mitogen/plugins/connection/mitogen_kubectl.py

Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -45,17 +45,11 @@
4545
import ansible_mitogen.loaders
4646

4747

48-
_class = ansible_mitogen.loaders.connection_loader__get(
48+
_get_result = ansible_mitogen.loaders.connection_loader__get(
4949
'kubectl',
5050
class_only=True,
5151
)
5252

53-
if _class:
54-
kubectl = sys.modules[_class.__module__]
55-
del _class
56-
else:
57-
kubectl = None
58-
5953

6054
class Connection(ansible_mitogen.connection.Connection):
6155
transport = 'kubectl'
@@ -66,13 +60,19 @@ class Connection(ansible_mitogen.connection.Connection):
6660
)
6761

6862
def __init__(self, *args, **kwargs):
69-
if kubectl is None:
63+
if not _get_result:
7064
raise AnsibleConnectionFailure(self.not_supported_msg)
7165
super(Connection, self).__init__(*args, **kwargs)
7266

7367
def get_extra_args(self):
68+
try:
69+
# Ansible < 2.10, _get_result is the connection class
70+
connection_options = _get_result.connection_options
71+
except AttributeError:
72+
# Ansible >= 2.10, _get_result is a get_with_context_result
73+
connection_options = _get_result.object.connection_options
7474
parameters = []
75-
for key, option in iteritems(kubectl.CONNECTION_OPTIONS):
75+
for key, option in iteritems(connection_options):
7676
if self.get_task_var('ansible_' + key) is not None:
7777
parameters += [ option, self.get_task_var('ansible_' + key) ]
7878

ansible_mitogen/target.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -144,7 +144,7 @@ def subprocess__Popen__close_fds(self, but):
144144

145145
if (
146146
sys.platform.startswith(u'linux') and
147-
sys.version < u'3.0' and
147+
sys.version_info < (3,) and
148148
hasattr(subprocess.Popen, u'_close_fds') and
149149
not mitogen.is_master
150150
):

ansible_mitogen/utils.py

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
from __future__ import absolute_import
2+
3+
import distutils.version
4+
5+
import ansible
6+
7+
__all__ = [
8+
'ansible_version',
9+
]
10+
11+
ansible_version = tuple(distutils.version.LooseVersion(ansible.__version__).version)
12+
del distutils
13+
del ansible

docs/changelog.rst

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,8 @@ v0.3.1.dev0 (unreleased)
2727
* :gh:issue:`860` Add initial support for podman connection (w/o Ansible support yet)
2828
* :gh:issue:`873` `python -c ...` first stage no longer uses :py:mod:`platform`` to detect the macOS release
2929
* :gh:issue:`876` `python -c ...` first stage no longer contains tab characters, to reduce size
30+
* :gh:issue:`878` Continuous Integration tests now correctly perform comparisons of 2 digit versions
31+
* :gh:issue:`878` Kubectl connector fixed with Ansible 2.10 and above
3032

3133

3234
v0.3.0 (2021-11-24)

tests/ansible/integration/async/result_shell_echo_hi.yml

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -46,7 +46,8 @@
4646
that:
4747
- async_out.invocation.module_args.stdin == None
4848
fail_msg: async_out={{async_out}}
49-
when: ansible_version.full > '2.4'
49+
when:
50+
- ansible_version.full is version('2.4', '>=', strict=True)
5051
vars:
5152
async_out: "{{result.content|b64decode|from_json}}"
5253
tags:

tests/ansible/integration/async/runner_one_job.yml

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -41,9 +41,9 @@
4141
- result1.changed == True
4242
# ansible/b72e989e1837ccad8dcdc926c43ccbc4d8cdfe44
4343
- |
44-
(ansible_version.full is version('2.8', ">=") and
44+
(ansible_version.full is version('2.8', ">=", strict=True) and
4545
result1.cmd == "echo alldone;\nsleep 1;\n") or
46-
(ansible_version.full is version('2.8', '<') and
46+
(ansible_version.full is version('2.8', '<', strict=True) and
4747
result1.cmd == "echo alldone;\n sleep 1;")
4848
- result1.delta|length == 14
4949
- result1.start|length == 26
@@ -58,12 +58,14 @@
5858
- result1.stdout == "alldone"
5959
- result1.stdout_lines == ["alldone"]
6060
fail_msg: result1={{result1}}
61-
when: ansible_version.full is version('2.8', '>') # ansible#51393
61+
when:
62+
- ansible_version.full is version('2.8', '>', strict=True) # ansible#51393
6263

6364
- assert:
6465
that:
6566
- result1.failed == False
6667
fail_msg: result1={{result1}}
67-
when: ansible_version.full is version('2.4', '>')
68+
when:
69+
- ansible_version.full is version('2.4', '>', strict=True)
6870
tags:
6971
- runner_one_job

tests/ansible/integration/async/runner_two_simultaneous_jobs.yml

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -62,6 +62,7 @@
6262
that:
6363
- result2.stdout == 'im_alive'
6464
fail_msg: result2={{result2}}
65-
when: ansible_version.full > '2.8' # ansible#51393
65+
when:
66+
- ansible_version.full is version('2.8', '>=', strict=True) # ansible#51393
6667
tags:
6768
- runner_two_simultaneous_jobs

tests/ansible/integration/connection/reset.yml

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -10,10 +10,12 @@
1010
when: not is_mitogen
1111

1212
- debug: msg="reset.yml skipped on Ansible<2.5.6"
13-
when: ansible_version.full < '2.5.6'
13+
when:
14+
- ansible_version.full is version('2.5.6', '<', strict=True)
1415

1516
- meta: end_play
16-
when: ansible_version.full < '2.5.6'
17+
when:
18+
- ansible_version.full is version('2.5.6', '<', strict=True)
1719

1820
- custom_python_detect_environment:
1921
register: out

0 commit comments

Comments
 (0)