From: Dan Mick Date: Fri, 12 Dec 2025 03:42:23 +0000 (-0800) Subject: maas: release machine when unlocking and wait for no longer Deployed X-Git-Url: http://git-server-git.apps.pok.os.sepia.ceph.com/?a=commitdiff_plain;h=b3e16aa0e5bc76fb720c4c7790ffafeae199adcb;p=teuthology.git maas: release machine when unlocking and wait for no longer Deployed To accomplish this, add "is_not" to _wait_for_status, and invert the sense of the test: wait until status is *not* the status in the status argument. Signed-off-by: Dan Mick --- diff --git a/teuthology/provision/maas.py b/teuthology/provision/maas.py index be690d35e..031e4921c 100644 --- a/teuthology/provision/maas.py +++ b/teuthology/provision/maas.py @@ -1,6 +1,7 @@ import io import json import logging +import operator from oauthlib.oauth1 import SIGNATURE_PLAINTEXT from requests import Response @@ -248,6 +249,8 @@ class MAAS(object): f"Machine '{self.shortname}' unlocking failed, " f"Current status: {data.get('locked')}" ) + self.release_machine(erase=False) + self._wait_for_status(status="Deployed", is_not=True) def deploy_machine(self) -> None: """Deploy the machine""" @@ -385,17 +388,28 @@ class MAAS(object): return open(user_data_template, "rb") def _wait_for_status( - self, status: str, interval: int = 60, timeout: int = 900 + self, status: str, is_not: bool = False, interval: int = 60, timeout: int = 900 ) -> None: - """Wait for the machine to reach a specific status + """Wait for the machine to reach a specific status, or to no longer + have a specific status :param status: The status to wait for + :param is_not: If True, wait for reported status *not* matching status :param interval: Time to wait between status checks, in seconds (default: 60) :param timeout: Maximum time to wait for the status, in seconds (default: 900) """ + if is_not: + compare = operator.ne + success = "leave" + succeeded = "left" + else: + compare = operator.eq + success = "reach" + succeeded = "reached" + self.log.info( f"Waiting for machine '{self.shortname}' with system_id '{self.system_id}' " - f"to reach status '{status}'" + f"to {success} status '{status}'" ) with safe_while( sleep=interval, timeout=int(config.maas.get("timeout", timeout)) @@ -403,11 +417,14 @@ class MAAS(object): while proceed(): maas_machine: Dict[str, Any] = self.get_machines_data() status_name = maas_machine["status_name"] - if status_name.lower() == status.lower(): + + if compare(status_name.lower(), status.lower()): log.info( f"MaaS machine system '{self.shortname}' with system_id " - f"'{self.system_id}' reached status '{status_name}'" + f"'{self.system_id}' {succeeded} status '{status_name}'" ) + if is_not: + log.info(f"New status: '{status_name}'") return self.log.debug(