Example #1
0
    def _set_vm_state_and_notify(self, method, updates, context, ex, *args, **kwargs):
        """changes VM state and notifies"""
        # FIXME(comstud): Re-factor this somehow. Not sure this belongs in the
        # scheduler manager like this. We should make this easier.
        # run_instance only sends a request_spec, and an instance may or may
        # not have been created in the API (or scheduler) already. If it was
        # created, there's a 'uuid' set in the instance_properties of the
        # request_spec.
        # (littleidea): I refactored this a bit, and I agree
        # it should be easier :)
        # The refactoring could go further but trying to minimize changes
        # for essex timeframe

        LOG.warning(_("Failed to schedule_%(method)s: %(ex)s") % locals())

        vm_state = updates["vm_state"]
        request_spec = kwargs.get("request_spec", {})
        properties = request_spec.get("instance_properties", {})
        instance_uuid = properties.get("uuid", {})

        if instance_uuid:
            state = vm_state.upper()
            LOG.warning(_("Setting instance to %(state)s state."), locals(), instance_uuid=instance_uuid)
            db.instance_update(context, instance_uuid, updates)

        payload = dict(
            request_spec=request_spec,
            instance_properties=properties,
            instance_id=instance_uuid,
            state=vm_state,
            method=method,
            reason=ex,
        )

        notifier.notify(notifier.publisher_id("scheduler"), "scheduler." + method, notifier.ERROR, payload)
Example #2
0
    def test_send_notification(self):
        self.notify_called = False

        def mock_notify(cls, *args):
            self.notify_called = True

        self.stubs.Set(cinder.notifier.no_op_notifier, 'notify',
                mock_notify)

        notifier_api.notify('publisher_id', 'event_type',
                cinder.notifier.api.WARN, dict(a=3))
        self.assertEqual(self.notify_called, True)
Example #3
0
    def test_send_rabbit_notification(self):
        self.stubs.Set(cinder.flags.FLAGS, 'notification_driver',
                'cinder.notifier.rabbit_notifier')
        self.mock_notify = False

        def mock_notify(cls, *args):
            self.mock_notify = True

        self.stubs.Set(cinder.openstack.common.rpc, 'notify', mock_notify)
        notifier_api.notify('publisher_id', 'event_type',
                cinder.notifier.api.WARN, dict(a=3))

        self.assertEqual(self.mock_notify, True)
Example #4
0
    def test_rabbit_priority_queue(self):
        flags.DECLARE('notification_topics', 'cinder.notifier.rabbit_notifier')
        self.stubs.Set(cinder.flags.FLAGS, 'notification_driver',
                'cinder.notifier.rabbit_notifier')
        self.stubs.Set(cinder.flags.FLAGS, 'notification_topics',
                       ['testnotify', ])

        self.test_topic = None

        def mock_notify(context, topic, msg):
            self.test_topic = topic

        self.stubs.Set(cinder.openstack.common.rpc, 'notify', mock_notify)
        notifier_api.notify('publisher_id', 'event_type', 'DEBUG', dict(a=3))
        self.assertEqual(self.test_topic, 'testnotify.debug')
Example #5
0
    def test_verify_message_format(self):
        """A test to ensure changing the message format is prohibitively
        annoying"""

        def message_assert(message):
            fields = [('publisher_id', 'publisher_id'),
                      ('event_type', 'event_type'),
                      ('priority', 'WARN'),
                      ('payload', dict(a=3))]
            for k, v in fields:
                self.assertEqual(message[k], v)
            self.assertTrue(len(message['message_id']) > 0)
            self.assertTrue(len(message['timestamp']) > 0)

        self.stubs.Set(cinder.notifier.no_op_notifier, 'notify',
                message_assert)
        notifier_api.notify('publisher_id', 'event_type',
                cinder.notifier.api.WARN, dict(a=3))