9
9
from collections import Counter
11
from .wait import wait
11
from .wait import wait, JujuWaitException
12
12
from ..shutil_which import get_command
14
14
# We can't use the implementation in .utils due to a circular import
472
472
def check_and_wait(self, wait_for_steady=False, max_wait=None, timeout=1800):
473
""" Check the current status of Juju raise JujuStatusError on error state. Optionally wait for busy states.
474
Note: max_wait and timeout are redundant and both exist only for compatibility with Juju1.
473
""" Wait for the current status of Juju to become ready (e.g. not blocked or in maintenance) and raise
474
JujuStatusError on error state. Optionally at the end wait for the current status to become steady
475
(i.e. not running any hook).
476
wait_for_steady: Wait for busy state to clear.
477
max_wait: If defined used instead of timeout.
478
timeout: Max amount of time to wait for a busy state to clear. Raise JujuWaitException if this passes.
477
wait_for_steady: Whether or not to wait for steadiness at the end.
478
max_wait: If defined used instead of timeout when waiting for steadiness.
479
timeout: Max amount of time to wait for readiness. Raise JujuWaitException after timeout. Also Max
480
amount of time to wait for steadiness if max_wait is None.
481
if max_wait is not None:
484
self.status(force_update=True)
486
# self.ready() will raise exceptions on error states
487
if self.ready() and not wait_for_steady:
483
logging.info("Waiting up to {} seconds for environment to become ready".format(timeout)
484
+ " (not blocked or in maintenance)")
485
check_and_wait_start = datetime.datetime.now()
487
check_and_wait_running = datetime.datetime.now() - check_and_wait_start
488
if check_and_wait_running.total_seconds() > int(timeout):
489
raise JujuWaitException("Timed out checking Juju status for stable state")
490
self.status(force_update=True)
491
if self.ready(): # self.ready() will raise exceptions on error states
494
logging.info("Environment is ready (not blocked or in maintenance)")
496
if not wait_for_steady:
497
logging.info("Not waiting for environment to reach steady state (not running any hook)")
490
logging.info("Waiting for environment to reach steady state")
491
wait(max_wait=timeout)
492
logging.info("Environment has reached steady state")
503
logging.info("Waiting up to {} seconds for environment to reach steady state".format(max_wait)
504
+ " (not running any hook)")
505
wait(max_wait=max_wait)
506
logging.info("Environment has reached steady state (not running any hook)")
494
508
def controller_version(self):
495
509
""" Parses the output of 'juju controllers' returning the controller version for the current controller.