def create(self,
               context,
               action,
               resource_type=message_field.Resource.VOLUME,
               resource_uuid=None,
               exception=None,
               detail=None,
               level="ERROR"):
        """Create a message with the specified information."""
        LOG.info("Creating message record for request_id = %s",
                 context.request_id)
        # Updates expiry time for message as per message_ttl config.
        expires_at = (timeutils.utcnow() +
                      datetime.timedelta(seconds=CONF.message_ttl))

        detail_id = message_field.translate_detail_id(exception, detail)
        message_record = {
            'project_id': context.project_id,
            'request_id': context.request_id,
            'resource_type': resource_type,
            'resource_uuid': resource_uuid,
            'action_id': action[0] if action else '',
            'message_level': level,
            'event_id':
            "VOLUME_%s_%s_%s" % (resource_type, action[0], detail_id),
            'detail_id': detail_id,
            'expires_at': expires_at
        }
        try:
            self.db.message_create(context, message_record)
        except Exception:
            LOG.exception(
                "Failed to create message record "
                "for request_id %s", context.request_id)
Exemple #2
0
    def create(self, context, action,
               resource_type=message_field.Resource.VOLUME,
               resource_uuid=None, exception=None, detail=None, level="ERROR"):
        """Create a message with the specified information."""
        LOG.info("Creating message record for request_id = %s",
                 context.request_id)
        # Updates expiry time for message as per message_ttl config.
        expires_at = (timeutils.utcnow() + datetime.timedelta(
                      seconds=CONF.message_ttl))

        detail_id = message_field.translate_detail_id(exception, detail)
        message_record = {'project_id': context.project_id,
                          'request_id': context.request_id,
                          'resource_type': resource_type,
                          'resource_uuid': resource_uuid,
                          'action_id': action[0] if action else '',
                          'message_level': level,
                          'event_id': "VOLUME_%s_%s_%s" % (resource_type,
                                                           action[0],
                                                           detail_id),
                          'detail_id': detail_id,
                          'expires_at': expires_at}
        try:
            self.db.message_create(context, message_record)
        except Exception:
            LOG.exception("Failed to create message record "
                          "for request_id %s", context.request_id)
Exemple #3
0
    def create(self, context, action,
               resource_type=message_field.Resource.VOLUME,
               resource_uuid=None, exception=None, detail=None, level="ERROR"):
        """Create a message record with the specified information.

        :param context: current context object
        :param action:
            a message_field.Action field describing what was taking place
            when this message was created
        :param resource_type:
            a message_field.Resource field describing the resource this
            message applies to.  Default is message_field.Resource.VOLUME
        :param resource_uuid:
            the resource ID if this message applies to an existing resource.
            Default is None
        :param exception:
            if an exception has occurred, you can pass it in and it will be
            translated into an appropriate message detail ID (possibly
            message_field.Detail.UNKNOWN_ERROR).  The message
            in the exception itself is ignored in order not to expose
            sensitive information to end users.  Default is None
        :param detail:
            a message_field.Detail field describing the event the message
            is about.  Default is None, in which case
            message_field.Detail.UNKNOWN_ERROR will be used for the message
            unless an exception in the message_field.EXCEPTION_DETAIL_MAPPINGS
            is passed; in that case the message_field.Detail field that's
            mapped to the exception is used.
        :param level:
            a string describing the severity of the message.  Suggested
            values are 'INFO', 'ERROR', 'WARNING'.  Default is 'ERROR'.
        """

        LOG.info("Creating message record for request_id = %s",
                 context.request_id)
        # Updates expiry time for message as per message_ttl config.
        expires_at = (timeutils.utcnow() + datetime.timedelta(
                      seconds=CONF.message_ttl))

        detail_id = message_field.translate_detail_id(exception, detail)
        message_record = {'project_id': context.project_id,
                          'request_id': context.request_id,
                          'resource_type': resource_type,
                          'resource_uuid': resource_uuid,
                          'action_id': action[0] if action else '',
                          'message_level': level,
                          'event_id': "VOLUME_%s_%s_%s" % (resource_type,
                                                           action[0],
                                                           detail_id),
                          'detail_id': detail_id,
                          'expires_at': expires_at}
        try:
            self.db.message_create(context, message_record)
        except Exception:
            LOG.exception("Failed to create message record "
                          "for request_id %s", context.request_id)
Exemple #4
0
    def create(self, context, action,
               resource_type=message_field.Resource.VOLUME,
               resource_uuid=None, exception=None, detail=None, level="ERROR"):
        """Create a message record with the specified information.

        :param context: current context object
        :param action:
            a message_field.Action field describing what was taking place
            when this message was created
        :param resource_type:
            a message_field.Resource field describing the resource this
            message applies to.  Default is message_field.Resource.VOLUME
        :param resource_uuid:
            the resource ID if this message applies to an existing resource.
            Default is None
        :param exception:
            if an exception has occurred, you can pass it in and it will be
            translated into an appropriate message detail ID (possibly
            message_field.Detail.UNKNOWN_ERROR).  The message
            in the exception itself is ignored in order not to expose
            sensitive information to end users.  Default is None
        :param detail:
            a message_field.Detail field describing the event the message
            is about.  Default is None, in which case
            message_field.Detail.UNKNOWN_ERROR will be used for the message
            unless an exception in the message_field.EXCEPTION_DETAIL_MAPPINGS
            is passed; in that case the message_field.Detail field that's
            mapped to the exception is used.
        :param level:
            a string describing the severity of the message.  Suggested
            values are 'INFO', 'ERROR', 'WARNING'.  Default is 'ERROR'.
        """

        LOG.info("Creating message record for request_id = %s",
                 context.request_id)
        # Updates expiry time for message as per message_ttl config.
        expires_at = (timeutils.utcnow() + datetime.timedelta(
                      seconds=CONF.message_ttl))

        detail_id = message_field.translate_detail_id(exception, detail)
        message_record = {'project_id': context.project_id,
                          'request_id': context.request_id,
                          'resource_type': resource_type,
                          'resource_uuid': resource_uuid,
                          'action_id': action[0] if action else '',
                          'message_level': level,
                          'event_id': "VOLUME_%s_%s_%s" % (resource_type,
                                                           action[0],
                                                           detail_id),
                          'detail_id': detail_id,
                          'expires_at': expires_at}
        try:
            self.db.message_create(context, message_record)
        except Exception:
            LOG.exception("Failed to create message record "
                          "for request_id %s", context.request_id)
Exemple #5
0
 def translate_detail_id(self, exception, detail, expected):
     result = message_field.translate_detail_id(exception, detail)
     self.assertEqual(expected, result)