def wait_for_server_termination(client, server_id, ignore_error=False): """Waits for server to reach termination.""" try: body = client.show_server(server_id)['server'] except lib_exc.NotFound: return old_status = server_status = body['status'] old_task_state = task_state = _get_task_state(body) start_time = int(time.time()) while True: time.sleep(client.build_interval) try: body = client.show_server(server_id)['server'] except lib_exc.NotFound: return server_status = body['status'] task_state = _get_task_state(body) if (server_status != old_status) or (task_state != old_task_state): LOG.info('State transition "%s" ==> "%s" after %d second wait', '/'.join((old_status, str(old_task_state))), '/'.join( (server_status, str(task_state))), time.time() - start_time) if server_status == 'ERROR' and not ignore_error: raise lib_exc.DeleteErrorException(resource_id=server_id) if int(time.time()) - start_time >= client.build_timeout: raise lib_exc.TimeoutException old_status = server_status old_task_state = task_state
def _wait(): try: firewall = self.fwaasv1_client.show_firewall(fw_id) except lib_exc.NotFound: return True fw_status = firewall['firewall']['status'] if fw_status == 'ERROR': raise lib_exc.DeleteErrorException(resource_id=fw_id)
def _wait(): try: fwg = self.firewall_groups_client.show_firewall_group(fwg_id) except lib_exc.NotFound: return True fwg_status = fwg['firewall_group']['status'] if fwg_status == 'ERROR': raise lib_exc.DeleteErrorException(resource_id=fwg_id)
def is_resource_deleted(self, id): """Check the specified resource is deleted or not. :param id: A checked resource id :raises lib_exc.DeleteErrorException: If the specified resource is on the status the delete was failed. """ try: volume = self.show_volume(id) except lib_exc.NotFound: return True if volume["volume"]["status"] == "error_deleting": raise lib_exc.DeleteErrorException(resource_id=id) return False
def wait_for_server_termination(client, server_id, ignore_error=False): """Waits for server to reach termination.""" try: body = client.show_server(server_id)['server'] except lib_exc.NotFound: return old_status = body['status'] old_task_state = _get_task_state(body) start_time = int(time.time()) while True: time.sleep(client.build_interval) try: body = client.show_server(server_id)['server'] except lib_exc.NotFound: return server_status = body['status'] task_state = _get_task_state(body) if (server_status != old_status) or (task_state != old_task_state): LOG.info('State transition "%s" ==> "%s" after %d second wait', '/'.join((old_status, str(old_task_state))), '/'.join( (server_status, str(task_state))), time.time() - start_time) if server_status == 'ERROR' and not ignore_error: raise lib_exc.DeleteErrorException( "Server %s failed to delete and is in ERROR status" % server_id) if server_status == 'SOFT_DELETED': # Soft-deleted instances need to be forcibly deleted to # prevent some test cases from failing. LOG.debug("Automatically force-deleting soft-deleted server %s", server_id) try: client.force_delete_server(server_id) except lib_exc.NotFound: # The instance may have been deleted so ignore # NotFound exception return if int(time.time()) - start_time >= client.build_timeout: raise lib_exc.TimeoutException old_status = server_status old_task_state = task_state