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.neutron().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 resource.ResourceInError(resource_status=vip_status, status_reason=_('error in vip')) raise resource.ResourceUnknownStatus( resource_status=vip_status, result=_('Pool creation failed due to vip')) elif status == 'ERROR': raise resource.ResourceInError(resource_status=status, status_reason=_('error in pool')) else: raise resource.ResourceUnknownStatus( resource_status=status, result=_('Pool creation failed'))
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 resource.ResourceInError(status_reason=reason) elif share_status == self.STATUS_ERROR: reason = _('Error during creation of share "{0}"').format( self.resource_id) raise resource.ResourceInError(status_reason=reason, resource_status=share_status) else: reason = _( 'Unknown share_status during creation of share "{0}"').format( self.resource_id) raise resource.ResourceUnknownStatus(status_reason=reason, resource_status=share_status)
def check_create_complete(self, instance_id): ''' Check if cloud DB instance creation is complete. ''' instance = self._refresh_instance(instance_id) # refresh attributes if instance is None: return False if instance.status in self.BAD_STATUSES: raise resource.ResourceInError( resource_status=instance.status, status_reason=self.TROVE_STATUS_REASON.get( instance.status, _("Unknown"))) if instance.status != self.ACTIVE: return False LOG.info( _LI("Database instance %(database)s created (flavor:%(" "flavor)s,volume:%(volume)s, datastore:%(" "datastore_type)s, datastore_version:%(" "datastore_version)s)"), { 'database': self._dbinstance_name(), 'flavor': self.flavor, 'volume': self.volume, 'datastore_type': self.datastore_type, 'datastore_version': self.datastore_version }) return True
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 resource.ResourceInError(resource_status=status, status_reason=errmsg) return False
def check_create_complete(self, container_id): status = self._get_container_status(container_id) exit_status = status.get('ExitCode') if exit_status is not None and exit_status != 0: logs = self.get_client().logs(self.resource_id) raise resource.ResourceInError(resource_status=self.FAILED, status_reason=logs) return status['Running']
def check_create_complete(self, cluster_id): cluster = self.client().clusters.get(cluster_id) if cluster.status == 'Error': raise resource.ResourceInError(resource_status=cluster.status) if cluster.status != 'Active': return False LOG.info(_LI("Cluster '%s' has been created"), cluster.name) return True
def is_built(attributes): status = attributes['status'] if status == 'BUILD': return False if status in ('ACTIVE', 'DOWN'): return True elif status == 'ERROR': raise resource.ResourceInError(resource_status=status) else: raise resource.ResourceUnknownStatus( resource_status=status, result=_('Resource is not built'))
def check_create_complete(self, vol): vol.get() if vol.status == 'available': return True if vol.status in self._volume_creating_status: return False if vol.status == 'error': raise resource.ResourceInError(resource_status=vol.status) else: raise resource.ResourceUnknownStatus( resource_status=vol.status, result=_('Volume create failed'))
def check_create_complete(self, cluster): cluster = self._refresh_cluster(cluster) for instance in cluster.instances: if instance['status'] in self.BAD_STATUSES: raise resource.ResourceInError( resource_status=instance['status'], status_reason=self.TROVE_STATUS_REASON.get( instance['status'], _("Unknown"))) if instance['status'] != self.ACTIVE: return False LOG.info(_LI("Cluster '%s' has been created"), cluster.name) return True
def check_delete_complete(self, resource_id): if not resource_id: return True try: cluster = self.client().clusters.get(resource_id) except Exception as ex: self.client_plugin().ignore_not_found(ex) LOG.info(_LI("Cluster '%s' has been deleted"), self._cluster_name()) return True else: if cluster.status == self.CLUSTER_ERROR: raise resource.ResourceInError(resource_status=cluster.status) return False
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 resource.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 resource.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 resource.ResourceInError( resource_status=status, status_reason=_("Message: %(message)s, Code: %(code)s") % { 'message': fault.get('message', _('Unknown')), 'code': fault.get('code', _('Unknown')) }) else: raise resource.ResourceUnknownStatus(resource_status=server.status, result=_('%s is not active') % res_name)
def _check_active(self, server): cp = self.client_plugin() status = cp.get_status(server) if status != 'ACTIVE': cp.refresh_server(server) status = cp.get_status(server) if status in cp.deferred_server_statuses: return False elif status == 'ACTIVE': return True elif status == 'ERROR': fault = getattr(server, 'fault', {}) raise resource.ResourceInError( resource_status=status, status_reason=_("Message: %(message)s, Code: %(code)s") % { 'message': fault.get('message', _('Unknown')), 'code': fault.get('code', _('Unknown')) }) else: raise resource.ResourceUnknownStatus( resource_status=server.status, result=_('Server is not active'))
def _check_action_complete(self, action): stack = self.heat().stacks.get(stack_id=self.resource_id) if stack.action == action: if stack.status == self.IN_PROGRESS: return False elif stack.status == self.COMPLETE: return True elif stack.status == self.FAILED: raise resource.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 resource.ResourceUnknownStatus( resource_status=stack.stack_status, status_reason=stack.stack_status_reason) else: msg = _('Resource action mismatch detected: expected=%(expected)s ' 'actual=%(actual)s') % dict(expected=action, actual=stack.action) raise resource.ResourceUnknownStatus( resource_status=stack.stack_status, status_reason=msg)
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 resource.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 resource.ResourceUnknownStatus( status_reason=reason, resource_status=share.status)
def check_create_complete(self, instance): ''' Check if cloud DB instance creation is complete. ''' self._refresh_instance(instance) # get updated attributes if instance.status in self.BAD_STATUSES: raise resource.ResourceInError(resource_status=instance.status) if instance.status != self.ACTIVE: return False msg = _("Database instance %(database)s created (flavor:%(flavor)s, " "volume:%(volume)s, datastore:%(datastore_type)s, " "datastore_version:%(datastore_version)s)") LOG.info( msg % { 'database': self._dbinstance_name(), 'flavor': self.flavor, 'volume': self.volume, 'datastore_type': self.datastore_type, 'datastore_version': self.datastore_version }) return True