summaryrefslogtreecommitdiffstats
path: root/nova/api
diff options
context:
space:
mode:
authorTushar Patil <tushar.vitthal.patil@gmail.com>2011-07-12 17:46:03 -0700
committerTushar Patil <tushar.vitthal.patil@gmail.com>2011-07-12 17:46:03 -0700
commit6e75e608cc7260317f014e57ba070b152f83d0e7 (patch)
tree7b952be0f06fb929c15257db3402b002d6273e79 /nova/api
parent2be9a4e19449f9cf37f62f3f6e380de3e7ca0d38 (diff)
downloadnova-6e75e608cc7260317f014e57ba070b152f83d0e7.tar.gz
nova-6e75e608cc7260317f014e57ba070b152f83d0e7.tar.xz
nova-6e75e608cc7260317f014e57ba070b152f83d0e7.zip
added unit test cases and minor changes (localization fix and added fixed_ip validation)
Diffstat (limited to 'nova/api')
-rw-r--r--nova/api/openstack/create_instance_helper.py18
1 files changed, 14 insertions, 4 deletions
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