def test_emit_notification(self, provision_mock):
     provision_mock.__name__ = 'NodeSetProvisionStateNotification'
     self.config(host='fake-host')
     node = obj_utils.get_test_node(self.context,
                                    provision_state='fake state',
                                    target_provision_state='fake target',
                                    instance_info={'foo': 'baz'})
     task = mock.Mock(spec=task_manager.TaskManager)
     task.node = node
     test_level = fields.NotificationLevel.INFO
     test_status = fields.NotificationStatus.SUCCESS
     notif_utils.emit_provision_set_notification(
         task, test_level, test_status, 'fake_old',
         'fake_old_target', 'event')
     init_kwargs = provision_mock.call_args[1]
     publisher = init_kwargs['publisher']
     event_type = init_kwargs['event_type']
     level = init_kwargs['level']
     payload = init_kwargs['payload']
     self.assertEqual('fake-host', publisher.host)
     self.assertEqual('ironic-conductor', publisher.service)
     self.assertEqual('node', event_type.object)
     self.assertEqual('provision_set', event_type.action)
     self.assertEqual(test_status, event_type.status)
     self.assertEqual(test_level, level)
     self.assertEqual(node.uuid, payload.uuid)
     self.assertEqual('fake state', payload.provision_state)
     self.assertEqual('fake target', payload.target_provision_state)
     self.assertEqual('fake_old', payload.previous_provision_state)
     self.assertEqual('fake_old_target',
                      payload.previous_target_provision_state)
     self.assertEqual({'foo': 'baz'}, payload.instance_info)
 def test_emit_notification(self, provision_mock):
     provision_mock.__name__ = 'NodeSetProvisionStateNotification'
     self.config(host='fake-host')
     node = obj_utils.get_test_node(self.context,
                                    provision_state='fake state',
                                    target_provision_state='fake target',
                                    instance_info={'foo': 'baz'})
     task = mock.Mock(spec=task_manager.TaskManager)
     task.node = node
     test_level = fields.NotificationLevel.INFO
     test_status = fields.NotificationStatus.SUCCESS
     notif_utils.emit_provision_set_notification(
         task, test_level, test_status, 'fake_old',
         'fake_old_target', 'event')
     init_kwargs = provision_mock.call_args[1]
     publisher = init_kwargs['publisher']
     event_type = init_kwargs['event_type']
     level = init_kwargs['level']
     payload = init_kwargs['payload']
     self.assertEqual('fake-host', publisher.host)
     self.assertEqual('ironic-conductor', publisher.service)
     self.assertEqual('node', event_type.object)
     self.assertEqual('provision_set', event_type.action)
     self.assertEqual(test_status, event_type.status)
     self.assertEqual(test_level, level)
     self.assertEqual(node.uuid, payload.uuid)
     self.assertEqual('fake state', payload.provision_state)
     self.assertEqual('fake target', payload.target_provision_state)
     self.assertEqual('fake_old', payload.previous_provision_state)
     self.assertEqual('fake_old_target',
                      payload.previous_target_provision_state)
     self.assertEqual({'foo': 'baz'}, payload.instance_info)
示例#3
0
    def _notify_provision_state_change(self):
        """Emit notification about change of the node provision state."""
        if self._event is None:
            return

        if self.node is None:
            # Rare case if resource released before notification
            task = copy.copy(self)
            task.fsm = states.machine.copy()
            task.node = self._saved_node
        else:
            task = self

        node = task.node

        state = node.provision_state
        prev_state = self._prev_provision_state
        new_unstable = state in states.UNSTABLE_STATES
        prev_unstable = prev_state in states.UNSTABLE_STATES
        level = fields.NotificationLevel.INFO

        if self._event in ('fail', 'error'):
            status = fields.NotificationStatus.ERROR
            level = fields.NotificationLevel.ERROR
        elif (prev_unstable, new_unstable) == (False, True):
            status = fields.NotificationStatus.START
        elif (prev_unstable, new_unstable) == (True, False):
            status = fields.NotificationStatus.END
        else:
            status = fields.NotificationStatus.SUCCESS

        notify.emit_provision_set_notification(
            task, level, status, self._prev_provision_state,
            self._prev_target_provision_state, self._event)

        # reset saved event, avoiding duplicate notification
        self._event = None