예제 #1
0
    def test_task_notif(self):

        # test config disable of just the task state notifications
        self.flags(notify_on_state_change="vm_state", group='notifications')

        # we should not get a notification on task stgate chagne now
        old = copy.copy(self.instance)
        self.instance.task_state = task_states.SPAWNING

        old_vm_state = old['vm_state']
        new_vm_state = self.instance.vm_state
        old_task_state = old['task_state']
        new_task_state = self.instance.task_state

        notifications.send_update_with_states(self.context, self.instance,
                old_vm_state, new_vm_state, old_task_state, new_task_state,
                verify_states=True)

        self.assertEqual(0, len(fake_notifier.NOTIFICATIONS))
        self.assertEqual(0, len(fake_notifier.VERSIONED_NOTIFICATIONS))

        # ok now enable task state notifications and re-try
        self.flags(notify_on_state_change="vm_and_task_state",
                   group='notifications')

        notifications.send_update(self.context, old, self.instance)
        self.assertEqual(1, len(fake_notifier.NOTIFICATIONS))
        self.assertEqual(1, len(fake_notifier.VERSIONED_NOTIFICATIONS))

        self.assertEqual(
                'instance.update',
                fake_notifier.VERSIONED_NOTIFICATIONS[0]['event_type'])
    def test_task_notif(self):

        # test config disable of just the task state notifications
        self.flags(notify_on_state_change="vm_state", group='notifications')

        # we should not get a notification on task stgate chagne now
        old = copy.copy(self.instance)
        self.instance.task_state = task_states.SPAWNING

        old_vm_state = old['vm_state']
        new_vm_state = self.instance.vm_state
        old_task_state = old['task_state']
        new_task_state = self.instance.task_state

        notifications.send_update_with_states(self.context, self.instance,
                old_vm_state, new_vm_state, old_task_state, new_task_state,
                verify_states=True)

        self.assertEqual(0, len(fake_notifier.NOTIFICATIONS))
        self.assertEqual(0, len(fake_notifier.VERSIONED_NOTIFICATIONS))

        # ok now enable task state notifications and re-try
        self.flags(notify_on_state_change="vm_and_task_state",
                   group='notifications')

        notifications.send_update(self.context, old, self.instance)
        self.assertEqual(1, len(fake_notifier.NOTIFICATIONS))
        self.assertEqual(1, len(fake_notifier.VERSIONED_NOTIFICATIONS))

        self.assertEqual(
                'instance.update',
                fake_notifier.VERSIONED_NOTIFICATIONS[0]['event_type'])
    def test_fail_sending_update(self):
        def fail_sending(context, instance, **kwargs):
            raise Exception('failed to notify')
        self.stub_out('nova.notifications.base.'
                      'send_instance_update_notification',
                       fail_sending)

        notifications.send_update(self.context, self.instance, self.instance)
        self.assertEqual(0, len(fake_notifier.NOTIFICATIONS))
예제 #4
0
    def test_send_versioned_tags_update(self):
        objects.TagList.create(self.context, self.instance.uuid,
                               [u'tag1', u'tag2'])
        notifications.send_update(self.context, self.instance, self.instance)
        self.assertEqual(1, len(self.notifier.versioned_notifications))

        self.assertEqual([u'tag1', u'tag2'],
                         self.notifier.versioned_notifications[0]['payload']
                         ['nova_object.data']['tags'])
예제 #5
0
    def test_send_versioned_tags_update(self):
        objects.TagList.create(self.context, self.instance.uuid,
                               ['tag1', 'tag2'])
        notifications.send_update(self.context, self.instance, self.instance)
        self.assertEqual(1, len(fake_notifier.VERSIONED_NOTIFICATIONS))

        self.assertEqual(['tag1', 'tag2'],
                         fake_notifier.VERSIONED_NOTIFICATIONS[0]['payload']
                         ['nova_object.data']['tags'])
예제 #6
0
    def test_send_on_task_change(self):

        old = obj_base.obj_to_primitive(self.instance)
        old['task_state'] = None
        # pretend we just transitioned to task SPAWNING:
        self.instance.task_state = task_states.SPAWNING
        notifications.send_update(self.context, old, self.instance)

        self.assertEqual(1, len(fake_notifier.NOTIFICATIONS))
예제 #7
0
    def test_send_versioned_tags_update(self):
        objects.TagList.create(self.context,
                               self.instance.uuid, [u'tag1', u'tag2'])
        notifications.send_update(self.context, self.instance, self.instance)
        self.assertEqual(1, len(fake_notifier.VERSIONED_NOTIFICATIONS))

        self.assertEqual([u'tag1', u'tag2'],
                         fake_notifier.VERSIONED_NOTIFICATIONS[0]
                         ['payload']['nova_object.data']['tags'])
예제 #8
0
    def test_fail_sending_update(self):
        def fail_sending(context, instance, **kwargs):
            raise Exception('failed to notify')
        self.stub_out('nova.notifications.base.'
                      'send_instance_update_notification',
                       fail_sending)

        notifications.send_update(self.context, self.instance, self.instance)
        self.assertEqual(0, len(fake_notifier.NOTIFICATIONS))
예제 #9
0
    def test_send_on_task_change(self):

        old = obj_base.obj_to_primitive(self.instance)
        old['task_state'] = None
        # pretend we just transitioned to task SPAWNING:
        self.instance.task_state = task_states.SPAWNING
        notifications.send_update(self.context, old, self.instance)

        self.assertEqual(1, len(fake_notifier.NOTIFICATIONS))
예제 #10
0
    def test_send_access_ip_update(self):
        notifications.send_update(self.context, self.instance, self.instance)
        self.assertEqual(1, len(fake_notifier.NOTIFICATIONS))
        notif = fake_notifier.NOTIFICATIONS[0]
        payload = notif.payload
        access_ip_v4 = str(self.instance.access_ip_v4)
        access_ip_v6 = str(self.instance.access_ip_v6)

        self.assertEqual(payload["access_ip_v4"], access_ip_v4)
        self.assertEqual(payload["access_ip_v6"], access_ip_v6)
예제 #11
0
    def test_send_access_ip_update(self):
        notifications.send_update(self.context, self.instance, self.instance)
        self.assertEqual(1, len(fake_notifier.NOTIFICATIONS))
        notif = fake_notifier.NOTIFICATIONS[0]
        payload = notif.payload
        access_ip_v4 = str(self.instance.access_ip_v4)
        access_ip_v6 = str(self.instance.access_ip_v6)

        self.assertEqual(payload["access_ip_v4"], access_ip_v4)
        self.assertEqual(payload["access_ip_v6"], access_ip_v6)
예제 #12
0
    def test_send_no_state_change(self):
        called = [False]

        def sending_no_state_change(context, instance, **kwargs):
            called[0] = True
        self.stub_out('nova.notifications.base.'
                      'send_instance_update_notification',
                       sending_no_state_change)
        notifications.send_update(self.context, self.instance, self.instance)
        self.assertTrue(called[0])
    def test_send_no_state_change(self):
        called = [False]

        def sending_no_state_change(context, instance, **kwargs):
            called[0] = True
        self.stub_out('nova.notifications.base.'
                      'send_instance_update_notification',
                       sending_no_state_change)
        notifications.send_update(self.context, self.instance, self.instance)
        self.assertTrue(called[0])
예제 #14
0
    def test_send_on_vm_change(self):
        old = obj_base.obj_to_primitive(self.instance)
        old['vm_state'] = None
        # pretend we just transitioned to ACTIVE:
        self.instance.vm_state = vm_states.ACTIVE
        notifications.send_update(self.context, old, self.instance)

        self.assertEqual(1, len(fake_notifier.NOTIFICATIONS))
        # service name should default to 'compute'
        notif = fake_notifier.NOTIFICATIONS[0]
        self.assertEqual('compute.testhost', notif.publisher_id)
예제 #15
0
    def test_send_on_vm_change(self):
        old = obj_base.obj_to_primitive(self.instance)
        old['vm_state'] = None
        # pretend we just transitioned to ACTIVE:
        self.instance.vm_state = vm_states.ACTIVE
        notifications.send_update(self.context, old, self.instance)

        self.assertEqual(1, len(fake_notifier.NOTIFICATIONS))
        # service name should default to 'compute'
        notif = fake_notifier.NOTIFICATIONS[0]
        self.assertEqual('compute.testhost', notif.publisher_id)
예제 #16
0
 def test_fail_sending_update_instance_not_found(self, mock_log_exception):
     # Tests that InstanceNotFound is handled as an expected exception and
     # not logged as an error.
     notfound = exception.InstanceNotFound(instance_id=self.instance.uuid)
     with mock.patch.object(notifications,
                            'send_instance_update_notification',
                            side_effect=notfound):
         notifications.send_update(
             self.context, self.instance, self.instance)
     self.assertEqual(0, len(fake_notifier.NOTIFICATIONS))
     self.assertEqual(0, mock_log_exception.call_count)
예제 #17
0
 def test_fail_sending_update_instance_not_found(self, mock_log_exception):
     # Tests that InstanceNotFound is handled as an expected exception and
     # not logged as an error.
     notfound = exception.InstanceNotFound(instance_id=self.instance.uuid)
     with mock.patch.object(notifications,
                            'send_instance_update_notification',
                            side_effect=notfound):
         notifications.send_update(self.context, self.instance,
                                   self.instance)
     self.assertEqual(0, len(fake_notifier.NOTIFICATIONS))
     self.assertEqual(0, mock_log_exception.call_count)
예제 #18
0
    def test_send_name_update(self):
        param = {"display_name": "new_display_name"}
        new_name_inst = self._wrapped_create(params=param)
        notifications.send_update(self.context, self.instance, new_name_inst)
        self.assertEqual(1, len(fake_notifier.NOTIFICATIONS))
        notif = fake_notifier.NOTIFICATIONS[0]
        payload = notif.payload
        old_display_name = self.instance.display_name
        new_display_name = new_name_inst.display_name

        self.assertEqual(payload["old_display_name"], old_display_name)
        self.assertEqual(payload["display_name"], new_display_name)
예제 #19
0
    def test_send_versioned_action_initiator_update(self):
        notifications.send_update(self.context, self.instance, self.instance)
        action_initiator_user = self.context.user_id
        action_initiator_project = self.context.project_id
        self.assertEqual(1, len(fake_notifier.VERSIONED_NOTIFICATIONS))

        self.assertEqual(
            action_initiator_user, fake_notifier.VERSIONED_NOTIFICATIONS[0]
            ['payload']['nova_object.data']['action_initiator_user'])
        self.assertEqual(
            action_initiator_project, fake_notifier.VERSIONED_NOTIFICATIONS[0]
            ['payload']['nova_object.data']['action_initiator_project'])
예제 #20
0
    def test_send_name_update(self):
        param = {"display_name": "new_display_name"}
        new_name_inst = self._wrapped_create(params=param)
        notifications.send_update(self.context, self.instance, new_name_inst)
        self.assertEqual(1, len(fake_notifier.NOTIFICATIONS))
        notif = fake_notifier.NOTIFICATIONS[0]
        payload = notif.payload
        old_display_name = self.instance.display_name
        new_display_name = new_name_inst.display_name

        self.assertEqual(payload["old_display_name"], old_display_name)
        self.assertEqual(payload["display_name"], new_display_name)
예제 #21
0
    def test_send_versioned_action_initiator_update(self):
        notifications.send_update(self.context, self.instance, self.instance)
        action_initiator_user = self.context.user_id
        action_initiator_project = self.context.project_id
        self.assertEqual(1, len(self.notifier.versioned_notifications))

        self.assertEqual(
            action_initiator_user, self.notifier.versioned_notifications[0]
            ['payload']['nova_object.data']['action_initiator_user'])
        self.assertEqual(
            action_initiator_project, self.notifier.versioned_notifications[0]
            ['payload']['nova_object.data']['action_initiator_project'])
예제 #22
0
    def test_send_on_task_change(self):

        old = obj_base.obj_to_primitive(self.instance)
        old['task_state'] = None
        # pretend we just transitioned to task SPAWNING:
        self.instance.task_state = task_states.SPAWNING
        notifications.send_update(self.context, old, self.instance)

        self.assertEqual(1, len(self.notifier.notifications))
        self.assertEqual(1, len(self.notifier.versioned_notifications))
        self.assertEqual(
            'instance.update',
            self.notifier.versioned_notifications[0]['event_type'])
예제 #23
0
    def test_send_versioned_action_initiator_update(self):
        notifications.send_update(self.context, self.instance, self.instance)
        action_initiator_user = self.context.user_id
        action_initiator_project = self.context.project_id
        self.assertEqual(1, len(fake_notifier.VERSIONED_NOTIFICATIONS))

        self.assertEqual(action_initiator_user,
                         fake_notifier.VERSIONED_NOTIFICATIONS[0]
                         ['payload']['nova_object.data']
                         ['action_initiator_user'])
        self.assertEqual(action_initiator_project,
                         fake_notifier.VERSIONED_NOTIFICATIONS[0]
                         ['payload']['nova_object.data']
                         ['action_initiator_project'])
예제 #24
0
    def test_send_name_update(self):
        param = {"display_name": "new_display_name"}
        new_name_inst = self._wrapped_create(params=param)
        notifications.send_update(self.context, self.instance, new_name_inst)
        self.assertEqual(1, len(self.notifier.notifications))
        self.assertEqual(1, len(self.notifier.versioned_notifications))

        old_display_name = self.instance.display_name
        new_display_name = new_name_inst.display_name

        for payload in [
            self.notifier.notifications[0].payload,
            self.notifier.versioned_notifications[0][
                'payload']['nova_object.data']]:

            self.assertEqual(payload["old_display_name"], old_display_name)
            self.assertEqual(payload["display_name"], new_display_name)
예제 #25
0
    def test_send_name_update(self):
        param = {"display_name": "new_display_name"}
        new_name_inst = self._wrapped_create(params=param)
        notifications.send_update(self.context, self.instance, new_name_inst)
        self.assertEqual(1, len(fake_notifier.NOTIFICATIONS))
        self.assertEqual(1, len(fake_notifier.VERSIONED_NOTIFICATIONS))

        old_display_name = self.instance.display_name
        new_display_name = new_name_inst.display_name

        for payload in [
            fake_notifier.NOTIFICATIONS[0].payload,
            fake_notifier.VERSIONED_NOTIFICATIONS[0][
                'payload']['nova_object.data']]:

            self.assertEqual(payload["old_display_name"], old_display_name)
            self.assertEqual(payload["display_name"], new_display_name)
    def test_send_name_update(self):
        param = {"display_name": "new_display_name"}
        new_name_inst = self._wrapped_create(params=param)
        notifications.send_update(self.context, self.instance, new_name_inst)
        self.assertEqual(1, len(fake_notifier.NOTIFICATIONS))
        self.assertEqual(1, len(fake_notifier.VERSIONED_NOTIFICATIONS))

        old_display_name = self.instance.display_name
        new_display_name = new_name_inst.display_name

        for payload in [
            fake_notifier.NOTIFICATIONS[0].payload,
            fake_notifier.VERSIONED_NOTIFICATIONS[0][
                'payload']['nova_object.data']]:

            self.assertEqual(payload["old_display_name"], old_display_name)
            self.assertEqual(payload["display_name"], new_display_name)
예제 #27
0
    def test_notif_disabled(self):

        # test config disable of the notifications
        self.flags(notify_on_state_change=None)

        old = copy.copy(self.instance)
        self.instance.vm_state = vm_states.ACTIVE

        old_vm_state = old['vm_state']
        new_vm_state = self.instance.vm_state
        old_task_state = old['task_state']
        new_task_state = self.instance.task_state

        notifications.send_update_with_states(self.context, self.instance,
                old_vm_state, new_vm_state, old_task_state, new_task_state,
                verify_states=True)

        notifications.send_update(self.context, old, self.instance)
        self.assertEqual(0, len(fake_notifier.NOTIFICATIONS))
예제 #28
0
    def test_send_on_vm_change(self):
        old = obj_base.obj_to_primitive(self.instance)
        old['vm_state'] = None
        # pretend we just transitioned to ACTIVE:
        self.instance.vm_state = vm_states.ACTIVE
        notifications.send_update(self.context, old, self.instance)

        self.assertEqual(1, len(self.notifier.notifications))
        # service name should default to 'compute'
        notif = self.notifier.notifications[0]
        self.assertEqual('compute.testhost', notif.publisher_id)

        self.assertEqual(1, len(self.notifier.versioned_notifications))
        self.assertEqual(
            'nova-compute:testhost',
            self.notifier.versioned_notifications[0]['publisher_id'])
        self.assertEqual(
            'instance.update',
            self.notifier.versioned_notifications[0]['event_type'])
    def test_notif_disabled(self):

        # test config disable of the notifications
        self.flags(notify_on_state_change=None, group='notifications')

        old = copy.copy(self.instance)
        self.instance.vm_state = vm_states.ACTIVE

        old_vm_state = old['vm_state']
        new_vm_state = self.instance.vm_state
        old_task_state = old['task_state']
        new_task_state = self.instance.task_state

        notifications.send_update_with_states(self.context, self.instance,
                old_vm_state, new_vm_state, old_task_state, new_task_state,
                verify_states=True)

        notifications.send_update(self.context, old, self.instance)
        self.assertEqual(0, len(fake_notifier.NOTIFICATIONS))
        self.assertEqual(0, len(fake_notifier.VERSIONED_NOTIFICATIONS))