diff --git a/juju/model.py b/juju/model.py index a3d4088c..715b8ed5 100644 --- a/juju/model.py +++ b/juju/model.py @@ -65,7 +65,7 @@ from ._sync import SyncCacheLine, ThreadedAsyncRunner if TYPE_CHECKING: - from .client._definitions import ApplicationStatus, FullStatus + from .client._definitions import ApplicationStatus, FullStatus, UnitStatus from .application import Application from .machine import Machine from .relation import Relation @@ -3062,11 +3062,58 @@ async def _check_idle( expected_idle_since = now - timedelta(seconds=idle_period) full_status = await self.get_status() + # FIXME check this precedence + for app_name in apps: + if not full_status.applications.get(app_name): + logging.info("Waiting for app %r", app_name) + return False + + # priority order is this: + # + # Machine error (any unit of any app from apps) + # Agent error (-"-) + # Workload error (-"-) + # App error (any app from apps) + # + # Workload blocked (any unit of any app from apps) + # App blocked (any app from apps) + units: Dict[str, UnitStatus] = {} + for app_name in apps: + #assert full_status.applications[app_name] + app = full_status.applications[app_name] + assert app + for unit_name, unit in app.units.items(): + assert unit + units[unit_name] = unit + + for unit_name, unit in units.items(): + if unit.machine: + ... + + for unit_name, unit in units.items(): + if unit.agent_status.status == "error" and ...: + ... + + for unit_name, unit in units.items(): + if unit.workload_status.status == "errpr" and ...: + ... + + # add app check + + for unit_name, unit in units.items(): + if unit.workload_status.status == "blocked" and ...: + ... + + # add app check + + + # remove this for app_name in apps: if not (app := full_status.applications.get(app_name)): logging.info("Waiting for app %r", app_name) return False + # FIXME compound status is not effective app_status, app_info = self._compound_status(full_status, app_name) if app_status == "error" and raise_on_error: raise JujuAppError(f"App {app_name!r} is in error: {app_info!r}")