Skip to content

Packs that have actions in sub-directories importing modules in same sub-directory fail #5126

@amanda11

Description

@amanda11

SUMMARY

I have observed in a couple of packs when using StackStorm 3.4dev that they now get ModuleNotFoundError when the pack has a module actions/lib/moduleA.py and that moduleA.py has an import moduleB where moduleB is in the same library.
These packs were working in previous versions.
Observed in both ActiveDirectory and Excel packs.

STACKSTORM VERSION

st2 3.4dev (c422f00), on Python 3.6.8

OS, environment, install method

CentOS 8.2, single line bash installer

Steps to reproduce the problem

Observed with following actions:

  • activedirectory.get_ad_user
  • excel.get_keys_for_rows

Expected Results

Actions to work as before and not throw ModuleNotFoundError

Actual Results

Excel Stack Trace:

{
  "stdout": "",
  "stderr": "Traceback (most recent call last):
  File \"/opt/stackstorm/st2/lib/python3.6/site-packages/python_runner/python_action_wrapper.py\", line 238, in _get_action_instance
    actions_cls = action_loader.register_plugin(Action, self._file_path)
  File \"/opt/stackstorm/st2/lib/python3.6/site-packages/st2common/util/loader.py\", line 166, in register_plugin
    module = imp.load_source(module_name, plugin_abs_file_path)
  File \"/opt/stackstorm/virtualenvs/excel/lib64/python3.6/imp.py\", line 172, in load_source
    module = _load(spec)
  File \"<frozen importlib._bootstrap>\", line 684, in _load
  File \"<frozen importlib._bootstrap>\", line 665, in _load_unlocked
  File \"<frozen importlib._bootstrap_external>\", line 678, in exec_module
  File \"<frozen importlib._bootstrap>\", line 219, in _call_with_frames_removed
  File \"/opt/stackstorm/packs/excel/actions/get_keys_for_rows.py\", line 14, in <module>
    from lib import excel_action, excel_reader
  File \"/opt/stackstorm/packs/excel/actions/lib/excel_reader.py\", line 16, in <module>
    import string_converter
ModuleNotFoundError: No module named 'string_converter'

During handling of the above exception, another exception occurred:

Traceback (most recent call last):
  File \"/opt/stackstorm/st2/lib/python3.6/site-packages/python_runner/python_action_wrapper.py\", line 334, in <module>
    obj.run()
  File \"/opt/stackstorm/st2/lib/python3.6/site-packages/python_runner/python_action_wrapper.py\", line 192, in run
    action = self._get_action_instance()
  File \"/opt/stackstorm/st2/lib/python3.6/site-packages/python_runner/python_action_wrapper.py\", line 245, in _get_action_instance
    raise exc_cls(msg)
ModuleNotFoundError: Failed to load action class from file \"/opt/stackstorm/packs/excel/actions/get_keys_for_rows.py\" (action file most likely doesn't exist or contains invalid syntax): No module named 'string_converter'

Traceback (most recent call last):
  File \"/opt/stackstorm/st2/lib/python3.6/site-packages/python_runner/python_action_wrapper.py\", line 238, in _get_action_instance
    actions_cls = action_loader.register_plugin(Action, self._file_path)
  File \"/opt/stackstorm/st2/lib/python3.6/site-packages/st2common/util/loader.py\", line 166, in register_plugin
    module = imp.load_source(module_name, plugin_abs_file_path)
  File \"/opt/stackstorm/virtualenvs/excel/lib64/python3.6/imp.py\", line 172, in load_source
    module = _load(spec)
  File \"<frozen importlib._bootstrap>\", line 684, in _load
  File \"<frozen importlib._bootstrap>\", line 665, in _load_unlocked
  File \"<frozen importlib._bootstrap_external>\", line 678, in exec_module
  File \"<frozen importlib._bootstrap>\", line 219, in _call_with_frames_removed
  File \"/opt/stackstorm/packs/excel/actions/get_keys_for_rows.py\", line 14, in <module>
    from lib import excel_action, excel_reader
  File \"/opt/stackstorm/packs/excel/actions/lib/excel_reader.py\", line 16, in <module>
    import string_converter
ModuleNotFoundError: No module named 'string_converter'

",
  "exit_code": 1,
  "result": "None"
}

Active Directory StackTrace:

{
  "stdout": "",
  "stderr": "Traceback (most recent call last):
  File \"/opt/stackstorm/st2/lib/python3.6/site-packages/python_runner/python_action_wrapper.py\", line 238, in _get_action_instance
    actions_cls = action_loader.register_plugin(Action, self._file_path)
  File \"/opt/stackstorm/st2/lib/python3.6/site-packages/st2common/util/loader.py\", line 166, in register_plugin
    module = imp.load_source(module_name, plugin_abs_file_path)
  File \"/opt/stackstorm/virtualenvs/activedirectory/lib64/python3.6/imp.py\", line 172, in load_source
    module = _load(spec)
  File \"<frozen importlib._bootstrap>\", line 684, in _load
  File \"<frozen importlib._bootstrap>\", line 665, in _load_unlocked
  File \"<frozen importlib._bootstrap_external>\", line 678, in exec_module
  File \"<frozen importlib._bootstrap>\", line 219, in _call_with_frames_removed
  File \"/opt/stackstorm/packs/activedirectory/actions/run_cmdlet.py\", line 1, in <module>
    from lib import action
  File \"/opt/stackstorm/packs/activedirectory/actions/lib/action.py\", line 1, in <module>
    from winrm_connection import WinRmConnection
ModuleNotFoundError: No module named 'winrm_connection'

During handling of the above exception, another exception occurred:

Traceback (most recent call last):
  File \"/opt/stackstorm/st2/lib/python3.6/site-packages/python_runner/python_action_wrapper.py\", line 334, in <module>
    obj.run()
  File \"/opt/stackstorm/st2/lib/python3.6/site-packages/python_runner/python_action_wrapper.py\", line 192, in run
    action = self._get_action_instance()
  File \"/opt/stackstorm/st2/lib/python3.6/site-packages/python_runner/python_action_wrapper.py\", line 245, in _get_action_instance
    raise exc_cls(msg)
ModuleNotFoundError: Failed to load action class from file \"/opt/stackstorm/packs/activedirectory/actions/run_cmdlet.py\" (action file most likely doesn't exist or contains invalid syntax): No module named 'winrm_connection'

Traceback (most recent call last):
  File \"/opt/stackstorm/st2/lib/python3.6/site-packages/python_runner/python_action_wrapper.py\", line 238, in _get_action_instance
    actions_cls = action_loader.register_plugin(Action, self._file_path)
  File \"/opt/stackstorm/st2/lib/python3.6/site-packages/st2common/util/loader.py\", line 166, in register_plugin
    module = imp.load_source(module_name, plugin_abs_file_path)
  File \"/opt/stackstorm/virtualenvs/activedirectory/lib64/python3.6/imp.py\", line 172, in load_source
    module = _load(spec)
  File \"<frozen importlib._bootstrap>\", line 684, in _load
  File \"<frozen importlib._bootstrap>\", line 665, in _load_unlocked
  File \"<frozen importlib._bootstrap_external>\", line 678, in exec_module
  File \"<frozen importlib._bootstrap>\", line 219, in _call_with_frames_removed
  File \"/opt/stackstorm/packs/activedirectory/actions/run_cmdlet.py\", line 1, in <module>
    from lib import action
  File \"/opt/stackstorm/packs/activedirectory/actions/lib/action.py\", line 1, in <module>
    from winrm_connection import WinRmConnection
ModuleNotFoundError: No module named 'winrm_connection'

",
  "exit_code": 1,
  "result": "None"
}

Workarounds were possible to get this to work, e.g. change the ActiveDirectory to use "from .winrm_connection import WinRm"

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

    Milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions