def setUp(self): super(_VirtDriverTestCase, self).setUp() self.flags(instances_path=self.useFixture(fixtures.TempDir()).path) self.connection = importutils.import_object(self.driver_module, fake.FakeVirtAPI()) self.ctxt = test_utils.get_test_admin_context() self.image_service = fake_image.FakeImageService() # NOTE(dripton): resolve_driver_format does some file reading and # writing and chowning that complicate testing too much by requiring # using real directories with proper permissions. Just stub it out # here; we test it in test_imagebackend.py self.stubs.Set(imagebackend.Image, 'resolve_driver_format', imagebackend.Image._get_driver_format)
def test_s3_create_is_public(self): self._initialize_mocks() metadata = {'properties': { 'image_location': 'mybucket/my.img.manifest.xml'}, 'name': 'mybucket/my.img'} img = self.image_service._s3_create(self.context, metadata) eventlet.sleep() translated = self.image_service._translate_id_to_uuid(self.context, img) uuid = translated['id'] image_service = fake.FakeImageService() updated_image = image_service.update(self.context, uuid, {'is_public': True}, purge_props=False) self.assertTrue(updated_image['is_public']) self.assertEqual(updated_image['status'], 'active') self.assertEqual(updated_image['properties']['image_state'], 'available')
def test_s3_create_image_locations(self): image_location_1 = 'testbucket_1/test.img.manifest.xml' # Use another location that starts with a '/' image_location_2 = '/testbucket_2/test.img.manifest.xml' metadata = [{'properties': {'image_location': image_location_1}}, {'properties': {'image_location': image_location_2}}] for mdata in metadata: self._initialize_mocks() image = self.image_service._s3_create(self.context, mdata) eventlet.sleep() translated = self.image_service._translate_id_to_uuid(self.context, image) uuid = translated['id'] image_service = fake.FakeImageService() updated_image = image_service.update(self.context, uuid, {'properties': {'image_state': 'available'}}, purge_props=False) self.assertEqual(updated_image['properties']['image_state'], 'available')
def setUp(self): super(EC2ValidateTestCase, self).setUp() self.flags(compute_driver='nova.virt.fake.FakeDriver') def dumb(*args, **kwargs): pass self.stubs.Set(compute_utils, 'notify_about_instance_usage', dumb) fake_network.set_stub_network_methods(self.stubs) # set up our cloud self.cloud = cloud.CloudController() # Short-circuit the conductor service self.flags(use_local=True, group='conductor') # Stub out the notification service so we use the no-op serializer # and avoid lazy-load traces with the wrap_exception decorator in # the compute service. fake_notifier.stub_notifier(self.stubs) self.addCleanup(fake_notifier.reset) # set up services self.conductor = self.start_service('conductor', manager=CONF.conductor.manager) self.compute = self.start_service('compute') self.scheduter = self.start_service('scheduler') self.network = self.start_service('network') self.image_service = fake.FakeImageService() self.user_id = 'fake' self.project_id = 'fake' self.context = context.RequestContext(self.user_id, self.project_id, is_admin=True) self.EC2_MALFORMED_IDS = ['foobar', '', 123] self.EC2_VALID__IDS = ['i-284f3a41', 'i-001', 'i-deadbeef'] self.ec2_id_exception_map = [(x, exception.InvalidInstanceIDMalformed) for x in self.EC2_MALFORMED_IDS] self.ec2_id_exception_map.extend([(x, exception.InstanceNotFound) for x in self.EC2_VALID__IDS]) self.volume_id_exception_map = [(x, exception.InvalidVolumeIDMalformed) for x in self.EC2_MALFORMED_IDS] self.volume_id_exception_map.extend([(x, exception.VolumeNotFound) for x in self.EC2_VALID__IDS]) def fake_show(meh, context, id, **kwargs): return { 'id': id, 'container_format': 'ami', 'properties': { 'kernel_id': 'cedef40a-ed67-4d10-800e-17455edce175', 'ramdisk_id': 'cedef40a-ed67-4d10-800e-17455edce175', 'type': 'machine', 'image_state': 'available' } } def fake_detail(self, context, **kwargs): image = fake_show(self, context, None) image['name'] = kwargs.get('name') return [image] fake.stub_out_image_service(self.stubs) self.stubs.Set(fake._FakeImageService, 'show', fake_show) self.stubs.Set(fake._FakeImageService, 'detail', fake_detail) self.useFixture(cast_as_call.CastAsCall(self.stubs)) # make sure we can map ami-00000001/2 to a uuid in FakeImageService db.s3_image_create(self.context, 'cedef40a-ed67-4d10-800e-17455edce175') db.s3_image_create(self.context, '76fa36fc-c930-4bf3-8c8a-ea2a2420deb6')