Skip to content

Commit

Permalink
Fix error on invalid delete_on_termination value
Browse files Browse the repository at this point in the history
1. Fixed 500 error when an invalid value is passed to 'delete_on_termination'
parameter in 'block_device_mapping' of create server API (json request).
Converted the value to 'bool' (similar to XML request workflow) to fix issue.
2. Also added unit test coverage.

Fixes LP: #1060955

Change-Id: Ib35040f17a3712dac45ec1e3c2f32fee17db7c03
  • Loading branch information
UnmeshG committed Oct 22, 2012
1 parent 8cb329b commit 7c9761b
Show file tree
Hide file tree
Showing 2 changed files with 28 additions and 1 deletion.
6 changes: 5 additions & 1 deletion nova/api/openstack/compute/servers.py
Expand Up @@ -792,7 +792,11 @@ def create(self, req, body):

block_device_mapping = None
if self.ext_mgr.is_loaded('os-volumes'):
block_device_mapping = server_dict.get('block_device_mapping')
block_device_mapping = server_dict.get('block_device_mapping', [])
for bdm in block_device_mapping:
if 'delete_on_termination' in bdm:
bdm['delete_on_termination'] = utils.bool_from_str(
bdm['delete_on_termination'])

ret_resv_id = False
# min_count and max_count are optional. If they exist, they may come
Expand Down
23 changes: 23 additions & 0 deletions nova/tests/api/openstack/compute/test_servers.py
Expand Up @@ -2047,6 +2047,29 @@ def create(*args, **kwargs):
self.stubs.Set(compute_api.API, 'create', create)
self._test_create_extra(params)

def test_create_instance_with_bdm_delete_on_termination(self):
self.ext_mgr.extensions = {'os-volumes': 'fake'}
bdm = [{'device_name': 'foo1', 'delete_on_termination': 1},
{'device_name': 'foo2', 'delete_on_termination': True},
{'device_name': 'foo3', 'delete_on_termination': 'invalid'},
{'device_name': 'foo4', 'delete_on_termination': 0},
{'device_name': 'foo5', 'delete_on_termination': False}]
expected_dbm = [
{'device_name': 'foo1', 'delete_on_termination': True},
{'device_name': 'foo2', 'delete_on_termination': True},
{'device_name': 'foo3', 'delete_on_termination': False},
{'device_name': 'foo4', 'delete_on_termination': False},
{'device_name': 'foo5', 'delete_on_termination': False}]
params = {'block_device_mapping': bdm}
old_create = compute_api.API.create

def create(*args, **kwargs):
self.assertEqual(kwargs['block_device_mapping'], expected_dbm)
return old_create(*args, **kwargs)

self.stubs.Set(compute_api.API, 'create', create)
self._test_create_extra(params)

def test_create_instance_with_user_data_enabled(self):
self.ext_mgr.extensions = {'os-user-data': 'fake'}
user_data = 'fake'
Expand Down

0 comments on commit 7c9761b

Please sign in to comment.