Skip to content

Commit

Permalink
Packaging files tests: move content retrieval into standalone function
Browse files Browse the repository at this point in the history
Change-Id: I80973e4f284284f04b35b12063ae47595df1efde
(cherry picked from commit 1055d5f)
  • Loading branch information
okin authored and TimotheusBachinger committed Feb 12, 2025
1 parent 0b4973d commit 4f76117
Showing 1 changed file with 19 additions and 10 deletions.
29 changes: 19 additions & 10 deletions tests/packaging/test_files.py
Original file line number Diff line number Diff line change
Expand Up @@ -107,6 +107,8 @@ def test_files_not_in_version_path(package_path: str, cmk_version: str) -> None:
if not package_path.endswith(".rpm") and not package_path.endswith(".deb"):
pytest.skip("%s is another package type" % os.path.basename(package_path))

paths = _get_paths_from_package(package_path)

version_allowed_patterns = [
"/opt/omd/versions/?$",
"/opt/omd/versions/###OMD_VERSION###/?$",
Expand All @@ -127,10 +129,6 @@ def test_files_not_in_version_path(package_path: str, cmk_version: str) -> None:
"/opt/omd/sites$",
"/var/lock/mkbackup$",
] + version_allowed_patterns

paths = subprocess.check_output(
["rpm", "-qlp", package_path], encoding="utf-8"
).splitlines()
elif package_path.endswith(".deb"):
allowed_patterns = [
"/$",
Expand All @@ -153,12 +151,6 @@ def test_files_not_in_version_path(package_path: str, cmk_version: str) -> None:
"/etc/init.d/$",
"/etc/init.d/check-mk-(raw|free|enterprise|managed|cloud|saas)-.*$",
] + version_allowed_patterns

paths = []
for line in subprocess.check_output(
["dpkg", "-c", package_path], encoding="utf-8"
).splitlines():
paths.append(line.split()[5].lstrip("."))
else:
raise NotImplementedError()

Expand All @@ -174,6 +166,23 @@ def test_files_not_in_version_path(package_path: str, cmk_version: str) -> None:
assert is_allowed, f"Found unexpected global file: {path} in {package_path}"


def _get_paths_from_package(path_to_package: str) -> list[str]:
if path_to_package.endswith(".rpm"):
paths = subprocess.check_output(
["rpm", "-qlp", path_to_package], encoding="utf-8"
).splitlines()
elif path_to_package.endswith(".deb"):
paths = []
for line in subprocess.check_output(
["dpkg", "-c", path_to_package], encoding="utf-8"
).splitlines():
paths.append(line.split()[5].lstrip("."))
else:
raise NotImplementedError()

return paths


def test_cma_only_contains_version_paths(package_path: str, cmk_version: str) -> None:
if not package_path.endswith(".cma"):
pytest.skip("%s is another package type" % os.path.basename(package_path))
Expand Down

0 comments on commit 4f76117

Please sign in to comment.