Fix pass incorrect volume_size while building bdm

If specify device_name, snapshot_id, delete_on_termination=True
and not specify volume_size for bdm while create a server,
heat will pass the bdm such as {'vdd': '1234:snap:0:True'} to
novaclient, the volume_size is incorrect,
nova won't create a volume from the snapshot because the
volume_size=0. If not specify volume_size, just to pass ''.

Change-Id: Ic1407671cc7bc6695bcf8e0c9f86fbdbaf245658
Closes-Bug: #1335728
This commit is contained in:
huangtianhua
2014-07-01 17:35:34 +08:00
parent b160972b08
commit 37f98778f2
2 changed files with 7 additions and 5 deletions

View File

@@ -572,8 +572,10 @@ class Server(stack_user.StackUser):
volume_size = mapping.get(cls.BLOCK_DEVICE_MAPPING_VOLUME_SIZE)
delete = mapping.get(cls.BLOCK_DEVICE_MAPPING_DELETE_ON_TERM)
if volume_size or delete:
mapping_parts.append(str(volume_size or 0))
if volume_size:
mapping_parts.append(str(volume_size))
else:
mapping_parts.append('')
if delete:
mapping_parts.append(str(delete))

View File

@@ -1678,8 +1678,8 @@ class ServersTest(HeatTestCase):
self.assertIsNone(servers.Server._build_block_device_mapping(None))
self.assertEqual({
'vda': '1234:',
'vdb': '1234:snap',
'vda': '1234::',
'vdb': '1234:snap:',
}, servers.Server._build_block_device_mapping([
{'device_name': 'vda', 'volume_id': '1234'},
{'device_name': 'vdb', 'snapshot_id': '1234'},
@@ -1687,7 +1687,7 @@ class ServersTest(HeatTestCase):
self.assertEqual({
'vdc': '1234::10',
'vdd': '1234:snap:0:True'
'vdd': '1234:snap::True'
}, servers.Server._build_block_device_mapping([
{
'device_name': 'vdc',