Example #1
0
 def _set_vm_state(context, instance, ex, vm_state=None,
                   task_state=None):
     request_spec = {'instance_properties': {
         'uuid': instance['uuid'], },
     }
     scheduler_utils.set_vm_state_and_notify(context,
         instance.uuid,
         'compute_task', 'migrate_server',
         dict(vm_state=vm_state,
              task_state=task_state,
              expected_task_state=task_states.MIGRATING,),
         ex, request_spec, self.db)
Example #2
0
 def _set_vm_state(context, instance, ex, vm_state=None, task_state=None):
     request_spec = {"instance_properties": {"uuid": instance["uuid"]}}
     scheduler_utils.set_vm_state_and_notify(
         context,
         instance.uuid,
         "compute_task",
         "migrate_server",
         dict(vm_state=vm_state, task_state=task_state, expected_task_state=task_states.MIGRATING),
         ex,
         request_spec,
         self.db,
     )
Example #3
0
    def test_set_vm_state_and_notify(self):
        expected_uuid = 'fake-uuid'
        request_spec = dict(instance_properties=dict(uuid='other-uuid'))
        updates = dict(vm_state='fake-vm-state')
        service = 'fake-service'
        method = 'fake-method'
        exc_info = 'exc_info'

        self.mox.StubOutWithMock(compute_utils,
                                 'add_instance_fault_from_exc')
        self.mox.StubOutWithMock(notifications, 'send_update')
        self.mox.StubOutWithMock(db, 'instance_update_and_get_original')

        self.mox.StubOutWithMock(rpc, 'get_notifier')
        notifier = self.mox.CreateMockAnything()
        rpc.get_notifier(service).AndReturn(notifier)

        old_ref = 'old_ref'
        new_ref = 'new_ref'
        inst_obj = 'inst_obj'

        db.instance_update_and_get_original(
            self.context, expected_uuid, updates,
            columns_to_join=['system_metadata']).AndReturn((old_ref, new_ref))
        notifications.send_update(self.context, old_ref, inst_obj,
                                  service=service)
        compute_utils.add_instance_fault_from_exc(
                self.context,
                inst_obj, exc_info, mox.IsA(tuple))

        payload = dict(request_spec=request_spec,
                       instance_properties=request_spec.get(
                           'instance_properties', {}),
                       instance_id=expected_uuid,
                       state='fake-vm-state',
                       method=method,
                       reason=exc_info)
        event_type = '%s.%s' % (service, method)
        notifier.error(self.context, event_type, payload)

        self.mox.ReplayAll()

        with mock.patch.object(objects.Instance, '_from_db_object',
                               return_value=inst_obj):
            scheduler_utils.set_vm_state_and_notify(self.context,
                                                    expected_uuid,
                                                    service,
                                                    method,
                                                    updates,
                                                    exc_info,
                                                    request_spec,
                                                    db)
    def test_set_vm_state_and_notify(self):
        expected_uuid = 'fake-uuid'
        request_spec = dict(instance_properties=dict(uuid='other-uuid'))
        updates = dict(vm_state='fake-vm-state')
        service = 'fake-service'
        method = 'fake-method'
        exc_info = 'exc_info'

        self.mox.StubOutWithMock(compute_utils, 'add_instance_fault_from_exc')
        self.mox.StubOutWithMock(notifications, 'send_update')
        self.mox.StubOutWithMock(db, 'instance_update_and_get_original')

        self.mox.StubOutWithMock(rpc, 'get_notifier')
        notifier = self.mox.CreateMockAnything()
        rpc.get_notifier(service).AndReturn(notifier)

        old_ref = 'old_ref'
        new_ref = 'new_ref'
        inst_obj = 'inst_obj'

        db.instance_update_and_get_original(
            self.context,
            expected_uuid,
            updates,
            columns_to_join=['system_metadata']).AndReturn((old_ref, new_ref))
        notifications.send_update(self.context,
                                  old_ref,
                                  inst_obj,
                                  service=service)
        compute_utils.add_instance_fault_from_exc(self.context, inst_obj,
                                                  exc_info, mox.IsA(tuple))

        payload = dict(request_spec=request_spec,
                       instance_properties=request_spec.get(
                           'instance_properties', {}),
                       instance_id=expected_uuid,
                       state='fake-vm-state',
                       method=method,
                       reason=exc_info)
        event_type = '%s.%s' % (service, method)
        notifier.error(self.context, event_type, payload)

        self.mox.ReplayAll()

        with mock.patch.object(objects.Instance,
                               '_from_db_object',
                               return_value=inst_obj):
            scheduler_utils.set_vm_state_and_notify(self.context,
                                                    expected_uuid, service,
                                                    method, updates, exc_info,
                                                    request_spec, db)
Example #5
0
 def _set_vm_state_and_notify(self, context, instance_uuid, method, updates,
                              ex, request_spec):
     scheduler_utils.set_vm_state_and_notify(
             context, instance_uuid, 'compute_task', method, updates,
             ex, request_spec, self.db)
Example #6
0
 def _set_vm_state_and_notify(self, context, instance_uuid, method, updates, ex, request_spec):
     scheduler_utils.set_vm_state_and_notify(
         context, instance_uuid, "compute_task", method, updates, ex, request_spec, self.db
     )