Esempio n. 1
0
    def schedule_prep_resize(self, context, request_spec, *args, **kwargs):
        """Select a target for resize.

        Selects a target host for the instance, post-resize, and casts
        the prep_resize operation to it.
        """

        # We need the new instance type ID...
        instance_type_id = kwargs["instance_type_id"]

        elevated = context.elevated()
        LOG.debug(
            _("Attempting to determine target host for resize to " "instance type %(instance_type_id)s") % locals()
        )

        # Convert it to an actual instance type
        instance_type = db.instance_type_get(elevated, instance_type_id)

        # Now let's grab a possibility
        hosts = self._schedule(elevated, "compute", request_spec, *args, **kwargs)
        if not hosts:
            raise exception.NoValidHost(reason=_(""))
        host = hosts.pop(0)

        # Forward off to the host
        driver.cast_to_compute_host(context, host.host_state.host, "prep_resize", **kwargs)
Esempio n. 2
0
 def _provision_resource_locally(self, context, weighted_host, request_spec,
                                 kwargs):
     """Create the requested resource in this Zone."""
     instance = self.create_instance_db_entry(context, request_spec)
     driver.cast_to_compute_host(context, weighted_host.host,
             'run_instance', instance_uuid=instance['uuid'], **kwargs)
     return driver.encode_instance(instance, local=True)
Esempio n. 3
0
    def test_live_migration_basic(self):
        """Test basic schedule_live_migration functionality"""
        self.mox.StubOutWithMock(db, 'instance_get')
        self.mox.StubOutWithMock(self.driver, '_live_migration_src_check')
        self.mox.StubOutWithMock(self.driver, '_live_migration_dest_check')
        self.mox.StubOutWithMock(self.driver, '_live_migration_common_check')
        self.mox.StubOutWithMock(db, 'instance_update_and_get_original')
        self.mox.StubOutWithMock(driver, 'cast_to_compute_host')

        dest = 'fake_host2'
        block_migration = False
        disk_over_commit = False
        instance = self._live_migration_instance()
        db.instance_get(self.context, instance['id']).AndReturn(instance)

        self.driver._live_migration_src_check(self.context, instance)
        self.driver._live_migration_dest_check(self.context, instance,
                dest, block_migration, disk_over_commit)
        self.driver._live_migration_common_check(self.context, instance,
                dest, block_migration, disk_over_commit)
        db.instance_update_and_get_original(self.context, instance['id'],
                {"task_state": task_states.MIGRATING}).AndReturn(
                        (instance, instance))

        driver.cast_to_compute_host(self.context, instance['host'],
                'live_migration', update_db=False,
                instance_id=instance['id'], dest=dest,
                block_migration=block_migration)

        self.mox.ReplayAll()
        self.driver.schedule_live_migration(self.context,
                instance_id=instance['id'], dest=dest,
                block_migration=block_migration,
                disk_over_commit=disk_over_commit)
Esempio n. 4
0
    def test_live_migration_basic(self):
        """Test basic schedule_live_migration functionality"""
        self.mox.StubOutWithMock(db, 'instance_get')
        self.mox.StubOutWithMock(self.driver, '_live_migration_src_check')
        self.mox.StubOutWithMock(self.driver, '_live_migration_dest_check')
        self.mox.StubOutWithMock(self.driver, '_live_migration_common_check')
        self.mox.StubOutWithMock(db, 'instance_update_and_get_original')
        self.mox.StubOutWithMock(driver, 'cast_to_compute_host')

        dest = 'fake_host2'
        block_migration = False
        disk_over_commit = False
        instance = self._live_migration_instance()
        db.instance_get(self.context, instance['id']).AndReturn(instance)

        self.driver._live_migration_src_check(self.context, instance)
        self.driver._live_migration_dest_check(self.context, instance,
                dest, block_migration, disk_over_commit)
        self.driver._live_migration_common_check(self.context, instance,
                dest, block_migration, disk_over_commit)
        db.instance_update_and_get_original(self.context, instance['id'],
                {"vm_state": vm_states.MIGRATING}).AndReturn(
                        (instance, instance))

        driver.cast_to_compute_host(self.context, instance['host'],
                'live_migration', update_db=False,
                instance_id=instance['id'], dest=dest,
                block_migration=block_migration)

        self.mox.ReplayAll()
        self.driver.schedule_live_migration(self.context,
                instance_id=instance['id'], dest=dest,
                block_migration=block_migration,
                disk_over_commit=disk_over_commit)
Esempio n. 5
0
    def _provision_resource(self, context, weighted_host, request_spec,
                            reservations, filter_properties, kwargs):
        """Create the requested resource in this Zone."""
        instance = self.create_instance_db_entry(context, request_spec,
                                                 reservations)

        # Add a retry entry for the selected compute host:
        self._add_retry_host(filter_properties, weighted_host.host_state.host)

        payload = dict(request_spec=request_spec,
                       weighted_host=weighted_host.to_dict(),
                       instance_id=instance['uuid'])
        notifier.notify(context, notifier.publisher_id("scheduler"),
                        'scheduler.run_instance.scheduled', notifier.INFO,
                        payload)

        driver.cast_to_compute_host(context,
                                    weighted_host.host_state.host,
                                    'run_instance',
                                    instance_uuid=instance['uuid'],
                                    request_spec=request_spec,
                                    filter_properties=filter_properties,
                                    **kwargs)
        inst = driver.encode_instance(instance, local=True)

        # So if another instance is created, create_instance_db_entry will
        # actually create a new entry, instead of assume it's been created
        # already
        del request_spec['instance_properties']['uuid']

        return inst
Esempio n. 6
0
    def schedule_prep_resize(self, context, request_spec, *args, **kwargs):
        """Select a target for resize.

        Selects a target host for the instance, post-resize, and casts
        the prep_resize operation to it.
        """

        # We need the new instance type ID...
        instance_type_id = kwargs['instance_type_id']

        elevated = context.elevated()
        LOG.debug(_("Attempting to determine target host for resize to "
                    "instance type %(instance_type_id)s") % locals())

        # Convert it to an actual instance type
        instance_type = db.instance_type_get(elevated, instance_type_id)

        # Now let's grab a possibility
        hosts = self._schedule(context, 'compute', request_spec,
                               *args, **kwargs)
        if not hosts:
            raise exception.NoValidHost(reason=_(""))
        host = hosts.pop(0)

        # NOTE(comstud): Make sure we do not pass this through.  It
        # contains an instance of RpcContext that cannot be serialized.
        kwargs.pop('filter_properties', None)

        # Forward off to the host
        driver.cast_to_compute_host(context, host.host_state.host,
                'prep_resize', **kwargs)
Esempio n. 7
0
    def schedule_prep_resize(self, context, request_spec, *args, **kwargs):
        """Select a target for resize.

        Selects a target host for the instance, post-resize, and casts
        the prep_resize operation to it.
        """

        # We need the new instance type ID...
        instance_type_id = kwargs['instance_type_id']

        elevated = context.elevated()
        LOG.debug(
            _("Attempting to determine target host for resize to "
              "instance type %(instance_type_id)s") % locals())

        # Convert it to an actual instance type
        instance_type = db.instance_type_get(elevated, instance_type_id)

        # Now let's grab a possibility
        hosts = self._schedule(context, 'compute', request_spec, *args,
                               **kwargs)
        if not hosts:
            raise exception.NoValidHost(reason=_(""))
        host = hosts.pop(0)

        # Forward off to the host
        driver.cast_to_compute_host(context, host.host_state.host,
                                    'prep_resize', **kwargs)
Esempio n. 8
0
    def _provision_resource(self, context, weighted_host, request_spec,
            reservations, filter_properties, kwargs):
        """Create the requested resource in this Zone."""
        instance = self.create_instance_db_entry(context, request_spec,
                                                 reservations)

        # Add a retry entry for the selected compute host:
        self._add_retry_host(filter_properties, weighted_host.host_state.host)

        payload = dict(request_spec=request_spec,
                       weighted_host=weighted_host.to_dict(),
                       instance_id=instance['uuid'])
        notifier.notify(context, notifier.publisher_id("scheduler"),
                        'scheduler.run_instance.scheduled', notifier.INFO,
                        payload)

        driver.cast_to_compute_host(context, weighted_host.host_state.host,
                'run_instance', instance_uuid=instance['uuid'],
                request_spec=request_spec, filter_properties=filter_properties,
                **kwargs)
        inst = driver.encode_instance(instance, local=True)

        # So if another instance is created, create_instance_db_entry will
        # actually create a new entry, instead of assume it's been created
        # already
        del request_spec['instance_properties']['uuid']

        return inst
 def _provision_resource_locally(self, context, build_plan_item,
         request_spec, kwargs):
     """Create the requested resource in this Zone."""
     host = build_plan_item['hostname']
     instance = self.create_instance_db_entry(context, request_spec)
     driver.cast_to_compute_host(context, host,
             'run_instance', instance_id=instance['id'], **kwargs)
     return driver.encode_instance(instance, local=True)
    def test_scheduler_includes_launch_index(self):
        ctxt = "fake-context"
        instance_opts = {'fake_opt1': 'meow'}
        request_spec = {
            'num_instances': 2,
            'instance_properties': instance_opts
        }
        instance1 = {'uuid': 'fake-uuid1'}
        instance2 = {'uuid': 'fake-uuid2'}

        # create_instance_db_entry() usually does this, but we're
        # stubbing it.
        def _add_uuid(num):
            """Return a function that adds the provided uuid number."""
            def _add_uuid_num(_, spec):
                spec['instance_properties']['uuid'] = 'fake-uuid%d' % num

            return _add_uuid_num

        def _has_launch_index(expected_index):
            """Return a function that verifies the expected index."""
            def _check_launch_index(value):
                if 'instance_properties' in value:
                    if 'launch_index' in value['instance_properties']:
                        index = value['instance_properties']['launch_index']
                        if index == expected_index:
                            return True
                return False

            return _check_launch_index

        self.mox.StubOutWithMock(self.driver, '_schedule')
        self.mox.StubOutWithMock(self.driver, 'create_instance_db_entry')
        self.mox.StubOutWithMock(driver, 'cast_to_compute_host')
        self.mox.StubOutWithMock(driver, 'encode_instance')
        # instance 1
        self.driver._schedule(ctxt, 'compute', request_spec).AndReturn('host')
        self.driver.create_instance_db_entry(
            ctxt, mox.Func(_has_launch_index(0))).WithSideEffects(
                _add_uuid(1)).AndReturn(instance1)
        driver.cast_to_compute_host(ctxt,
                                    'host',
                                    'run_instance',
                                    instance_uuid=instance1['uuid'])
        driver.encode_instance(instance1).AndReturn(instance1)
        # instance 2
        self.driver._schedule(ctxt, 'compute', request_spec).AndReturn('host')
        self.driver.create_instance_db_entry(
            ctxt, mox.Func(_has_launch_index(1))).WithSideEffects(
                _add_uuid(2)).AndReturn(instance2)
        driver.cast_to_compute_host(ctxt,
                                    'host',
                                    'run_instance',
                                    instance_uuid=instance2['uuid'])
        driver.encode_instance(instance2).AndReturn(instance2)
        self.mox.ReplayAll()

        self.driver.schedule_run_instance(ctxt, request_spec)
Esempio n. 11
0
    def test_basic_schedule_run_instance(self):
        ctxt = context.RequestContext('fake', 'fake', False)
        ctxt_elevated = 'fake-context-elevated'
        fake_args = (1, 2, 3)
        fake_kwargs = {'fake_kwarg1': 'fake_value1',
                       'fake_kwarg2': 'fake_value2'}
        instance_opts = {'fake_opt1': 'meow'}
        request_spec = {'num_instances': 2,
                        'instance_properties': instance_opts}
        instance1 = {'uuid': 'fake-uuid1'}
        instance2 = {'uuid': 'fake-uuid2'}
        instance1_encoded = {'uuid': 'fake-uuid1', '_is_precooked': False}
        instance2_encoded = {'uuid': 'fake-uuid2', '_is_precooked': False}
        reservations = ['resv1', 'resv2']

        # create_instance_db_entry() usually does this, but we're
        # stubbing it.
        def _add_uuid1(ctxt, request_spec, reservations):
            request_spec['instance_properties']['uuid'] = 'fake-uuid1'

        def _add_uuid2(ctxt, request_spec, reservations):
            request_spec['instance_properties']['uuid'] = 'fake-uuid2'

        self.mox.StubOutWithMock(ctxt, 'elevated')
        self.mox.StubOutWithMock(self.driver, 'hosts_up')
        self.mox.StubOutWithMock(random, 'random')
        self.mox.StubOutWithMock(self.driver, 'create_instance_db_entry')
        self.mox.StubOutWithMock(driver, 'cast_to_compute_host')
        self.mox.StubOutWithMock(driver, 'encode_instance')

        ctxt.elevated().AndReturn(ctxt_elevated)
        # instance 1
        self.driver.hosts_up(ctxt_elevated, 'compute').AndReturn(
                ['host1', 'host2', 'host3', 'host4'])
        random.random().AndReturn(.5)
        self.driver.create_instance_db_entry(ctxt, request_spec,
                reservations).WithSideEffects(_add_uuid1).AndReturn(
                instance1)
        driver.cast_to_compute_host(ctxt, 'host3', 'run_instance',
                instance_uuid=instance1['uuid'], **fake_kwargs)
        driver.encode_instance(instance1).AndReturn(instance1_encoded)
        # instance 2
        ctxt.elevated().AndReturn(ctxt_elevated)
        self.driver.hosts_up(ctxt_elevated, 'compute').AndReturn(
                ['host1', 'host2', 'host3', 'host4'])
        random.random().AndReturn(.2)
        self.driver.create_instance_db_entry(ctxt, request_spec,
                reservations).WithSideEffects(_add_uuid2).AndReturn(
                instance2)
        driver.cast_to_compute_host(ctxt, 'host1', 'run_instance',
                instance_uuid=instance2['uuid'], **fake_kwargs)
        driver.encode_instance(instance2).AndReturn(instance2_encoded)

        self.mox.ReplayAll()
        result = self.driver.schedule_run_instance(ctxt, request_spec,
                reservations, *fake_args, **fake_kwargs)
        expected = [instance1_encoded, instance2_encoded]
        self.assertEqual(result, expected)
Esempio n. 12
0
    def test_basic_schedule_run_instance(self):
        ctxt = context.RequestContext('fake', 'fake', False)
        ctxt_elevated = 'fake-context-elevated'
        fake_args = (1, 2, 3)
        fake_kwargs = {'fake_kwarg1': 'fake_value1',
                       'fake_kwarg2': 'fake_value2'}
        instance_opts = {'fake_opt1': 'meow'}
        request_spec = {'num_instances': 2,
                        'instance_properties': instance_opts}
        instance1 = {'uuid': 'fake-uuid1'}
        instance2 = {'uuid': 'fake-uuid2'}
        instance1_encoded = {'uuid': 'fake-uuid1', '_is_precooked': False}
        instance2_encoded = {'uuid': 'fake-uuid2', '_is_precooked': False}

        # create_instance_db_entry() usually does this, but we're
        # stubbing it.
        def _add_uuid1(ctxt, request_spec):
            request_spec['instance_properties']['uuid'] = 'fake-uuid1'

        def _add_uuid2(ctxt, request_spec):
            request_spec['instance_properties']['uuid'] = 'fake-uuid2'

        self.mox.StubOutWithMock(ctxt, 'elevated')
        self.mox.StubOutWithMock(self.driver, 'hosts_up')
        self.mox.StubOutWithMock(random, 'random')
        self.mox.StubOutWithMock(self.driver, 'create_instance_db_entry')
        self.mox.StubOutWithMock(driver, 'cast_to_compute_host')
        self.mox.StubOutWithMock(driver, 'encode_instance')

        ctxt.elevated().AndReturn(ctxt_elevated)
        # instance 1
        self.driver.hosts_up(ctxt_elevated, 'compute').AndReturn(
                ['host1', 'host2', 'host3', 'host4'])
        random.random().AndReturn(.5)
        self.driver.create_instance_db_entry(ctxt,
                request_spec).WithSideEffects(_add_uuid1).AndReturn(
                instance1)
        driver.cast_to_compute_host(ctxt, 'host3', 'run_instance',
                instance_uuid=instance1['uuid'], **fake_kwargs)
        driver.encode_instance(instance1).AndReturn(instance1_encoded)
        # instance 2
        ctxt.elevated().AndReturn(ctxt_elevated)
        self.driver.hosts_up(ctxt_elevated, 'compute').AndReturn(
                ['host1', 'host2', 'host3', 'host4'])
        random.random().AndReturn(.2)
        self.driver.create_instance_db_entry(ctxt,
                request_spec).WithSideEffects(_add_uuid2).AndReturn(
                instance2)
        driver.cast_to_compute_host(ctxt, 'host1', 'run_instance',
                instance_uuid=instance2['uuid'], **fake_kwargs)
        driver.encode_instance(instance2).AndReturn(instance2_encoded)

        self.mox.ReplayAll()
        result = self.driver.schedule_run_instance(ctxt, request_spec,
                *fake_args, **fake_kwargs)
        expected = [instance1_encoded, instance2_encoded]
        self.assertEqual(result, expected)
Esempio n. 13
0
 def schedule_start_instance(self, context, instance_id, *_args, **_kwargs):
     instance_ref = db.instance_get(context, instance_id)
     host = self._schedule_instance(context, instance_ref, *_args,
                                    **_kwargs)
     driver.cast_to_compute_host(context,
                                 host,
                                 'start_instance',
                                 instance_id=instance_id,
                                 **_kwargs)
Esempio n. 14
0
 def schedule_run_instance(self, context, request_spec, *_args, **_kwargs):
     num_instances = request_spec.get("num_instances", 1)
     instances = []
     for num in xrange(num_instances):
         host = self._schedule_instance(context, request_spec["instance_properties"], *_args, **_kwargs)
         instance_ref = self.create_instance_db_entry(context, request_spec)
         driver.cast_to_compute_host(context, host, "run_instance", instance_id=instance_ref["id"], **_kwargs)
         instances.append(driver.encode_instance(instance_ref))
     return instances
Esempio n. 15
0
    def test_cast_to_host_compute_topic(self):
        host = "fake_host1"
        method = "fake_method"
        fake_kwargs = {"extra_arg": "meow"}

        self.mox.StubOutWithMock(driver, "cast_to_compute_host")
        driver.cast_to_compute_host(self.context, host, method, **fake_kwargs)

        self.mox.ReplayAll()
        driver.cast_to_host(self.context, "compute", host, method, **fake_kwargs)
Esempio n. 16
0
    def test_cast_to_host_compute_topic(self):
        host = 'fake_host1'
        method = 'fake_method'
        fake_kwargs = {'extra_arg': 'meow'}

        self.mox.StubOutWithMock(driver, 'cast_to_compute_host')
        driver.cast_to_compute_host(self.context, host, method, **fake_kwargs)

        self.mox.ReplayAll()
        driver.cast_to_host(self.context, 'compute', host, method,
                            **fake_kwargs)
Esempio n. 17
0
File: zone.py Progetto: Oneiroi/nova
 def schedule_run_instance(self, context, request_spec, *_args, **kwargs):
     """Builds and starts instances on selected hosts"""
     num_instances = request_spec.get('num_instances', 1)
     instances = []
     for num in xrange(num_instances):
         host = self._schedule(context, 'compute', request_spec, **kwargs)
         instance = self.create_instance_db_entry(context, request_spec)
         driver.cast_to_compute_host(context, host,
                 'run_instance', instance_id=instance['id'], **kwargs)
         instances.append(driver.encode_instance(instance))
     return instances
Esempio n. 18
0
 def _provision_resource_locally(self, context, weighted_host, request_spec, kwargs):
     """Create the requested resource in this Zone."""
     instance = self.create_instance_db_entry(context, request_spec)
     driver.cast_to_compute_host(
         context, weighted_host.host, "run_instance", instance_uuid=instance["uuid"], **kwargs
     )
     inst = driver.encode_instance(instance, local=True)
     # So if another instance is created, create_instance_db_entry will
     # actually create a new entry, instead of assume it's been created
     # already
     del request_spec["instance_properties"]["uuid"]
     return inst
Esempio n. 19
0
 def schedule_run_instance(self, context, request_spec, *_args, **_kwargs):
     num_instances = request_spec.get('num_instances', 1)
     instances = []
     for num in xrange(num_instances):
         host = self._schedule_instance(context,
                 request_spec['instance_properties'], *_args, **_kwargs)
         instance_ref = self.create_instance_db_entry(context,
                 request_spec)
         driver.cast_to_compute_host(context, host, 'run_instance',
                 instance_uuid=instance_ref['uuid'], **_kwargs)
         instances.append(driver.encode_instance(instance_ref))
     return instances
Esempio n. 20
0
    def schedule_run_instance(self, context, request_spec, *_args, **kwargs):
        """Create and run an instance or instances"""
        elevated = context.elevated()
        num_instances = request_spec.get("num_instances", 1)
        instances = []
        for num in xrange(num_instances):
            host = self._schedule(context, "compute", **kwargs)
            instance = self.create_instance_db_entry(elevated, request_spec)
            driver.cast_to_compute_host(context, host, "run_instance", instance_id=instance["id"], **kwargs)
            instances.append(driver.encode_instance(instance))

        return instances
Esempio n. 21
0
    def test_cast_to_host_compute_topic(self):
        host = 'fake_host1'
        method = 'fake_method'
        fake_kwargs = {'extra_arg': 'meow'}

        self.mox.StubOutWithMock(driver, 'cast_to_compute_host')
        driver.cast_to_compute_host(self.context, host, method,
                update_db=False, **fake_kwargs)

        self.mox.ReplayAll()
        driver.cast_to_host(self.context, 'compute', host, method,
                update_db=False, **fake_kwargs)
Esempio n. 22
0
 def _provision_resource_locally(self, context, weighted_host, request_spec,
                                 kwargs):
     """Create the requested resource in this Zone."""
     instance = self.create_instance_db_entry(context, request_spec)
     driver.cast_to_compute_host(context, weighted_host.host,
             'run_instance', instance_uuid=instance['uuid'], **kwargs)
     inst = driver.encode_instance(instance, local=True)
     # So if another instance is created, create_instance_db_entry will
     # actually create a new entry, instead of assume it's been created
     # already
     del request_spec['instance_properties']['uuid']
     return inst
Esempio n. 23
0
    def test_cast_to_compute_host_update_db_without_instance_uuid(self):
        host = 'fake_host1'
        method = 'fake_method'
        fake_kwargs = {'extra_arg': 'meow'}
        queue = 'fake_queue'

        self.mox.StubOutWithMock(rpc, 'queue_get_for')
        self.mox.StubOutWithMock(rpc, 'cast')

        rpc.queue_get_for(self.context, 'compute', host).AndReturn(queue)
        rpc.cast(self.context, queue, {'method': method, 'args': fake_kwargs})

        self.mox.ReplayAll()
        driver.cast_to_compute_host(self.context, host, method, **fake_kwargs)
Esempio n. 24
0
    def test_cast_to_compute_host_update_db_without_instance_uuid(self):
        host = "fake_host1"
        method = "fake_method"
        fake_kwargs = {"extra_arg": "meow"}
        queue = "fake_queue"

        self.mox.StubOutWithMock(rpc, "queue_get_for")
        self.mox.StubOutWithMock(rpc, "cast")

        rpc.queue_get_for(self.context, "compute", host).AndReturn(queue)
        rpc.cast(self.context, queue, {"method": method, "args": fake_kwargs})

        self.mox.ReplayAll()
        driver.cast_to_compute_host(self.context, host, method, **fake_kwargs)
Esempio n. 25
0
    def test_scheduler_includes_launch_index(self):
        ctxt = "fake-context"
        instance_opts = {'fake_opt1': 'meow'}
        request_spec = {'num_instances': 2,
                        'instance_properties': instance_opts}
        instance1 = {'uuid': 'fake-uuid1'}
        instance2 = {'uuid': 'fake-uuid2'}

        # create_instance_db_entry() usually does this, but we're
        # stubbing it.
        def _add_uuid(num):
            """Return a function that adds the provided uuid number."""
            def _add_uuid_num(_, spec, reservations):
                spec['instance_properties']['uuid'] = 'fake-uuid%d' % num
            return _add_uuid_num

        def _has_launch_index(expected_index):
            """Return a function that verifies the expected index."""
            def _check_launch_index(value):
                if 'instance_properties' in value:
                    if 'launch_index' in value['instance_properties']:
                        index = value['instance_properties']['launch_index']
                        if index == expected_index:
                            return True
                return False
            return _check_launch_index

        self.mox.StubOutWithMock(self.driver, '_schedule')
        self.mox.StubOutWithMock(self.driver, 'create_instance_db_entry')
        self.mox.StubOutWithMock(driver, 'cast_to_compute_host')
        self.mox.StubOutWithMock(driver, 'encode_instance')
        # instance 1
        self.driver._schedule(ctxt, 'compute', request_spec).AndReturn('host')
        self.driver.create_instance_db_entry(
            ctxt, mox.Func(_has_launch_index(0)), None
            ).WithSideEffects(_add_uuid(1)).AndReturn(instance1)
        driver.cast_to_compute_host(ctxt, 'host', 'run_instance',
                                    instance_uuid=instance1['uuid'])
        driver.encode_instance(instance1).AndReturn(instance1)
        # instance 2
        self.driver._schedule(ctxt, 'compute', request_spec).AndReturn('host')
        self.driver.create_instance_db_entry(
            ctxt, mox.Func(_has_launch_index(1)), None
            ).WithSideEffects(_add_uuid(2)).AndReturn(instance2)
        driver.cast_to_compute_host(ctxt, 'host', 'run_instance',
                                    instance_uuid=instance2['uuid'])
        driver.encode_instance(instance2).AndReturn(instance2)
        self.mox.ReplayAll()

        self.driver.schedule_run_instance(ctxt, request_spec, None)
Esempio n. 26
0
 def schedule_run_instance(self, context, request_spec, *_args, **_kwargs):
     num_instances = request_spec.get("num_instances", 1)
     instances = []
     for num in xrange(num_instances):
         host = self._schedule_instance(context, request_spec["instance_properties"], *_args, **_kwargs)
         request_spec["instance_properties"]["launch_index"] = num
         instance_ref = self.create_instance_db_entry(context, request_spec)
         driver.cast_to_compute_host(context, host, "run_instance", instance_uuid=instance_ref["uuid"], **_kwargs)
         instances.append(driver.encode_instance(instance_ref))
         # So if we loop around, create_instance_db_entry will actually
         # create a new entry, instead of assume it's been created
         # already
         del request_spec["instance_properties"]["uuid"]
     return instances
Esempio n. 27
0
 def schedule_run_instance(self, context, request_spec, *_args, **kwargs):
     """Create and run an instance or instances"""
     num_instances = request_spec.get('num_instances', 1)
     instances = []
     for num in xrange(num_instances):
         host = self._schedule(context, 'compute', request_spec, **kwargs)
         instance = self.create_instance_db_entry(context, request_spec)
         driver.cast_to_compute_host(context, host,
                 'run_instance', instance_uuid=instance['uuid'], **kwargs)
         instances.append(driver.encode_instance(instance))
         # So if we loop around, create_instance_db_entry will actually
         # create a new entry, instead of assume it's been created
         # already
         del request_spec['instance_properties']['uuid']
     return instances
Esempio n. 28
0
    def schedule_run_instance(self, context, request_spec, *_args, **kwargs):
        """Create and run an instance or instances"""
        elevated = context.elevated()
        num_instances = request_spec.get('num_instances', 1)
        instances = []
        for num in xrange(num_instances):
            host = self._schedule(context, 'compute', request_spec, **kwargs)
            instance = self.create_instance_db_entry(elevated, request_spec)
            driver.cast_to_compute_host(context,
                                        host,
                                        'run_instance',
                                        instance_uuid=instance['uuid'],
                                        **kwargs)
            instances.append(driver.encode_instance(instance))

        return instances
Esempio n. 29
0
    def test_cast_to_compute_host_no_update_db(self):
        host = 'fake_host1'
        method = 'fake_method'
        fake_kwargs = {'extra_arg': 'meow'}
        queue = 'fake_queue'

        self.mox.StubOutWithMock(db, 'queue_get_for')
        self.mox.StubOutWithMock(rpc, 'cast')

        db.queue_get_for(self.context, 'compute', host).AndReturn(queue)
        rpc.cast(self.context, queue,
                {'method': method,
                 'args': fake_kwargs})

        self.mox.ReplayAll()
        driver.cast_to_compute_host(self.context, host, method,
                update_db=False, **fake_kwargs)
Esempio n. 30
0
 def schedule_run_instance(self, context, request_spec, *_args, **kwargs):
     """Create and run an instance or instances"""
     num_instances = request_spec.get('num_instances', 1)
     instances = []
     for num in xrange(num_instances):
         host = self._schedule(context, 'compute', request_spec, **kwargs)
         instance = self.create_instance_db_entry(context, request_spec)
         driver.cast_to_compute_host(context,
                                     host,
                                     'run_instance',
                                     instance_uuid=instance['uuid'],
                                     **kwargs)
         instances.append(driver.encode_instance(instance))
         # So if we loop around, create_instance_db_entry will actually
         # create a new entry, instead of assume it's been created
         # already
         del request_spec['instance_properties']['uuid']
     return instances
Esempio n. 31
0
 def schedule_run_instance(self, context, request_spec, reservations,
                           *_args, **_kwargs):
     num_instances = request_spec.get('num_instances', 1)
     instances = []
     for num in xrange(num_instances):
         host = self._schedule_instance(context,
                 request_spec['instance_properties'], *_args, **_kwargs)
         request_spec['instance_properties']['launch_index'] = num
         instance_ref = self.create_instance_db_entry(context,
                 request_spec, reservations)
         driver.cast_to_compute_host(context, host, 'run_instance',
                 instance_uuid=instance_ref['uuid'], **_kwargs)
         instances.append(driver.encode_instance(instance_ref))
         # So if we loop around, create_instance_db_entry will actually
         # create a new entry, instead of assume it's been created
         # already
         del request_spec['instance_properties']['uuid']
     return instances
Esempio n. 32
0
    def test_cast_to_compute_host_update_db_with_instance_uuid(self):
        host = "fake_host1"
        method = "fake_method"
        fake_kwargs = {"instance_uuid": "fake_uuid", "extra_arg": "meow"}
        queue = "fake_queue"

        self.mox.StubOutWithMock(timeutils, "utcnow")
        self.mox.StubOutWithMock(db, "instance_update")
        self.mox.StubOutWithMock(rpc, "queue_get_for")
        self.mox.StubOutWithMock(rpc, "cast")

        timeutils.utcnow().AndReturn("fake-now")
        db.instance_update(self.context, "fake_uuid", {"host": None, "scheduled_at": "fake-now"})
        rpc.queue_get_for(self.context, "compute", host).AndReturn(queue)
        rpc.cast(self.context, queue, {"method": method, "args": fake_kwargs})

        self.mox.ReplayAll()
        driver.cast_to_compute_host(self.context, host, method, **fake_kwargs)
Esempio n. 33
0
    def test_live_migration_basic(self):
        """Test basic schedule_live_migration functionality"""
        self.mox.StubOutWithMock(db, 'instance_get')
        self.mox.StubOutWithMock(self.driver, '_live_migration_src_check')
        self.mox.StubOutWithMock(self.driver, '_live_migration_dest_check')
        self.mox.StubOutWithMock(self.driver, '_live_migration_common_check')
        self.mox.StubOutWithMock(self.driver.compute_rpcapi,
                                 'check_can_live_migrate_destination')
        self.mox.StubOutWithMock(db, 'instance_update_and_get_original')
        self.mox.StubOutWithMock(driver, 'cast_to_compute_host')
        self.mox.StubOutWithMock(notifications, 'send_update')

        dest = 'fake_host2'
        block_migration = False
        disk_over_commit = False
        instance = self._live_migration_instance()
        instance_id = instance['id']
        instance_uuid = instance['uuid']
        db.instance_get(self.context,
                        instance_id).AndReturn(instance)

        self.driver._live_migration_src_check(self.context, instance)
        self.driver._live_migration_dest_check(self.context, instance, dest)
        self.driver._live_migration_common_check(self.context, instance,
                                                 dest)
        self.driver.compute_rpcapi.check_can_live_migrate_destination(
               self.context, instance, dest, block_migration, disk_over_commit)
        db.instance_update_and_get_original(self.context, instance_uuid,
                {"task_state": task_states.MIGRATING}).AndReturn(
                        (instance, instance))
        notifications.send_update(self.context, instance, instance,
                                  service="scheduler")

        driver.cast_to_compute_host(self.context, instance['host'],
                'live_migration', update_db=False,
                instance_id=instance['id'], dest=dest,
                block_migration=block_migration)

        self.mox.ReplayAll()
        self.driver.schedule_live_migration(self.context,
                instance_id=instance['id'], dest=dest,
                block_migration=block_migration,
                disk_over_commit=disk_over_commit)
Esempio n. 34
0
    def schedule_prep_resize(self, context, request_spec, *args, **kwargs):
        """Select a target for resize.

        Selects a target host for the instance, post-resize, and casts
        the prep_resize operation to it.
        """

        hosts = self._schedule(context, 'compute', request_spec,
                               *args, **kwargs)
        if not hosts:
            raise exception.NoValidHost(reason="")
        host = hosts.pop(0)

        # NOTE(comstud): Make sure we do not pass this through.  It
        # contains an instance of RpcContext that cannot be serialized.
        kwargs.pop('filter_properties', None)

        # Forward off to the host
        driver.cast_to_compute_host(context, host.host_state.host,
                'prep_resize', **kwargs)
Esempio n. 35
0
    def schedule_prep_resize(self, context, request_spec, *args, **kwargs):
        """Select a target for resize.

        Selects a target host for the instance, post-resize, and casts
        the prep_resize operation to it.
        """

        hosts = self._schedule(context, 'compute', request_spec, *args,
                               **kwargs)
        if not hosts:
            raise exception.NoValidHost(reason=_(""))
        host = hosts.pop(0)

        # NOTE(comstud): Make sure we do not pass this through.  It
        # contains an instance of RpcContext that cannot be serialized.
        kwargs.pop('filter_properties', None)

        # Forward off to the host
        driver.cast_to_compute_host(context, host.host_state.host,
                                    'prep_resize', **kwargs)
Esempio n. 36
0
    def test_cast_to_compute_host_update_db_with_instance_uuid(self):
        host = 'fake_host1'
        method = 'fake_method'
        fake_kwargs = {'instance_uuid': 'fake_uuid', 'extra_arg': 'meow'}
        queue = 'fake_queue'

        self.mox.StubOutWithMock(timeutils, 'utcnow')
        self.mox.StubOutWithMock(db, 'instance_update')
        self.mox.StubOutWithMock(rpc, 'queue_get_for')
        self.mox.StubOutWithMock(rpc, 'cast')

        timeutils.utcnow().AndReturn('fake-now')
        db.instance_update(self.context, 'fake_uuid', {
            'host': None,
            'scheduled_at': 'fake-now'
        })
        rpc.queue_get_for(self.context, 'compute', host).AndReturn(queue)
        rpc.cast(self.context, queue, {'method': method, 'args': fake_kwargs})

        self.mox.ReplayAll()
        driver.cast_to_compute_host(self.context, host, method, **fake_kwargs)
Esempio n. 37
0
 def schedule_run_instance(self, context, request_spec, reservations,
                           *_args, **_kwargs):
     num_instances = request_spec.get('num_instances', 1)
     instances = []
     for num in xrange(num_instances):
         host = self._schedule_instance(context,
                                        request_spec['instance_properties'],
                                        *_args, **_kwargs)
         request_spec['instance_properties']['launch_index'] = num
         instance_ref = self.create_instance_db_entry(
             context, request_spec, reservations)
         driver.cast_to_compute_host(context,
                                     host,
                                     'run_instance',
                                     instance_uuid=instance_ref['uuid'],
                                     **_kwargs)
         instances.append(driver.encode_instance(instance_ref))
         # So if we loop around, create_instance_db_entry will actually
         # create a new entry, instead of assume it's been created
         # already
         del request_spec['instance_properties']['uuid']
     return instances
Esempio n. 38
0
 def schedule_run_instance(self, context, request_spec, *_args, **_kwargs):
     num_instances = request_spec.get('num_instances', 1)
     instances = []
     #Grazie ad xrange cicla num parte da 0 e arriva a num_instances-1
     for num in xrange(num_instances):
         host = self._schedule_instance(context, 
                 request_spec['instance_properties'], *_args, **_kwargs)
         request_spec['instance_properties']['launch_index'] = num
         instance_ref = self.create_instance_db_entry(context, 
                 request_spec)
         driver.cast_to_compute_host(context, host, 'run_instance', 
                 instance_uuid=instance_ref['uuid'], **_kwargs)
         instances.append(driver.encode_instance(instance_ref))
         # So if we loop around, create_instance_db_entry will actually
         # create a new entry, instead of assume it's been created
         # already
         del request_spec['instance_properties']['uuid']
         
         #Chiamo la funzione per aggiornare/creare le informazioni sulla VM che deve essere messa in esecuzione 
         #set_vm_information(instance_ref, context, "information")
         
     return instances
Esempio n. 39
0
    def test_cast_to_compute_host_update_db_with_instance_id(self):
        host = 'fake_host1'
        method = 'fake_method'
        fake_kwargs = {'instance_id': 31337,
                       'extra_arg': 'meow'}
        queue = 'fake_queue'

        self.mox.StubOutWithMock(utils, 'utcnow')
        self.mox.StubOutWithMock(db, 'instance_update')
        self.mox.StubOutWithMock(db, 'queue_get_for')
        self.mox.StubOutWithMock(rpc, 'cast')

        utils.utcnow().AndReturn('fake-now')
        db.instance_update(self.context, 31337,
                {'host': host, 'scheduled_at': 'fake-now'})
        db.queue_get_for(self.context, 'compute', host).AndReturn(queue)
        rpc.cast(self.context, queue,
                {'method': method,
                 'args': fake_kwargs})

        self.mox.ReplayAll()
        driver.cast_to_compute_host(self.context, host, method,
                update_db=True, **fake_kwargs)
Esempio n. 40
0
 def schedule_prep_resize(self, context, request_spec, *args, **kwargs):
     """Select a target for resize."""
     host = self._schedule(context, 'compute', request_spec, **kwargs)
     driver.cast_to_compute_host(context, host, 'prep_resize', **kwargs)
Esempio n. 41
0
    def test_live_migration_all_checks_pass(self):
        """Test live migration when all checks pass."""

        self.mox.StubOutWithMock(db, 'instance_get')
        self.mox.StubOutWithMock(db, 'service_get_all_by_topic')
        self.mox.StubOutWithMock(utils, 'service_is_up')
        self.mox.StubOutWithMock(db, 'service_get_all_compute_by_host')
        self.mox.StubOutWithMock(self.driver, '_get_compute_info')
        self.mox.StubOutWithMock(db, 'instance_get_all_by_host')
        self.mox.StubOutWithMock(db, 'queue_get_for')
        self.mox.StubOutWithMock(rpc, 'call')
        self.mox.StubOutWithMock(rpc, 'cast')
        self.mox.StubOutWithMock(db, 'instance_update')
        self.mox.StubOutWithMock(db, 'volume_update')
        self.mox.StubOutWithMock(driver, 'cast_to_compute_host')

        dest = 'fake_host2'
        block_migration = True
        disk_over_commit = True
        instance = self._live_migration_instance()
        db.instance_get(self.context, instance['id']).AndReturn(instance)

        # Source checks (volume and source compute are up)
        db.service_get_all_by_topic(self.context, 'volume').AndReturn(
                ['fake_service'])
        utils.service_is_up('fake_service').AndReturn(True)
        db.service_get_all_compute_by_host(self.context,
                instance['host']).AndReturn(['fake_service2'])
        utils.service_is_up('fake_service2').AndReturn(True)

        # Destination checks (compute is up, enough memory, disk)
        db.service_get_all_compute_by_host(self.context,
                dest).AndReturn(['fake_service3'])
        utils.service_is_up('fake_service3').AndReturn(True)
        # assert_compute_node_has_enough_memory()
        self.driver._get_compute_info(self.context, dest,
                'memory_mb').AndReturn(2048)
        db.instance_get_all_by_host(self.context, dest).AndReturn(
                [dict(memory_mb=256), dict(memory_mb=512)])
        # assert_compute_node_has_enough_disk()
        db.queue_get_for(self.context, FLAGS.compute_topic,
                dest).AndReturn('dest_queue1')
        rpc.call(self.context, 'dest_queue1',
                {'method': 'update_available_resource'})
        self.driver._get_compute_info(self.context, dest,
                'disk_available_least').AndReturn(1025)
        db.queue_get_for(self.context, FLAGS.compute_topic,
                instance['host']).AndReturn('src_queue1')
        rpc.call(self.context, 'src_queue1',
                {'method': 'get_instance_disk_info',
                 'args': {'instance_name': instance['name']}}).AndReturn(
                        json.dumps([{'disk_size': 1024 * (1024 ** 3)}]))

        # Common checks (shared storage ok, same hypervisor,e tc)
        db.queue_get_for(self.context, FLAGS.compute_topic,
                dest).AndReturn('dest_queue')
        db.queue_get_for(self.context, FLAGS.compute_topic,
                instance['host']).AndReturn('src_queue')
        tmp_filename = 'test-filename'
        rpc.call(self.context, 'dest_queue',
                {'method': 'create_shared_storage_test_file'}
                ).AndReturn(tmp_filename)
        rpc.call(self.context, 'src_queue',
                {'method': 'check_shared_storage_test_file',
                 'args': {'filename': tmp_filename}}).AndReturn(False)
        rpc.call(self.context, 'dest_queue',
                {'method': 'cleanup_shared_storage_test_file',
                 'args': {'filename': tmp_filename}})
        db.service_get_all_compute_by_host(self.context, dest).AndReturn(
                [{'compute_node': [{'hypervisor_type': 'xen',
                                    'hypervisor_version': 1}]}])
        # newer hypervisor version for src
        db.service_get_all_compute_by_host(self.context,
            instance['host']).AndReturn(
                    [{'compute_node': [{'hypervisor_type': 'xen',
                                        'hypervisor_version': 1,
                                        'cpu_info': 'fake_cpu_info'}]}])
        db.queue_get_for(self.context, FLAGS.compute_topic,
                dest).AndReturn('dest_queue')
        rpc.call(self.context, 'dest_queue',
                {'method': 'compare_cpu',
                 'args': {'cpu_info': 'fake_cpu_info'}}).AndReturn(True)

        db.instance_update(self.context, instance['id'],
                {'vm_state': vm_states.MIGRATING})
        db.volume_update(self.context, instance['volumes'][0]['id'],
                {'status': 'migrating'})
        db.volume_update(self.context, instance['volumes'][1]['id'],
                {'status': 'migrating'})

        driver.cast_to_compute_host(self.context, instance['host'],
                'live_migration', update_db=False,
                instance_id=instance['id'], dest=dest,
                block_migration=block_migration)

        self.mox.ReplayAll()
        result = self.driver.schedule_live_migration(self.context,
                instance_id=instance['id'], dest=dest,
                block_migration=block_migration,
                disk_over_commit=disk_over_commit)
        self.assertEqual(result, None)
Esempio n. 42
0
    def test_live_migration_all_checks_pass(self):
        """Test live migration when all checks pass."""

        self.mox.StubOutWithMock(db, 'instance_get')
        self.mox.StubOutWithMock(utils, 'service_is_up')
        self.mox.StubOutWithMock(db, 'service_get_all_compute_by_host')
        self.mox.StubOutWithMock(db, 'instance_get_all_by_host')
        self.mox.StubOutWithMock(rpc, 'call')
        self.mox.StubOutWithMock(rpc, 'cast')
        self.mox.StubOutWithMock(db, 'instance_update_and_get_original')
        self.mox.StubOutWithMock(driver, 'cast_to_compute_host')

        dest = 'fake_host2'
        block_migration = True
        disk_over_commit = True
        instance = jsonutils.to_primitive(self._live_migration_instance())
        instance_id = instance['id']
        instance_uuid = instance['uuid']
        db.instance_get(self.context,
                        instance_id).AndReturn(instance)

        # Source checks
        db.service_get_all_compute_by_host(self.context,
                instance['host']).AndReturn(['fake_service2'])
        utils.service_is_up('fake_service2').AndReturn(True)

        # Destination checks (compute is up, enough memory, disk)
        db.service_get_all_compute_by_host(self.context,
                dest).AndReturn(['fake_service3'])
        utils.service_is_up('fake_service3').AndReturn(True)
        # assert_compute_node_has_enough_memory()
        db.service_get_all_compute_by_host(self.context, dest).AndReturn(
                [{'compute_node': [{'memory_mb': 2048,
                                    'hypervisor_version': 1}]}])
        db.instance_get_all_by_host(self.context, dest).AndReturn(
                [dict(memory_mb=256), dict(memory_mb=512)])

        # Common checks (same hypervisor, etc)
        db.service_get_all_compute_by_host(self.context, dest).AndReturn(
                [{'compute_node': [{'hypervisor_type': 'xen',
                                    'hypervisor_version': 1}]}])
        db.service_get_all_compute_by_host(self.context,
            instance['host']).AndReturn(
                    [{'compute_node': [{'hypervisor_type': 'xen',
                                        'hypervisor_version': 1,
                                        'cpu_info': 'fake_cpu_info'}]}])

        rpc.call(self.context, "compute.fake_host2",
                   {"method": 'check_can_live_migrate_destination',
                    "args": {'instance': instance,
                             'block_migration': block_migration,
                             'disk_over_commit': disk_over_commit},
                    "version": "1.10"},
                 None)

        db.instance_update_and_get_original(self.context, instance_uuid,
                {"task_state": task_states.MIGRATING}).AndReturn(
                        (instance, instance))

        driver.cast_to_compute_host(self.context, instance['host'],
                'live_migration', update_db=False,
                instance_id=instance_id, dest=dest,
                block_migration=block_migration)

        self.mox.ReplayAll()
        result = self.driver.schedule_live_migration(self.context,
                instance_id=instance_id, dest=dest,
                block_migration=block_migration,
                disk_over_commit=disk_over_commit)
        self.assertEqual(result, None)
Esempio n. 43
0
 def schedule_start_instance(self, context, instance_id, *_args, **_kwargs):
     instance_ref = db.instance_get(context, instance_id)
     host = self._schedule_instance(context, instance_ref,
             *_args, **_kwargs)
     driver.cast_to_compute_host(context, host, 'start_instance',
             instance_id=instance_id, **_kwargs)
Esempio n. 44
0
    def test_live_migration_all_checks_pass(self):
        """Test live migration when all checks pass."""

        self.mox.StubOutWithMock(db, 'instance_get')
        self.mox.StubOutWithMock(utils, 'service_is_up')
        self.mox.StubOutWithMock(db, 'service_get_all_compute_by_host')
        self.mox.StubOutWithMock(db, 'instance_get_all_by_host')
        self.mox.StubOutWithMock(rpc, 'call')
        self.mox.StubOutWithMock(rpc, 'cast')
        self.mox.StubOutWithMock(db, 'instance_update_and_get_original')
        self.mox.StubOutWithMock(driver, 'cast_to_compute_host')

        dest = 'fake_host2'
        block_migration = True
        disk_over_commit = True
        instance = self._live_migration_instance()
        instance_id = instance['id']
        instance_uuid = instance['uuid']
        db.instance_get(self.context,
                        instance_id).AndReturn(instance)

        # Source checks
        db.service_get_all_compute_by_host(self.context,
                instance['host']).AndReturn(['fake_service2'])
        utils.service_is_up('fake_service2').AndReturn(True)

        # Destination checks (compute is up, enough memory, disk)
        db.service_get_all_compute_by_host(self.context,
                dest).AndReturn(['fake_service3'])
        utils.service_is_up('fake_service3').AndReturn(True)
        # assert_compute_node_has_enough_memory()
        db.service_get_all_compute_by_host(self.context, dest).AndReturn(
                [{'compute_node': [{'memory_mb': 2048,
                                    'hypervisor_version': 1}]}])
        db.instance_get_all_by_host(self.context, dest).AndReturn(
                [dict(memory_mb=256), dict(memory_mb=512)])

        # Common checks (same hypervisor, etc)
        db.service_get_all_compute_by_host(self.context, dest).AndReturn(
                [{'compute_node': [{'hypervisor_type': 'xen',
                                    'hypervisor_version': 1}]}])
        db.service_get_all_compute_by_host(self.context,
            instance['host']).AndReturn(
                    [{'compute_node': [{'hypervisor_type': 'xen',
                                        'hypervisor_version': 1,
                                        'cpu_info': 'fake_cpu_info'}]}])

        rpc.call(self.context, "compute.fake_host2",
                   {"method": 'check_can_live_migrate_destination',
                    "args": {'instance_id': instance_id,
                             'block_migration': block_migration,
                             'disk_over_commit': disk_over_commit},
                    "version": "1.2"},
                 None)

        db.instance_update_and_get_original(self.context, instance_uuid,
                {"task_state": task_states.MIGRATING}).AndReturn(
                        (instance, instance))

        driver.cast_to_compute_host(self.context, instance['host'],
                'live_migration', update_db=False,
                instance_id=instance_id, dest=dest,
                block_migration=block_migration)

        self.mox.ReplayAll()
        result = self.driver.schedule_live_migration(self.context,
                instance_id=instance_id, dest=dest,
                block_migration=block_migration,
                disk_over_commit=disk_over_commit)
        self.assertEqual(result, None)
Esempio n. 45
0
    def test_live_migration_all_checks_pass(self):
        """Test live migration when all checks pass."""

        self.mox.StubOutWithMock(db, 'instance_get')
        self.mox.StubOutWithMock(utils, 'service_is_up')
        self.mox.StubOutWithMock(db, 'service_get_all_compute_by_host')
        self.mox.StubOutWithMock(self.driver, '_get_compute_info')
        self.mox.StubOutWithMock(db, 'instance_get_all_by_host')
        self.mox.StubOutWithMock(rpc, 'queue_get_for')
        self.mox.StubOutWithMock(rpc, 'call')
        self.mox.StubOutWithMock(rpc, 'cast')
        self.mox.StubOutWithMock(db, 'instance_update_and_get_original')
        self.mox.StubOutWithMock(driver, 'cast_to_compute_host')

        dest = 'fake_host2'
        block_migration = True
        disk_over_commit = True
        instance = self._live_migration_instance()
        db.instance_get(self.context, instance['id']).AndReturn(instance)

        db.service_get_all_compute_by_host(self.context,
                instance['host']).AndReturn(['fake_service2'])
        utils.service_is_up('fake_service2').AndReturn(True)

        # Destination checks (compute is up, enough memory, disk)
        db.service_get_all_compute_by_host(self.context,
                dest).AndReturn(['fake_service3'])
        utils.service_is_up('fake_service3').AndReturn(True)
        # assert_compute_node_has_enough_memory()
        self.driver._get_compute_info(self.context, dest,
                'memory_mb').AndReturn(2048)
        db.instance_get_all_by_host(self.context, dest).AndReturn(
                [dict(memory_mb=256), dict(memory_mb=512)])
        # assert_compute_node_has_enough_disk()
        self.driver._get_compute_info(self.context, dest,
                'disk_available_least').AndReturn(1025)
        rpc.queue_get_for(self.context, FLAGS.compute_topic,
                instance['host']).AndReturn('src_queue1')
        instance_disk_info_msg = {
            'method': 'get_instance_disk_info',
            'args': {
                'instance_name': instance['name'],
            },
            'version': compute_rpcapi.ComputeAPI.RPC_API_VERSION,
        }
        instance_disk_info = [{'disk_size': 1024 * (1024 ** 3)}]
        rpc.call(self.context,
                 'src_queue1',
                 instance_disk_info_msg,
                 None).AndReturn(jsonutils.dumps(instance_disk_info))

        # Common checks (shared storage ok, same hypervisor, etc)
        self._check_shared_storage(dest, instance, False)

        db.service_get_all_compute_by_host(self.context, dest).AndReturn(
                [{'compute_node': [{'hypervisor_type': 'xen',
                                    'hypervisor_version': 1}]}])
        # newer hypervisor version for src
        db.service_get_all_compute_by_host(self.context,
            instance['host']).AndReturn(
                    [{'compute_node': [{'hypervisor_type': 'xen',
                                        'hypervisor_version': 1,
                                        'cpu_info': 'fake_cpu_info'}]}])
        rpc.queue_get_for(self.context, FLAGS.compute_topic,
                dest).AndReturn('dest_queue')
        rpc.call(self.context, 'dest_queue',
                {'method': 'compare_cpu',
                 'args': {'cpu_info': 'fake_cpu_info'},
                 'version': compute_rpcapi.ComputeAPI.RPC_API_VERSION}, None
                ).AndReturn(True)

        db.instance_update_and_get_original(self.context, instance['id'],
                {"vm_state": vm_states.MIGRATING}).AndReturn(
                        (instance, instance))

        driver.cast_to_compute_host(self.context, instance['host'],
                'live_migration', update_db=False,
                instance_id=instance['id'], dest=dest,
                block_migration=block_migration)

        self.mox.ReplayAll()
        result = self.driver.schedule_live_migration(self.context,
                instance_id=instance['id'], dest=dest,
                block_migration=block_migration,
                disk_over_commit=disk_over_commit)
        self.assertEqual(result, None)
Esempio n. 46
0
    def test_live_migration_all_checks_pass(self):
        """Test live migration when all checks pass."""

        self.mox.StubOutWithMock(db, 'instance_get')
        self.mox.StubOutWithMock(utils, 'service_is_up')
        self.mox.StubOutWithMock(db, 'service_get_all_compute_by_host')
        self.mox.StubOutWithMock(self.driver, '_get_compute_info')
        self.mox.StubOutWithMock(db, 'instance_get_all_by_host')
        self.mox.StubOutWithMock(rpc, 'queue_get_for')
        self.mox.StubOutWithMock(rpc, 'call')
        self.mox.StubOutWithMock(rpc, 'cast')
        self.mox.StubOutWithMock(db, 'instance_update_and_get_original')
        self.mox.StubOutWithMock(driver, 'cast_to_compute_host')

        dest = 'fake_host2'
        block_migration = True
        disk_over_commit = True
        instance = self._live_migration_instance()
        db.instance_get(self.context, instance['id']).AndReturn(instance)

        db.service_get_all_compute_by_host(self.context,
                instance['host']).AndReturn(['fake_service2'])
        utils.service_is_up('fake_service2').AndReturn(True)

        # Destination checks (compute is up, enough memory, disk)
        db.service_get_all_compute_by_host(self.context,
                dest).AndReturn(['fake_service3'])
        utils.service_is_up('fake_service3').AndReturn(True)
        # assert_compute_node_has_enough_memory()
        self.driver._get_compute_info(self.context, dest,
                'memory_mb').AndReturn(2048)
        db.instance_get_all_by_host(self.context, dest).AndReturn(
                [dict(memory_mb=256), dict(memory_mb=512)])
        # assert_compute_node_has_enough_disk()
        self.driver._get_compute_info(self.context, dest,
                'disk_available_least').AndReturn(1025)
        rpc.queue_get_for(self.context, FLAGS.compute_topic,
                instance['host']).AndReturn('src_queue1')
        instance_disk_info_msg = {
            'method': 'get_instance_disk_info',
            'args': {
                'instance_name': instance['name'],
            },
            'version': compute_rpcapi.ComputeAPI.BASE_RPC_API_VERSION,
        }
        instance_disk_info = [{'disk_size': 1024 * (1024 ** 3)}]
        rpc.call(self.context,
                 'src_queue1',
                 instance_disk_info_msg,
                 None).AndReturn(jsonutils.dumps(instance_disk_info))

        # Common checks (shared storage ok, same hypervisor, etc)
        self._check_shared_storage(dest, instance, False)

        db.service_get_all_compute_by_host(self.context, dest).AndReturn(
                [{'compute_node': [{'hypervisor_type': 'xen',
                                    'hypervisor_version': 1}]}])
        # newer hypervisor version for src
        db.service_get_all_compute_by_host(self.context,
            instance['host']).AndReturn(
                    [{'compute_node': [{'hypervisor_type': 'xen',
                                        'hypervisor_version': 1,
                                        'cpu_info': 'fake_cpu_info'}]}])
        rpc.queue_get_for(self.context, FLAGS.compute_topic,
                dest).AndReturn('dest_queue')
        rpc.call(self.context, 'dest_queue',
                {'method': 'compare_cpu',
                 'args': {'cpu_info': 'fake_cpu_info'},
                 'version': compute_rpcapi.ComputeAPI.BASE_RPC_API_VERSION},
                None).AndReturn(True)

        db.instance_update_and_get_original(self.context, instance['id'],
                {"task_state": task_states.MIGRATING}).AndReturn(
                        (instance, instance))

        driver.cast_to_compute_host(self.context, instance['host'],
                'live_migration', update_db=False,
                instance_id=instance['id'], dest=dest,
                block_migration=block_migration)

        self.mox.ReplayAll()
        result = self.driver.schedule_live_migration(self.context,
                instance_id=instance['id'], dest=dest,
                block_migration=block_migration,
                disk_over_commit=disk_over_commit)
        self.assertEqual(result, None)
Esempio n. 47
0
 def schedule_prep_resize(self, context, request_spec, *args, **kwargs):
     """Select a target for resize."""
     host = self._schedule(context, 'compute', request_spec, **kwargs)
     driver.cast_to_compute_host(context, host, 'prep_resize', **kwargs)