oeqa/selftest/base: backup and restore local configuration files
Selftests' cleanup method during test setup is not capable of restoring local configuration files that remain modified after aborting a test through a keyboard interruption. This change creates backups for local.conf and bblayers.conf at test setup, restore them when found, and deletes them at cleanup. [YOCTO #9390] (From OE-Core rev: 0877278e07e4c2494c4c23199490dc47a5cee69d) Signed-off-by: Jose Lamego <jose.a.lamego@linux.intel.com> Signed-off-by: Ross Burton <ross.burton@intel.com> Signed-off-by: Richard Purdie <richard.purdie@linuxfoundation.org>
This commit is contained in:
parent
659fab4291
commit
c902e7b937
|
@ -28,17 +28,47 @@ class oeSelfTest(unittest.TestCase):
|
||||||
def __init__(self, methodName="runTest"):
|
def __init__(self, methodName="runTest"):
|
||||||
self.builddir = os.environ.get("BUILDDIR")
|
self.builddir = os.environ.get("BUILDDIR")
|
||||||
self.localconf_path = os.path.join(self.builddir, "conf/local.conf")
|
self.localconf_path = os.path.join(self.builddir, "conf/local.conf")
|
||||||
|
self.localconf_backup = os.path.join(self.builddir, "conf/local.bk")
|
||||||
self.testinc_path = os.path.join(self.builddir, "conf/selftest.inc")
|
self.testinc_path = os.path.join(self.builddir, "conf/selftest.inc")
|
||||||
self.local_bblayers_path = os.path.join(self.builddir, "conf/bblayers.conf")
|
self.local_bblayers_path = os.path.join(self.builddir, "conf/bblayers.conf")
|
||||||
|
self.local_bblayers_backup = os.path.join(self.builddir,
|
||||||
|
"conf/bblayers.bk")
|
||||||
self.testinc_bblayers_path = os.path.join(self.builddir, "conf/bblayers.inc")
|
self.testinc_bblayers_path = os.path.join(self.builddir, "conf/bblayers.inc")
|
||||||
self.machineinc_path = os.path.join(self.builddir, "conf/machine.inc")
|
self.machineinc_path = os.path.join(self.builddir, "conf/machine.inc")
|
||||||
self.testlayer_path = oeSelfTest.testlayer_path
|
self.testlayer_path = oeSelfTest.testlayer_path
|
||||||
self._extra_tear_down_commands = []
|
self._extra_tear_down_commands = []
|
||||||
self._track_for_cleanup = [self.testinc_path, self.testinc_bblayers_path, self.machineinc_path]
|
self._track_for_cleanup = [
|
||||||
|
self.testinc_path, self.testinc_bblayers_path,
|
||||||
|
self.machineinc_path, self.localconf_backup,
|
||||||
|
self.local_bblayers_backup]
|
||||||
super(oeSelfTest, self).__init__(methodName)
|
super(oeSelfTest, self).__init__(methodName)
|
||||||
|
|
||||||
def setUp(self):
|
def setUp(self):
|
||||||
os.chdir(self.builddir)
|
os.chdir(self.builddir)
|
||||||
|
# Check if local.conf or bblayers.conf files backup exists
|
||||||
|
# from a previous failed test and restore them
|
||||||
|
if os.path.isfile(self.localconf_backup) or os.path.isfile(
|
||||||
|
self.local_bblayers_backup):
|
||||||
|
self.log.debug("Found a local.conf and/or bblayers.conf backup \
|
||||||
|
from a previously aborted test. Restoring these files now, but tests should \
|
||||||
|
be re-executed from a clean environment to ensure accurate results.")
|
||||||
|
try:
|
||||||
|
shutil.copyfile(self.localconf_backup, self.localconf_path)
|
||||||
|
except OSError as e:
|
||||||
|
if e.errno != errno.ENOENT:
|
||||||
|
raise
|
||||||
|
try:
|
||||||
|
shutil.copyfile(self.local_bblayers_backup,
|
||||||
|
self.local_bblayers_path)
|
||||||
|
except OSError as e:
|
||||||
|
if e.errno != errno.ENOENT:
|
||||||
|
raise
|
||||||
|
else:
|
||||||
|
# backup local.conf and bblayers.conf
|
||||||
|
shutil.copyfile(self.localconf_path, self.localconf_backup)
|
||||||
|
shutil.copyfile(self.local_bblayers_path,
|
||||||
|
self.local_bblayers_backup)
|
||||||
|
self.log.debug("Creating local.conf and bblayers.conf backups.")
|
||||||
# we don't know what the previous test left around in config or inc files
|
# we don't know what the previous test left around in config or inc files
|
||||||
# if it failed so we need a fresh start
|
# if it failed so we need a fresh start
|
||||||
try:
|
try:
|
||||||
|
|
Loading…
Reference in New Issue