Exemplo n.º 1
0
        def instance_create(context, inst):
            inst_type = flavors.get_flavor_by_flavor_id(3)
            image_uuid = '76fa36fc-c930-4bf3-8c8a-ea2a2420deb6'
            def_image_ref = 'http://localhost/images/%s' % image_uuid
            self.instance_cache_num += 1
            instance = fake_instance.fake_db_instance(**{
                'id': self.instance_cache_num,
                'display_name': inst['display_name'] or 'test',
                'uuid': FAKE_UUID,
                'instance_type': inst_type,
                'access_ip_v4': '1.2.3.4',
                'access_ip_v6': 'fead::1234',
                'image_ref': inst.get('image_ref', def_image_ref),
                'user_id': 'fake',
                'project_id': 'fake',
                'availability_zone': 'nova',
                'reservation_id': inst['reservation_id'],
                "created_at": datetime.datetime(2010, 10, 10, 12, 0, 0),
                "updated_at": datetime.datetime(2010, 11, 11, 11, 0, 0),
                "progress": 0,
                "fixed_ips": [],
                "task_state": "",
                "vm_state": "",
                "root_device_name": inst.get('root_device_name', 'vda'),
            })

            return instance
Exemplo n.º 2
0
        def instance_create(context, inst):
            inst_type = flavors.get_flavor_by_flavor_id(3)
            image_uuid = "76fa36fc-c930-4bf3-8c8a-ea2a2420deb6"
            def_image_ref = "http://localhost/images/%s" % image_uuid
            self.instance_cache_num += 1
            instance = fake_instance.fake_db_instance(
                **{
                    "id": self.instance_cache_num,
                    "display_name": inst["display_name"] or "test",
                    "uuid": fakes.FAKE_UUID,
                    "instance_type": inst_type,
                    "access_ip_v4": "1.2.3.4",
                    "access_ip_v6": "fead::1234",
                    "image_ref": inst.get("image_ref", def_image_ref),
                    "user_id": "fake",
                    "project_id": "fake",
                    "reservation_id": inst["reservation_id"],
                    "created_at": datetime.datetime(2010, 10, 10, 12, 0, 0),
                    "updated_at": datetime.datetime(2010, 11, 11, 11, 0, 0),
                    "progress": 0,
                    "fixed_ips": [],
                    "task_state": "",
                    "vm_state": "",
                    "root_device_name": inst.get("root_device_name", "vda"),
                }
            )

            return instance
Exemplo n.º 3
0
    def setUp(self):
        super(MigrationTaskTestCase, self).setUp()
        self.user_id = 'fake'
        self.project_id = 'fake'
        self.context = FakeContext(self.user_id, self.project_id)
        self.flavor = fake_flavor.fake_flavor_obj(self.context)
        self.flavor.extra_specs = {'extra_specs': 'fake'}
        inst = fake_instance.fake_db_instance(image_ref='image_ref',
                                              instance_type=self.flavor)
        inst_object = objects.Instance(
            flavor=self.flavor,
            numa_topology=None,
            pci_requests=None,
            system_metadata={'image_hw_disk_bus': 'scsi'})
        self.instance = objects.Instance._from_db_object(
            self.context, inst_object, inst, [])
        self.request_spec = objects.RequestSpec(image=objects.ImageMeta())
        self.host_lists = [[objects.Selection(service_host="host1",
                nodename="node1", cell_uuid=uuids.cell1)]]
        self.filter_properties = {'limits': {}, 'retry': {'num_attempts': 1,
                                  'hosts': [['host1', 'node1']]}}
        self.reservations = []
        self.clean_shutdown = True

        _p = mock.patch('nova.compute.utils.heal_reqspec_is_bfv')
        self.heal_reqspec_is_bfv_mock = _p.start()
        self.addCleanup(_p.stop)

        _p = mock.patch('nova.objects.RequestSpec.ensure_network_metadata')
        self.ensure_network_metadata_mock = _p.start()
        self.addCleanup(_p.stop)
Exemplo n.º 4
0
        def instance_create(context, inst):
            inst_type = flavors.get_flavor_by_flavor_id(3)
            image_uuid = '76fa36fc-c930-4bf3-8c8a-ea2a2420deb6'
            def_image_ref = 'http://localhost/images/%s' % image_uuid
            self.instance_cache_num += 1
            instance = fake_instance.fake_db_instance(**{
                'id': self.instance_cache_num,
                'display_name': inst['display_name'] or 'test',
                'uuid': FAKE_UUID,
                'instance_type': inst_type,
                'access_ip_v4': '1.2.3.4',
                'access_ip_v6': 'fead::1234',
                'image_ref': inst.get('image_ref', def_image_ref),
                'user_id': 'fake',
                'project_id': 'fake',
                'reservation_id': inst['reservation_id'],
                "created_at": datetime.datetime(2010, 10, 10, 12, 0, 0),
                "updated_at": datetime.datetime(2010, 11, 11, 11, 0, 0),
                "config_drive": None,
                "progress": 0,
                "fixed_ips": [],
                "task_state": "",
                "vm_state": "",
                "root_device_name": inst.get('root_device_name', 'vda'),
                "security_groups": inst['security_groups'],
                "extra": {"pci_requests": None,
                          "numa_topology": None},
            })

            self.instance_cache_by_id[instance['id']] = instance
            self.instance_cache_by_uuid[instance['uuid']] = instance
            return instance
Exemplo n.º 5
0
 def test_build_instances_old_instances(self):
     args = {'instances': [fake_instance.fake_db_instance()]}
     with mock.patch.object(self.msg_runner, 'build_instances') as mock_bi:
         self.cells_manager.build_instances(self.ctxt,
                                            build_inst_kwargs=args)
         self.assertIsInstance(mock_bi.call_args[0][2]['instances'][0],
                               objects.Instance)
Exemplo n.º 6
0
 def _get_instance(self):
     updates = self._get_instance_data()
     expected_attrs = updates.pop('expected_attrs', None)
     return objects.Instance._from_db_object(
         context, objects.Instance(),
         fake_instance.fake_db_instance(**updates),
         expected_attrs=expected_attrs)
Exemplo n.º 7
0
        def instance_create(context, inst):
            inst_type = flavors.get_flavor_by_flavor_id(3)
            image_uuid = '76fa36fc-c930-4bf3-8c8a-ea2a2420deb6'
            def_image_ref = 'http://localhost/images/{0!s}'.format(image_uuid)
            self.instance_cache_num += 1
            instance = fake_instance.fake_db_instance(**{
                'id': self.instance_cache_num,
                'display_name': inst['display_name'] or 'test',
                'uuid': inst['uuid'],
                'instance_type': inst_type,
                'access_ip_v4': '1.2.3.4',
                'access_ip_v6': 'fead::1234',
                'image_ref': inst.get('image_ref', def_image_ref),
                'user_id': 'fake',
                'project_id': 'fake',
                'reservation_id': inst['reservation_id'],
                "created_at": datetime.datetime(2010, 10, 10, 12, 0, 0),
                "updated_at": datetime.datetime(2010, 11, 11, 11, 0, 0),
                "progress": 0,
                "fixed_ips": [],
                "task_state": "",
                "vm_state": "",
                "security_groups": inst['security_groups'],
            })

            self.instance_cache_by_id[instance['id']] = instance
            self.instance_cache_by_uuid[instance['uuid']] = instance
            return instance
Exemplo n.º 8
0
        def fake_instance_create(context, inst_, session=None):
            inst = fake_instance.fake_db_instance(
                **{
                    "id": 1,
                    "uuid": AUTO_INSTANCE_UUID,
                    "created_at": datetime.datetime(2010, 10, 10, 12, 0, 0),
                    "updated_at": datetime.datetime(2010, 10, 10, 12, 0, 0),
                    "progress": 0,
                    "name": "instance-1",  # this is a property
                    "task_state": "",
                    "vm_state": "",
                    "auto_disk_config": inst_["auto_disk_config"],
                    "security_groups": inst_["security_groups"],
                    "instance_type": flavors.get_default_flavor(),
                }
            )

            def fake_instance_get_for_create(context, id_, *args, **kwargs):
                return (inst, inst)

            self.stubs.Set(db, "instance_update_and_get_original", fake_instance_get_for_create)

            def fake_instance_get_all_for_create(context, *args, **kwargs):
                return [inst]

            self.stubs.Set(db, "instance_get_all", fake_instance_get_all_for_create)
            self.stubs.Set(db, "instance_get_all_by_filters", fake_instance_get_all_for_create)

            def fake_instance_add_security_group(context, instance_id, security_group_id):
                pass

            self.stubs.Set(db, "instance_add_security_group", fake_instance_add_security_group)

            return inst
Exemplo n.º 9
0
    def test_sync_power_states_instance_not_found(self):
        db_instance = fake_instance.fake_db_instance()
        ctxt = context.get_admin_context()
        instance_list = instance_obj._make_instance_list(ctxt,
                objects.InstanceList(), [db_instance], None)
        instance = instance_list[0]

        @mock.patch.object(vm_utils, 'lookup')
        @mock.patch.object(objects.InstanceList, 'get_by_host')
        @mock.patch.object(self.compute.driver, 'get_num_instances')
        @mock.patch.object(self.compute, '_sync_instance_power_state')
        def do_test(mock_compute_sync_powerstate,
              mock_compute_get_num_instances,
              mock_instance_list_get_by_host,
              mock_vm_utils_lookup):
            mock_instance_list_get_by_host.return_value = instance_list
            mock_compute_get_num_instances.return_value = 1
            mock_vm_utils_lookup.return_value = None

            self.compute._sync_power_states(ctxt)

            mock_instance_list_get_by_host.assert_called_once_with(
               ctxt, self.compute.host, expected_attrs=[], use_slave=True)
            mock_compute_get_num_instances.assert_called_once_with()
            mock_compute_sync_powerstate.assert_called_once_with(
               ctxt, instance, power_state.NOSTATE, use_slave=True)
            mock_vm_utils_lookup.assert_called_once_with(
               self.compute.driver._session, instance['name'],
               False)

        do_test()
Exemplo n.º 10
0
    def test_prep_resize_post_populates_retry(self):
        self.manager.driver = fakes.FakeFilterScheduler()

        image = 'image'
        instance_uuid = 'fake-instance-id'
        instance = fake_instance.fake_db_instance(uuid=instance_uuid)

        instance_properties = {'project_id': 'fake', 'os_type': 'Linux'}
        instance_type = "m1.tiny"
        request_spec = {'instance_properties': instance_properties,
                        'instance_type': instance_type,
                        'instance_uuids': [instance_uuid]}
        retry = {'hosts': [], 'num_attempts': 1}
        filter_properties = {'retry': retry}
        reservations = None

        hosts = [dict(host='host', nodename='node', limits={})]

        self._mox_schedule_method_helper('select_destinations')
        self.manager.driver.select_destinations(
            self.context, request_spec, filter_properties).AndReturn(hosts)

        self.mox.StubOutWithMock(self.manager.compute_rpcapi, 'prep_resize')
        self.manager.compute_rpcapi.prep_resize(self.context, image,
                mox.IsA(objects.Instance),
                instance_type, 'host', reservations, request_spec=request_spec,
                filter_properties=filter_properties, node='node')

        self.mox.ReplayAll()
        self.manager.prep_resize(self.context, image, request_spec,
                filter_properties, instance, instance_type, reservations)

        self.assertEqual([['host', 'node']],
                         filter_properties['retry']['hosts'])
Exemplo n.º 11
0
    def setUp(self):
        super(ComputeGetImageMetadataTestCase, self).setUp()
        self.context = context.RequestContext("fake", "fake")

        self.image = {"min_ram": 10, "min_disk": 1, "disk_format": "raw", "container_format": "bare", "properties": {}}

        self.mock_image_api = mock.Mock()
        self.mock_image_api.get.return_value = self.image

        self.ctx = context.RequestContext("fake", "fake")

        sys_meta = {
            "image_min_ram": 10,
            "image_min_disk": 1,
            "image_disk_format": "raw",
            "image_container_format": "bare",
            "instance_type_id": 0,
            "instance_type_name": "m1.fake",
            "instance_type_memory_mb": 10,
            "instance_type_vcpus": 1,
            "instance_type_root_gb": 1,
            "instance_type_ephemeral_gb": 1,
            "instance_type_flavorid": "0",
            "instance_type_swap": 1,
            "instance_type_rxtx_factor": 0.0,
            "instance_type_vcpu_weight": None,
        }

        self.instance = fake_instance.fake_db_instance(memory_mb=0, root_gb=0, system_metadata=sys_meta)
Exemplo n.º 12
0
    def setUp(self):
        super(LiveMigrationTaskTestCase, self).setUp()
        self.context = nova_context.get_admin_context()
        self.instance_host = "host"
        self.instance_uuid = uuids.instance
        self.instance_image = "image_ref"
        db_instance = fake_instance.fake_db_instance(
                host=self.instance_host,
                uuid=self.instance_uuid,
                power_state=power_state.RUNNING,
                vm_state = vm_states.ACTIVE,
                memory_mb=512,
                image_ref=self.instance_image)
        self.instance = objects.Instance._from_db_object(
                self.context, objects.Instance(), db_instance)
        self.instance.system_metadata = {'image_hw_disk_bus': 'scsi'}
        self.instance.numa_topology = None
        self.destination = "destination"
        self.block_migration = "bm"
        self.disk_over_commit = "doc"
        self.migration = objects.Migration()
        self.fake_spec = objects.RequestSpec()
        self._generate_task()

        _p = mock.patch('nova.compute.utils.heal_reqspec_is_bfv')
        self.heal_reqspec_is_bfv_mock = _p.start()
        self.addCleanup(_p.stop)

        _p = mock.patch('nova.objects.RequestSpec.ensure_network_metadata')
        self.ensure_network_metadata_mock = _p.start()
        self.addCleanup(_p.stop)
Exemplo n.º 13
0
 def test_deallocate_fixed_ip(self):
     instance = fake_instance.fake_db_instance()
     self._test_network_api('deallocate_fixed_ip',
                            rpc_method='call',
                            address='fake_addr',
                            host='fake_host',
                            instance=instance,
                            version='1.12')
Exemplo n.º 14
0
 def _get_instance(self):
     updates = self._get_instance_data()
     expected_attrs = updates.pop('expected_attrs', None)
     return objects.Instance._from_db_object(
         context,
         objects.Instance(),
         fake_instance.fake_db_instance(**updates),
         expected_attrs=expected_attrs)
Exemplo n.º 15
0
 def fake_get_all_by_filters(context, *args, **kwargs):
     was["called"] = True
     instances = []
     for x in range(2):
         instances.append(
             fake_instance.fake_db_instance(image_ref="1", uuid=x, name=x, vm_state="", task_state="")
         )
     return instances
Exemplo n.º 16
0
 def _return_server_in_build_by_uuid(self, context, server_uuid,
                                     columns_to_join=None, use_slave=False):
     return fake_instance.fake_db_instance(
         **{'id': 1,
            'uuid': '0cc3346e-9fef-4445-abe6-5d2b2690ec64',
            'name': 'fake',
            'locked': False,
            'vm_state': vm_states.BUILDING})
Exemplo n.º 17
0
def return_server(context, server_id, columns_to_join=None):
    return fake_instance.fake_db_instance(
        **{'id': server_id,
           'uuid': '0cc3346e-9fef-4445-abe6-5d2b2690ec64',
           'name': 'fake',
           'locked': False,
           'launched_at': timeutils.utcnow(),
           'vm_state': vm_states.ACTIVE})
Exemplo n.º 18
0
 def _fake_compute_api_get(self, context, instance_id, **kwargs):
     instance = fake_instance.fake_db_instance(id=1,
                                               uuid=uuid,
                                               task_state=None,
                                               host='host1',
                                               vm_state=vm_states.ACTIVE)
     instance = instance_obj.Instance._from_db_object(
         context, instance_obj.Instance(), instance)
     return instance
 def fake_instance_get_by_uuid(context,
                               instance_id,
                               columns_to_join=None,
                               use_slave=False):
     return fake_instance.fake_db_instance(
         **{
             'name': 'fake',
             'project_id': '%s_unequal' % context.project_id
         })
Exemplo n.º 20
0
    def test_get_by_volume_id_with_expected(self, get_by_vol_id):
        get_by_vol_id.return_value = self.fake_bdm(fake_instance.fake_db_instance())

        vol_bdm = objects.BlockDeviceMapping.get_by_volume_id(
            self.context, "fake-volume-id", expected_attrs=["instance"]
        )
        for attr in block_device_obj.BLOCK_DEVICE_OPTIONAL_ATTRS:
            self.assertTrue(vol_bdm.obj_attr_is_set(attr))
        get_by_vol_id.assert_called_once_with(self.context, "fake-volume-id", ["instance"])
 def _fake_compute_api_get(self, context, instance_id, **kwargs):
     instance = fake_instance.fake_db_instance(id=1, uuid=uuid,
                                               task_state=None,
                                               host='host1',
                                               vm_state=vm_states.ACTIVE)
     instance = instance_obj.Instance._from_db_object(context,
                                                 instance_obj.Instance(),
                                                 instance)
     return instance
Exemplo n.º 22
0
    def test_get_by_instance_and_volume_id(self, mock_get):
        fake_inst = fake_instance.fake_db_instance()
        mock_get.return_value = self.fake_bdm(fake_inst)

        obj_bdm = objects.BlockDeviceMapping
        vol_bdm = obj_bdm.get_by_volume_and_instance(
            self.context, 'fake-volume-id', 'fake-instance-id')
        for attr in block_device_obj.BLOCK_DEVICE_OPTIONAL_ATTRS:
            self.assertFalse(vol_bdm.obj_attr_is_set(attr))
Exemplo n.º 23
0
    def _stub_instance_get(self, uuid=None):
        self.mox.StubOutWithMock(compute_api.API, "get")
        if uuid is None:
            uuid = uuidutils.generate_uuid()
        instance = fake_instance.fake_db_instance(id=1, uuid=uuid, vm_state=vm_states.ACTIVE, task_state=None)
        instance = objects.Instance._from_db_object(self.context, objects.Instance(), instance)

        self.compute_api.get(self.context, uuid, expected_attrs=["flavor"], want_objects=True).AndReturn(instance)
        return instance
Exemplo n.º 24
0
    def test_get_by_instance_and_volume_id(self, mock_get):
        fake_inst = fake_instance.fake_db_instance()
        mock_get.return_value = self.fake_bdm(fake_inst)

        obj_bdm = objects.BlockDeviceMapping
        vol_bdm = obj_bdm.get_by_volume_and_instance(
            self.context, 'fake-volume-id', 'fake-instance-id')
        for attr in block_device_obj.BLOCK_DEVICE_OPTIONAL_ATTRS:
            self.assertFalse(vol_bdm.obj_attr_is_set(attr))
Exemplo n.º 25
0
 def test_deallocate_fixed_ip(self):
     instance = fake_instance.fake_db_instance()
     self._test_network_api(
         "deallocate_fixed_ip",
         rpc_method="call",
         address="fake_addr",
         host="fake_host",
         instance=instance,
         version="1.12",
     )
Exemplo n.º 26
0
def return_server_by_uuid(context, server_uuid,
                          columns_to_join=None, use_slave=False):
    return fake_instance.fake_db_instance(
        **{'id': 1,
           'uuid': '0cc3346e-9fef-4445-abe6-5d2b2690ec64',
           'name': 'fake',
           'locked': False,
           'launched_at': timeutils.utcnow(),
           'metadata': stub_server_metadata(),
           'vm_state': vm_states.ACTIVE})
def return_server(context, server_id, columns_to_join=None):
    return fake_instance.fake_db_instance(
        **{
            'id': server_id,
            'uuid': '0cc3346e-9fef-4445-abe6-5d2b2690ec64',
            'name': 'fake',
            'locked': False,
            'launched_at': timeutils.utcnow(),
            'vm_state': vm_states.ACTIVE
        })
Exemplo n.º 28
0
def return_server_by_uuid(context, server_uuid,
                          columns_to_join=None, use_slave=False):
    return fake_instance.fake_db_instance(
        **{'id': 1,
           'uuid': '0cc3346e-9fef-4445-abe6-5d2b2690ec64',
           'name': 'fake',
           'locked': False,
           'launched_at': timeutils.utcnow(),
           'metadata': stub_server_metadata(),
           'vm_state': vm_states.ACTIVE})
Exemplo n.º 29
0
 def test_get_by_address_with_extras(self, instance_get, network_get, fixed_get):
     db_fixed = dict(fake_fixed_ip, network=test_network.fake_network, instance=fake_instance.fake_db_instance())
     fixed_get.return_value = db_fixed
     fixedip = fixed_ip.FixedIP.get_by_address(self.context, "1.2.3.4", expected_attrs=["network", "instance"])
     fixed_get.assert_called_once_with(self.context, "1.2.3.4", columns_to_join=["network", "instance"])
     self._compare(fixedip, db_fixed)
     self.assertEqual(db_fixed["network"]["uuid"], fixedip.network.uuid)
     self.assertEqual(db_fixed["instance"]["uuid"], fixedip.instance.uuid)
     self.assertFalse(network_get.called)
     self.assertFalse(instance_get.called)
Exemplo n.º 30
0
    def test_get_by_volume_id_with_expected(self, get_by_vol_id):
        get_by_vol_id.return_value = [self.fake_bdm(
                fake_instance.fake_db_instance())]

        vol_bdm = objects.BlockDeviceMapping.get_by_volume_id(
                self.context, 'fake-volume-id', expected_attrs=['instance'])
        for attr in block_device_obj.BLOCK_DEVICE_OPTIONAL_ATTRS:
            self.assertTrue(vol_bdm.obj_attr_is_set(attr))
        get_by_vol_id.assert_called_once_with(self.context, 'fake-volume-id',
                                              ['instance'])
Exemplo n.º 31
0
 def _stub_instance_get(self, uuid=None):
     if uuid is None:
         uuid = uuidutils.generate_uuid()
     instance = fake_instance.fake_db_instance(
             id=1, uuid=uuid, vm_state=vm_states.ACTIVE,
             task_state=None, launched_at=timeutils.utcnow())
     instance = objects.Instance._from_db_object(
             self.context, objects.Instance(), instance)
     self.compute_api.get(self.context, uuid, expected_attrs=None,
                          want_objects=True).AndReturn(instance)
     return instance
Exemplo n.º 32
0
 def fake_get_all_by_filters(context, *args, **kwargs):
     was['called'] = True
     instances = []
     for x in xrange(2):
         instances.append(fake_instance.fake_db_instance(
                                                 image_ref='1',
                                                 uuid=x,
                                                 name=x,
                                                 vm_state='',
                                                 task_state=''))
     return instances
 def fake_get_all_by_filters(context, *args, **kwargs):
     was['called'] = True
     instances = []
     for x in range(2):
         instances.append(
             fake_instance.fake_db_instance(image_ref='1',
                                            uuid=x,
                                            name=x,
                                            vm_state='',
                                            task_state=''))
     return instances
Exemplo n.º 34
0
    def test_test_get_by_instance_and_volume_id_with_expected(self, mock_get):
        fake_inst = fake_instance.fake_db_instance()
        mock_get.return_value = self.fake_bdm(fake_inst)

        obj_bdm = objects.BlockDeviceMapping
        vol_bdm = obj_bdm.get_by_volume_and_instance(
            self.context, 'fake-volume-id', fake_inst['uuid'],
            expected_attrs=['instance'])
        for attr in block_device_obj.BLOCK_DEVICE_OPTIONAL_ATTRS:
            self.assertTrue(vol_bdm.obj_attr_is_set(attr))
        mock_get.assert_called_once_with(self.context, 'fake-volume-id',
                                         fake_inst['uuid'], ['instance'])
Exemplo n.º 35
0
 def fake_instances(ctxt):
     instances = []
     for x in range(2):
         instances.append(
             fake_instance.fake_db_instance(
                 image_ref=uuids.fake_image_ref,
                 uuid=getattr(uuids, 'instance_%s' % x),
                 name='instance-%s' % x,
                 vm_state='',
                 task_state=''))
     return objects.instance._make_instance_list(
         ctxt, objects.InstanceList(), instances, None)
Exemplo n.º 36
0
 def fake_instances(ctxt):
     instances = []
     for x in range(2):
         instances.append(
             fake_instance.fake_db_instance(
                 image_ref=uuids.fake_image_ref,
                 uuid=getattr(uuids, 'instance_%s' % x),
                 name='instance-%s' % x,
                 vm_state='',
                 task_state=''))
     return objects.instance._make_instance_list(
         ctxt, objects.InstanceList(), instances, None)
Exemplo n.º 37
0
 def fake_get_all_by_filters(context, *args, **kwargs):
     was['called'] = True
     instances = []
     for x in range(2):
         instances.append(
             fake_instance.fake_db_instance(
                 image_ref=uuids.fake_image_ref,
                 uuid=getattr(uuids, 'instance_%s' % x),
                 name='instance-%s' % x,
                 vm_state='',
                 task_state=''))
     return instances
 def _return_server_in_build(self,
                             context,
                             server_id,
                             columns_to_join=None):
     return fake_instance.fake_db_instance(
         **{
             'id': server_id,
             'uuid': '0cc3346e-9fef-4445-abe6-5d2b2690ec64',
             'name': 'fake',
             'locked': False,
             'vm_state': vm_states.BUILDING
         })
 def test_get_target_instance(self, mock_instance_get,
                              mock_get_admin_context):
     admin_context = nova_context.RequestContext(is_admin=True)
     mock_get_admin_context.return_value = admin_context
     given_target = ['instance_id=fake_id']
     mock_instance_get.return_value = fake_instance.fake_db_instance()
     target = self.cmd._get_target(mock.sentinel.context,
                                   given_target)
     self.assertEqual(target,
         {'user_id': 'fake-user', 'project_id': 'fake-project'})
     mock_instance_get.assert_called_once_with(admin_context,
                                               'fake_id')
Exemplo n.º 40
0
 def fake_get_all_by_filters(context, *args, **kwargs):
     was['called'] = True
     instances = []
     for x in range(2):
         instances.append(
             fake_instance.fake_db_instance(
                 image_ref=uuids.fake_image_ref,
                 uuid=getattr(uuids, 'instance_%s' % x),
                 name='instance-%s' % x,
                 vm_state='',
                 task_state=''))
     return instances
Exemplo n.º 41
0
    def test_test_get_by_instance_and_volume_id_with_expected(self, mock_get):
        fake_inst = fake_instance.fake_db_instance()
        mock_get.return_value = self.fake_bdm(fake_inst)

        obj_bdm = objects.BlockDeviceMapping
        vol_bdm = obj_bdm.get_by_volume_and_instance(
            self.context, 'fake-volume-id', fake_inst['uuid'],
            expected_attrs=['instance'])
        for attr in block_device_obj.BLOCK_DEVICE_OPTIONAL_ATTRS:
            self.assertTrue(vol_bdm.obj_attr_is_set(attr))
        mock_get.assert_called_once_with(self.context, 'fake-volume-id',
                                         fake_inst['uuid'], ['instance'])
Exemplo n.º 42
0
 def instance_get_all_by_filters(context, filters,
         sort_key, sort_dir, limit, marker):
     # Pretend we return a full list the first time otherwise we loop
     # infinitely
     if marker is not None:
         return []
     self.assertEqual(fake_context, context)
     self.assertEqual('deleted', sort_key)
     self.assertEqual('asc', sort_dir)
     call_info['got_filters'] = filters
     call_info['get_all'] += 1
     instances = [fake_instance.fake_db_instance() for i in range(3)]
     return instances
 def instance_get_all_by_filters(context, filters, sort_key, sort_dir,
                                 limit, marker):
     # Pretend we return a full list the first time otherwise we loop
     # infinitely
     if marker is not None:
         return []
     self.assertEqual(fake_context, context)
     self.assertEqual('deleted', sort_key)
     self.assertEqual('asc', sort_dir)
     call_info['got_filters'] = filters
     call_info['get_all'] += 1
     instances = [fake_instance.fake_db_instance() for i in range(3)]
     return instances
Exemplo n.º 44
0
    def _stub_instance_get(self, uuid=None):
        self.mox.StubOutWithMock(compute_api.API, 'get')
        if uuid is None:
            uuid = uuidutils.generate_uuid()
        instance = fake_instance.fake_db_instance(
            id=1, uuid=uuid, vm_state=vm_states.ACTIVE, task_state=None)
        instance = objects.Instance._from_db_object(
            self.context, objects.Instance(), instance)

        self.compute_api.get(self.context, uuid,
                             expected_attrs=['flavor'],
                             want_objects=True).AndReturn(instance)
        return instance
Exemplo n.º 45
0
 def test_instance(self, mock_get):
     ctxt = context.get_admin_context()
     fake_migration = fake_db_migration()
     fake_inst = fake_instance.fake_db_instance()
     mock_get.return_value = fake_inst
     mig = migration.Migration._from_db_object(ctxt, migration.Migration(),
                                               fake_migration)
     mig._context = ctxt
     self.assertEqual(mig.instance.host, fake_inst['host'])
     mock_get.assert_called_once_with(
         ctxt,
         fake_migration['instance_uuid'],
         columns_to_join=['info_cache', 'security_groups'])
Exemplo n.º 46
0
    def _stub_instance_get(self, uuid=None):
        self.mox.StubOutWithMock(compute_api.API, 'get')
        if uuid is None:
            uuid = uuidutils.generate_uuid()
        instance = fake_instance.fake_db_instance(
            id=1, uuid=uuid, vm_state=vm_states.ACTIVE, task_state=None)
        instance = objects.Instance._from_db_object(
            self.context, objects.Instance(), instance)

        self.compute_api.get(self.context, uuid,
                             expected_attrs=['flavor', 'pci_devices',
                                             'numa_topology']
                             ).AndReturn(instance)
        return instance
Exemplo n.º 47
0
 def test_instance(self):
     ctxt = context.get_admin_context()
     fake_migration = fake_db_migration()
     fake_inst = fake_instance.fake_db_instance()
     self.mox.StubOutWithMock(db, 'instance_get_by_uuid')
     db.instance_get_by_uuid(
         ctxt,
         fake_migration['instance_uuid'],
         columns_to_join=['info_cache', 'security_groups'],
         use_slave=False).AndReturn(fake_inst)
     mig = migration.Migration._from_db_object(ctxt, migration.Migration(),
                                               fake_migration)
     mig._context = ctxt
     self.mox.ReplayAll()
     self.assertEqual(mig.instance.host, fake_inst['host'])
Exemplo n.º 48
0
 def test_get_by_address_with_extras(self, instance_get, network_get,
                                     fixed_get):
     db_fixed = dict(fake_fixed_ip,
                     network=test_network.fake_network,
                     instance=fake_instance.fake_db_instance())
     fixed_get.return_value = db_fixed
     fixedip = fixed_ip.FixedIP.get_by_address(
         self.context, '1.2.3.4', expected_attrs=['network', 'instance'])
     fixed_get.assert_called_once_with(
         self.context, '1.2.3.4', columns_to_join=['network', 'instance'])
     self._compare(fixedip, db_fixed)
     self.assertEqual(db_fixed['network']['uuid'], fixedip.network.uuid)
     self.assertEqual(db_fixed['instance']['uuid'], fixedip.instance.uuid)
     self.assertFalse(network_get.called)
     self.assertFalse(instance_get.called)
Exemplo n.º 49
0
    def _test_get_instances_pagination(self, mock_shuffle,
            mock_get_by_filters, shuffle=False, updated_since=None,
            project_id=None):
        fake_context = 'fake_context'

        instances0 = objects.instance._make_instance_list(fake_context,
                objects.InstanceList(),
                [fake_instance.fake_db_instance() for i in range(3)],
                expected_attrs=None)
        marker0 = instances0[-1]['uuid']
        instances1 = objects.instance._make_instance_list(fake_context,
                objects.InstanceList(),
                [fake_instance.fake_db_instance() for i in range(3)],
                expected_attrs=None)
        marker1 = instances1[-1]['uuid']

        mock_get_by_filters.side_effect = [instances0, instances1, []]

        instances = cells_utils.get_instances_to_sync(fake_context,
                updated_since, project_id, shuffle=shuffle)
        self.assertEqual(len([x for x in instances]), 6)

        filters = {}
        if updated_since is not None:
            filters['changes-since'] = updated_since
        if project_id is not None:
            filters['project_id'] = project_id
        limit = 100
        expected_calls = [mock.call(fake_context, filters, sort_key='deleted',
                              sort_dir='asc', limit=limit, marker=None),
                          mock.call(fake_context, filters, sort_key='deleted',
                              sort_dir='asc', limit=limit, marker=marker0),
                          mock.call(fake_context, filters, sort_key='deleted',
                              sort_dir='asc', limit=limit, marker=marker1)]
        mock_get_by_filters.assert_has_calls(expected_calls)
        self.assertEqual(3, mock_get_by_filters.call_count)
Exemplo n.º 50
0
    def _stub_instance_get(self, context, uuid=None):
        self.mox.StubOutWithMock(compute_api.API, 'get')
        if uuid is None:
            uuid = uuids.fake
        instance = fake_instance.fake_db_instance(
            id=1, uuid=uuid, vm_state=vm_states.ACTIVE, task_state=None,
            project_id=context.project_id,
            user_id=context.user_id)
        instance = objects.Instance._from_db_object(
            self.context, objects.Instance(), instance)

        self.compute_api.get(self.context, uuid,
                             expected_attrs=['flavor', 'pci_devices',
                                             'numa_topology']
                             ).AndReturn(instance)
        return instance
Exemplo n.º 51
0
        def fake_instance_create(context, inst_, session=None):
            inst = fake_instance.fake_db_instance(**{
                    'id': 1,
                    'uuid': AUTO_INSTANCE_UUID,
                    'created_at': datetime.datetime(2010, 10, 10, 12, 0, 0),
                    'updated_at': datetime.datetime(2010, 10, 10, 12, 0, 0),
                    'progress': 0,
                    'name': 'instance-1',  # this is a property
                    'task_state': '',
                    'vm_state': '',
                    'auto_disk_config': inst_['auto_disk_config'],
                    'security_groups': inst_['security_groups'],
                    'instance_type': flavors.get_default_flavor(),
                    })

            return inst
Exemplo n.º 52
0
    def setUp(self):
        super(MigrationTaskTestCase, self).setUp()
        self.user_id = 'fake'
        self.project_id = 'fake'
        self.context = FakeContext(self.user_id, self.project_id)
        # Normally RequestContext.cell_uuid would be set when targeting
        # the context in nova.conductor.manager.targets_cell but we just
        # fake it here.
        self.context.cell_uuid = uuids.cell1
        self.flavor = fake_flavor.fake_flavor_obj(self.context)
        self.flavor.extra_specs = {'extra_specs': 'fake'}
        inst = fake_instance.fake_db_instance(image_ref='image_ref',
                                              instance_type=self.flavor)
        inst_object = objects.Instance(
            flavor=self.flavor,
            numa_topology=None,
            pci_requests=None,
            system_metadata={'image_hw_disk_bus': 'scsi'})
        self.instance = objects.Instance._from_db_object(
            self.context, inst_object, inst, [])
        self.request_spec = objects.RequestSpec(image=objects.ImageMeta())
        self.host_lists = [[
            objects.Selection(service_host="host1",
                              nodename="node1",
                              cell_uuid=uuids.cell1)
        ]]
        self.filter_properties = {
            'limits': {},
            'retry': {
                'num_attempts': 1,
                'hosts': [['host1', 'node1']]
            }
        }
        self.reservations = []
        self.clean_shutdown = True

        _p = mock.patch('nova.compute.utils.heal_reqspec_is_bfv')
        self.heal_reqspec_is_bfv_mock = _p.start()
        self.addCleanup(_p.stop)

        _p = mock.patch('nova.objects.RequestSpec.ensure_network_information')
        self.ensure_network_information_mock = _p.start()
        self.addCleanup(_p.stop)

        self.mock_network_api = mock.Mock()
Exemplo n.º 53
0
    def setUp(self):
        super(ComputeGetImageMetadataTestCase, self).setUp()
        self.context = context.RequestContext('fake', 'fake')

        self.image = {
            "min_ram": 10,
            "min_disk": 1,
            "disk_format": "raw",
            "container_format": "bare",
            "properties": {},
        }

        self.mock_image_api = mock.Mock()
        self.mock_image_api.get.return_value = self.image

        self.ctx = context.RequestContext('fake', 'fake')

        sys_meta = {
            'image_min_ram': 10,
            'image_min_disk': 1,
            'image_disk_format': 'raw',
            'image_container_format': 'bare',
        }

        flavor = objects.Flavor(id=0,
                                name='m1.fake',
                                memory_mb=10,
                                vcpus=1,
                                root_gb=1,
                                ephemeral_gb=1,
                                flavorid='0',
                                swap=1,
                                rxtx_factor=0.0,
                                vcpu_weight=None)

        instance = fake_instance.fake_db_instance(memory_mb=0,
                                                  root_gb=0,
                                                  system_metadata=sys_meta)
        self.instance_obj = objects.Instance._from_db_object(
            self.ctx,
            objects.Instance(),
            instance,
            expected_attrs=instance_obj.INSTANCE_DEFAULT_FIELDS)
        with mock.patch.object(self.instance_obj, 'save'):
            self.instance_obj.set_flavor(flavor)
Exemplo n.º 54
0
 def setUp(self):
     super(LiveMigrationTaskTestCase, self).setUp()
     self.context = "context"
     self.instance_host = "host"
     self.instance_uuid = "uuid"
     self.instance_image = "image_ref"
     db_instance = fake_instance.fake_db_instance(
         host=self.instance_host,
         uuid=self.instance_uuid,
         power_state=power_state.RUNNING,
         memory_mb=512,
         image_ref=self.instance_image)
     self.instance = objects.Instance._from_db_object(
         self.context, objects.Instance(), db_instance)
     self.destination = "destination"
     self.block_migration = "bm"
     self.disk_over_commit = "doc"
     self._generate_task()
Exemplo n.º 55
0
    def test_prep_resize_post_populates_retry(self):
        self.manager.driver = fakes.FakeFilterScheduler()

        image = 'image'
        instance_uuid = 'fake-instance-id'
        instance = fake_instance.fake_db_instance(uuid=instance_uuid)

        instance_properties = {'project_id': 'fake', 'os_type': 'Linux'}
        instance_type = "m1.tiny"
        request_spec = {
            'instance_properties': instance_properties,
            'instance_type': instance_type,
            'instance_uuids': [instance_uuid]
        }
        retry = {'hosts': [], 'num_attempts': 1}
        filter_properties = {'retry': retry}
        reservations = None

        hosts = [dict(host='host', nodename='node', limits={})]

        self._mox_schedule_method_helper('select_destinations')
        self.manager.driver.select_destinations(
            self.context, request_spec, filter_properties).AndReturn(hosts)

        self.mox.StubOutWithMock(self.manager.compute_rpcapi, 'prep_resize')
        self.manager.compute_rpcapi.prep_resize(
            self.context,
            image,
            mox.IsA(objects.Instance),
            instance_type,
            'host',
            reservations,
            request_spec=request_spec,
            filter_properties=filter_properties,
            node='node')

        self.mox.ReplayAll()
        self.manager.prep_resize(self.context, image, request_spec,
                                 filter_properties, instance, instance_type,
                                 reservations)

        self.assertEqual([['host', 'node']],
                         filter_properties['retry']['hosts'])
 def setUp(self):
     super(MigrationTaskTestCase, self).setUp()
     self.user_id = 'fake'
     self.project_id = 'fake'
     self.context = FakeContext(self.user_id, self.project_id)
     inst = fake_instance.fake_db_instance(image_ref='image_ref')
     self.instance = objects.Instance._from_db_object(
         self.context, objects.Instance(), inst, [])
     self.instance.system_metadata = {'image_hw_disk_bus': 'scsi'}
     self.flavor = fake_flavor.fake_flavor_obj(self.context)
     self.flavor.extra_specs = {'extra_specs': 'fake'}
     self.request_spec = {'instance_type':
                              obj_base.obj_to_primitive(self.flavor),
                          'instance_properties': {},
                          'image': 'image'}
     self.hosts = [dict(host='host1', nodename=None, limits={})]
     self.filter_properties = {'limits': {}, 'retry': {'num_attempts': 1,
                               'hosts': [['host1', None]]}}
     self.reservations = []
     self.clean_shutdown = True
Exemplo n.º 57
0
 def test_ensure_ephemeral_resize_with_root_volume(self, mock_sizes,
                                                   mock_resize):
     mock_sizes.return_value = [2000, 1000]
     instance = fake_instance.fake_db_instance(root_gb=20, ephemeral_gb=20)
     ephemerals = {"4": {"ref": 4}, "5": {"ref": 5}}
     vdis = {
         'root': {
             'osvol': True,
             'ref': 'vdi_ref'
         },
         'ephemerals': ephemerals
     }
     with mock.patch.object(vm_utils,
                            'generate_single_ephemeral',
                            autospec=True) as g:
         self.vmops._resize_up_vdis(instance, vdis)
         self.assertEqual([
             mock.call(self.vmops._session, instance, 4, 2000),
             mock.call(self.vmops._session, instance, 5, 1000)
         ], mock_resize.call_args_list)
         self.assertFalse(g.called)
Exemplo n.º 58
0
    def setUp(self):
        super(ServerMigrationsSamplesJsonTestV2_23, self).setUp()
        fake_context = context.RequestContext('fake', 'fake')

        self.mig1 = objects.Migration(context=fake_context,
                                      **self.fake_migrations[0])
        self.mig1.create()

        self.mig2 = objects.Migration(context=fake_context,
                                      **self.fake_migrations[1])
        self.mig2.create()

        fake_ins = fake_instance.fake_db_instance(uuid=self.UUID_1)
        fake_ins.pop("pci_devices")
        fake_ins.pop("security_groups")
        fake_ins.pop("services")
        fake_ins.pop("tags")
        fake_ins.pop("info_cache")
        fake_ins.pop("id")
        self.instance = objects.Instance(context=fake_context, **fake_ins)
        self.instance.create()