From: Ondrej Lichtner <olichtne(a)redhat.com>
The BaseTestModule class should be part of the lnst.Tests package, which
gets dynamically sent to the slave when required.
I also added the wait_for_interrupt method to the BaseTestModule class.
This is functionality that we've had in the old TestModule classes but
didn't yet implement for the new Python recipes.
Even though this doesn't act as any sort of tester API or public code I
think it's a piece of code that is going to be reused a lot in many of
our test modules so it makes sense to add it to the base class.
Signed-off-by: Ondrej Lichtner <olichtne(a)redhat.com>
---
lnst/Controller/Job.py | 2 +-
lnst/Controller/Machine.py | 2 +-
lnst/Controller/MessageDispatcher.py | 2 +-
lnst/Slave/NetTestSlave.py | 8 ++++++--
.../TestModule.py => Tests/BaseTestModule.py} | 20 +++++++++++++++++++
lnst/Tests/Iperf.py | 2 +-
lnst/Tests/Netperf.py | 3 +--
lnst/Tests/Ping.py | 2 +-
8 files changed, 32 insertions(+), 9 deletions(-)
rename lnst/{Common/TestModule.py => Tests/BaseTestModule.py} (85%)
diff --git a/lnst/Controller/Job.py b/lnst/Controller/Job.py
index 4416d9a..f1feae6 100644
--- a/lnst/Controller/Job.py
+++ b/lnst/Controller/Job.py
@@ -14,7 +14,7 @@ olichtne(a)redhat.com (Ondrej Lichtner)
import logging
import signal
from lnst.Common.JobError import JobError
-from lnst.Common.TestModule import BaseTestModule
+from lnst.Tests.BaseTestModule import BaseTestModule
from lnst.Controller.RecipeResults import ResultLevel
class Job(object):
diff --git a/lnst/Controller/Machine.py b/lnst/Controller/Machine.py
index f51798c..11055c8 100644
--- a/lnst/Controller/Machine.py
+++ b/lnst/Controller/Machine.py
@@ -17,7 +17,6 @@ import sys
import signal
from lnst.Common.Utils import sha256sum
from lnst.Common.Utils import check_process_running
-from lnst.Common.TestModule import BaseTestModule
from lnst.Common.Version import lnst_version
from lnst.Controller.Common import ControllerError
from lnst.Controller.CtlSecSocket import CtlSecSocket
@@ -26,6 +25,7 @@ from lnst.Devices import device_classes
from lnst.Devices.Device import Device
from lnst.Devices.RemoteDevice import RemoteDevice
from lnst.Devices.VirtualDevice import VirtualDevice
+from lnst.Tests.BaseTestModule import BaseTestModule
# conditional support for libvirt
if check_process_running("libvirtd"):
diff --git a/lnst/Controller/MessageDispatcher.py b/lnst/Controller/MessageDispatcher.py
index abd3b21..6b12d68 100644
--- a/lnst/Controller/MessageDispatcher.py
+++ b/lnst/Controller/MessageDispatcher.py
@@ -18,11 +18,11 @@ import logging
import copy
from lnst.Common.ConnectionHandler import send_data
from lnst.Common.ConnectionHandler import ConnectionHandler
-from lnst.Common.TestModule import BaseTestModule
from lnst.Common.Parameters import Parameters, DeviceParam
from lnst.Common.DeviceRef import DeviceRef
from lnst.Controller.Common import ControllerError
from lnst.Devices.RemoteDevice import RemoteDevice
+from lnst.Tests.BaseTestModule import BaseTestModule
def deviceref_to_remote_device(machine, obj):
if isinstance(obj, DeviceRef):
diff --git a/lnst/Slave/NetTestSlave.py b/lnst/Slave/NetTestSlave.py
index d99fc54..f98db6c 100644
--- a/lnst/Slave/NetTestSlave.py
+++ b/lnst/Slave/NetTestSlave.py
@@ -41,7 +41,6 @@ from lnst.Common.DeviceRef import DeviceRef
from lnst.Common.LnstError import LnstError
from lnst.Common.DeviceError import DeviceDeleted, DeviceDisabled
from lnst.Common.DeviceError import DeviceConfigValueError
-from lnst.Common.TestModule import BaseTestModule
from lnst.Common.Parameters import Parameters, DeviceParam
from lnst.Common.IpAddress import ipaddress
from lnst.Common.Version import lnst_version
@@ -889,6 +888,11 @@ def device_to_deviceref(obj):
return obj
def deviceref_to_device(if_manager, obj):
+ try:
+ from lnst.Tests.BaseTestModule import BaseTestModule
+ except:
+ BaseTestModule = None
+
if isinstance(obj, DeviceRef):
dev = if_manager.get_device(obj.ifindex)
return dev
@@ -911,7 +915,7 @@ def deviceref_to_device(if_manager, obj):
for param_name, param in obj:
setattr(obj, param_name, deviceref_to_device(if_manager, param))
return obj
- elif isinstance(obj, BaseTestModule):
+ elif BaseTestModule is not None and isinstance(obj, BaseTestModule):
obj.params = deviceref_to_device(if_manager, obj.params)
return obj
else:
diff --git a/lnst/Common/TestModule.py b/lnst/Tests/BaseTestModule.py
similarity index 85%
rename from lnst/Common/TestModule.py
rename to lnst/Tests/BaseTestModule.py
index 37d6856..d96c1a4 100644
--- a/lnst/Common/TestModule.py
+++ b/lnst/Tests/BaseTestModule.py
@@ -10,14 +10,22 @@ __author__ = """
olichtne(a)redhat.com (Ondrej Lichtner)
"""
+import time
import copy
+import signal
from lnst.Common.Parameters import Parameters, Param
from lnst.Common.LnstError import LnstError
+from lnst.Common.Logs import log_exc_traceback
+
class TestModuleError(LnstError):
"""Exception used by BaseTestModule and derived
classes"""
pass
+class InterruptException(TestModuleError):
+ """Exception used to handle SIGINT waiting"""
+ pass
+
class BaseTestModule(object):
"""Base class for test modules
@@ -79,5 +87,17 @@ class BaseTestModule(object):
def run(self):
raise NotImplementedError("Method 'run' MUST be defined")
+ def wait_for_interrupt(self):
+ def handler(signum, frame):
+ raise InterruptException()
+
+ try:
+ old_handler = signal.signal(signal.SIGINT, handler)
+ signal.pause()
+ except InterruptException:
+ pass
+ finally:
+ signal.signal(signal.SIGINT, old_handler)
+
def _get_res_data(self):
return self._res_data
diff --git a/lnst/Tests/Iperf.py b/lnst/Tests/Iperf.py
index ec85f3b..213ee04 100644
--- a/lnst/Tests/Iperf.py
+++ b/lnst/Tests/Iperf.py
@@ -5,10 +5,10 @@ import signal
import time
import subprocess
import json
-from lnst.Common.TestModule import BaseTestModule, TestModuleError
from lnst.Common.Parameters import IntParam, IpParam, StrParam, Param, BoolParam
from lnst.Common.Parameters import HostnameParam
from lnst.Common.Utils import is_installed
+from lnst.Tests.BaseTestModule import BaseTestModule, TestModuleError
class IperfBase(BaseTestModule):
def run(self):
diff --git a/lnst/Tests/Netperf.py b/lnst/Tests/Netperf.py
index 70d4b6d..9e9dd5e 100644
--- a/lnst/Tests/Netperf.py
+++ b/lnst/Tests/Netperf.py
@@ -5,10 +5,9 @@ import signal
import time
import subprocess
from lnst.Common.Parameters import IntParam, IpParam, StrParam, Param
-from lnst.Common.TestModule import BaseTestModule, TestModuleError
from lnst.Common.ShellProcess import ShellProcess
from lnst.Common.Utils import is_installed, std_deviation
-
+from lnst.Tests.BaseTestModule import BaseTestModule, TestModuleError
class Netserver(BaseTestModule):
bind = IpParam(mandatory=True)
diff --git a/lnst/Tests/Ping.py b/lnst/Tests/Ping.py
index aacad05..039cb7e 100644
--- a/lnst/Tests/Ping.py
+++ b/lnst/Tests/Ping.py
@@ -2,9 +2,9 @@ import re
import logging
import subprocess
from lnst.Common.Parameters import IntParam, FloatParam, IpParam, DeviceOrIpParam
-from lnst.Common.TestModule import BaseTestModule, TestModuleError
from lnst.Common.ExecCmd import exec_cmd
from lnst.Common.Utils import is_installed
+from lnst.Tests.BaseTestModule import BaseTestModule, TestModuleError
class Ping(BaseTestModule):
"""Port of old IcmpPing test modules"""
--
2.17.0