Skip to content

Commit f105a81

Browse files
committed
ansible: descriptive version check during startup.
1 parent a7fdb55 commit f105a81

File tree

1 file changed

+39
-0
lines changed

1 file changed

+39
-0
lines changed

ansible_mitogen/strategy.py

Lines changed: 39 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -37,9 +37,46 @@
3737
import ansible_mitogen.mixins
3838
import ansible_mitogen.process
3939

40+
import ansible
4041
import ansible.executor.process.worker
4142

4243

44+
ANSIBLE_VERSION_MIN = '2.3'
45+
ANSIBLE_VERSION_MAX = '2.7'
46+
NEW_VERSION_MSG = (
47+
"Your Ansible version (%s) is too recent. The most recent version\n"
48+
"supported by Mitogen for Ansible is %s.x. Please check the Mitogen\n"
49+
"release notes to see if a new version is available, otherwise\n"
50+
"subscribe to the corresponding GitHub issue to be notified when\n"
51+
"support becomes available.\n"
52+
"\n"
53+
" https://mitogen.rtfd.io/en/latest/changelog.html\n"
54+
" https://github.com/dw/mitogen/issues/\n"
55+
)
56+
OLD_VERSION_MSG = (
57+
"Your version of Ansible (%s) is too old. The oldest version supported by "
58+
"Mitogen for Ansible is %s."
59+
)
60+
61+
62+
def _assert_supported_release():
63+
"""
64+
Throw AnsibleError with a descriptive message in case of being loaded into
65+
an unsupported Ansible release.
66+
"""
67+
v = ansible.__version__
68+
69+
if v[:len(ANSIBLE_VERSION_MIN)] < ANSIBLE_VERSION_MIN:
70+
raise ansible.errors.AnsibleError(
71+
OLD_VERSION_MSG % (v, ANSIBLE_VERSION_MIN)
72+
)
73+
74+
if v[:len(ANSIBLE_VERSION_MAX)] > ANSIBLE_VERSION_MAX:
75+
raise ansible.errors.AnsibleError(
76+
NEW_VERSION_MSG % (ansible.__version__, ANSIBLE_VERSION_MAX)
77+
)
78+
79+
4380
def _patch_awx_callback():
4481
"""
4582
issue #400: AWX loads a display callback that suffers from thread-safety
@@ -245,6 +282,8 @@ def run(self, iterator, play_context, result=0):
245282
Arrange for a mitogen.master.Router to be available for the duration of
246283
the strategy's real run() method.
247284
"""
285+
_assert_supported_release()
286+
248287
ansible_mitogen.process.MuxProcess.start()
249288
run = super(StrategyMixin, self).run
250289
self._add_plugin_paths()

0 commit comments

Comments
 (0)