summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorBrian Waldon <bcwaldon@gmail.com>2012-05-01 08:19:02 -0700
committerBrian Waldon <bcwaldon@gmail.com>2012-05-01 10:32:44 -0700
commitac21815ecb977840e90cee807fac7992d060c643 (patch)
tree2b3157888dd2fa54b32484ada5fb963ea7405a08
parente6b1370d823cdcdb5201152010f0bb27e424b2d3 (diff)
downloadnova-ac21815ecb977840e90cee807fac7992d060c643.tar.gz
nova-ac21815ecb977840e90cee807fac7992d060c643.tar.xz
nova-ac21815ecb977840e90cee807fac7992d060c643.zip
Allow blank adminPass on server create
* Fixes bug 992648 Change-Id: Ib796904b3155300a178e37d129e398817c8747d6
-rw-r--r--nova/api/openstack/compute/servers.py17
-rw-r--r--nova/tests/api/openstack/compute/test_servers.py7
2 files changed, 15 insertions, 9 deletions
diff --git a/nova/api/openstack/compute/servers.py b/nova/api/openstack/compute/servers.py
index af6d9c7d6..4468af401 100644
--- a/nova/api/openstack/compute/servers.py
+++ b/nova/api/openstack/compute/servers.py
@@ -1145,15 +1145,20 @@ class Controller(wsgi.Controller):
def _get_server_admin_password(self, server):
"""Determine the admin password for a server on creation."""
- password = server.get('adminPass')
+ try:
+ password = server['adminPass']
+ self._validate_admin_password(password)
+ except KeyError:
+ password = utils.generate_password(FLAGS.password_length)
+ except ValueError:
+ raise exc.HTTPBadRequest(explanation=_("Invalid adminPass"))
- if password is None:
- return utils.generate_password(FLAGS.password_length)
- if not isinstance(password, basestring) or password == '':
- msg = _("Invalid adminPass")
- raise exc.HTTPBadRequest(explanation=msg)
return password
+ def _validate_admin_password(self, password):
+ if not isinstance(password, basestring):
+ raise ValueError()
+
def _get_server_search_options(self):
"""Return server search options allowed by non-admin."""
return ('reservation_id', 'name', 'status', 'image', 'flavor',
diff --git a/nova/tests/api/openstack/compute/test_servers.py b/nova/tests/api/openstack/compute/test_servers.py
index 514d7cf84..e1a01b09f 100644
--- a/nova/tests/api/openstack/compute/test_servers.py
+++ b/nova/tests/api/openstack/compute/test_servers.py
@@ -2119,10 +2119,11 @@ class ServersControllerCreateTest(test.TestCase):
self.assertTrue('adminPass' not in server)
def test_create_instance_admin_pass_empty(self):
+ image_uuid = '76fa36fc-c930-4bf3-8c8a-ea2a2420deb6'
body = {
'server': {
'name': 'server_test',
- 'imageRef': 3,
+ 'imageRef': image_uuid,
'flavorRef': 3,
'adminPass': '',
},
@@ -2133,8 +2134,8 @@ class ServersControllerCreateTest(test.TestCase):
req.body = json.dumps(body)
req.headers['content-type'] = "application/json"
- self.assertRaises(webob.exc.HTTPBadRequest,
- self.controller.create, req, body)
+ # The fact that the action doesn't raise is enough validation
+ self.controller.create(req, body)
def test_create_instance_malformed_entity(self):
req = fakes.HTTPRequest.blank('/v2/fake/servers')