mitogen-hq / mitogen

Distributed self-replicating programs in Python
https://mitogen.networkgenomics.com/
BSD 3-Clause "New" or "Revised" License
2.33k stars 198 forks source link

'retrying' is present in the Mitogen importer blacklist #727

Open kevinkirkup opened 4 years ago

kevinkirkup commented 4 years ago
The full traceback is:
Traceback (most recent call last):
  File "master:/usr/local/lib/python3.6/dist-packages/ansible_mitogen/runner.py", line 961, in _run
    self._run_code(code, mod)
  File "master:/usr/local/lib/python3.6/dist-packages/ansible_mitogen/runner.py", line 938, in _run_code
    exec(code, vars(mod))
  File "master:/ansible/roles/kafka_topics/library/kafka_topic.py", line 66, in <module>
  File "<stdin>", line 1475, in load_module
  File "<stdin>", line 1404, in _refuse_imports
ModuleNotFoundError: 'retrying' is present in the Mitogen importer blacklist, therefore this context will not attempt to request it from the master, as the request will always be refused.

Feel free to write an issue in your preferred format, however if in doubt, use the following checklist as a guide for what to include.

kevinkirkup commented 4 years ago

I've tried a number of different thing to figure this out without any luck. Any help would be appreciated.

kevinkirkup commented 4 years ago

Set: strategy: linear for this role and seeing a similar error from Ansible.

TASK [kafka_topics : Create Topics] ****************************************************************************************************************************************************************************************************
An exception occurred during task execution. To see the full traceback, use -vvv. The error was: ModuleNotFoundError: No module named 'retrying'
failed: [kato-virtual-pod-26-openstack1] (item={'key': 'containers_bgp_status', 'value': {'state': 'present', 'name': 'containers_bgp_status', 'partitions': 48, 'replication_factor': 1, 'config': {'retention.ms': 604800000}}}) => {"ansible_loop_var": "item", "changed": false, "item": {"key": "containers_bgp_status", "value": {"config": {"retention.ms": 604800000}, "name": "containers_bgp_status", "partitions": 48, "replication_factor": 1, "state": "present"}}, "module_stderr": "Traceback (most recent call last):\n  File \"<stdin>\", line 114, in <module>\n  File \"<stdin>\", line 106, in _ansiballz_main\n  File \"<stdin>\", line 49, in invoke_module\n  File \"/usr/lib/python3.6/imp.py\", line 235, in load_module\n    return load_source(name, filename, file)\n  File \"/usr/lib/python3.6/imp.py\", line 170, in load_source\n    module = _exec(spec, sys.modules[name])\n  File \"<frozen importlib._bootstrap>\", line 618, in _exec\n  File \"<frozen importlib._bootstrap_external>\", line 678, in exec_module\n  File \"<frozen importlib._bootstrap>\", line 219, in _call_with_frames_removed\n  File \"/tmp/ansible_kafka_topic_payload_5xu4r5v6/__main__.py\", line 66, in <module>\nModuleNotFoundError: No module named 'retrying'\n", "module_stdout": "", "msg": "MODULE FAILURE\nSee stdout/stderr for the exact error", "rc": 1}
An exception occurred during task execution. To see the full traceback, use -vvv. The error was: ModuleNotFoundError: No module named 'retrying'
kevinkirkup commented 4 years ago

Import is working:

>>> import retrying
>>> os.path.abspath(retrying.__file__)
'/usr/local/lib/python3.6/dist-packages/retrying.py'

But isn't in sys.module:

def load_source(name, pathname, file=None):
    loader = _LoadSourceCompatibility(name, pathname, file)
    spec = util.spec_from_file_location(name, pathname, loader=loader)
    if name in sys.modules:
        module = _exec(spec, sys.modules[name])                                          <------------ Failing here
kevinkirkup commented 4 years ago

I was able to resolve this by manually installing the package on the target host. I'm was thinking that should be covered by mitogen or Ansible, but maybe not.

s1113950 commented 4 years ago

You're correct, Ansible requires external python packages to be installed in order for it to use them. Glad you got your issue worked out though!

kevinkirkup commented 4 years ago

I think what confused me was the comment in #724. It made it sound like Mitogen would install it on the remote host.

s1113950 commented 4 years ago

I just checked the comment you mentioned; you're correct in that Mitogen should fetch it from the host node. Ooh but if it's a module that's not in sys.modules then the issue might be that Mitogen's import helper code couldn't find it (there's a few different ways Mitogen tries to find modules and sys.modules is one of them). I ran into a similar error with trying to get collections support to work for Mitogen: Ansible collections do a bit of a hack on the import system so that you can import X but stuff doesn't exist in the usual places Python looks when you import something. I haven't used https://pypi.org/project/retrying/ before myself so I can't say for sure.

Would you be able to provide a sample playbook so I can reproduce the error inside of the bionic container you tried?

kevinkirkup commented 4 years ago

Let me see what I can do. It could be a few days b/c of the holiday.

s1113950 commented 4 years ago

No rush! 😄