diff options
| author | Vishvananda Ishaya <vishvananda@gmail.com> | 2011-06-29 09:49:49 -0700 |
|---|---|---|
| committer | Vishvananda Ishaya <vishvananda@gmail.com> | 2011-06-29 09:49:49 -0700 |
| commit | 5686488517f702bd4ba714edeea89ea1993ac220 (patch) | |
| tree | da6ae903a728955ceebffd1b80dbe705cc1ffdf8 | |
| parent | 0bfa9aad9c1f74ca962351d90265e5fb56156841 (diff) | |
| download | nova-5686488517f702bd4ba714edeea89ea1993ac220.tar.gz nova-5686488517f702bd4ba714edeea89ea1993ac220.tar.xz nova-5686488517f702bd4ba714edeea89ea1993ac220.zip | |
Allow a port name in the server ref for image create
| -rw-r--r-- | nova/api/openstack/images.py | 11 | ||||
| -rw-r--r-- | nova/tests/api/openstack/test_images.py | 13 |
2 files changed, 21 insertions, 3 deletions
diff --git a/nova/api/openstack/images.py b/nova/api/openstack/images.py index d43340e10..22c79e2e9 100644 --- a/nova/api/openstack/images.py +++ b/nova/api/openstack/images.py @@ -208,9 +208,14 @@ class ControllerV11(Controller): msg = _("Expected serverRef attribute on server entity.") raise webob.exc.HTTPBadRequest(explanation=msg) - head, tail = os.path.split(server_ref) - - if head and head != os.path.join(req.application_url, 'servers'): + head, _sep, tail = server_ref.rpartition('/') + + url, _sep, version = req.application_url.rpartition('/') + long_url = '%s:%s/%s' % (url, FLAGS.osapi_port, version) + valid_urls = ['%s/servers' % req.application_url, + '%s/servers' % long_url] + if head and head not in valid_urls: + LOG.warn(head) msg = _("serverRef must match request url") raise webob.exc.HTTPBadRequest(explanation=msg) diff --git a/nova/tests/api/openstack/test_images.py b/nova/tests/api/openstack/test_images.py index 446d68e9e..6c36f96a7 100644 --- a/nova/tests/api/openstack/test_images.py +++ b/nova/tests/api/openstack/test_images.py @@ -1011,6 +1011,19 @@ class ImageControllerWithGlanceServiceTest(test.TestCase): result = json.loads(response.body) self.assertEqual(result['image']['serverRef'], serverRef) + def test_create_image_v1_1_actual_server_ref_port(self): + + serverRef = 'http://localhost:8774/v1.1/servers/1' + body = dict(image=dict(serverRef=serverRef, name='Backup 1')) + req = webob.Request.blank('/v1.1/images') + req.method = 'POST' + req.body = json.dumps(body) + req.headers["content-type"] = "application/json" + response = req.get_response(fakes.wsgi_app()) + self.assertEqual(200, response.status_int) + result = json.loads(response.body) + self.assertEqual(result['image']['serverRef'], serverRef) + def test_create_image_v1_1_server_ref_bad_hostname(self): serverRef = 'http://asdf/v1.1/servers/1' |
