]> code.ossystems Code Review - openembedded-core.git/commitdiff
oeqa/utils/decorators: LogResults fix race condition in linkfile
authorAníbal Limón <anibal.limon@linux.intel.com>
Tue, 13 Sep 2016 20:25:42 +0000 (15:25 -0500)
committerRichard Purdie <richard.purdie@linuxfoundation.org>
Thu, 15 Sep 2016 11:14:40 +0000 (12:14 +0100)
In order to avoid race condition when test if exists the linkfile
use bb.utils.lock, the best solution is to create a unique name
for the link file.

There is no way to create a unique linkfile name at this decorator
because is needed the machine and image variables, those variables
can't be passed easily in this code.

To avoid broke test export functionality use a try/except because bb
isn't available when use test export

[YOCTO #10225]

Signed-off-by: Aníbal Limón <anibal.limon@linux.intel.com>
Signed-off-by: Richard Purdie <richard.purdie@linuxfoundation.org>
meta/lib/oeqa/utils/decorators.py

index 615fd956b561535cd6d7fc772732c13b710e6f62..25f9c54e6babb828b7581bce2b4c4ddcb0f61eac 100644 (file)
@@ -189,10 +189,24 @@ def LogResults(original_class):
         if passed:
             local_log.results("Testcase "+str(test_case)+": PASSED")
 
+        # XXX: In order to avoid race condition when test if exists the linkfile
+        # use bb.utils.lock, the best solution is to create a unique name for the
+        # link file.
+        try:
+            import bb
+            has_bb = True
+            lockfilename = linkfile + '.lock'
+        except ImportError:
+            has_bb = False
+
+        if has_bb:
+            lf = bb.utils.lockfile(lockfilename, block=True)
         # Create symlink to the current log
         if os.path.lexists(linkfile):
             os.remove(linkfile)
         os.symlink(logfile, linkfile)
+        if has_bb:
+            bb.utils.unlockfile(lf)
 
     original_class.run = run