Skip to contentSkip to conversation

oeqa/selftest/{context, case}: Add signal handlers SIG{INT, TERM}

PATCH In review Aníbal Limón 2 participants 4 messages Jun 26, 2017 – Jun 27, 2017

lore
Share & tools
lore
#0 lore raw

PATCH 1/2 oeqa/selftest/{context, case}: Add signal handlers SIG{INT, TERM}

In order to avoid corrupt local.conf and bblayers.conf adds signal handlers for SIGINT and SIGTERM to restore previously backuped configuration.

[YOCTO #11650]

---
 meta/lib/oeqa/selftest/case.py    | 36 ++++++++++++++-----------
 meta/lib/oeqa/selftest/context.py | 56 +++++++++++++++++++++++++++++++++++----
 2 files changed, 72 insertions(+), 20 deletions(-)
meta/lib/oeqa/selftest/case.py +21 -15
index 31a11fddda9..871009c568b 100644
@@ -13,28 +13,34 @@ from oeqa.utils.commands import runCmd, bitbake, get_bb_var
 from oeqa.core.case import OETestCase
 
 class OESelftestTestCase(OETestCase):
-    builddir = os.environ.get("BUILDDIR") or ""
-    localconf_path = os.path.join(builddir, "conf/local.conf")
-    localconf_backup = os.path.join(builddir, "conf/local.bk")
-    testinc_path = os.path.join(builddir, "conf/selftest.inc")
-    local_bblayers_path = os.path.join(builddir, "conf/bblayers.conf")
-    local_bblayers_backup = os.path.join(builddir, "conf/bblayers.bk")
-    testinc_bblayers_path = os.path.join(builddir, "conf/bblayers.inc")
-    machineinc_path = os.path.join(builddir, "conf/machine.inc")
-
     def __init__(self, methodName="runTest"):
         self._extra_tear_down_commands = []
-        self._track_for_cleanup = [
-            self.testinc_path, self.testinc_bblayers_path,
-            self.machineinc_path, self.localconf_backup,
-            self.local_bblayers_backup]
-
         super(OESelftestTestCase, self).__init__(methodName)
 
     @classmethod
     def setUpClass(cls):
         super(OESelftestTestCase, cls).setUpClass()
-        cls.testlayer_path = cls.tc.testlayer_path
+
+        cls.testlayer_path = cls.tc.config_paths['testlayer_path']
+        cls.builddir = cls.tc.config_paths['builddir']
+
+        cls.localconf_path = cls.tc.config_paths['localconf']
+        cls.localconf_backup = cls.tc.config_paths['localconf_class_backup']
+        cls.local_bblayers_path = cls.tc.config_paths['bblayers']
+        cls.local_bblayers_backup = cls.tc.config_paths['bblayers_class_backup']
+
+        cls.testinc_path = os.path.join(cls.tc.config_paths['builddir'],
+                "conf/selftest.inc")
+        cls.testinc_bblayers_path = os.path.join(cls.tc.config_paths['builddir'],
+                "conf/bblayers.inc")
+        cls.machineinc_path = os.path.join(cls.tc.config_paths['builddir'],
+                "conf/machine.inc")
+
+        cls._track_for_cleanup = [
+            cls.testinc_path, cls.testinc_bblayers_path,
+            cls.machineinc_path, cls.localconf_backup,
+            cls.local_bblayers_backup]
+
         cls.add_include()
 
     @classmethod
meta/lib/oeqa/selftest/context.py +51 -5

99 lines not on this page · raw message

Signature · 1 line
2.11.0
#1 lore raw

PATCH 2/2 selftest/cases/package: Call parent setUpClass method

Since config paths are now passed in Test context the setUpClass method is expected to be call.

---
 meta/lib/oeqa/selftest/cases/package.py | 2 ++
 1 file changed, 2 insertions(+)
meta/lib/oeqa/selftest/cases/package.py +2 -0
index 5b9a6d15851..b07d6ed0abe 100644
@@ -17,6 +17,8 @@ class VersionOrdering(OESelftestTestCase):
 
     @classmethod
     def setUpClass(cls):
+        super(VersionOrdering, cls).setUpClass()
+
         # Build the tools we need and populate a sysroot
         bitbake("dpkg-native opkg-native rpm-native python3-native")
         bitbake("build-sysroots -c build_native_sysroot")
Signature · 1 line
2.11.0
#2 lore raw
In reply to Aníbal Limón
Quoted 14 lines · Aníbal Limón

def run(self, logger, args):
self._process_args(logger, args)

meta/lib/oeqa/selftest/context.py +4 -0
+
+        signal.signal(signal.SIGTERM, self._signal_clean_handler)
+        signal.signal(signal.SIGINT, self._signal_clean_handler)
+
         rc = None
 
         if args.machine:
@@ -220,6 +264,8 @@ class

OESelftestTestContextExecutor(OETestContextExecutor):
os.remove(output_link)
os.symlink(args.output_log, output_link)

meta/lib/oeqa/selftest/context.py class OESelftestTestContextExecutor(OETestContextExecutor): · line 268

Quoted 2 lines
meta/lib/oeqa/selftest/context.py +2 -0
+        self._signal_clean_handler(None, None)
+

Can't you achieve the same thing with less code by using a
try:
... modify configuration ...
... run tests ...
finally:

      ... clean up ...

block in run()?

Then you are also guaranteed to clean up if an unexpected exception triggers the aborting of run().

Signature · 6 lines
Best Regards, Patrick Ohly

The content of this message is my personal opinion only and although
I am an employee of Intel, the statements I make here in no way
represent Intel's position on the issue, nor am I authorized to speak
on behalf of Intel on this matter.
#3 lore raw
Quoted 23 lines · Patrick Ohly
Quoted 14 lines · Aníbal Limón

def run(self, logger, args):
self._process_args(logger, args)

meta/lib/oeqa/selftest/context.py +4 -0
+
+        signal.signal(signal.SIGTERM, self._signal_clean_handler)
+        signal.signal(signal.SIGINT, self._signal_clean_handler)
+
         rc = None
 
         if args.machine:
@@ -220,6 +264,8 @@ class

OESelftestTestContextExecutor(OETestContextExecutor):
os.remove(output_link)
os.symlink(args.output_log, output_link)

meta/lib/oeqa/selftest/context.py class OESelftestTestContextExecutor(OETestContextExecutor): · line 268

Quoted 2 lines
meta/lib/oeqa/selftest/context.py +2 -0
+        self._signal_clean_handler(None, None)
+

Can't you achieve the same thing with less code by using a
try:
... modify configuration ...
... run tests ...
finally:

Quoted 5 lines
      ... clean up ...

block in run()?

Then you are also guaranteed to clean up if an unexpected exception triggers the aborting of run().

Yes but this will only work with SIGINT because it raises KeyboardInterrupt exception but there is a need to set SIGTERM too.

Cheers,
Anibal

Quoted 1 line