Module: check_mk
Branch: master
Commit: 5f297833c60ce03526a126c01163c76f8e0def57
URL:
http://git.mathias-kettner.de/git/?p=check_mk.git;a=commit;h=5f297833c60ce0…
Author: Lars Michelsen <lm(a)mathias-kettner.de>
Date: Thu Jul 20 14:22:36 2017 +0200
Tests: Use simple file lock to prevent race conditions during site creation
Change-Id: Ibea515d893f03c4366064d5faad21eb0771f8a96
---
tests/Makefile | 1 +
tests/testlib/__init__.py | 22 ++++++++++++----------
2 files changed, 13 insertions(+), 10 deletions(-)
diff --git a/tests/Makefile b/tests/Makefile
index c803afa..a6055f2 100644
--- a/tests/Makefile
+++ b/tests/Makefile
@@ -49,6 +49,7 @@ setup:
python-pip \
python-lxml \
python-enchant \
+ python-lockfile \
chrpath
sudo pip install --upgrade pip
sudo pip install --upgrade \
diff --git a/tests/testlib/__init__.py b/tests/testlib/__init__.py
index d077f30..3b5b2ef 100644
--- a/tests/testlib/__init__.py
+++ b/tests/testlib/__init__.py
@@ -13,6 +13,7 @@ import pipes
import subprocess
import sys
import shutil
+import lockfile
from urlparse import urlparse
from bs4 import BeautifulSoup
@@ -353,16 +354,17 @@ class Site(object):
raise Exception("The site %s already exists." % self.id)
if not self.exists():
- print("[%0.2f] Creating site '%s'" % (time.time(),
self.id))
- p = subprocess.Popen(["/usr/bin/sudo", "/usr/bin/omd",
- "-V", self.version.version_directory(),
- "create",
- "--admin-password", "cmk",
- "--apache-reload", self.id])
- exit_code = p.wait()
- print("[%0.2f] Executed create command" % time.time())
- assert exit_code == 0
- assert os.path.exists("/omd/sites/%s" % self.id)
+ with lockfile.LockFile("/tmp/cmk-test-create-site.lock"):
+ print("[%0.2f] Creating site '%s'" % (time.time(),
self.id))
+ p = subprocess.Popen(["/usr/bin/sudo",
"/usr/bin/omd",
+ "-V", self.version.version_directory(),
+ "create",
+ "--admin-password", "cmk",
+ "--apache-reload", self.id])
+ exit_code = p.wait()
+ print("[%0.2f] Executed create command" % time.time())
+ assert exit_code == 0
+ assert os.path.exists("/omd/sites/%s" % self.id)
if self.update_with_git:
self._update_with_f12_files()