Skip to content

Commit

Permalink
ensure only the minimal amount of modules are loading during the firs…
Browse files Browse the repository at this point in the history
…t stage

Raise an exception if third party modules are loaded during the first
stage.
  • Loading branch information
goneri committed Sep 16, 2021
1 parent c0e46bb commit 3f3a266
Show file tree
Hide file tree
Showing 3 changed files with 11 additions and 0 deletions.
3 changes: 3 additions & 0 deletions changelogs/fragments/too_many_loaded_modules.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
---
minor_changes:
- Ensure only the minimal amount of modules are loading during the first stage.
4 changes: 4 additions & 0 deletions plugins/module_utils/turbo/exceptions.py
Original file line number Diff line number Diff line change
Expand Up @@ -34,3 +34,7 @@ def __str__(self):
class EmbeddedModuleSuccess(Exception):
def __init__(self, **kwargs):
self.kwargs = kwargs


class TooManyLoadedModules(EmbeddedModuleUnexpectedFailure):
pass
4 changes: 4 additions & 0 deletions plugins/module_utils/turbo/module.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@
from .exceptions import (
EmbeddedModuleSuccess,
EmbeddedModuleFailure,
TooManyLoadedModules,
)
import ansible_collections.cloud.common.plugins.module_utils.turbo.common

Expand Down Expand Up @@ -80,6 +81,9 @@ def __init__(self, *args, **kwargs):
)
self._running = None
if not self.embedded_in_server:
external_libs = [name for name in sys.modules if "site-packages" in str(sys.modules[name])]
if external_libs:
raise TooManyLoadedModules(external_libs)
self.run_on_daemon()

def socket_path(self):
Expand Down

0 comments on commit 3f3a266

Please sign in to comment.