Fix block_device_mapping property validation when using get_attr

Change-Id: I6501395ab458b75ba7d27c8ce9643bd6d18cb203
Closes-Bug: #1463531
This commit is contained in:
Rabi Mishra 2015-06-10 08:24:58 +05:30
parent 90191ae185
commit 4d2b275358
2 changed files with 21 additions and 2 deletions

View File

@ -1183,11 +1183,11 @@ class Server(stack_user.StackUser):
volume_id = mapping.get(self.BLOCK_DEVICE_MAPPING_VOLUME_ID)
snapshot_id = mapping.get(self.BLOCK_DEVICE_MAPPING_SNAPSHOT_ID)
if volume_id and snapshot_id:
if volume_id is not None and snapshot_id is not None:
raise exception.ResourcePropertyConflict(
self.BLOCK_DEVICE_MAPPING_VOLUME_ID,
self.BLOCK_DEVICE_MAPPING_SNAPSHOT_ID)
if not volume_id and not snapshot_id:
if volume_id is None and snapshot_id is None:
msg = _('Either volume_id or snapshot_id must be specified for'
' device mapping %s') % device_name
raise exception.StackValidationFailed(message=msg)

View File

@ -2128,6 +2128,25 @@ class ServersTest(common.HeatTestCase):
self.m.VerifyAll()
def test_validate_block_device_mapping_with_empty_ref(self):
stack_name = 'val_blkdev2'
(tmpl, stack) = self._setup_test_stack(stack_name)
bdm = [{'device_name': 'vda', 'volume_id': '',
'volume_size': '10'}]
wsp = tmpl.t['Resources']['WebServer']['Properties']
wsp['block_device_mapping'] = bdm
resource_defns = tmpl.resource_definitions(stack)
server = servers.Server('server_create_image_err',
resource_defns['WebServer'], stack)
self.m.StubOutWithMock(nova.NovaClientPlugin, '_create')
self.stub_VolumeConstraint_validate()
nova.NovaClientPlugin._create().AndReturn(self.fc)
self._mock_get_image_id_success('F17-x86_64-gold', 'image_id')
self.m.ReplayAll()
self.assertIsNone(server.validate())
self.m.VerifyAll()
def test_validate_without_image_or_bootable_volume(self):
stack_name = 'val_imgvol'
(tmpl, stack) = self._setup_test_stack(stack_name)