Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add support for same-file condition #374

Open
enhaut opened this issue Jul 12, 2024 · 1 comment
Open

Add support for same-file condition #374

enhaut opened this issue Jul 12, 2024 · 1 comment

Comments

@enhaut
Copy link
Member

enhaut commented Jul 12, 2024

#370 added support of remote conditional wait. However, due to limitations of LNST, having condition class in the same file as recipe is not supported.

The remote agent process crashes with exception:

Traceback (most recent call last):
  File "/root/lnst_venv/bin/lnst-agent", line 8, in <module>
    sys.exit(main())
  File "/root/lnst_venv/lib/python3.9/site-packages/lnst/Agent/__main__.py", line 45, in main
    agent.run()
  File "/root/lnst_venv/lib/python3.9/site-packages/lnst/Agent/Agent.py", line 1000, in run
    self._process_msg(msg[1])
  File "/root/lnst_venv/lib/python3.9/site-packages/lnst/Agent/Agent.py", line 1033, in _process_msg
    result = method(*args, **kwargs)
  File "/root/lnst_venv/lib/python3.9/site-packages/lnst/Agent/Agent.py", line 165, in load_cached_module
    module = module_loader.load_module()
  File "<frozen importlib._bootstrap_external>", line 529, in _check_name_wrapper
  File "<frozen importlib._bootstrap_external>", line 1029, in load_module
  File "<frozen importlib._bootstrap_external>", line 854, in load_module
  File "<frozen importlib._bootstrap>", line 274, in _load_module_shim
  File "<frozen importlib._bootstrap>", line 711, in _load
  File "<frozen importlib._bootstrap>", line 680, in _load_unlocked
  File "<frozen importlib._bootstrap_external>", line 850, in exec_module
  File "<frozen importlib._bootstrap>", line 228, in _call_with_frames_removed
  File "/root/lnst_venv/bin/cache/04d190987ef8ce3aab89897187c916ddaec65a737b353202dcc4655b7a2f4261", line 6, in <module>
    from lnst.Tests.LongLivedConnections import LongLivedServer, LongLivedClient
ModuleNotFoundError: No module named 'lnst.Tests.LongLivedConnections'

The file with definition of class is transferred to agent and then loaded. However, its' imports are loaded from Agent._dynamic_modules (Agent.load_chached_module method) which contains only files that have been already transferred using this mechanism so if recipe uses an module, that haven't been transferred to agent, it crashes.

Reproducing patch:

diff --git a/lnst/Recipes/ENRT/ConfigMixins/LongLivedConnectionsMixin.py b/lnst/Recipes/ENRT/ConfigMixins/LongLivedConnectionsMixin.py
index 81e76a97..91a9febe 100644
--- a/lnst/Recipes/ENRT/ConfigMixins/LongLivedConnectionsMixin.py
+++ b/lnst/Recipes/ENRT/ConfigMixins/LongLivedConnectionsMixin.py
@@ -10,6 +10,13 @@ from lnst.Common.Parameters import IPv4NetworkParam, IPv6NetworkParam
 from lnst.Common.conditions.WaitForEstablishedConnections import (
     WaitForEstablishedConnections,
 )
+from lnst.Common.conditions.WaitForConditionModule import WaitForConditionModule
+
+
+class DummyCondition(WaitForConditionModule):
+    def _condition(self):
+        return True
+
 
 
 class LongLivedConnectionsMixin:
@@ -49,6 +56,8 @@ class LongLivedConnectionsMixin:
         host1.eth0.keep_addrs_on_down()
         host2.eth0.keep_addrs_on_down()
 
+        host1.wait_for_condition(DummyCondition())
+
         config = super().test_wide_configuration()
         # L4 can address up to 65535 ports (size of addresable space
         # defined in long_lived_conns_per_ip) Therefore opening connections
@enhaut
Copy link
Member Author

enhaut commented Jul 12, 2024

When using SimpleNetworkRecipe it crashes on:

Traceback (most recent call last):
  File "/root/lnst_venv/bin/lnst-agent", line 8, in <module>
    sys.exit(main())
  File "/root/lnst_venv/lib/python3.9/site-packages/lnst/Agent/__main__.py", line 45, in main
    agent.run()
  File "/root/lnst_venv/lib/python3.9/site-packages/lnst/Agent/Agent.py", line 1000, in run
    self._process_msg(msg[1])
  File "/root/lnst_venv/lib/python3.9/site-packages/lnst/Agent/Agent.py", line 1033, in _process_msg
    result = method(*args, **kwargs)
  File "/root/lnst_venv/lib/python3.9/site-packages/lnst/Agent/Agent.py", line 165, in load_cached_module
    module = module_loader.load_module()
  File "<frozen importlib._bootstrap_external>", line 529, in _check_name_wrapper
  File "<frozen importlib._bootstrap_external>", line 1029, in load_module
  File "<frozen importlib._bootstrap_external>", line 854, in load_module
  File "<frozen importlib._bootstrap>", line 274, in _load_module_shim
  File "<frozen importlib._bootstrap>", line 711, in _load
  File "<frozen importlib._bootstrap>", line 680, in _load_unlocked
  File "<frozen importlib._bootstrap_external>", line 850, in exec_module
  File "<frozen importlib._bootstrap>", line 228, in _call_with_frames_removed
  File "/root/lnst_venv/bin/cache/debffc56a4f072f3c648dabcc1e74c26c6550776050edbe797a13c2cf1f87850", line 4, in <module>
    from lnst.Controller import HostReq, DeviceReq, RecipeParam
  File "/root/lnst_venv/lib/python3.9/site-packages/lnst/Controller/__init__.py", line 8, in <module>
    from lnst.Controller.Controller import Controller
  File "/root/lnst_venv/lib/python3.9/site-packages/lnst/Controller/Controller.py", line 19, in <module>
    from lnst.Devices.VirtualDevice import VirtualDevice
ModuleNotFoundError: No module named 'lnst.Devices.VirtualDevice'

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant