def test_format_mappings(self): db_api = self.mock_db() # check virtual mapping formatting properties = { 'mappings': [{ 'virtual': 'ami', 'device': '/dev/sda' }, { 'virtual': 'root', 'device': 'sda' }, { 'virtual': 'ephemeral0', 'device': 'sdb' }, { 'virtual': 'swap', 'device': 'sdc' }, { 'virtual': 'ephemeral1', 'device': 'sdd' }, { 'virtual': 'ephemeral2', 'device': 'sde' }, { 'virtual': 'ephemeral', 'device': 'sdf' }, { 'virtual': '/dev/sdf1', 'device': 'root' }], } expected = [ { 'virtualName': 'ephemeral0', 'deviceName': '/dev/sdb' }, { 'virtualName': 'swap', 'deviceName': '/dev/sdc' }, { 'virtualName': 'ephemeral1', 'deviceName': '/dev/sdd' }, { 'virtualName': 'ephemeral2', 'deviceName': '/dev/sde' }, ] result = image_api._format_mappings('fake_context', properties) self.assertEqual(expected, result) # check bdm v2 formatting db_api.set_mock_items(fakes.DB_IMAGE_2, fakes.DB_VOLUME_3) properties = { 'bdm_v2': True, 'block_device_mapping': [ { 'boot_index': 0, 'snapshot_id': fakes.ID_OS_SNAPSHOT_1, 'source_type': 'snapshot', 'destination_type': 'volume' }, { 'boot_index': None, 'snapshot_id': fakes.ID_OS_SNAPSHOT_2, 'source_type': 'snapshot', 'destination_type': 'volume' }, { 'device_name': 'vdi', 'boot_index': -1, 'image_id': fakes.ID_OS_IMAGE_2, 'source_type': 'image', 'destination_type': 'volume', 'volume_size': 20 }, { 'device_name': 'vdv', 'boot_index': -1, 'volume_id': fakes.ID_OS_VOLUME_3, 'source_type': 'volume', 'destination_type': 'volume' }, { 'device_name': 'vdb', 'boot_index': -1, 'source_type': 'blank', 'destination_type': 'volume', 'volume_size': 100, 'delete_on_termination': True }, ], } expected = [ { 'deviceName': 'vdx', 'ebs': { 'snapshotId': fakes.ID_EC2_SNAPSHOT_1, 'deleteOnTermination': False } }, { 'ebs': { 'snapshotId': fakes.ID_EC2_SNAPSHOT_2, 'deleteOnTermination': False } }, { 'deviceName': 'vdi', 'ebs': { 'snapshotId': fakes.ID_EC2_IMAGE_2, 'volumeSize': 20, 'deleteOnTermination': False } }, { 'deviceName': 'vdv', 'ebs': { 'snapshotId': fakes.ID_EC2_VOLUME_3, 'deleteOnTermination': False } }, { 'deviceName': 'vdb', 'ebs': { 'volumeSize': 100, 'deleteOnTermination': True } }, ] result = image_api._format_mappings('fake_context', properties, root_device_name='vdx', snapshot_ids={ fakes.ID_OS_SNAPSHOT_1: fakes.ID_EC2_SNAPSHOT_1, fakes.ID_OS_SNAPSHOT_2: fakes.ID_EC2_SNAPSHOT_2 }) self.assertEqual(expected, result) # check inheritance and generation of virtual name properties = { 'mappings': [ { 'device': 'vdd', 'virtual': 'ephemeral1' }, ], 'bdm_v2': True, 'block_device_mapping': [ { 'device_name': '/dev/vdb', 'source_type': 'blank', 'destination_type': 'local', 'guest_format': 'swap' }, { 'device_name': 'vdc', 'source_type': 'blank', 'destination_type': 'local', 'volume_size': 5 }, { 'device_name': 'vde', 'source_type': 'blank', 'destination_type': 'local' }, ], } expected = [ { 'deviceName': '/dev/vdd', 'virtualName': 'ephemeral1' }, { 'deviceName': '/dev/vdb', 'virtualName': 'swap' }, { 'deviceName': 'vdc', 'virtualName': 'ephemeral0' }, { 'deviceName': 'vde', 'virtualName': 'ephemeral2' }, ] result = image_api._format_mappings('fake_context', properties) self.assertEqual(expected, result)
def test_format_mappings(self): db_api = self.mock_db() # check virtual mapping formatting properties = { 'mappings': [ {'virtual': 'ami', 'device': '/dev/sda'}, {'virtual': 'root', 'device': 'sda'}, {'virtual': 'ephemeral0', 'device': 'sdb'}, {'virtual': 'swap', 'device': 'sdc'}, {'virtual': 'ephemeral1', 'device': 'sdd'}, {'virtual': 'ephemeral2', 'device': 'sde'}, {'virtual': 'ephemeral', 'device': 'sdf'}, {'virtual': '/dev/sdf1', 'device': 'root'}], } expected = [ {'virtualName': 'ephemeral0', 'deviceName': '/dev/sdb'}, {'virtualName': 'swap', 'deviceName': '/dev/sdc'}, {'virtualName': 'ephemeral1', 'deviceName': '/dev/sdd'}, {'virtualName': 'ephemeral2', 'deviceName': '/dev/sde'}, ] result = image_api._format_mappings('fake_context', properties) self.assertEqual(expected, result) # check bdm v2 formatting db_api.set_mock_items(fakes.DB_IMAGE_2, fakes.DB_VOLUME_3) properties = { 'bdm_v2': True, 'block_device_mapping': [ {'boot_index': 0, 'snapshot_id': fakes.ID_OS_SNAPSHOT_1, 'source_type': 'snapshot', 'destination_type': 'volume'}, {'boot_index': None, 'snapshot_id': fakes.ID_OS_SNAPSHOT_2, 'source_type': 'snapshot', 'destination_type': 'volume'}, {'device_name': 'vdi', 'boot_index': -1, 'image_id': fakes.ID_OS_IMAGE_2, 'source_type': 'image', 'destination_type': 'volume', 'volume_size': 20}, {'device_name': 'vdv', 'boot_index': -1, 'volume_id': fakes.ID_OS_VOLUME_3, 'source_type': 'volume', 'destination_type': 'volume'}, {'device_name': 'vdb', 'boot_index': -1, 'source_type': 'blank', 'destination_type': 'volume', 'volume_size': 100, 'delete_on_termination': True}, ], } expected = [ {'deviceName': 'vdx', 'ebs': {'snapshotId': fakes.ID_EC2_SNAPSHOT_1, 'deleteOnTermination': False}}, {'ebs': {'snapshotId': fakes.ID_EC2_SNAPSHOT_2, 'deleteOnTermination': False}}, {'deviceName': 'vdi', 'ebs': {'snapshotId': fakes.ID_EC2_IMAGE_2, 'volumeSize': 20, 'deleteOnTermination': False}}, {'deviceName': 'vdv', 'ebs': {'snapshotId': fakes.ID_EC2_VOLUME_3, 'deleteOnTermination': False}}, {'deviceName': 'vdb', 'ebs': {'volumeSize': 100, 'deleteOnTermination': True}}, ] result = image_api._format_mappings( 'fake_context', properties, root_device_name='vdx', snapshot_ids={fakes.ID_OS_SNAPSHOT_1: fakes.ID_EC2_SNAPSHOT_1, fakes.ID_OS_SNAPSHOT_2: fakes.ID_EC2_SNAPSHOT_2}) self.assertEqual(expected, result) # check inheritance and generation of virtual name properties = { 'mappings': [ {'device': 'vdd', 'virtual': 'ephemeral1'}, ], 'bdm_v2': True, 'block_device_mapping': [ {'device_name': '/dev/vdb', 'source_type': 'blank', 'destination_type': 'local', 'guest_format': 'swap'}, {'device_name': 'vdc', 'source_type': 'blank', 'destination_type': 'local', 'volume_size': 5}, {'device_name': 'vde', 'source_type': 'blank', 'destination_type': 'local'}, ], } expected = [ {'deviceName': '/dev/vdd', 'virtualName': 'ephemeral1'}, {'deviceName': '/dev/vdb', 'virtualName': 'swap'}, {'deviceName': 'vdc', 'virtualName': 'ephemeral0'}, {'deviceName': 'vde', 'virtualName': 'ephemeral2'}, ] result = image_api._format_mappings('fake_context', properties) self.assertEqual(expected, result)