def test_format_mapping(self): properties = { "mappings": [ {"virtual": "ami", "device": "sda1"}, {"virtual": "root", "device": "/dev/sda1"}, {"virtual": "swap", "device": "sdb1"}, {"virtual": "swap", "device": "sdb2"}, {"virtual": "swap", "device": "sdb3"}, {"virtual": "swap", "device": "sdb4"}, {"virtual": "ephemeral0", "device": "sdc1"}, {"virtual": "ephemeral1", "device": "sdc2"}, {"virtual": "ephemeral2", "device": "sdc3"}, ], "block_device_mapping": [ # root {"device_name": "/dev/sda1", "snapshot_id": 0x12345678, "delete_on_termination": False}, # overwrite swap {"device_name": "/dev/sdb2", "snapshot_id": 0x23456789, "delete_on_termination": False}, {"device_name": "/dev/sdb3", "snapshot_id": 0x3456789A}, {"device_name": "/dev/sdb4", "no_device": True}, # overwrite ephemeral {"device_name": "/dev/sdc2", "snapshot_id": 0x3456789A, "delete_on_termination": False}, {"device_name": "/dev/sdc3", "snapshot_id": 0x456789AB}, {"device_name": "/dev/sdc4", "no_device": True}, # volume {"device_name": "/dev/sdd1", "snapshot_id": 0x87654321, "delete_on_termination": False}, {"device_name": "/dev/sdd2", "snapshot_id": 0x98765432}, {"device_name": "/dev/sdd3", "snapshot_id": 0xA9875463}, {"device_name": "/dev/sdd4", "no_device": True}, ], } expected_result = { "blockDeviceMapping": [ # root {"deviceName": "/dev/sda1", "ebs": {"snapshotId": "snap-12345678", "deleteOnTermination": False}}, # swap {"deviceName": "/dev/sdb1", "virtualName": "swap"}, {"deviceName": "/dev/sdb2", "ebs": {"snapshotId": "snap-23456789", "deleteOnTermination": False}}, {"deviceName": "/dev/sdb3", "ebs": {"snapshotId": "snap-3456789a"}}, # ephemeral {"deviceName": "/dev/sdc1", "virtualName": "ephemeral0"}, {"deviceName": "/dev/sdc2", "ebs": {"snapshotId": "snap-3456789a", "deleteOnTermination": False}}, {"deviceName": "/dev/sdc3", "ebs": {"snapshotId": "snap-456789ab"}}, # volume {"deviceName": "/dev/sdd1", "ebs": {"snapshotId": "snap-87654321", "deleteOnTermination": False}}, {"deviceName": "/dev/sdd2", "ebs": {"snapshotId": "snap-98765432"}}, {"deviceName": "/dev/sdd3", "ebs": {"snapshotId": "snap-a9875463"}}, ] } result = {} cloud._format_mappings(properties, result) print result self.assertEqual(result["blockDeviceMapping"].sort(), expected_result["blockDeviceMapping"].sort())
def test_format_mapping(self): properties = { 'mappings': [ {'virtual': 'ami', 'device': 'sda1'}, {'virtual': 'root', 'device': '/dev/sda1'}, {'virtual': 'swap', 'device': 'sdb1'}, {'virtual': 'swap', 'device': 'sdb2'}, {'virtual': 'swap', 'device': 'sdb3'}, {'virtual': 'swap', 'device': 'sdb4'}, {'virtual': 'ephemeral0', 'device': 'sdc1'}, {'virtual': 'ephemeral1', 'device': 'sdc2'}, {'virtual': 'ephemeral2', 'device': 'sdc3'}, ], 'block_device_mapping': [ # root {'device_name': '/dev/sda1', 'snapshot_id': 0x12345678, 'delete_on_termination': False}, # overwrite swap {'device_name': '/dev/sdb2', 'snapshot_id': 0x23456789, 'delete_on_termination': False}, {'device_name': '/dev/sdb3', 'snapshot_id': 0x3456789A}, {'device_name': '/dev/sdb4', 'no_device': True}, # overwrite ephemeral {'device_name': '/dev/sdc2', 'snapshot_id': 0x3456789A, 'delete_on_termination': False}, {'device_name': '/dev/sdc3', 'snapshot_id': 0x456789AB}, {'device_name': '/dev/sdc4', 'no_device': True}, # volume {'device_name': '/dev/sdd1', 'snapshot_id': 0x87654321, 'delete_on_termination': False}, {'device_name': '/dev/sdd2', 'snapshot_id': 0x98765432}, {'device_name': '/dev/sdd3', 'snapshot_id': 0xA9875463}, {'device_name': '/dev/sdd4', 'no_device': True}]} expected_result = { 'blockDeviceMapping': [ # root {'deviceName': '/dev/sda1', 'ebs': {'snapshotId': 'snap-12345678', 'deleteOnTermination': False}}, # swap {'deviceName': '/dev/sdb1', 'virtualName': 'swap'}, {'deviceName': '/dev/sdb2', 'ebs': {'snapshotId': 'snap-23456789', 'deleteOnTermination': False}}, {'deviceName': '/dev/sdb3', 'ebs': {'snapshotId': 'snap-3456789a'}}, # ephemeral {'deviceName': '/dev/sdc1', 'virtualName': 'ephemeral0'}, {'deviceName': '/dev/sdc2', 'ebs': {'snapshotId': 'snap-3456789a', 'deleteOnTermination': False}}, {'deviceName': '/dev/sdc3', 'ebs': {'snapshotId': 'snap-456789ab'}}, # volume {'deviceName': '/dev/sdd1', 'ebs': {'snapshotId': 'snap-87654321', 'deleteOnTermination': False}}, {'deviceName': '/dev/sdd2', 'ebs': {'snapshotId': 'snap-98765432'}}, {'deviceName': '/dev/sdd3', 'ebs': {'snapshotId': 'snap-a9875463'}}]} result = {} cloud._format_mappings(properties, result) print result self.assertEqual(result['blockDeviceMapping'].sort(), expected_result['blockDeviceMapping'].sort())