Ejemplo n.º 1
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)
Ejemplo n.º 2
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)
Ejemplo n.º 3
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
Ejemplo n.º 4
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')
Ejemplo n.º 5
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)
Ejemplo n.º 6
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})
Ejemplo n.º 7
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})
Ejemplo n.º 8
0
 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
         })
Ejemplo n.º 9
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
        })
Ejemplo n.º 10
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})
Ejemplo n.º 11
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'])
        self.assertRemotes()
Ejemplo n.º 12
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'])
        self.assertRemotes()
Ejemplo n.º 13
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
Ejemplo n.º 14
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
Ejemplo n.º 15
0
 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
         })
Ejemplo n.º 16
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
Ejemplo n.º 17
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
        })
Ejemplo n.º 18
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)
Ejemplo n.º 19
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'])
Ejemplo n.º 20
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'])
Ejemplo n.º 21
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()
Ejemplo n.º 22
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()
Ejemplo n.º 23
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)
Ejemplo n.º 24
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
Ejemplo n.º 25
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
Ejemplo n.º 26
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]

        self.mox.StubOutWithMock(objects.InstanceList, 'get_by_host')
        self.mox.StubOutWithMock(self.compute.driver, 'get_num_instances')
        self.mox.StubOutWithMock(vm_utils, 'lookup')
        self.mox.StubOutWithMock(self.compute, '_sync_instance_power_state')

        objects.InstanceList.get_by_host(ctxt,
                self.compute.host, expected_attrs=[],
                use_slave=True).AndReturn(instance_list)
        self.compute.driver.get_num_instances().AndReturn(1)
        vm_utils.lookup(self.compute.driver._session, instance['name'],
                False).AndReturn(None)
        self.compute._sync_instance_power_state(ctxt, instance,
                power_state.NOSTATE)

        self.mox.ReplayAll()

        self.compute._sync_power_states(ctxt)
Ejemplo n.º 27
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]

        self.mox.StubOutWithMock(objects.InstanceList, 'get_by_host')
        self.mox.StubOutWithMock(self.compute.driver, 'get_num_instances')
        self.mox.StubOutWithMock(vm_utils, 'lookup')
        self.mox.StubOutWithMock(self.compute, '_sync_instance_power_state')

        objects.InstanceList.get_by_host(
            ctxt, self.compute.host, expected_attrs=[],
            use_slave=True).AndReturn(instance_list)
        self.compute.driver.get_num_instances().AndReturn(1)
        vm_utils.lookup(self.compute.driver._session, instance['name'],
                        False).AndReturn(None)
        self.compute._sync_instance_power_state(ctxt, instance,
                                                power_state.NOSTATE)

        self.mox.ReplayAll()

        self.compute._sync_power_states(ctxt)
Ejemplo n.º 28
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')
Ejemplo n.º 29
0
 def setUp(self):
     super(_TestQuotasObject, self).setUp()
     self.context = context.RequestContext('fake_user1', 'fake_proj1')
     self.instance = fake_instance.fake_db_instance(project_id='fake_proj2',
                                                    user_id='fake_user2')
Ejemplo n.º 30
0
 def setUp(self):
     super(_TestQuotasObject, self).setUp()
     self.context = context.RequestContext('fake_user1', 'fake_proj1')
     self.instance = fake_instance.fake_db_instance(
             project_id='fake_proj2', user_id='fake_user2')
Ejemplo n.º 31
0
 def fake_instance_get_by_uuid(context, instance_uuid,
                               columns_to_join=None,
                               use_slave=None):
     return fake_instance.fake_db_instance(uuid=instance_uuid)
Ejemplo n.º 32
0
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})