22
22
from nova.api.ec2 import cloud
23
from nova.api.ec2 import ec2utils
23
24
from nova import test
26
27
class BlockDeviceMappingEc2CloudTestCase(test.TestCase):
27
28
"""Test Case for Block Device Mapping"""
30
def fake_ec2_vol_id_to_uuid(obj, ec2_id):
31
if ec2_id == 'snap-12345678':
32
return '00000000-1111-2222-3333-444444444444'
33
elif ec2_id == 'snap-23456789':
34
return '11111111-2222-3333-4444-555555555555'
35
elif ec2_id == 'vol-87654321':
36
return '22222222-3333-4444-5555-666666666666'
37
elif ec2_id == 'vol-98765432':
38
return '77777777-8888-9999-0000-aaaaaaaaaaaa'
29
42
def _assertApply(self, action, bdm_list):
30
43
for bdm, expected_result in bdm_list:
31
44
self.assertDictMatch(action(bdm), expected_result)
33
46
def test_parse_block_device_mapping(self):
47
self.stubs.Set(ec2utils,
49
self.fake_ec2_vol_id_to_uuid)
35
52
({'device_name': '/dev/fake0',
36
53
'ebs': {'snapshot_id': 'snap-12345678',
37
54
'volume_size': 1}},
38
55
{'device_name': '/dev/fake0',
39
'snapshot_id': 0x12345678,
56
'snapshot_id': '00000000-1111-2222-3333-444444444444',
41
58
'delete_on_termination': True}),
44
61
'ebs': {'snapshot_id': 'snap-23456789',
45
62
'delete_on_termination': False}},
46
63
{'device_name': '/dev/fake1',
47
'snapshot_id': 0x23456789,
64
'snapshot_id': '11111111-2222-3333-4444-555555555555',
48
65
'delete_on_termination': False}),
50
67
({'device_name': '/dev/fake2',
51
68
'ebs': {'snapshot_id': 'vol-87654321',
52
69
'volume_size': 2}},
53
70
{'device_name': '/dev/fake2',
54
'volume_id': 0x87654321,
71
'volume_id': '22222222-3333-4444-5555-666666666666',
56
73
'delete_on_termination': True}),
59
76
'ebs': {'snapshot_id': 'vol-98765432',
60
77
'delete_on_termination': False}},
61
78
{'device_name': '/dev/fake3',
62
'volume_id': 0x98765432,
79
'volume_id': '77777777-8888-9999-0000-aaaaaaaaaaaa',
63
80
'delete_on_termination': False}),
65
82
({'device_name': '/dev/fake4',