@@ -2564,12 +2564,24 @@ def _raise_for_status(entities, status):
25642564 if raise_on_blocked and unit .workload_status == "blocked" :
25652565 blocks .setdefault ("Unit" , []).append (unit .name )
25662566 continue
2567- waiting_for_a_particular_status = status and unit .workload_status != status
2568- if not waiting_for_a_particular_status and unit .agent_status == "idle" :
2569- # We'll be here in two cases:
2570- # 1) We're not waiting for a particular status and the agent is "idle"
2571- # 2) We're waiting for a particular status and the workload is in that status
2572- # Either way, the unit is ready, start measuring the time period that
2567+ # TODO (cderici): we need two versions of wait_for_idle, one for waiting on
2568+ # individual units, another one for waiting for an application.
2569+ # The convoluted logic below is the result of trying to do both at the same
2570+ # time
2571+ need_to_wait_more_for_a_particular_status = status and unit .workload_status != status
2572+ if not need_to_wait_more_for_a_particular_status and \
2573+ unit .agent_status == "idle" and \
2574+ (wait_for_units or (not status or app_status == status )):
2575+ # A unit is ready if either:
2576+ # 1) Don't need to wait more for a particular status and the agent is "idle"
2577+ # 2) We're looking for a particular status and the unit's workload,
2578+ # as well as the application, is in that status. If the user wants to
2579+ # see only a particular number of units in that state -- i.e. a subset of
2580+ # the units is needed, then we don't care about the application status
2581+ # (because e.g. app can be in 'waiting' while unit.0 is 'active' and unit.1
2582+ # is 'waiting')
2583+
2584+ # The unit is ready, start measuring the time period that
25732585 # it needs to stay in that state (i.e. idle_period)
25742586 units_ready .add (unit .name )
25752587 now = datetime .now ()
0 commit comments