Skip to content

Commit 9d84e04

Browse files
committed
tests: Improve logging and exceptions.
+ Mention commit-hash when package is installed successfully. + Display the package details, rather than only the package version. 'package details' includes the version & edition. CMK-33087 Change-Id: Ia0ae73f423834cf7e2276604284090f87d8debc2 (cherry picked from commit 7df9e54)
1 parent 03735da commit 9d84e04

4 files changed

Lines changed: 45 additions & 15 deletions

File tree

tests/scripts/install-cmk.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -73,9 +73,9 @@ def main():
7373
manager = ABCPackageManager.factory()
7474
try:
7575
if args.uninstall:
76-
manager.uninstall(version.version_rc_aware, version.edition)
76+
manager.uninstall(version)
7777
else:
78-
manager.install(version.version_rc_aware, version.edition)
78+
manager.install(version)
7979
except subprocess.CalledProcessError as excp:
8080
excp.add_note(f"Failed to {operation} {version.edition} {version.version}!")
8181
logger.exception(excp)

tests/testlib/package_manager.py

Lines changed: 21 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,7 @@
2727

2828
from cmk.ccc.version import Edition
2929

30-
logger = logging.getLogger()
30+
logger = logging.getLogger(__name__)
3131

3232
PackageUrl = NewType("PackageUrl", str)
3333

@@ -116,18 +116,19 @@ def download(
116116

117117
return target_path
118118

119-
def install(self, version: str, edition: Edition) -> None:
120-
package_name = self.package_name(edition, version)
121-
build_system_path = self._build_system_package_path(version, package_name)
119+
def install(self, version: CMKVersion) -> None:
120+
version_ = version.version_rc_aware
121+
package_name = self.package_name(version.edition, version_)
122+
build_system_path = self._build_system_package_path(version_, package_name)
122123
packages_dir = Path(__file__).parent.parent.parent / "package_download"
123124
if (package_path := packages_dir / package_name).exists():
124125
logger.info("Install from locally available package %s", package_path)
125-
self._write_package_hash(version, edition, package_path)
126+
self._write_package_hash(version_, version.edition, package_path)
126127
self._install_package(package_path)
127128

128129
elif build_system_path.exists():
129130
logger.info("Install from build system package (%s)", build_system_path)
130-
self._write_package_hash(version, edition, build_system_path)
131+
self._write_package_hash(version_, version.edition, build_system_path)
131132
self._install_package(build_system_path)
132133

133134
else:
@@ -137,19 +138,28 @@ def install(self, version: str, edition: Edition) -> None:
137138
# should be found.
138139
logger.info("Try install from tstbuild")
139140
self._download_package(
140-
self.package_url_internal(version, package_name), package_path
141+
self.package_url_internal(version_, package_name), package_path
141142
)
142143
except requests.exceptions.HTTPError:
143144
logger.info("Could not Install from tstbuild, trying download portal...")
144-
self._download_package(self.package_url_public(version, package_name), package_path)
145+
self._download_package(
146+
self.package_url_public(version_, package_name), package_path
147+
)
145148

146149
logger.info("Install from tstbuild or portal (%s)", package_path)
147-
self._write_package_hash(version, edition, package_path)
150+
self._write_package_hash(version_, version.edition, package_path)
148151
self._install_package(package_path)
149152
os.unlink(package_path)
150153

151-
def uninstall(self, version: str, edition: Edition) -> None:
152-
package_name = self.package_name(edition, version)
154+
logger.info(
155+
"Checkmk package '%s' built using commit: '%s'",
156+
version.omd_version(),
157+
version.commit_hash,
158+
)
159+
160+
def uninstall(self, version: CMKVersion) -> None:
161+
version_ = version.version_rc_aware
162+
package_name = self.package_name(version.edition, version_)
153163
self._uninstall_package(package_name)
154164

155165
def _write_package_hash(self, version: str, edition: Edition, package_path: Path) -> None:

tests/testlib/site.py

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -856,17 +856,22 @@ def install_cmk(self) -> None:
856856
os.environ, VERSION=self.version.version, EDITION=self.version.edition.short
857857
),
858858
)
859+
logger.info(
860+
"Checkmk package '%s' built using commit: '%s'",
861+
self.version.omd_version(),
862+
self.version.commit_hash,
863+
)
859864
except subprocess.CalledProcessError as excp:
860865
excp.add_note("Execute 'tests/scripts/install-cmk.py' manually to debug the issue.")
861866
excp.add_note(excp.stdout)
862867
excp.add_note(excp.stderr)
863868
if excp.returncode == 22:
864869
raise RuntimeError(
865-
f"Version {self.version.version} could not be installed!"
870+
f"Checkmk package {self.version.omd_version()} could not be installed!"
866871
) from excp
867872
if excp.returncode == 11:
868873
raise FileNotFoundError(
869-
f"Version {self.version.version} could not be downloaded!"
874+
f"Checkmk package {self.version.omd_version()} could not be downloaded!"
870875
) from excp
871876
raise excp
872877

tests/testlib/version.py

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@
1010
import re
1111
import time
1212
from collections.abc import Callable
13+
from pathlib import Path
1314
from typing import Final, Self
1415

1516
from packaging.version import Version
@@ -80,6 +81,20 @@ def __init__(
8081
self.branch: Final = branch
8182
self.branch_version: Final = branch_version
8283

84+
@property
85+
def commit_hash(self) -> str:
86+
short_hand = self.omd_version()
87+
try:
88+
return Path(f"/opt/omd/versions/{short_hand}/share/doc/COMMIT").read_text().strip()
89+
except FileNotFoundError as excp:
90+
if self.is_installed():
91+
excp.add_note(
92+
f"Checkmk package '{short_hand}' is installed! Checkmk packaging issues?"
93+
)
94+
else:
95+
excp.add_note(f"Missing Checkmk package '{short_hand}' installation!")
96+
raise excp
97+
8398
@staticmethod
8499
def _get_default_version() -> str:
85100
if os.path.exists("/etc/alternatives/omd"):

0 commit comments

Comments
 (0)