def check_create_complete(self, data): attributes = self._show_resource() status = attributes['status'] if status == 'PENDING_CREATE': return False elif status == 'ACTIVE': vip_attributes = self.client().show_vip( self.metadata_get()['vip'])['vip'] vip_status = vip_attributes['status'] if vip_status == 'PENDING_CREATE': return False if vip_status == 'ACTIVE': return True if vip_status == 'ERROR': raise exception.ResourceInError( resource_status=vip_status, status_reason=_('error in vip')) raise exception.ResourceUnknownStatus( resource_status=vip_status, result=_('Pool creation failed due to vip')) elif status == 'ERROR': raise exception.ResourceInError(resource_status=status, status_reason=_('error in pool')) else: raise exception.ResourceUnknownStatus( resource_status=status, result=_('Pool creation failed'))
def check_create_complete(self, id): print("111111111111") container = self.client().containers.get(id) if container.status == 'Creating': return False elif container.status is None: return False elif container.status in ('Running', 'Created'): print("container: " + repr(container)) return True elif container.status == 'Error': msg = (_("Failed to create Container '%(name)s' - %(reason)s") % { 'name': self.name, 'reason': container.status_reason }) raise exception.ResourceInError(status_reason=msg, resource_status=container.status) else: msg = ( _("Unknown status creating Container '%(name)s' - %(reason)s") % { 'name': self.name, 'reason': container.status_reason }) raise exception.ResourceUnknownStatus( status_reason=msg, resource_status=container.status)
def check_update_complete(self, id): cluster = self.client().clusters.get(id) # Check update complete request might get status before the status # got changed to update in progress, so we allow `CREATE_COMPLETE` # for it. # TODO(ricolin): we should find way to make sure status check will # only perform after action really started. if cluster.status in ['UPDATE_IN_PROGRESS', 'CREATE_COMPLETE']: return False elif cluster.status == 'UPDATE_COMPLETE': return True elif cluster.status == 'UPDATE_FAILED': msg = (_("Failed to update Cluster '%(name)s' - %(reason)s") % { 'name': self.name, 'reason': cluster.status_reason }) raise exception.ResourceInError(status_reason=msg, resource_status=cluster.status) else: msg = ( _("Unknown status updating Cluster '%(name)s' - %(reason)s") % { 'name': self.name, 'reason': cluster.status_reason }) raise exception.ResourceUnknownStatus( status_reason=msg, resource_status=cluster.status)
def check_create_complete(self, *args): share_status = self._request_share().status if share_status == self.STATUS_CREATING: return False elif share_status == self.STATUS_AVAILABLE: LOG.info(_LI('Applying access rules to created Share.')) # apply access rules to created share. please note that it is not # possible to define rules for share with share_status = creating access_rules = self.properties.get(self.ACCESS_RULES) try: if access_rules: for rule in access_rules: self.client().shares.allow( share=self.resource_id, access_type=rule.get(self.ACCESS_TYPE), access=rule.get(self.ACCESS_TO), access_level=rule.get(self.ACCESS_LEVEL)) return True except Exception as ex: reason = _( 'Error during applying access rules to share "{0}". ' 'The root cause of the problem is the following: {1}.' ).format(self.resource_id, ex.message) raise exception.ResourceInError(status_reason=reason) elif share_status == self.STATUS_ERROR: reason = _('Error during creation of share "{0}"').format( self.resource_id) raise exception.ResourceInError(status_reason=reason, resource_status=share_status) else: reason = _('Unknown share_status during creation of share "{0}"' ).format(self.resource_id) raise exception.ResourceUnknownStatus( status_reason=reason, resource_status=share_status)
def check_delete_complete(self, *args): if not self.resource_id: return True try: share = self._request_share() except Exception as ex: self.client_plugin().ignore_not_found(ex) return True else: # when share creation is not finished proceed listening if share.status == self.STATUS_DELETING: return False elif share.status in (self.STATUS_ERROR, self.STATUS_ERROR_DELETING): raise exception.ResourceInError( status_reason=_( 'Error during deleting share "{0}".' ).format(self.resource_id), resource_status=share.status) else: reason = _('Unknown status during deleting share ' '"{0}"').format(self.resource_id) raise exception.ResourceUnknownStatus( status_reason=reason, resource_status=share.status)
def check_detach_volume_complete(self, vol_id): try: vol = self.client().volumes.get(vol_id) except Exception as ex: self.ignore_not_found(ex) return True if vol.status in ('in-use', 'detaching'): LOG.debug('%s - volume still in use' % vol_id) return False LOG.debug('Volume %(id)s - status: %(status)s' % { 'id': vol.id, 'status': vol.status }) if vol.status not in ('available', 'deleting'): LOG.debug("Detachment failed - volume %(vol)s " "is in %(status)s status" % { "vol": vol.id, "status": vol.status }) raise exception.ResourceUnknownStatus( resource_status=vol.status, result=_('Volume detachment failed')) else: return True
def check_update_complete(self, id): bay = self.client().bays.get(id) if bay.status == 'UPDATE_IN_PROGRESS': return False # check for None due to Magnum bug # https://bugs.launchpad.net/magnum/+bug/1507598 elif bay.status is None: return False elif bay.status == 'UPDATE_COMPLETE': return True elif bay.status == 'UPDATE_FAILED': msg = (_("Failed to update Bay '%(name)s' - %(reason)s") % { 'name': self.name, 'reason': bay.status_reason }) raise exception.ResourceInError(status_reason=msg, resource_status=bay.status) else: msg = (_("Unknown status updating Bay '%(name)s' - %(reason)s") % { 'name': self.name, 'reason': bay.status_reason }) raise exception.ResourceUnknownStatus(status_reason=msg, resource_status=bay.status)
def _check_execution(self, action, execution_id): """Check execution status. Returns False if in IDLE, RUNNING or PAUSED returns True if in SUCCESS raises ResourceFailure if in ERROR, CANCELLED raises ResourceUnknownState otherwise. """ execution = self.client().executions.get(execution_id) LOG.debug('Mistral execution %(id)s is in state ' '%(state)s' % { 'id': execution_id, 'state': execution.state }) if execution.state in ('IDLE', 'RUNNING', 'PAUSED'): return False, {} if execution.state in ('SUCCESS', ): return True, jsonutils.loads(execution.output) if execution.state in ('ERROR', 'CANCELLED'): raise exception.ResourceFailure(exception_or_error=execution.state, resource=self, action=action) raise exception.ResourceUnknownStatus( resource_status=execution.state, result=_('Mistral execution is in unknown state.'))
def check_create_complete(self, id): container = self.client().containers.get(id) if container.status in ('Creating', 'Created'): return False elif container.status == 'Running': return True elif container.status == 'Stopped': if container.interactive: msg = (_("Error in creating container '%(name)s' - " "interactive mode was enabled but the container " "has stopped running") % { 'name': self.name }) raise exception.ResourceInError( status_reason=msg, resource_status=container.status) return True elif container.status == 'Error': msg = (_("Error in creating container '%(name)s' - %(reason)s") % { 'name': self.name, 'reason': container.status_reason }) raise exception.ResourceInError(status_reason=msg, resource_status=container.status) else: msg = (_("Unknown status Container '%(name)s' - %(reason)s") % { 'name': self.name, 'reason': container.status_reason }) raise exception.ResourceUnknownStatus( status_reason=msg, resource_status=container.status)
def _check_status_complete(self, expected_action, cookie=None): try: data = stack_object.Stack.get_status(self.context, self.resource_id) except exception.NotFound: if expected_action == self.DELETE: return True # It's possible the engine handling the create hasn't persisted # the stack to the DB when we first start polling for state return False action, status, status_reason, updated_time = data if action != expected_action: return False # Has the action really started? # # The rpc call to update does not guarantee that the stack will be # placed into IN_PROGRESS by the time it returns (it runs stack.update # in a thread) so you could also have a situation where we get into # this method and the update hasn't even started. # # So we are using a mixture of state (action+status) and updated_at # to see if the action has actually progressed. # - very fast updates (like something with one RandomString) we will # probably miss the state change, but we should catch the updated_at. # - very slow updates we won't see the updated_at for quite a while, # but should see the state change. if cookie is not None: prev_state = cookie['previous']['state'] prev_updated_at = cookie['previous']['updated_at'] if (prev_updated_at == updated_time and prev_state == (action, status)): return False if status == self.IN_PROGRESS: return False elif status == self.COMPLETE: # For operations where we do not take a resource lock # (i.e. legacy-style), check that the stack lock has been # released before reporting completeness. done = (self._should_lock_on_action(expected_action) or stack_lock.StackLock.get_engine_id( self.context, self.resource_id) is None) if done: # Reset nested, to indicate we changed status self._nested = None return done elif status == self.FAILED: raise exception.ResourceFailure(status_reason, self, action=action) else: raise exception.ResourceUnknownStatus( resource_status=status, status_reason=status_reason, result=_('Stack unknown status'))
def _check_create_backup_complete(self, prg): backup = self.client().backups.get(prg.backup_id) if backup.status == 'creating': return False if backup.status == 'available': return True else: raise exception.ResourceUnknownStatus( resource_status=backup.status, result=_('Volume backup failed'))
def is_built(attributes): status = attributes['status'] if status == 'BUILD': return False if status in ('ACTIVE', 'DOWN'): return True elif status == 'ERROR': raise exception.ResourceInError(resource_status=status) else: raise exception.ResourceUnknownStatus( resource_status=status, result=_('Resource is not built'))
def verify_resize(self, server_id): server = self.fetch_server(server_id) if not server: return False status = self.get_status(server) if status == 'VERIFY_RESIZE': server.confirm_resize() return True else: msg = _("Could not confirm resize of server %s") % server_id raise exception.ResourceUnknownStatus(result=msg, resource_status=status)
def check_create_complete(self, vol_id): vol = self.client().volumes.get(vol_id) if vol.status == 'available': return True if vol.status in self._volume_creating_status: return False if vol.status == 'error': raise exception.ResourceInError(resource_status=vol.status) else: raise exception.ResourceUnknownStatus( resource_status=vol.status, result=_('Volume create failed'))
def check_create_complete(self, data): attributes = self._show_resource() status = attributes['status'] if status == 'PENDING_CREATE': return False elif status == 'ACTIVE': return True elif status == 'ERROR': raise exception.ResourceInError( resource_status=status, status_reason=_('Error in Firewall')) else: raise exception.ResourceUnknownStatus( resource_status=status, result=_('Firewall creation failed'))
def check_verify_resize(self, server_id): server = self.fetch_server(server_id) if not server: return False status = self.get_status(server) if status == 'ACTIVE': return True if status == 'VERIFY_RESIZE': return False else: msg = _("Confirm resize for server %s failed") % server_id raise exception.ResourceUnknownStatus(result=msg, resource_status=status)
def _check_backup_restore_complete(self): vol = self.client().volumes.get(self.resource_id) if vol.status == 'restoring-backup': LOG.debug("Volume %s is being restoring from backup", vol.id) return False if vol.status != 'available': LOG.info("Restore failed: Volume %(vol)s is in %(status)s " "state.", {'vol': vol.id, 'status': vol.status}) raise exception.ResourceUnknownStatus( resource_status=vol.status, result=_('Volume backup restore failed')) LOG.info('Volume %s backup restore complete', vol.id) return True
def check_suspend_complete(self, server_id): cp = self.client_plugin() server = cp.fetch_server(server_id) if not server: return False status = cp.get_status(server) LOG.debug('%(name)s check_suspend_complete status = %(status)s' % {'name': self.name, 'status': status}) if status in list(cp.deferred_server_statuses + ['ACTIVE']): return status == 'SUSPENDED' else: exc = exception.ResourceUnknownStatus( result=_('Suspend of instance %s failed') % server.name, resource_status=status) raise exc
def check_create_complete(self, id): cluster = self.client().clusters.get(id) if cluster.status == 'CREATE_IN_PROGRESS': return False elif cluster.status == 'CREATE_COMPLETE': return True elif cluster.status == 'CREATE_FAILED': msg = (_("Failed to create Cluster '%(name)s' - %(reason)s") % {'name': self.name, 'reason': cluster.status_reason}) raise exception.ResourceInError(status_reason=msg, resource_status=cluster.status) else: msg = (_("Unknown status creating Cluster '%(name)s' - %(reason)s") % {'name': self.name, 'reason': cluster.status_reason}) raise exception.ResourceUnknownStatus( status_reason=msg, resource_status=cluster.status)
def _check_extend_volume_complete(self): vol = self.client().volumes.get(self.resource_id) if vol.status == 'extending': LOG.debug("Volume %s is being extended", vol.id) return False if vol.status != 'available': LOG.info("Resize failed: Volume %(vol)s " "is in %(status)s state.", {'vol': vol.id, 'status': vol.status}) raise exception.ResourceUnknownStatus( resource_status=vol.status, result=_('Volume resize failed')) LOG.info('Volume %(id)s resize complete', {'id': vol.id}) return True
def _check_status_complete(self, expected_action, cookie=None): try: data = stack_object.Stack.get_status(self.context, self.resource_id) except exception.NotFound: if expected_action == self.DELETE: return True # It's possible the engine handling the create hasn't persisted # the stack to the DB when we first start polling for state return False action, status, status_reason, updated_time = data if action != expected_action: return False if status == self.IN_PROGRESS: if cookie is not None and 'fail_count' in cookie: prev_status_reason = cookie['previous']['status_reason'] if status_reason != prev_status_reason: # State has changed, so fail on the next failure cookie['fail_count'] = 1 return False elif status == self.COMPLETE: # For operations where we do not take a resource lock # (i.e. legacy-style), check that the stack lock has been # released before reporting completeness. done = (self._should_lock_on_action(expected_action) or stack_lock.StackLock.get_engine_id( self.context, self.resource_id) is None) if done: # Reset nested, to indicate we changed status self._nested = None return done elif status == self.FAILED: if cookie is not None and 'fail_count' in cookie: cookie['fail_count'] -= 1 if cookie['fail_count'] > 0: raise resource.PollDelay(10) raise exception.ResourceFailure(status_reason, self, action=action) else: raise exception.ResourceUnknownStatus( resource_status=status, status_reason=status_reason, result=_('Stack unknown status'))
def check_verify_resize(self, server_id): server = self.fetch_server(server_id) if not server: return False status = self.get_status(server) if status == 'ACTIVE': return True if status == 'VERIFY_RESIZE': return False task_state_in_nova = getattr(server, 'OS-EXT-STS:task_state', None) # Wait till move out from any resize steps (including resize_finish). if task_state_in_nova is not None and 'resize' in task_state_in_nova: return False else: msg = _("Confirm resize for server %s failed") % server_id raise exception.ResourceUnknownStatus(result=msg, resource_status=status)
def check_update_complete(self, id): bay = self.client().bays.get(id) if bay.status == 'UPDATE_IN_PROGRESS': return False elif bay.status == 'UPDATE_COMPLETE': return True elif bay.status == 'UPDATE_FAILED': msg = (_("Failed to update Bay '%(name)s' - %(reason)s") % {'name': self.name, 'reason': bay.status_reason}) raise exception.ResourceInError(status_reason=msg, resource_status=bay.status) else: msg = (_("Unknown status updating Bay '%(name)s' - %(reason)s") % {'name': self.name, 'reason': bay.status_reason}) raise exception.ResourceUnknownStatus(status_reason=msg, resource_status=bay.status)
def _check_status_complete(self, action, show_deleted=False, cookie=None): nested = self.nested(force_reload=True, show_deleted=show_deleted) if nested is None: if action == resource.Resource.DELETE: return True # It's possible the engine handling the create hasn't persisted # the stack to the DB when we first start polling for state return False if nested.action != action: return False # Has the action really started? # # The rpc call to update does not guarantee that the stack will be # placed into IN_PROGRESS by the time it returns (it runs stack.update # in a thread) so you could also have a situation where we get into # this method and the update hasn't even started. # # So we are using a mixture of state (action+status) and updated_at # to see if the action has actually progressed. # - very fast updates (like something with one RandomString) we will # probably miss the state change, but we should catch the updated_at. # - very slow updates we won't see the updated_at for quite a while, # but should see the state change. if cookie is not None: prev_state = cookie['previous']['state'] prev_updated_at = cookie['previous']['updated_at'] if (prev_updated_at == nested.updated_time and prev_state == nested.state): return False if nested.status == resource.Resource.IN_PROGRESS: return False elif nested.status == resource.Resource.COMPLETE: return True elif nested.status == resource.Resource.FAILED: raise exception.ResourceFailure(nested.status_reason, self, action=action) else: raise exception.ResourceUnknownStatus( resource_status=nested.status, status_reason=nested.status_reason, result=_('Stack unknown status'))
def check_attach_volume_complete(self, vol_id): vol = self.client().volumes.get(vol_id) if vol.status in ('available', 'attaching'): LOG.debug("Volume %(id)s is being attached - " "volume status: %(status)s" % {'id': vol_id, 'status': vol.status}) return False if vol.status != 'in-use': LOG.debug("Attachment failed - volume %(vol)s is " "in %(status)s status" % {"vol": vol_id, "status": vol.status}) raise exception.ResourceUnknownStatus( resource_status=vol.status, result=_('Volume attachment failed')) LOG.info(_LI('Attaching volume %(id)s complete'), {'id': vol_id}) return True
def _check_action_complete(self, action): stack = self.heat().stacks.get(stack_id=self.resource_id) if stack.action != action: return False if stack.status == self.IN_PROGRESS: return False elif stack.status == self.COMPLETE: return True elif stack.status == self.FAILED: raise exception.ResourceInError( resource_status=stack.stack_status, status_reason=stack.stack_status_reason) else: # Note: this should never happen, so it really means that # the resource/engine is in serious problem if it happens. raise exception.ResourceUnknownStatus( resource_status=stack.stack_status, status_reason=stack.stack_status_reason)
def _check_active(self, server, res_name='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 Heat status, returns False otherwise. :param res_name: name of the resource to use in the exception message """ # 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.ResourceInError( resource_status=status, status_reason=_("Message: %(message)s, Code: %(code)s") % { 'message': fault.get('message', _('Unknown')), 'code': fault.get('code', _('Unknown')) }) else: raise exception.ResourceUnknownStatus( resource_status=server.status, result=_('%s is not active') % res_name)
def check_update_complete(self, id): bay = self.client().bays.get(id) # Check update complete request might get status before the status # got changed to update in progress, so we allow `CREATE_COMPLETE` # for it. if bay.status in ['UPDATE_IN_PROGRESS', 'CREATE_COMPLETE']: return False elif bay.status == 'UPDATE_COMPLETE': return True elif bay.status == 'UPDATE_FAILED': msg = (_("Failed to update Bay '%(name)s' - %(reason)s") % { 'name': self.name, 'reason': bay.status_reason }) raise exception.ResourceInError(status_reason=msg, resource_status=bay.status) else: msg = (_("Unknown status updating Bay '%(name)s' - %(reason)s") % { 'name': self.name, 'reason': bay.status_reason }) raise exception.ResourceUnknownStatus(status_reason=msg, resource_status=bay.status)