From 3f3a2665585ad8ea06e462f2068194a23c7e6310 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Gon=C3=A9ri=20Le=20Bouder?= Date: Thu, 16 Sep 2021 13:04:29 -0400 Subject: [PATCH] ensure only the minimal amount of modules are loading during the first stage Raise an exception if third party modules are loaded during the first stage. --- changelogs/fragments/too_many_loaded_modules.yaml | 3 +++ plugins/module_utils/turbo/exceptions.py | 4 ++++ plugins/module_utils/turbo/module.py | 4 ++++ 3 files changed, 11 insertions(+) create mode 100644 changelogs/fragments/too_many_loaded_modules.yaml diff --git a/changelogs/fragments/too_many_loaded_modules.yaml b/changelogs/fragments/too_many_loaded_modules.yaml new file mode 100644 index 0000000..eacdc76 --- /dev/null +++ b/changelogs/fragments/too_many_loaded_modules.yaml @@ -0,0 +1,3 @@ +--- +minor_changes: +- Ensure only the minimal amount of modules are loading during the first stage. diff --git a/plugins/module_utils/turbo/exceptions.py b/plugins/module_utils/turbo/exceptions.py index bf161fb..099e982 100644 --- a/plugins/module_utils/turbo/exceptions.py +++ b/plugins/module_utils/turbo/exceptions.py @@ -34,3 +34,7 @@ def __str__(self): class EmbeddedModuleSuccess(Exception): def __init__(self, **kwargs): self.kwargs = kwargs + + +class TooManyLoadedModules(EmbeddedModuleUnexpectedFailure): + pass diff --git a/plugins/module_utils/turbo/module.py b/plugins/module_utils/turbo/module.py index 5848a5c..115f483 100644 --- a/plugins/module_utils/turbo/module.py +++ b/plugins/module_utils/turbo/module.py @@ -6,6 +6,7 @@ from .exceptions import ( EmbeddedModuleSuccess, EmbeddedModuleFailure, + TooManyLoadedModules, ) import ansible_collections.cloud.common.plugins.module_utils.turbo.common @@ -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):