Skip to content

Commit fdf878f

Browse files
authored
ocp_resources, resource: Extend 'wait_for_condition' criteria (#2544)
In some scenarios, tests are looking for a specific reason or message to be included in the condition. Although not a formal strict API, the message text includes extended reasoning which is useful for a user operator. Therefore, it is also included but with an inclusion check. See usage at: https://github.com/RedHatQE/openshift-virtualization-tests/blob/0116f056176dbb25da5e8846537264dccb8ef202/tests/network/general/test_bridge_marker.py#L130 Signed-off-by: Edward Haas <edwardh@redhat.com>
1 parent bdcd015 commit fdf878f

1 file changed

Lines changed: 19 additions & 10 deletions

File tree

ocp_resources/resource.py

Lines changed: 19 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -1230,13 +1230,23 @@ def watcher(self, timeout: int, resource_version: str = "") -> Generator[dict[st
12301230
resource_version=resource_version or self.initial_resource_version,
12311231
)
12321232

1233-
def wait_for_condition(self, condition: str, status: str, timeout: int = 300, sleep_time: int = 1) -> None:
1233+
def wait_for_condition(
1234+
self,
1235+
condition: str,
1236+
status: str,
1237+
timeout: int = 300,
1238+
sleep_time: int = 1,
1239+
reason: str | None = None,
1240+
message: str = "",
1241+
) -> None:
12341242
"""
12351243
Wait for Resource condition to be in desire status.
12361244
12371245
Args:
12381246
condition (str): Condition to query.
12391247
status (str): Expected condition status.
1248+
reason (None): Expected condition reason.
1249+
message (str): Expected condition text inclusion.
12401250
timeout (int): Time to wait for the resource.
12411251
sleep_time(int): Interval between each retry when checking the resource's condition.
12421252
@@ -1246,22 +1256,21 @@ def wait_for_condition(self, condition: str, status: str, timeout: int = 300, sl
12461256
self.logger.info(f"Wait for {self.kind}/{self.name}'s '{condition}' condition to be '{status}'")
12471257

12481258
timeout_watcher = TimeoutWatch(timeout=timeout)
1249-
for sample in TimeoutSampler(
1250-
wait_timeout=timeout,
1251-
sleep=sleep_time,
1252-
func=lambda: self.exists,
1253-
):
1254-
if sample:
1255-
break
1256-
1259+
self.wait(timeout=timeout, sleep=sleep_time)
12571260
for sample in TimeoutSampler(
12581261
wait_timeout=timeout_watcher.remaining_time(),
12591262
sleep=sleep_time,
12601263
func=lambda: self.instance,
12611264
):
12621265
if sample:
12631266
for cond in sample.get("status", {}).get("conditions", []):
1264-
if cond["type"] == condition and cond["status"] == status:
1267+
actual_condition = {"type": cond["type"], "status": cond["status"]}
1268+
expected_condition = {"type": condition, "status": status}
1269+
if reason is not None:
1270+
actual_condition["reason"] = cond.get("reason", "")
1271+
expected_condition["reason"] = reason
1272+
1273+
if actual_condition == expected_condition and message in cond.get("message", ""):
12651274
return
12661275

12671276
def api_request(

0 commit comments

Comments
 (0)