Skip to content

Commit a78906f

Browse files
committed
Fix failing wait_for_idle test
As per discussion in #841 (comment) Should fix #837
1 parent a571283 commit a78906f

1 file changed

Lines changed: 10 additions & 5 deletions

File tree

juju/model.py

Lines changed: 10 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -2429,7 +2429,7 @@ async def _get_source_api(self, url, controller_name=None):
24292429

24302430
async def wait_for_idle(self, apps=None, raise_on_error=True, raise_on_blocked=False,
24312431
wait_for_active=False, timeout=10 * 60, idle_period=15, check_freq=0.5,
2432-
status=None, wait_for_units=1, wait_for_exact_units=-1):
2432+
status=None, wait_for_units=None, wait_for_exact_units=-1):
24332433
"""Wait for applications in the model to settle into an idle state.
24342434
24352435
:param apps (list[str]): Optional list of specific app names to wait on.
@@ -2478,6 +2478,9 @@ async def wait_for_idle(self, apps=None, raise_on_error=True, raise_on_blocked=F
24782478
warnings.warn("wait_for_active is deprecated; use status", DeprecationWarning)
24792479
status = "active"
24802480

2481+
if wait_for_units is None:
2482+
_wait_for_units = 1
2483+
24812484
timeout = timedelta(seconds=timeout) if timeout is not None else None
24822485
idle_period = timedelta(seconds=idle_period)
24832486
start_time = datetime.now()
@@ -2527,12 +2530,14 @@ def _raise_for_status(entities, status):
25272530
(wait_for_exact_units, len(app.units)))
25282531
continue
25292532
# If we have less # of units then required, then wait a bit more
2530-
elif len(app.units) < wait_for_units:
2533+
elif len(app.units) < _wait_for_units:
25312534
busy.append(app.name + " (not enough units yet - %s/%s)" %
2532-
(len(app.units), wait_for_units))
2535+
(len(app.units), _wait_for_units))
25332536
continue
2534-
elif len(units_ready) >= wait_for_units:
2535-
# No need to keep looking, we have the desired number of units ready to go
2537+
# User wants to see a certain # of units, and we have enough
2538+
elif wait_for_units and len(units_ready) >= _wait_for_units:
2539+
# So no need to keep looking, we have the desired number of units ready to go,
2540+
# exit the loop. Don't return, though, we might still have some errors to raise
25362541
break
25372542
for unit in app.units:
25382543
if unit.machine is not None and unit.machine.status == "error":

0 commit comments

Comments
 (0)