def test_create_image(self): # Other images are registered implicitly when they are dropped into # the SR by a dom0 plugin or some other process self.flags(cache_images='none') def fake_fetch_image(*args): return {'root': {'uuid': 'fake-uuid'}} self.stubs.Set(vm_utils, '_fetch_image', fake_fetch_image) other_config = {} def VDI_add_to_other_config(ref, key, value): other_config[key] = value def VDI_get_record(ref): return {'other_config': {}} # Stubbing on the session object and not class so we don't pollute # other tests self.session.VDI_add_to_other_config = VDI_add_to_other_config self.session.VDI_get_record = VDI_get_record vm_utils._create_image(self.context, self.session, self.fake_instance, 'myvdi', 'image1', vm_utils.ImageType.DISK_VHD) expected = {'nova_disk_type': 'root', 'nova_instance_uuid': 'aaaa-bbbb-cccc-dddd'} self.assertEqual(expected, other_config)
def _test_create_image(self, cache_type): sys_meta = {'image_cache_in_nova': True} instance = db.instance_create(self.context, {'system_metadata': sys_meta}) instance = db.instance_get_by_uuid(self.context, instance['uuid']) self.flags(cache_images=cache_type) was = {'called': None} def fake_create_cached_image(*args): was['called'] = 'some' return {} self.stubs.Set(vm_utils, '_create_cached_image', fake_create_cached_image) def fake_fetch_image(*args): was['called'] = 'none' return {} self.stubs.Set(vm_utils, '_fetch_image', fake_fetch_image) vm_utils._create_image(self.context, None, instance, 'foo', 'bar', 'baz') self.assertEqual(was['called'], cache_type)
def test_create_image(self): # Other images are registered implicitly when they are dropped into # the SR by a dom0 plugin or some other process self.flags(cache_images="none") def fake_fetch_image(*args): return {"root": {"uuid": "fake-uuid"}} self.stubs.Set(vm_utils, "_fetch_image", fake_fetch_image) other_config = {} def VDI_add_to_other_config(ref, key, value): other_config[key] = value def VDI_get_record(ref): return {"other_config": {}} # Stubbing on the session object and not class so we don't pollute # other tests self.session.VDI_add_to_other_config = VDI_add_to_other_config self.session.VDI_get_record = VDI_get_record vm_utils._create_image( self.context, self.session, self.fake_instance, "myvdi", "image1", vm_utils.ImageType.DISK_VHD ) expected = {"nova_disk_type": "root", "nova_instance_uuid": "aaaa-bbbb-cccc-dddd"} self.assertEqual(expected, other_config)
def _test_create_image(self, cache_type): sys_meta = {"image_cache_in_nova": True} instance = db.instance_create(self.context, {"system_metadata": sys_meta}) instance = db.instance_get_by_uuid(self.context, instance["uuid"]) self.flags(cache_images=cache_type) was = {"called": None} def fake_create_cached_image(*args): was["called"] = "some" return {} self.stubs.Set(vm_utils, "_create_cached_image", fake_create_cached_image) def fake_fetch_image(*args): was["called"] = "none" return {} self.stubs.Set(vm_utils, "_fetch_image", fake_fetch_image) vm_utils._create_image(self.context, None, instance, "foo", "bar", "baz") self.assertEqual(was["called"], cache_type)