* [PATCH 1/2] oeqa/selftest/{context, case}: Add signal handlers SIG{INT, TERM}
@ 2017-06-26 20:42 Aníbal Limón
2017-06-26 20:42 ` [PATCH 2/2] selftest/cases/package: Call parent setUpClass method Aníbal Limón
2017-06-27 6:53 ` [PATCH 1/2] oeqa/selftest/{context, case}: Add signal handlers SIG{INT, TERM} Patrick Ohly
0 siblings, 2 replies; 4+ messages in thread
From: Aníbal Limón @ 2017-06-26 20:42 UTC (permalink / raw)
To: openembedded-core
In order to avoid corrupt local.conf and bblayers.conf adds
signal handlers for SIGINT and SIGTERM to restore previously
backuped configuration.
[YOCTO #11650]
Signed-off-by: Aníbal Limón <anibal.limon@linux.intel.com>
---
meta/lib/oeqa/selftest/case.py | 36 ++++++++++++++-----------
meta/lib/oeqa/selftest/context.py | 56 +++++++++++++++++++++++++++++++++++----
2 files changed, 72 insertions(+), 20 deletions(-)
diff --git a/meta/lib/oeqa/selftest/case.py b/meta/lib/oeqa/selftest/case.py
index 31a11fddda9..871009c568b 100644
--- a/meta/lib/oeqa/selftest/case.py
+++ b/meta/lib/oeqa/selftest/case.py
@@ -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
diff --git a/meta/lib/oeqa/selftest/context.py b/meta/lib/oeqa/selftest/context.py
index ca87398224c..e2e6283ffdc 100644
--- a/meta/lib/oeqa/selftest/context.py
+++ b/meta/lib/oeqa/selftest/context.py
@@ -6,6 +6,8 @@ import time
import glob
import sys
import imp
+import signal
+from shutil import copyfile
from random import choice
import oeqa
@@ -16,13 +18,12 @@ from oeqa.core.exception import OEQAPreRun
from oeqa.utils.commands import runCmd, get_bb_vars, get_test_layer
class OESelftestTestContext(OETestContext):
- def __init__(self, td=None, logger=None, machines=None, testlayer_path=None):
+ def __init__(self, td=None, logger=None, machines=None, config_paths=None):
super(OESelftestTestContext, self).__init__(td, logger)
self.machines = machines
self.custommachine = None
-
- self.testlayer_path = testlayer_path
+ self.config_paths = config_paths
def runTests(self, machine=None):
if machine:
@@ -108,7 +109,29 @@ class OESelftestTestContextExecutor(OETestContextExecutor):
self.tc_kwargs['init']['td'] = get_bb_vars()
self.tc_kwargs['init']['machines'] = self._get_available_machines()
- self.tc_kwargs['init']['testlayer_path'] = get_test_layer()
+
+ builddir = os.environ.get("BUILDDIR")
+ self.tc_kwargs['init']['config_paths'] = {}
+ self.tc_kwargs['init']['config_paths']['testlayer_path'] = \
+ get_test_layer()
+ self.tc_kwargs['init']['config_paths']['builddir'] = builddir
+ self.tc_kwargs['init']['config_paths']['localconf'] = \
+ os.path.join(builddir, "conf/local.conf")
+ self.tc_kwargs['init']['config_paths']['localconf_backup'] = \
+ os.path.join(builddir, "conf/local.conf.orig")
+ self.tc_kwargs['init']['config_paths']['localconf_class_backup'] = \
+ os.path.join(builddir, "conf/local.conf.bk")
+ self.tc_kwargs['init']['config_paths']['bblayers'] = \
+ os.path.join(builddir, "conf/bblayers.conf")
+ self.tc_kwargs['init']['config_paths']['bblayers_backup'] = \
+ os.path.join(builddir, "conf/bblayers.conf.orig")
+ self.tc_kwargs['init']['config_paths']['bblayers_class_backup'] = \
+ os.path.join(builddir, "conf/bblayers.conf.bk")
+
+ copyfile(self.tc_kwargs['init']['config_paths']['localconf'],
+ self.tc_kwargs['init']['config_paths']['localconf_backup'])
+ copyfile(self.tc_kwargs['init']['config_paths']['bblayers'],
+ self.tc_kwargs['init']['config_paths']['bblayers_backup'])
def _pre_run(self):
def _check_required_env_variables(vars):
@@ -131,7 +154,7 @@ class OESelftestTestContextExecutor(OETestContextExecutor):
runCmd("bitbake-layers add-layer %s" %meta_selftestdir)
# reload data is needed because a meta-selftest layer was add
self.tc.td = get_bb_vars()
- self.tc.testlayer_path = get_test_layer()
+ self.tc.config_paths['testlayer_path'] = get_test_layer()
else:
self.tc.logger.error("could not locate meta-selftest in:\n%s" % meta_selftestdir)
raise OEQAPreRun
@@ -184,9 +207,30 @@ class OESelftestTestContextExecutor(OETestContextExecutor):
rc.logSummary(self.name)
return rc
+
+ def _signal_clean_handler(self, signum, frame):
+ config_paths = self.tc_kwargs['init']['config_paths']
+ if os.path.exists(config_paths['localconf_backup']):
+ copyfile(config_paths['localconf_backup'],
+ config_paths['localconf'])
+ os.remove(config_paths['localconf_backup'])
+
+ if os.path.exists(config_paths['bblayers_backup']):
+ copyfile(config_paths['bblayers_backup'],
+ config_paths['bblayers'])
+ os.remove(config_paths['bblayers_backup'])
+
+ if os.path.exists(config_paths['localconf_class_backup']):
+ os.remove(config_paths['localconf_class_backup'])
+ if os.path.exists(config_paths['bblayers_class_backup']):
+ os.remove(config_paths['bblayers_class_backup'])
def run(self, logger, args):
self._process_args(logger, args)
+
+ 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)
+ self._signal_clean_handler(None, None)
+
return rc
_executor_class = OESelftestTestContextExecutor
--
2.11.0
^ permalink raw reply related [flat|nested] 4+ messages in thread
* [PATCH 2/2] selftest/cases/package: Call parent setUpClass method
2017-06-26 20:42 [PATCH 1/2] oeqa/selftest/{context, case}: Add signal handlers SIG{INT, TERM} Aníbal Limón
@ 2017-06-26 20:42 ` Aníbal Limón
2017-06-27 6:53 ` [PATCH 1/2] oeqa/selftest/{context, case}: Add signal handlers SIG{INT, TERM} Patrick Ohly
1 sibling, 0 replies; 4+ messages in thread
From: Aníbal Limón @ 2017-06-26 20:42 UTC (permalink / raw)
To: openembedded-core
Since config paths are now passed in Test context the setUpClass
method is expected to be call.
Signed-off-by: Aníbal Limón <anibal.limon@linux.intel.com>
---
meta/lib/oeqa/selftest/cases/package.py | 2 ++
1 file changed, 2 insertions(+)
diff --git a/meta/lib/oeqa/selftest/cases/package.py b/meta/lib/oeqa/selftest/cases/package.py
index 5b9a6d15851..b07d6ed0abe 100644
--- a/meta/lib/oeqa/selftest/cases/package.py
+++ b/meta/lib/oeqa/selftest/cases/package.py
@@ -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")
--
2.11.0
^ permalink raw reply related [flat|nested] 4+ messages in thread
* Re: [PATCH 1/2] oeqa/selftest/{context, case}: Add signal handlers SIG{INT, TERM}
2017-06-26 20:42 [PATCH 1/2] oeqa/selftest/{context, case}: Add signal handlers SIG{INT, TERM} Aníbal Limón
2017-06-26 20:42 ` [PATCH 2/2] selftest/cases/package: Call parent setUpClass method Aníbal Limón
@ 2017-06-27 6:53 ` Patrick Ohly
2017-06-27 15:41 ` Aníbal Limón
1 sibling, 1 reply; 4+ messages in thread
From: Patrick Ohly @ 2017-06-27 6:53 UTC (permalink / raw)
To: Aníbal Limón; +Cc: openembedded-core
On Mon, 2017-06-26 at 15:42 -0500, Aníbal Limón wrote:
> def run(self, logger, args):
> self._process_args(logger, args)
> +
> + 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)
>
> + 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().
--
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.
^ permalink raw reply [flat|nested] 4+ messages in thread
* Re: [PATCH 1/2] oeqa/selftest/{context, case}: Add signal handlers SIG{INT, TERM}
2017-06-27 6:53 ` [PATCH 1/2] oeqa/selftest/{context, case}: Add signal handlers SIG{INT, TERM} Patrick Ohly
@ 2017-06-27 15:41 ` Aníbal Limón
0 siblings, 0 replies; 4+ messages in thread
From: Aníbal Limón @ 2017-06-27 15:41 UTC (permalink / raw)
To: Patrick Ohly; +Cc: openembedded-core
On 06/27/2017 01:53 AM, Patrick Ohly wrote:
> On Mon, 2017-06-26 at 15:42 -0500, Aníbal Limón wrote:
>> def run(self, logger, args):
>> self._process_args(logger, args)
>> +
>> + 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)
>>
>> + 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().
Yes but this will only work with SIGINT because it raises
KeyboardInterrupt exception but there is a need to set SIGTERM too.
Cheers,
Anibal
>
^ permalink raw reply [flat|nested] 4+ messages in thread
end of thread, other threads:[~2017-06-27 15:41 UTC | newest]
Thread overview: 4+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2017-06-26 20:42 [PATCH 1/2] oeqa/selftest/{context, case}: Add signal handlers SIG{INT, TERM} Aníbal Limón
2017-06-26 20:42 ` [PATCH 2/2] selftest/cases/package: Call parent setUpClass method Aníbal Limón
2017-06-27 6:53 ` [PATCH 1/2] oeqa/selftest/{context, case}: Add signal handlers SIG{INT, TERM} Patrick Ohly
2017-06-27 15:41 ` Aníbal Limón
This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.