def test_format_image(self): image_ids = {fakes.ID_OS_IMAGE_1: fakes.ID_EC2_IMAGE_1, fakes.ID_OS_IMAGE_AKI_1: fakes.ID_EC2_IMAGE_AKI_1, fakes.ID_OS_IMAGE_ARI_1: fakes.ID_EC2_IMAGE_ARI_1} os_image = copy.deepcopy(fakes.OS_IMAGE_1) # check name and location attributes for an unnamed image os_image['properties'] = {'image_location': 'location'} os_image['name'] = None image = image_api._format_image( 'fake_context', fakes.DB_IMAGE_1, fakes.OSImage(os_image), None, image_ids) self.assertEqual('location', image['imageLocation']) self.assertEqual('location', image['name']) # check name and location attributes for complete image os_image['properties'] = {} os_image['name'] = 'fake_name' image = image_api._format_image( 'fake_context', fakes.DB_IMAGE_1, fakes.OSImage(os_image), None, image_ids) self.assertEqual('None (fake_name)', image['imageLocation']) self.assertEqual('fake_name', image['name']) # check ebs image type for bdm_v2 mapping type os_image['properties'] = { 'bdm_v2': True, 'root_device_name': '/dev/vda', 'block_device_mapping': [ {'boot_index': 0, 'snapshot_id': fakes.ID_OS_SNAPSHOT_2, 'source_type': 'snapshot', 'destination_type': 'volume'}]} image = image_api._format_image( 'fake_context', fakes.DB_IMAGE_1, fakes.OSImage(os_image), None, image_ids, snapshot_ids={fakes.ID_OS_SNAPSHOT_2: fakes.ID_EC2_SNAPSHOT_2}) self.assertEqual('ebs', image['rootDeviceType']) # check instance-store image attributes with no any device mappings os_image['properties'] = {'root_device_name': '/dev/vda'} image = image_api._format_image( 'fake_context', fakes.DB_IMAGE_1, fakes.OSImage(os_image), None, None) self.assertEqual('instance-store', image['rootDeviceType']) self.assertNotIn('blockDeviceMapping', image)
def test_format_image(self): image_ids = { fakes.ID_OS_IMAGE_1: fakes.ID_EC2_IMAGE_1, fakes.ID_OS_IMAGE_AKI_1: fakes.ID_EC2_IMAGE_AKI_1, fakes.ID_OS_IMAGE_ARI_1: fakes.ID_EC2_IMAGE_ARI_1 } os_image = copy.deepcopy(fakes.OS_IMAGE_1) os_image['properties'] = {'image_location': 'location'} os_image['name'] = None image = image_api._format_image('fake_context', fakes.DB_IMAGE_1, fakes.OSImage(os_image), None, image_ids) self.assertEqual('location', image['imageLocation']) self.assertEqual('location', image['name']) os_image['properties'] = {} os_image['name'] = 'fake_name' image = image_api._format_image('fake_context', fakes.DB_IMAGE_1, fakes.OSImage(os_image), None, image_ids) self.assertEqual('None (fake_name)', image['imageLocation']) self.assertEqual('fake_name', image['name']) os_image['properties'] = { 'bdm_v2': True, 'root_device_name': '/dev/vda', 'block_device_mapping': [{ 'boot_index': 0, 'snapshot_id': fakes.ID_OS_SNAPSHOT_2 }] } image = image_api._format_image( 'fake_context', fakes.DB_IMAGE_1, fakes.OSImage(os_image), None, image_ids, snapshot_ids={fakes.ID_OS_SNAPSHOT_2: fakes.ID_EC2_SNAPSHOT_2}) self.assertEqual('ebs', image['rootDeviceType'])
def check_state_translation(state, expected): os_image.properties['image_state'] = state image = image_api._format_image('fake_context', fakes.DB_IMAGE_1, os_image, None, None) self.assertEqual(expected, image['imageState'], "Wrong '%s' internal state translation" % state)
def check_status_translation(status, expected): os_image.status = status image = image_api._format_image('fake_context', fakes.DB_IMAGE_1, os_image, None, None) self.assertEqual(expected, image['imageState'], "Wrong '%s' Glance status translation" % status)
def test_format_image(self): image_ids = { fakes.ID_OS_IMAGE_1: fakes.ID_EC2_IMAGE_1, fakes.ID_OS_IMAGE_AKI_1: fakes.ID_EC2_IMAGE_AKI_1, fakes.ID_OS_IMAGE_ARI_1: fakes.ID_EC2_IMAGE_ARI_1 } os_image = copy.deepcopy(fakes.OS_IMAGE_1) # check name and location attributes for an unnamed image os_image['properties'] = {'image_location': 'location'} os_image['name'] = None image = image_api._format_image('fake_context', fakes.DB_IMAGE_1, fakes.OSImage(os_image), None, image_ids) self.assertEqual('location', image['imageLocation']) self.assertEqual('location', image['name']) # check name and location attributes for complete image os_image['properties'] = {} os_image['name'] = 'fake_name' image = image_api._format_image('fake_context', fakes.DB_IMAGE_1, fakes.OSImage(os_image), None, image_ids) self.assertEqual('None (fake_name)', image['imageLocation']) self.assertEqual('fake_name', image['name']) # check ebs image type for bdm_v2 mapping type os_image['properties'] = { 'bdm_v2': True, 'root_device_name': '/dev/vda', 'block_device_mapping': [{ 'boot_index': 0, 'snapshot_id': fakes.ID_OS_SNAPSHOT_2, 'source_type': 'snapshot', 'destination_type': 'volume' }] } image = image_api._format_image( 'fake_context', fakes.DB_IMAGE_1, fakes.OSImage(os_image), None, image_ids, snapshot_ids={fakes.ID_OS_SNAPSHOT_2: fakes.ID_EC2_SNAPSHOT_2}) self.assertEqual('ebs', image['rootDeviceType']) # check instance-store image attributes with no any device mappings os_image['properties'] = {'root_device_name': '/dev/vda'} image = image_api._format_image('fake_context', fakes.DB_IMAGE_1, fakes.OSImage(os_image), None, None) self.assertEqual('instance-store', image['rootDeviceType']) self.assertNotIn('blockDeviceMapping', image) # check Glance status translation os_image = fakes.OSImage({'id': fakes.ID_OS_IMAGE_1}) def check_status_translation(status, expected): os_image.status = status image = image_api._format_image('fake_context', fakes.DB_IMAGE_1, os_image, None, None) self.assertEqual(expected, image['imageState'], "Wrong '%s' Glance status translation" % status) check_status_translation('queued', 'pending') check_status_translation('saving', 'pending') check_status_translation('active', 'available') check_status_translation('killed', 'deregistered') check_status_translation('pending_delete', 'deregistered') check_status_translation('deleted', 'deregistered') check_status_translation('deactivated', 'invalid') check_status_translation('unknown-status', 'error') # check internal state translation os_image.status = 'queued' def check_state_translation(state, expected): os_image.properties['image_state'] = state image = image_api._format_image('fake_context', fakes.DB_IMAGE_1, os_image, None, None) self.assertEqual(expected, image['imageState'], "Wrong '%s' internal state translation" % state) for state in ('downloading', 'decrypting', 'untarring', 'uploading'): check_state_translation(state, 'pending') for state in ('failed_download', 'failed_decrypt', 'failed_untar', 'failed_upload'): check_state_translation(state, 'failed') os_image.status = 'active' check_state_translation('available', 'available') check_state_translation('unknown-state', 'available')
def check_state_translation(state, expected): os_image.image_state = state image = image_api._format_image( 'fake_context', fakes.DB_IMAGE_1, os_image, None, None) self.assertEqual(expected, image['imageState'], "Wrong '%s' internal state translation" % state)
def check_status_translation(status, expected): os_image.status = status image = image_api._format_image( 'fake_context', fakes.DB_IMAGE_1, os_image, None, None) self.assertEqual(expected, image['imageState'], "Wrong '%s' Glance status translation" % status)
def test_format_image(self): image_ids = {fakes.ID_OS_IMAGE_1: fakes.ID_EC2_IMAGE_1, fakes.ID_OS_IMAGE_AKI_1: fakes.ID_EC2_IMAGE_AKI_1, fakes.ID_OS_IMAGE_ARI_1: fakes.ID_EC2_IMAGE_ARI_1} os_image = {'id': fakes.ID_OS_IMAGE_1, 'owner': fakes.ID_OS_PROJECT, 'created_at': fakes.TIME_CREATE_IMAGE, 'visibility': 'private', 'status': 'active', 'container_format': 'ami', 'name': 'fake_name'} # check name and location attributes for an unnamed image os_image['image_location'] = 'location' os_image['name'] = None image = image_api._format_image( 'fake_context', fakes.DB_IMAGE_1, fakes.OSImage(os_image), None, image_ids) self.assertEqual('location', image['imageLocation']) self.assertEqual('location', image['name']) # check name and location attributes for complete image os_image['image_location'] = None os_image['name'] = 'fake_name' image = image_api._format_image( 'fake_context', fakes.DB_IMAGE_1, fakes.OSImage(os_image), None, image_ids) self.assertEqual('None (fake_name)', image['imageLocation']) self.assertEqual('fake_name', image['name']) # check ebs image type for bdm_v2 mapping type os_image['bdm_v2'] = True os_image['root_device_name'] = '/dev/vda' os_image['block_device_mapping'] = [ {'boot_index': 0, 'snapshot_id': fakes.ID_OS_SNAPSHOT_2, 'source_type': 'snapshot', 'destination_type': 'volume'}] image = image_api._format_image( 'fake_context', fakes.DB_IMAGE_1, fakes.OSImage(os_image), None, image_ids, snapshot_ids={fakes.ID_OS_SNAPSHOT_2: fakes.ID_EC2_SNAPSHOT_2}) self.assertEqual('ebs', image['rootDeviceType']) # check instance-store image attributes with no any device mappings os_image['bdm_v2'] = False os_image['root_device_name'] = '/dev/vda' os_image['block_device_mapping'] = [] image = image_api._format_image( 'fake_context', fakes.DB_IMAGE_1, fakes.OSImage(os_image), None, None) self.assertEqual('instance-store', image['rootDeviceType']) self.assertNotIn('blockDeviceMapping', image) # check Glance status translation os_image = fakes.OSImage({'id': fakes.ID_OS_IMAGE_1}) def check_status_translation(status, expected): os_image.status = status image = image_api._format_image( 'fake_context', fakes.DB_IMAGE_1, os_image, None, None) self.assertEqual(expected, image['imageState'], "Wrong '%s' Glance status translation" % status) check_status_translation('queued', 'pending') check_status_translation('saving', 'pending') check_status_translation('active', 'available') check_status_translation('killed', 'deregistered') check_status_translation('pending_delete', 'deregistered') check_status_translation('deleted', 'deregistered') check_status_translation('deactivated', 'invalid') check_status_translation('unknown-status', 'error') # check internal state translation os_image.status = 'queued' def check_state_translation(state, expected): os_image.image_state = state image = image_api._format_image( 'fake_context', fakes.DB_IMAGE_1, os_image, None, None) self.assertEqual(expected, image['imageState'], "Wrong '%s' internal state translation" % state) for state in ('downloading', 'decrypting', 'untarring', 'uploading'): check_state_translation(state, 'pending') for state in ('failed_download', 'failed_decrypt', 'failed_untar', 'failed_upload'): check_state_translation(state, 'failed') os_image.status = 'active' check_state_translation('available', 'available') check_state_translation('unknown-state', 'available')
def test_format_image(self): image_ids = { fakes.ID_OS_IMAGE_1: fakes.ID_EC2_IMAGE_1, fakes.ID_OS_IMAGE_AKI_1: fakes.ID_EC2_IMAGE_AKI_1, fakes.ID_OS_IMAGE_ARI_1: fakes.ID_EC2_IMAGE_ARI_1 } os_image = copy.deepcopy(fakes.OS_IMAGE_1) # check name and location attributes for an unnamed image os_image['properties'] = {'image_location': 'location'} os_image['name'] = None image = image_api._format_image('fake_context', fakes.DB_IMAGE_1, fakes.OSImage(os_image), None, image_ids) self.assertEqual('location', image['imageLocation']) self.assertEqual('location', image['name']) # check name and location attributes for complete image os_image['properties'] = {} os_image['name'] = 'fake_name' image = image_api._format_image('fake_context', fakes.DB_IMAGE_1, fakes.OSImage(os_image), None, image_ids) self.assertEqual('None (fake_name)', image['imageLocation']) self.assertEqual('fake_name', image['name']) # check ebs image type for bdm_v2 mapping type os_image['properties'] = { 'bdm_v2': True, 'root_device_name': '/dev/vda', 'block_device_mapping': [{ 'boot_index': 0, 'snapshot_id': fakes.ID_OS_SNAPSHOT_2, 'source_type': 'snapshot', 'destination_type': 'volume' }] } image = image_api._format_image( 'fake_context', fakes.DB_IMAGE_1, fakes.OSImage(os_image), None, image_ids, snapshot_ids={fakes.ID_OS_SNAPSHOT_2: fakes.ID_EC2_SNAPSHOT_2}) self.assertEqual('ebs', image['rootDeviceType']) # check instance-store image attributes with no any device mappings os_image['properties'] = {'root_device_name': '/dev/vda'} image = image_api._format_image('fake_context', fakes.DB_IMAGE_1, fakes.OSImage(os_image), None, None) self.assertEqual('instance-store', image['rootDeviceType']) self.assertNotIn('blockDeviceMapping', image)