Skip to content

Commit

Permalink
Speed up activate changes II: Compute UUID and hostname from UUID lin…
Browse files Browse the repository at this point in the history
…k only once

SUP-21229

Change-Id: I7f48854cc7e040e9bee60811ce53bc0d3760024b
  • Loading branch information
jherbel committed Jan 16, 2025
1 parent a4c81da commit aadbdaf
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 13 deletions.
19 changes: 7 additions & 12 deletions cmk/utils/agent_registration.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@
from collections.abc import Container, Iterator, Mapping, Sequence
from os.path import relpath
from pathlib import Path
from typing import Any, NamedTuple
from typing import Any, Final
from uuid import UUID

import cmk.utils.paths
Expand Down Expand Up @@ -43,17 +43,12 @@ def connection_mode_from_host_config(
)


class UUIDLink(NamedTuple):
source: Path
target: Path

@property
def uuid(self) -> UUID:
return UUID(self.source.name)

@property
def hostname(self) -> HostName:
return HostName(self.target.name)
class UUIDLink:
def __init__(self, *, source: Path, target: Path) -> None:
self.source: Final = source
self.target: Final = target
self.uuid: Final = UUID(self.source.name)
self.hostname: Final = HostName(self.target.name)

def unlink(self) -> None:
self.source.unlink(missing_ok=True)
Expand Down
5 changes: 4 additions & 1 deletion tests/unit/cmk/utils/test_agent_registration.py
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,10 @@
class TestUUIDLink:
@pytest.fixture
def link(self, tmp_path: Path) -> UUIDLink:
return UUIDLink(tmp_path / "59e631e9-de89-40d6-9662-ba54569a24fb", tmp_path / "hostname")
return UUIDLink(
source=tmp_path / "59e631e9-de89-40d6-9662-ba54569a24fb",
target=tmp_path / "hostname",
)

def test_uuid(self, link: UUIDLink) -> None:
assert isinstance(link.uuid, UUID)
Expand Down

0 comments on commit aadbdaf

Please sign in to comment.