Skip to content

Commit

Permalink
Support rc_aware version CMKVersion of testlib
Browse files Browse the repository at this point in the history
- ignore rc for debian package file names
- add is_release_candidate function in CMKVersion
- add "version_without_rc" and "version_rc_aware" property in Version

CMK-19234

Change-Id: I7fd4cd0c172bb1e409ac1bd4f7998beab3e22278
  • Loading branch information
JonasScharpf committed Oct 23, 2024
1 parent d41ca85 commit 3d56180
Show file tree
Hide file tree
Showing 5 changed files with 29 additions and 18 deletions.
11 changes: 9 additions & 2 deletions cmk/gui/utils/agent.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,15 +7,22 @@

import cmk.utils.paths
from cmk.utils.version import __version__ as cmk_version
from cmk.utils.version import Version


def packed_agent_path_windows_msi() -> Path:
return Path(cmk.utils.paths.agents_dir) / "windows" / "check_mk_agent.msi"


def packed_agent_path_linux_deb() -> Path:
return Path(cmk.utils.paths.agents_dir) / f"check-mk-agent_{cmk_version}-1_all.deb"
return (
Path(cmk.utils.paths.agents_dir)
/ f"check-mk-agent_{Version.from_str(cmk_version).version_without_rc}-1_all.deb"
)


def packed_agent_path_linux_rpm() -> Path:
return Path(cmk.utils.paths.agents_dir) / f"check-mk-agent-{cmk_version}-1.noarch.rpm"
return (
Path(cmk.utils.paths.agents_dir)
/ f"check-mk-agent-{Version.from_str(cmk_version).version_without_rc}-1.noarch.rpm"
)
8 changes: 8 additions & 0 deletions cmk/utils/version.py
Original file line number Diff line number Diff line change
Expand Up @@ -269,6 +269,14 @@ def __init__(
def version_base(self) -> str:
return "" if self.base is None else str(self.base)

@property
def version_without_rc(self) -> str:
return f"{'' if self.base is None else self.base}{self.release.suffix()}".lstrip("-")

@property
def version_rc_aware(self) -> str:
return str(self)

def __repr__(self) -> str:
return f"{self.__class__.__name__}({self.base!r}, {self.release!r}, {self.release_candidate!r})"

Expand Down
13 changes: 4 additions & 9 deletions tests/testlib/containers.py
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,6 @@

# Make the tests.testlib available
sys.path.insert(0, os.path.dirname(os.path.dirname(os.path.dirname(os.path.realpath(__file__)))))
from cmk.utils.version import Version

_DOCKER_REGISTRY = "artifacts.lan.tribe29.com:4000"
_DOCKER_REGISTRY_URL = "https://%s/v2/" % _DOCKER_REGISTRY
Expand Down Expand Up @@ -284,9 +283,7 @@ def _create_cmk_image(

# This installs the requested Checkmk Edition+Version into the new image, for this reason we add
# these parts to the target image name. The tag is equal to the origin image.
image_name_with_tag = (
f"{_DOCKER_REGISTRY}/{distro_name}-{version.edition.short}-{version.version}:{docker_tag}"
)
image_name_with_tag = f"{_DOCKER_REGISTRY}/{distro_name}-{version.edition.short}-{version.version_rc_aware}:{docker_tag}"
if use_local_package := check_for_local_package(version, distro_name):
logger.info("+====================================================================+")
logger.info("| Use locally available package (i.e. don't try to fetch test-image) |")
Expand Down Expand Up @@ -321,6 +318,7 @@ def _create_cmk_image(
"com.checkmk.base_image_hash": base_image.short_id,
"com.checkmk.cmk_edition_short": version.edition.short,
"com.checkmk.cmk_version": version.version,
"com.checkmk.cmk_version_rc_aware": version.version_rc_aware,
"com.checkmk.cmk_branch": version.branch,
# override the base image label
"com.checkmk.image_type": "cmk-image",
Expand Down Expand Up @@ -380,10 +378,7 @@ def _create_cmk_image(
labeled_container.remove(v=True, force=True)

logger.info("Commited image [%s] (%s)", image_name_with_tag, image.short_id)
if (
not use_local_package
and Version.from_str(version.version).release_candidate.value is None
):
if not use_local_package and not version.is_release_candidate():
try:
logger.info(
"Uploading [%s] to registry (%s)",
Expand Down Expand Up @@ -452,7 +447,7 @@ def _is_using_current_cmk_package(image: Image, version: CMKVersion) -> bool:
def get_current_cmk_hash_for_artifact(version: CMKVersion, package_name: str) -> str:
hash_file_name = f"{package_name}.hash"
r = requests.get(
f"https://tstbuilds-artifacts.lan.tribe29.com/{version.version}/{hash_file_name}",
f"https://tstbuilds-artifacts.lan.tribe29.com/{version.version_rc_aware}/{hash_file_name}",
auth=get_cmk_download_credentials(),
timeout=30,
)
Expand Down
2 changes: 1 addition & 1 deletion tests/testlib/docker.py
Original file line number Diff line number Diff line change
Expand Up @@ -65,7 +65,7 @@ def image_name(version: CMKVersion) -> str:


def package_name(version: CMKVersion) -> str:
return f"check-mk-{version.edition.long}-{version.version.split('-rc')[0]}_0.{distro_codename}_amd64.deb"
return f"check-mk-{version.edition.long}-{version.version}_0.{distro_codename}_amd64.deb"


def prepare_build() -> None:
Expand Down
13 changes: 7 additions & 6 deletions tests/testlib/version.py
Original file line number Diff line number Diff line change
Expand Up @@ -53,7 +53,8 @@ def __init__(
branch_version: str = current_branch_version(),
) -> None:
self.version_spec: Final = version_spec
self.version: Final = self._version(version_spec, branch, branch_version)
self.version_rc_aware: Final = self._version(version_spec, branch, branch_version)
self.version: Final = re.sub(r"-rc(\d+)", "", self.version_rc_aware)
self.edition: Final = edition
self.branch: Final = branch
self.branch_version: Final = branch_version
Expand Down Expand Up @@ -101,11 +102,14 @@ def is_cloud_edition(self) -> bool:
def is_saas_edition(self) -> bool:
return self.edition is Edition.CSE

def is_release_candidate(self) -> bool:
return self.version != self.version_rc_aware

def version_directory(self) -> str:
return self.omd_version()

def omd_version(self) -> str:
return f"{self.version.split('-rc')[0]}.{self.edition.short}"
return f"{self.version}.{self.edition.short}"

def version_path(self) -> str:
return "/omd/versions/%s" % self.version_directory()
Expand Down Expand Up @@ -158,11 +162,8 @@ def _sanitize_version_spec(version: str) -> tuple[Version, time.struct_time | No
"""
_timestamp = None

# ignore release candidate
_version = re.sub(r"-rc(\d+)", "", version)

# treat `patch-version` as `micro-version`.
_version = _version.replace("0p", "")
_version = version.replace("0p", "")

# detect daily builds
if match := re.search(
Expand Down

0 comments on commit 3d56180

Please sign in to comment.