Skip to content

Commit

Permalink
Fail rename_and_wait_for_completion in case the rename_host job failed
Browse files Browse the repository at this point in the history
So far the wait polling just ended without any follow-up check on the
success of the action.

The rename operation is a complex task which involves multiple actions
on the central and remote site. This is not a transaction which can be
rolled back. So a rename operation may actually be applied partially,
which is unfortunate. But this is the way it is right now.

We now want at least better error reporting about the failed job to
understand error situations easier.

CMK-20848

Change-Id: Ia443107dc6d0f6f20d414a62aecb88f3cc051432
  • Loading branch information
LarsMichelsen committed Dec 17, 2024
1 parent e86ce0b commit ef3d8f1
Showing 1 changed file with 22 additions and 0 deletions.
22 changes: 22 additions & 0 deletions tests/testlib/openapi_session.py
Original file line number Diff line number Diff line change
Expand Up @@ -119,6 +119,7 @@ def __init__(
self.rulesets = RulesetsAPI(self)
self.broker_connections = BrokerConnectionsAPI(self)
self.sites = SitesAPI(self)
self.background_jobs = BackgroundJobsAPI(self)

def set_authentication_header(self, user: str, password: str) -> None:
self.headers["Authorization"] = f"Bearer {user} {password}"
Expand Down Expand Up @@ -734,6 +735,11 @@ def rename_and_wait_for_completion(
self.get(hostname_new) is not None
), 'Failed to rename host "{hostname_old}" to "{hostname_new}"!'

response = self.session.background_jobs.show("rename-hosts")
assert (
response["extensions"]["status"]["state"] == "finished"
), f"Rename job failed: {response}"


class HostGroupsAPI(BaseAPI):
def create(self, name: str, alias: str) -> requests.Response:
Expand Down Expand Up @@ -1108,3 +1114,19 @@ def login(self, site_id: str, user: str = "cmkadmin", password: str = "cmk") ->

if response.status_code != 204:
raise UnexpectedResponse.from_response(response)


class BackgroundJobsAPI(BaseAPI):
def show(self, job_id: str) -> dict[str, Any]:
response = self.session.get(
f"/objects/background_job/{job_id}",
headers={
"Content-Type": "application/json",
},
)

if response.status_code != 200:
raise UnexpectedResponse.from_response(response)

value: dict[str, Any] = response.json()
return value

0 comments on commit ef3d8f1

Please sign in to comment.