Пример #1
0
def create_fake_notification(type="VM", id=1, payload=None,
                             source_host_uuid=uuidsentinel.fake_host,
                             generated_time=NOW, status="new",
                             notification_uuid=uuidsentinel.fake_notification):
    return objects.Notification(
        type=type, id=id, payload=payload, source_host_uuid=source_host_uuid,
        generated_time=generated_time, status=status,
        notification_uuid=notification_uuid)
Пример #2
0
    def create_notification(self, context, notification_data):
        """Create notification"""

        # Check whether host from which the notification came is already
        # present in failover segment or not
        host_name = notification_data.get('hostname')
        host_object = objects.Host.get_by_name(context, host_name)
        host_on_maintenance = host_object.on_maintenance

        if host_on_maintenance:
            message = (_("Notification received from host %(host)s of type "
                         "'%(type)s' is ignored as the host is already under "
                         "maintenance.") % {
                             'host': host_name,
                             'type': notification_data.get('type')
                         })
            raise exception.HostOnMaintenanceError(message=message)

        notification = objects.Notification(context=context)

        # Populate notification object for create
        notification.type = notification_data.get('type')
        notification.generated_time = notification_data.get('generated_time')
        notification.source_host_uuid = host_object.uuid
        notification.payload = notification_data.get('payload')
        notification.status = fields.NotificationStatus.NEW

        if self._is_duplicate_notification(context, notification):
            message = (_("Notification received from host %(host)s of "
                         " type '%(type)s' is duplicate.") % {
                             'host': host_name,
                             'type': notification.type
                         })
            raise exception.DuplicateNotification(message=message)

        try:
            notification.create()
            self.engine_rpcapi.process_notification(context, notification)
        except Exception as e:
            with excutils.save_and_reraise_exception():
                tb = traceback.format_exc()
                api_utils.notify_about_notification_api(
                    context,
                    notification,
                    action=fields.EventNotificationAction.NOTIFICATION_CREATE,
                    phase=fields.EventNotificationPhase.ERROR,
                    exception=e,
                    tb=tb)
        return notification
Пример #3
0
    def create_notification(self, context, notification_data):
        """Create notification"""

        # Check whether host from which the notification came is already
        # present in failover segment or not
        host_name = notification_data.get('hostname')
        host_object = objects.Host.get_by_name(context, host_name)
        host_on_maintenance = host_object.on_maintenance

        if host_on_maintenance:
            message = (_("Notification received from host %(host)s of type "
                         "'%(type)s' is ignored as the host is already under "
                         "maintenance.") % {
                             'host': host_name,
                             'type': notification_data.get('type')
                         })
            raise exception.HostOnMaintenanceError(message=message)

        notification = objects.Notification(context=context)

        # Populate notification object for create
        notification.type = notification_data.get('type')
        notification.generated_time = notification_data.get('generated_time')
        notification.source_host_uuid = host_object.uuid
        notification.payload = notification_data.get('payload')
        notification.status = fields.NotificationStatus.NEW

        if self._is_duplicate_notification(context, notification):
            message = (_("Notification received from host %(host)s of "
                         " type '%(type)s' is duplicate.") % {
                             'host': host_name,
                             'type': notification.type
                         })
            raise exception.DuplicateNotification(message=message)

        notification.create()
        self.engine_rpcapi.process_notification(context, notification)

        return notification
Пример #4
0
def fake_notification_obj(context, **updates):
    return objects.Notification(**updates)