+ @staticmethod
+ async def wait_for_model(model: Model, timeout: float = 3600):
+ """
+ Wait for all entities in model to reach its final state.
+
+ :param: model: Model to observe
+ :param: timeout: Timeout for the model applications to be active
+
+ :raises: asyncio.TimeoutError when timeout reaches
+ """
+
+ if timeout is None:
+ timeout = 3600.0
+
+ # Coroutine to wait until the entity reaches the final state
+ wait_for_entity = asyncio.ensure_future(
+ asyncio.wait_for(
+ model.block_until(
+ lambda: all(
+ entity_ready(entity) for entity in model.applications.values()
+ )
+ ),
+ timeout=timeout,
+ )
+ )
+
+ tasks = [wait_for_entity]
+ try:
+ await asyncio.wait(tasks, return_when=asyncio.FIRST_COMPLETED)
+ finally:
+ # Cancel tasks
+ for task in tasks:
+ task.cancel()
+