Merge "bdm: Make sure that delete_on_termination is a boolean"
This commit is contained in:
@@ -86,6 +86,8 @@ class BlockDeviceDict(dict):
|
|||||||
self._validate(bdm_dict)
|
self._validate(bdm_dict)
|
||||||
if bdm_dict.get('device_name'):
|
if bdm_dict.get('device_name'):
|
||||||
bdm_dict['device_name'] = prepend_dev(bdm_dict['device_name'])
|
bdm_dict['device_name'] = prepend_dev(bdm_dict['device_name'])
|
||||||
|
bdm_dict['delete_on_termination'] = bool(
|
||||||
|
bdm_dict.get('delete_on_termination'))
|
||||||
# NOTE (ndipanov): Never default db fields
|
# NOTE (ndipanov): Never default db fields
|
||||||
self.update({field: None for field in self._fields - do_not_default})
|
self.update({field: None for field in self._fields - do_not_default})
|
||||||
self.update(list(six.iteritems(bdm_dict)))
|
self.update(list(six.iteritems(bdm_dict)))
|
||||||
|
@@ -1989,7 +1989,7 @@ class _ComputeAPIUnitTestMixIn(object):
|
|||||||
'image_id': None, 'volume_id': None, 'disk_bus': None,
|
'image_id': None, 'volume_id': None, 'disk_bus': None,
|
||||||
'volume_size': None, 'source_type': 'snapshot',
|
'volume_size': None, 'source_type': 'snapshot',
|
||||||
'device_type': None, 'snapshot_id': '1-snapshot',
|
'device_type': None, 'snapshot_id': '1-snapshot',
|
||||||
'destination_type': 'volume', 'delete_on_termination': None})
|
'destination_type': 'volume', 'delete_on_termination': False})
|
||||||
|
|
||||||
# All the db_only fields and the volume ones are removed
|
# All the db_only fields and the volume ones are removed
|
||||||
self.compute_api.snapshot_volume_backed(
|
self.compute_api.snapshot_volume_backed(
|
||||||
|
@@ -427,6 +427,18 @@ class TestBlockDeviceDict(test.NoDBTestCase):
|
|||||||
bdm_dict = block_device.BlockDeviceDict(bdm)
|
bdm_dict = block_device.BlockDeviceDict(bdm)
|
||||||
self.assertIsNone(bdm_dict['device_name'])
|
self.assertIsNone(bdm_dict['device_name'])
|
||||||
|
|
||||||
|
def test_init_boolify_delete_on_termination(self):
|
||||||
|
# Make sure that when delete_on_termination is not passed it's
|
||||||
|
# still set to False and not None
|
||||||
|
bdm = {'id': 3, 'instance_uuid': 'fake-instance',
|
||||||
|
'device_name': 'vda',
|
||||||
|
'source_type': 'volume',
|
||||||
|
'destination_type': 'volume',
|
||||||
|
'volume_id': 'fake-volume-id-1',
|
||||||
|
'boot_index': 0}
|
||||||
|
bdm_dict = block_device.BlockDeviceDict(bdm)
|
||||||
|
self.assertEqual(False, bdm_dict['delete_on_termination'])
|
||||||
|
|
||||||
def test_validate(self):
|
def test_validate(self):
|
||||||
self.assertRaises(exception.InvalidBDMFormat,
|
self.assertRaises(exception.InvalidBDMFormat,
|
||||||
block_device.BlockDeviceDict,
|
block_device.BlockDeviceDict,
|
||||||
|
Reference in New Issue
Block a user