diff options
| author | Unmesh Gurjar <unmesh.gurjar@nttdata.com> | 2012-12-06 01:14:20 -0800 |
|---|---|---|
| committer | Unmesh Gurjar <unmesh.gurjar@nttdata.com> | 2013-01-10 22:28:30 -0800 |
| commit | 3b5679e44754ad5138e1697ba233d91776199853 (patch) | |
| tree | 65a439cd9309f297b9f467e515ed68aa3ea08dd2 /nova/api | |
| parent | 6a2c0a4dab60150ace5850cca4de348ab22dfaa8 (diff) | |
Validated device_name value in block device map
1. Checked value of device_name parameter provided in block device
mapping section of Create server API.
2. Added unit test coverage.
Fixes LP: #1087165
Change-Id: I32ed59a577167d9bf42cb3667bfb1ba3963d6c71
Diffstat (limited to 'nova/api')
| -rw-r--r-- | nova/api/openstack/compute/servers.py | 22 |
1 files changed, 17 insertions, 5 deletions
diff --git a/nova/api/openstack/compute/servers.py b/nova/api/openstack/compute/servers.py index d3a6fc8a9..c6bbee98b 100644 --- a/nova/api/openstack/compute/servers.py +++ b/nova/api/openstack/compute/servers.py @@ -561,17 +561,28 @@ class Controller(wsgi.Controller): req.cache_db_instance(instance) return instance - def _validate_server_name(self, value): + def _check_string_length(self, value, name, max_length=None): if not isinstance(value, basestring): - msg = _("Server name is not a string or unicode") + msg = _("%s is not a string or unicode") % name raise exc.HTTPBadRequest(explanation=msg) if not value.strip(): - msg = _("Server name is an empty string") + msg = _("%s is an empty string") % name + raise exc.HTTPBadRequest(explanation=msg) + + if max_length and len(value) > max_length: + msg = _("%(name)s can be at most %(max_length)s " + "characters.") % locals() raise exc.HTTPBadRequest(explanation=msg) - if not len(value) < 256: - msg = _("Server name must be less than 256 characters.") + def _validate_server_name(self, value): + self._check_string_length(value, 'Server name', max_length=255) + + def _validate_device_name(self, value): + self._check_string_length(value, 'Device name', max_length=255) + + if ' ' in value: + msg = _("Device name cannot include spaces.") raise exc.HTTPBadRequest(explanation=msg) def _get_injected_files(self, personality): @@ -809,6 +820,7 @@ class Controller(wsgi.Controller): if self.ext_mgr.is_loaded('os-volumes'): block_device_mapping = server_dict.get('block_device_mapping', []) for bdm in block_device_mapping: + self._validate_device_name(bdm["device_name"]) if 'delete_on_termination' in bdm: bdm['delete_on_termination'] = utils.bool_from_str( bdm['delete_on_termination']) |
