Skip to content

Commit 8264500

Browse files
committed
ocp_resources, resource: Extend 'wait_for_condition' criteria
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 <[email protected]>
1 parent 6bac9ea commit 8264500

File tree

1 file changed

+19
-10
lines changed

1 file changed

+19
-10
lines changed

ocp_resources/resource.py

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

1225-
def wait_for_condition(self, condition: str, status: str, timeout: int = 300, sleep_time: int = 1) -> None:
1225+
def wait_for_condition(
1226+
self,
1227+
condition: str,
1228+
status: str,
1229+
timeout: int = 300,
1230+
sleep_time: int = 1,
1231+
reason: str | None = None,
1232+
message: str = "",
1233+
) -> None:
12261234
"""
12271235
Wait for Resource condition to be in desire status.
12281236
12291237
Args:
12301238
condition (str): Condition to query.
12311239
status (str): Expected condition status.
1240+
reason (None): Expected condition reason.
1241+
message (str): Expected condition text inclusion.
12321242
timeout (int): Time to wait for the resource.
12331243
sleep_time(int): Interval between each retry when checking the resource's condition.
12341244
@@ -1238,22 +1248,21 @@ def wait_for_condition(self, condition: str, status: str, timeout: int = 300, sl
12381248
self.logger.info(f"Wait for {self.kind}/{self.name}'s '{condition}' condition to be '{status}'")
12391249

12401250
timeout_watcher = TimeoutWatch(timeout=timeout)
1241-
for sample in TimeoutSampler(
1242-
wait_timeout=timeout,
1243-
sleep=sleep_time,
1244-
func=lambda: self.exists,
1245-
):
1246-
if sample:
1247-
break
1248-
1251+
self.wait(timeout=timeout, sleep=sleep_time)
12491252
for sample in TimeoutSampler(
12501253
wait_timeout=timeout_watcher.remaining_time(),
12511254
sleep=sleep_time,
12521255
func=lambda: self.instance,
12531256
):
12541257
if sample:
12551258
for cond in sample.get("status", {}).get("conditions", []):
1256-
if cond["type"] == condition and cond["status"] == status:
1259+
actual_condition = {"type": cond["type"], "status": cond["status"]}
1260+
expected_condition = {"type": condition, "status": status}
1261+
if reason is not None:
1262+
actual_condition["reason"] = cond.get("reason", "")
1263+
expected_condition["reason"] = reason
1264+
1265+
if actual_condition == expected_condition and message in cond.get("message", ""):
12571266
return
12581267

12591268
def api_request(

0 commit comments

Comments
 (0)