Module: check_mk
Branch: master
Commit: 0aad4a03299eacc1ce2e5fd76337fe37ec930362
URL:
http://git.mathias-kettner.de/git/?p=check_mk.git;a=commit;h=0aad4a03299eac…
Author: Lars Michelsen <lm(a)mathias-kettner.de>
Date: Fri Dec 23 08:41:44 2016 +0100
Added tests for testbuild resulting packages
Change-Id: I47904c2c3dd9aebfb3c6835ca250e980a86201a5
---
.../packaging/{test_setuid_bits.py => conftest.py} | 14 +---
tests/packaging/test_files.py | 96 ++++++++++++++++++++++
2 files changed, 98 insertions(+), 12 deletions(-)
diff --git a/tests/packaging/test_setuid_bits.py b/tests/packaging/conftest.py
similarity index 62%
rename from tests/packaging/test_setuid_bits.py
rename to tests/packaging/conftest.py
index f2a0052..77bfffa 100644
--- a/tests/packaging/test_setuid_bits.py
+++ b/tests/packaging/conftest.py
@@ -1,20 +1,10 @@
-import pytest
import os
+import pytest
-pytestmark = pytest.mark.packaging
-
+(a)pytest.fixture(scope="module")
def version_path():
path = os.environ.get("VERSION_PATH")
if not path:
raise Exception("VERSION_PATH environment variable pointing to the version
"
"directory (e.g. /bauwelt/download/2016.12.22) is
missing")
return path
-
-
-def test_setuid_bits():
- print version_path()
- print os.listdir(version_path())
-
-
-def test_files_not_in_version_path():
- pass
diff --git a/tests/packaging/test_files.py b/tests/packaging/test_files.py
new file mode 100644
index 0000000..549d239
--- /dev/null
+++ b/tests/packaging/test_files.py
@@ -0,0 +1,96 @@
+import pytest
+import os
+import subprocess
+import re
+
+pytestmark = pytest.mark.packaging
+
+(a)pytest.mark.parametrize("what"what", [
+ ("rpm"),
+ ("deb"),
+ ("cma"),
+])
+def test_package_built(version_path, what):
+ files = os.listdir(version_path)
+ count = len([ e for e in files if e.startswith("check-mk-") and
e.endswith("."+what) ])
+ assert count > 0, "Found no %s package in %s" % (what.upper(),
version_path)
+
+
+def _get_package_paths(version_path, what):
+ for filename in os.listdir(version_path):
+ if filename.startswith("check-mk-") and
filename.endswith(".%s" % what):
+ yield os.path.join(version_path, filename)
+
+
+# In case packages grow/shrink this check has to be changed.
+(a)pytest.mark.parametrize("what,min_size,max_size"size", [
+ ("rpm", 95*1024*1024, 160*1024*1024),
+ ("deb", 80*1024*1024, 160*1024*1024),
+ ("cma", 150*1024*1024, 160*1024*1024),
+])
+def test_package_sizes(version_path, what, min_size, max_size):
+ for pkg in _get_package_paths(version_path, what):
+ size = os.stat(pkg).st_size
+ assert size > min_size and size < max_size, \
+ "Package %s size %s not between %s and %s bytes." % \
+ (pkg, size, min_size, max_size)
+
+
+(a)pytest.mark.parametrize("what"what", [
+ ("rpm"),
+ ("deb"),
+])
+def test_files_not_in_version_path(version_path, what):
+ allowed_patterns = {
+ "rpm": [
+ "/opt",
+ "/opt/omd",
+ "/opt/omd/apache",
+ "/opt/omd/sites",
+ "/opt/omd/versions",
+ ],
+ "deb": [
+ "/",
+ "/opt/",
+ "/opt/omd/",
+ "/usr/",
+ "/usr/share/",
+ "/usr/share/man/",
+ "/usr/share/man/man8/",
+ "/usr/share/doc/",
+ "/usr/share/doc/check-mk-(raw|enterprise)-*/",
+ "/usr/share/doc/check-mk-(raw|enterprise)-*/changelog.gz",
+ "/usr/share/doc/check-mk-(raw|enterprise)-*/COPYING.gz",
+ "/usr/share/doc/check-mk-(raw|enterprise)-*/TEAM",
+ "/usr/share/doc/check-mk-(raw|enterprise)-*/copyright",
+ "/usr/share/doc/check-mk-(raw|enterprise)-*/README",
+ "/usr/share/doc/check-mk-(raw|enterprise)-*/README.Debian",
+ "/etc/",
+ "/etc/init.d/",
+ "/etc/init.d/check-mk-(raw|enterprise)-*",
+ ],
+ }
+
+ for pkg in _get_package_paths(version_path, what):
+ print "Testing %s" % pkg
+
+ if what == "rpm":
+ paths = subprocess.check_output(["rpm", "-qlp",
pkg]).splitlines()
+
+ elif what == "deb":
+ paths = []
+ for line in subprocess.check_output(["dpkg", "-c",
pkg]).splitlines():
+ paths.append(line.split()[5].lstrip("."))
+
+ for path in paths:
+ if not path.startswith("/opt/omd/versions/"):
+ is_allowed = any(re.match(p, path) for p in allowed_patterns[what])
+ assert is_allowed, "Found unexpected global file: %s" % path
+
+
+def test_cma_only_contains_version_paths(version_path):
+ for pkg in _get_package_paths(version_path, "cma"):
+ version = os.path.basename(pkg).split("-")[3]
+ for line in subprocess.check_output(["tar", "tvf",
pkg]).splitlines():
+ path = line.split()[5]
+ assert not path.startswith(version + "/")