From 6e75e608cc7260317f014e57ba070b152f83d0e7 Mon Sep 17 00:00:00 2001 From: Tushar Patil Date: Tue, 12 Jul 2011 17:46:03 -0700 Subject: added unit test cases and minor changes (localization fix and added fixed_ip validation) --- nova/api/openstack/create_instance_helper.py | 18 ++++++++++++++---- 1 file changed, 14 insertions(+), 4 deletions(-) (limited to 'nova/api') diff --git a/nova/api/openstack/create_instance_helper.py b/nova/api/openstack/create_instance_helper.py index 86fa8becc..5eef0ae00 100644 --- a/nova/api/openstack/create_instance_helper.py +++ b/nova/api/openstack/create_instance_helper.py @@ -162,8 +162,7 @@ class CreateInstanceHelper(object): msg = _("Can not find requested image") raise faults.Fault(exc.HTTPBadRequest(explanation=msg)) except rpc.RemoteError as err: - LOG.error(err) - msg = _("%s:%s") % (err.exc_type, err.value) + msg = _("%(err.exc_type)s:%(err.value)s") raise faults.Fault(exc.HTTPBadRequest(explanation=msg)) # Let the caller deal with unhandled exceptions. @@ -205,6 +204,15 @@ class CreateInstanceHelper(object): msg = _("Server name is an empty string") raise exc.HTTPBadRequest(explanation=msg) + def _validate_fixed_ip(self, value): + if not isinstance(value, basestring): + msg = _("Fixed IP is not a string or unicode") + raise exc.HTTPBadRequest(explanation=msg) + + if value.strip() == '': + msg = _("Fixed IP is an empty string") + raise exc.HTTPBadRequest(explanation=msg) + def _get_kernel_ramdisk_from_image(self, req, image_id): """Fetch an image from the ImageService, then if present, return the associated kernel and ramdisk image IDs. @@ -298,9 +306,10 @@ class CreateInstanceHelper(object): network_id = int(network_id) #fixed IP address is optional #if the fixed IP address is not provided then - #it will used one of the available IP address from the network + #it will use one of the available IP address from the network fixed_ip = network.get('fixed_ip', None) - + if fixed_ip is not None: + self._validate_fixed_ip(fixed_ip) # check if the network id is already present in the list, # we don't want duplicate networks to be passed # at the boot time @@ -404,6 +413,7 @@ class ServerXMLDeserializer(wsgi.XMLDeserializer): def _find_first_child_named(self, parent, name): """Search a nodes children for the first child with a given name""" for node in parent.childNodes: + LOG.debug(node.nodeName) if node.nodeName == name: return node return None -- cgit