Module: check_mk
Branch: master
Commit: 1cc3b878f858733a05644c7ba0e6ab7b9205638f
URL:
http://git.mathias-kettner.de/git/?p=check_mk.git;a=commit;h=1cc3b878f85873…
Author: Lars Michelsen <lm(a)mathias-kettner.de>
Date: Thu Mar 7 14:25:25 2019 +0100
Replace "fasteners" locking in test with small own inter process lock
Change-Id: Ied8c2fb533f1f185ae3ac74cb7033d85c1f7608f
---
Pipfile | 1 -
Pipfile.lock | 19 ++-----------------
tests/integration/bin/test_mkbackup.py | 5 ++---
tests/testlib/__init__.py | 23 +++++++++++++++++++----
4 files changed, 23 insertions(+), 25 deletions(-)
diff --git a/Pipfile b/Pipfile
index e500e43..42899f7 100644
--- a/Pipfile
+++ b/Pipfile
@@ -13,7 +13,6 @@ pytest-mock = "*"
pytest-stepwise = "*"
dill = "*"
bandit = "*"
-fasteners = "*"
lxml = "*"
pylint = "*"
pyenchant = "*"
diff --git a/Pipfile.lock b/Pipfile.lock
index fa19cbf..73fc0b2 100644
--- a/Pipfile.lock
+++ b/Pipfile.lock
@@ -1,7 +1,7 @@
{
"_meta": {
"hash": {
- "sha256":
"05a52b60adff22655b0b32c0877104d8a918ddbf2f6987492916eb0444490315"
+ "sha256":
"e4e451366caf430af6048ea42109837b9bc49a9da374e1aa1686914ef220edd8"
},
"pipfile-spec": 6,
"requires": {
@@ -1121,14 +1121,6 @@
],
"version": "==0.8"
},
- "fasteners": {
- "hashes": [
-
"sha256:427c76773fe036ddfa41e57d89086ea03111bbac57c55fc55f3006d027107e18",
-
"sha256:564a115ff9698767df401efca29620cbb1a1c2146b7095ebd304b79cc5807a7c"
- ],
- "index": "pypi",
- "version": "==0.14.1"
- },
"funcparserlib": {
"hashes": [
"sha256:b7992eac1a3eb97b3d91faa342bfda0729e990bd8a43774c1592c091e563c91d"
@@ -1140,7 +1132,7 @@
"sha256:330cc27ccbf7f1e992e69fef78261dc7c6569012cf397db8d3de0234e6c937ca",
"sha256:a7bb0f2cf3a3fd1ab2732cb49eba4252c2af4240442415b4abce3b87022a8f50"
],
- "markers": "python_version < '3.3'",
+ "markers": "python_version < '3.0'",
"version": "==1.0.2"
},
"futures": {
@@ -1278,13 +1270,6 @@
"index": "pypi",
"version": "==0.3.0"
},
- "monotonic": {
- "hashes": [
-
"sha256:23953d55076df038541e648a53676fb24980f7a1be290cdda21300b3bc21dfb0",
-
"sha256:552a91f381532e33cbd07c6a2655a21908088962bb8fa7239ecbcc6ad1140cc7"
- ],
- "version": "==1.5"
- },
"more-itertools": {
"hashes": [
"sha256:38a936c0a6d98a38bcc2d03fdaaedaba9f412879461dd2ceff8d37564d6522e4",
diff --git a/tests/integration/bin/test_mkbackup.py
b/tests/integration/bin/test_mkbackup.py
index a3f0dfa..1cfcbc7 100644
--- a/tests/integration/bin/test_mkbackup.py
+++ b/tests/integration/bin/test_mkbackup.py
@@ -5,10 +5,9 @@ import re
import os
import tarfile
import fnmatch
-import fasteners
import pytest # type: ignore
-from testlib import web # pylint: disable=unused-import
+from testlib import web, InterProcessLock # pylint: disable=unused-import
@pytest.fixture()
@@ -90,7 +89,7 @@ def test_cfg(web, site, backup_path):
def BackupLock():
- return fasteners.InterProcessLock("/tmp/cmk-test-execute-backup")
+ return InterProcessLock("/tmp/cmk-test-execute-backup")
def _execute_backup(site, job_id="testjob"):
diff --git a/tests/testlib/__init__.py b/tests/testlib/__init__.py
index 2290980..2320773 100644
--- a/tests/testlib/__init__.py
+++ b/tests/testlib/__init__.py
@@ -16,12 +16,13 @@ import shutil
import ast
import abc
import json
+import fcntl
+from contextlib import contextmanager
from urlparse import urlparse
import pathlib2 as pathlib
import pytest # type: ignore
import requests # type: ignore
-import fasteners # type: ignore
import urllib3 # type: ignore
from bs4 import BeautifulSoup # type: ignore
@@ -93,6 +94,20 @@ class APIError(Exception):
pass
+# Used fasteners before, but that was using a file mode that made it impossible to do
+# inter process locking involving different users (different sites)
+@contextmanager
+def InterProcessLock(filename):
+ try:
+ fd = os.open(filename, os.O_RDONLY | os.O_CREAT, 0660)
+ fcntl.flock(fd, fcntl.LOCK_EX)
+ yield
+ fcntl.flock(fd, fcntl.LOCK_UN)
+ finally:
+ if fd:
+ os.close(fd)
+
+
# It's ok to make it currently only work on debian based distros
class CMKVersion(object):
DEFAULT = "default"
@@ -244,7 +259,7 @@ class CMKVersion(object):
# Improve the protection against other test runs installing packages
print "Getting install file lock
(/tmp/cmk-test-install-version.lock)..."
- with fasteners.InterProcessLock("/tmp/cmk-test-install-version"):
+ with InterProcessLock("/tmp/cmk-test-install-version"):
print "Have install file lock"
cmd = "sudo /usr/bin/gdebi --non-interactive %s" % package_path
print cmd
@@ -553,7 +568,7 @@ class Site(object):
if not self.exists():
print "Getting site create lock
(/tmp/cmk-test-create-site.lock)..."
- with fasteners.InterProcessLock("/tmp/cmk-test-create-site"):
+ with InterProcessLock("/tmp/cmk-test-create-site"):
print "Have site create lock"
print "[%0.2f] Creating site '%s'" % (time.time(),
self.id)
@@ -923,7 +938,7 @@ class Site(object):
self.stop()
sys.stdout.write("Getting livestatus port lock
(/tmp/cmk-test-open-livestatus-port)...\n")
- with fasteners.InterProcessLock("/tmp/cmk-test-livestatus-port"):
+ with InterProcessLock("/tmp/cmk-test-livestatus-port"):
sys.stdout.write("Have livestatus port lock\n")
self.set_config("LIVESTATUS_TCP", "on")
self._gather_livestatus_port()