Ejemplo n.º 1
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.º 2
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.º 3
0
    def test_create_instances_here(self):
        # Just grab the first instance type
        inst_type = flavors.get_flavor(1)
        image = {'properties': {}}
        instance_uuids = self.instance_uuids
        instance_props = {'id': 'removed',
                          'security_groups': 'removed',
                          'info_cache': 'removed',
                          'name': 'instance-00000001',
                          'hostname': 'meow',
                          'display_name': 'moo',
                          'image_ref': 'fake_image_ref',
                          'user_id': self.ctxt.user_id,
                          # Test these as lists
                          'metadata': {'moo': 'cow'},
                          'system_metadata': {'meow': 'cat'},
                          'flavor': inst_type,
                          'project_id': self.ctxt.project_id}

        call_info = {'uuids': []}
        block_device_mapping = [
                objects.BlockDeviceMapping(context=self.ctxt,
                    **fake_block_device.FakeDbBlockDeviceDict(
                            block_device.create_image_bdm('fake_image_ref'),
                            anon=True))
               ]

        def _fake_instance_update_at_top(_ctxt, instance):
            call_info['uuids'].append(instance['uuid'])

        self.stubs.Set(self.msg_runner, 'instance_update_at_top',
                       _fake_instance_update_at_top)

        self.scheduler._create_instances_here(self.ctxt, instance_uuids,
                instance_props, inst_type, image,
                ['default'], block_device_mapping)
        self.assertEqual(instance_uuids, call_info['uuids'])

        for count, instance_uuid in enumerate(instance_uuids):
            instance = db.instance_get_by_uuid(self.ctxt, instance_uuid)
            meta = utils.instance_meta(instance)
            self.assertEqual('cow', meta['moo'])
            sys_meta = utils.instance_sys_meta(instance)
            self.assertEqual('cat', sys_meta['meow'])
            self.assertEqual('meow', instance['hostname'])
            self.assertEqual('moo-%d' % (count + 1),
                             instance['display_name'])
            self.assertEqual('fake_image_ref', instance['image_ref'])