Skip to content

Commit fb4ae24

Browse files
committed
ansible_mitogen: Fix errant ModuleNotFoundError blacklist exceptions
Current module whitelist/blacklist behaviour is to reject any module not on the whitelist if the whitelist is populated. Adding `ansible` and `ansible_mitogen` to the whitelist effectively blocklisted every other Python module/package, negating much of the benefit of Mitogen. Fixes #1011
1 parent ec212a1 commit fb4ae24

File tree

7 files changed

+66
-30
lines changed

7 files changed

+66
-30
lines changed

.ci/azure-pipelines.yml

Lines changed: 2 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -33,13 +33,9 @@ jobs:
3333

3434
# NOTE: this hangs when ran in Ubuntu 18.04
3535
Van_27_210:
36-
tox.env: py27-mode_localhost-ansible2.10
37-
STRATEGY: linear
38-
ANSIBLE_SKIP_TAGS: resource_intensive
36+
tox.env: py27-mode_localhost-ansible2.10-strategy_linear
3937
Van_27_4:
40-
tox.env: py27-mode_localhost-ansible4
41-
STRATEGY: linear
42-
ANSIBLE_SKIP_TAGS: resource_intensive
38+
tox.env: py27-mode_localhost-ansible4-strategy_linear
4339

4440
- job: Linux
4541
pool:

ansible_mitogen/process.py

Lines changed: 0 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -180,29 +180,6 @@ def setup_pool(pool):
180180
LOG.debug('Service pool configured: size=%d', pool.size)
181181

182182

183-
def _setup_responder(responder):
184-
"""
185-
Configure :class:`mitogen.master.ModuleResponder` to only permit
186-
certain packages, and to generate custom responses for certain modules.
187-
"""
188-
responder.whitelist_prefix('ansible')
189-
responder.whitelist_prefix('ansible_mitogen')
190-
191-
# Ansible 2.3 is compatible with Python 2.4 targets, however
192-
# ansible/__init__.py is not. Instead, executor/module_common.py writes
193-
# out a 2.4-compatible namespace package for unknown reasons. So we
194-
# copy it here.
195-
responder.add_source_override(
196-
fullname='ansible',
197-
path=ansible.__file__,
198-
source=(ANSIBLE_PKG_OVERRIDE % (
199-
ansible.__version__,
200-
ansible.__author__,
201-
)).encode(),
202-
is_pkg=True,
203-
)
204-
205-
206183
def increase_open_file_limit():
207184
"""
208185
#549: in order to reduce the possibility of hitting an open files limit,
@@ -669,7 +646,6 @@ def _setup_master(self):
669646
broker=self.broker,
670647
max_message_size=MAX_MESSAGE_SIZE,
671648
)
672-
_setup_responder(self.router.responder)
673649
mitogen.core.listen(self.broker, 'shutdown', self._on_broker_shutdown)
674650
mitogen.core.listen(self.broker, 'exit', self._on_broker_exit)
675651
self.listener = mitogen.unix.Listener.build_stream(

tests/ansible/integration/all.yml

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -29,6 +29,8 @@
2929
tags: playbook_semantics
3030
- import_playbook: process/all.yml
3131
tags: process
32+
- import_playbook: responder/all.yml
33+
tags: responder
3234
- import_playbook: runner/all.yml
3335
tags: runner
3436
- import_playbook: ssh/all.yml
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
- import_playbook: imports.yml
Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
1+
- name: integration/responder/imports.yml
2+
hosts: test-targets
3+
tasks:
4+
- meta: end_play
5+
when: not is_mitogen
6+
7+
- name: Import pure Python module via Ansible module
8+
mitogen_plain_old_add:
9+
x: 2
10+
y: 2
11+
register: mitogen_plain_old_add_result
12+
13+
- name: Import binary module via Responder
14+
custom_python_run_script:
15+
script: |
16+
import lxml
17+
register: binary_module_result
18+
19+
- name: Import missing module via Responder
20+
custom_python_run_script:
21+
script: |
22+
import does_not_exist
23+
register: missing_module_result
Lines changed: 36 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,36 @@
1+
#!/usr/bin/env python
2+
3+
DOCUMENTATION = '''
4+
module: mitogen_plain_old_add
5+
options:
6+
x: {type: int, required: true}
7+
y: {type: int, required: true}
8+
author:
9+
- Alex Willmer (@moreati)
10+
'''
11+
12+
RETURN = '''
13+
total: {type: int, returned: always, sample: 42}
14+
'''
15+
16+
from ansible.module_utils.basic import AnsibleModule
17+
18+
import plain_old_module
19+
20+
def main():
21+
module = AnsibleModule(
22+
argument_spec={
23+
'x': {'type': int, 'required': True},
24+
'x': {'type': int, 'required': True},
25+
},
26+
supports_check_mode=True,
27+
)
28+
result = {
29+
'changed': False,
30+
'total': plain_old_module.add(module.params['x'], module.params['y']),
31+
}
32+
module.exit_json(**result)
33+
34+
35+
if __name__ == '__main__':
36+
main()

tests/ansible/run_ansible_playbook.py

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -35,6 +35,8 @@
3535
os.environ['PATH'],
3636
)
3737

38+
os.environ['PYTHONPATH'] = os.path.join(GIT_BASEDIR, 'tests', 'data')
39+
3840
extra = {
3941
'is_mitogen': os.environ.get('ANSIBLE_STRATEGY', '').startswith('mitogen'),
4042
'git_basedir': GIT_BASEDIR,

0 commit comments

Comments
 (0)