4141from ocp_resources .event import Event
4242from ocp_resources .exceptions import (
4343 ClientWithBasicAuthError ,
44+ ConditionError ,
4445 MissingRequiredArgumentError ,
4546 MissingResourceResError ,
4647 ResourceTeardownError ,
@@ -1239,6 +1240,8 @@ def wait_for_condition(
12391240 sleep_time : int = 1 ,
12401241 reason : str | None = None ,
12411242 message : str = "" ,
1243+ stop_condition : str | None = None ,
1244+ stop_status : str = "True" ,
12421245 ) -> None :
12431246 """
12441247 Wait for Resource condition to be in desire status.
@@ -1250,9 +1253,14 @@ def wait_for_condition(
12501253 message (str): Expected condition text inclusion.
12511254 timeout (int): Time to wait for the resource.
12521255 sleep_time(int): Interval between each retry when checking the resource's condition.
1256+ stop_condition (str | None): Condition which should stop the wait and fail.
1257+ Note: Matching for stop_condition only uses condition type and status.
1258+ The reason and message fields are ignored when checking for stop_condition.
1259+ stop_status (str): Status of the stop condition which should stop the wait and fail.
12531260
12541261 Raises:
1255- TimeoutExpiredError: If Resource condition in not in desire status.
1262+ TimeoutExpiredError: If Resource condition is not in desired status within timeout.
1263+ ConditionError: If the desired condition is not met and stop_condition is detected before timeout.
12561264 """
12571265 self .logger .info (f"Wait for { self .kind } /{ self .name } 's '{ condition } ' condition to be '{ status } '" )
12581266
@@ -1266,6 +1274,12 @@ def wait_for_condition(
12661274 if sample :
12671275 for cond in sample .get ("status" , {}).get ("conditions" , []):
12681276 actual_condition = {"type" : cond ["type" ], "status" : cond ["status" ]}
1277+
1278+ if stop_condition and actual_condition == {"type" : stop_condition , "status" : stop_status }:
1279+ raise ConditionError (
1280+ f"{ self .kind } { self .name } reached stop_condition '{ stop_condition } ' in status '{ stop_status } ':\n { cond } "
1281+ )
1282+
12691283 expected_condition = {"type" : condition , "status" : status }
12701284 if reason is not None :
12711285 actual_condition ["reason" ] = cond .get ("reason" , "" )
0 commit comments