def check_delete_server_complete(self, server_id): """Wait for server to disappear from Nova.""" try: server = self.fetch_server(server_id) except Exception as exc: self.ignore_not_found(exc) return True if not server: return False task_state_in_nova = getattr(server, 'OS-EXT-STS:task_state', None) # the status of server won't change until the delete task has done if task_state_in_nova == 'deleting': return False status = self.get_status(server) if status in ("DELETED", "SOFT_DELETED"): return True if status == 'ERROR': fault = getattr(server, 'fault', {}) message = fault.get('message', 'Unknown') code = fault.get('code') errmsg = _("Server %(name)s delete failed: (%(code)s) " "%(message)s") % dict( name=server.name, code=code, message=message) raise exception.ServerInError(resource_status=status, status_reason=errmsg) return False
def check_active(self, server): """Check server status. Accepts both server IDs and server objects. Returns True if server is ACTIVE, raises errors when server has an ERROR or unknown to Zun status, returns False otherwise. """ # not checking with is_uuid_like as most tests use strings e.g. '1234' if isinstance(server, six.string_types): server = self.fetch_server(server) if server is None: return False else: status = self.get_status(server) else: status = self.get_status(server) if status != 'ACTIVE': self.refresh_server(server) status = self.get_status(server) if status in self.deferred_server_statuses: return False elif status == 'ACTIVE': return True elif status == 'ERROR': fault = getattr(server, 'fault', {}) raise exception.ServerInError( resource_status=status, status_reason=_("Message: %(message)s, Code: %(code)s") % { 'message': fault.get('message', _('Unknown')), 'code': fault.get('code', _('Unknown')) }) else: raise exception.ServerUnknownStatus( resource_status=server.status, status_reason=_('Unknown'), result=_('Server is not active'))