def test_snapshot(self): def update_task_state(task_state, expected_state=None): self._loc_task_state = task_state self._loc_expected_task_state = expected_state loc_context = context.get_admin_context() properties = { 'instance_id': self.instance['id'], 'user_id': str(loc_context.user_id) } sent_meta = { 'name': 'fake_snap', 'is_public': False, 'status': 'creating', 'properties': properties } image_service = fake.FakeImageService() recv_meta = image_service.create(loc_context, sent_meta) self.powervm_connection.snapshot(loc_context, self.instance, recv_meta['id'], update_task_state) self.assertTrue(self._loc_task_state == task_states.IMAGE_UPLOADING and self._loc_expected_task_state == task_states.IMAGE_PENDING_UPLOAD)
def test_snapshot(self): def update_task_state(task_state, expected_state=None): self._loc_task_state = task_state self._loc_expected_task_state = expected_state loc_context = context.get_admin_context() arch = 'fake_arch' properties = { 'instance_id': self.instance['id'], 'user_id': str(loc_context.user_id), 'architecture': arch } snapshot_name = 'fake_snap' sent_meta = { 'name': snapshot_name, 'is_public': False, 'status': 'creating', 'properties': properties } image_service = fake.FakeImageService() recv_meta = image_service.create(loc_context, sent_meta) self.powervm_connection.snapshot(loc_context, self.instance, recv_meta['id'], update_task_state) self.assertTrue(self._loc_task_state == task_states.IMAGE_UPLOADING and self._loc_expected_task_state == task_states.IMAGE_PENDING_UPLOAD) snapshot = image_service.show(context, recv_meta['id']) self.assertEquals(snapshot['properties']['image_state'], 'available') self.assertEquals(snapshot['properties']['architecture'], arch) self.assertEquals(snapshot['status'], 'active') self.assertEquals(snapshot['name'], snapshot_name)
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(_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()
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_is_public(self): metadata = { 'properties': { 'image_location': 'mybucket/my.img.manifest.xml' }, 'name': 'mybucket/my.img' } handle, tempf = tempfile.mkstemp(dir='/tmp') ignore = mox.IgnoreArg() mockobj = self.mox.CreateMockAnything() self.stubs.Set(self.image_service, '_conn', mockobj) mockobj(ignore).AndReturn(mockobj) self.stubs.Set(mockobj, 'get_bucket', mockobj) mockobj(ignore).AndReturn(mockobj) self.stubs.Set(mockobj, 'get_key', mockobj) mockobj(ignore).AndReturn(mockobj) self.stubs.Set(mockobj, 'get_contents_as_string', mockobj) mockobj().AndReturn(file_manifest_xml) self.stubs.Set(self.image_service, '_download_file', mockobj) mockobj(ignore, ignore, ignore).AndReturn(tempf) self.stubs.Set(binascii, 'a2b_hex', mockobj) mockobj(ignore).AndReturn('foo') mockobj(ignore).AndReturn('foo') self.stubs.Set(self.image_service, '_decrypt_image', mockobj) mockobj(ignore, ignore, ignore, ignore, ignore).AndReturn(mockobj) self.stubs.Set(self.image_service, '_untarzip_image', mockobj) mockobj(ignore, ignore).AndReturn(tempf) self.mox.ReplayAll() 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 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() # 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.InvalidInstanceIDMalformed) 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): 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) # NOTE(comstud): Make 'cast' behave like a 'call' which will # ensure that operations complete self.stubs.Set(rpc, 'cast', rpc.call) # make sure we can map ami-00000001/2 to a uuid in FakeImageService db.api.s3_image_create(self.context, 'cedef40a-ed67-4d10-800e-17455edce175') db.api.s3_image_create(self.context, '76fa36fc-c930-4bf3-8c8a-ea2a2420deb6')
def setUp(self): super(_VirtDriverTestCase, self).setUp() self.connection = importutils.import_object(self.driver_module, fake.FakeVirtAPI()) self.ctxt = test_utils.get_test_admin_context() self.image_service = fake_image.FakeImageService()
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.InvalidInstanceIDMalformed) 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')