diff options
| author | Brian Waldon <brian.waldon@rackspace.com> | 2011-08-12 16:09:01 +0000 |
|---|---|---|
| committer | Tarmac <> | 2011-08-12 16:09:01 +0000 |
| commit | 7610b839a05bbde730b28d73586ba8ba096d0044 (patch) | |
| tree | 3dd666fee7411220c00dd53c44cc536c6a3c5cb1 /nova | |
| parent | 1f116df9b65fc317db26492115bc36ce465ba296 (diff) | |
| parent | 954e8e24c6b8ceb541c539ce7c26da4b35b5f0b1 (diff) | |
Fixing a 500 error when -1 is supplied for flavorRef on server create.
Diffstat (limited to 'nova')
| -rw-r--r-- | nova/api/openstack/common.py | 15 | ||||
| -rw-r--r-- | nova/tests/api/openstack/test_common.py | 4 | ||||
| -rw-r--r-- | nova/tests/api/openstack/test_servers.py | 16 |
3 files changed, 31 insertions, 4 deletions
diff --git a/nova/api/openstack/common.py b/nova/api/openstack/common.py index dfdd62201..b2a675653 100644 --- a/nova/api/openstack/common.py +++ b/nova/api/openstack/common.py @@ -169,13 +169,20 @@ def get_id_from_href(href): Returns: 123 """ - if re.match(r'\d+$', str(href)): + LOG.debug(_("Attempting to treat %(href)s as an integer ID.") % locals()) + + try: return int(href) + except ValueError: + pass + + LOG.debug(_("Attempting to treat %(href)s as a URL.") % locals()) + try: return int(urlparse.urlsplit(href).path.split('/')[-1]) - except ValueError, e: - LOG.debug(_("Error extracting id from href: %s") % href) - raise ValueError(_('could not parse id from href')) + except ValueError as error: + LOG.debug(_("Failed to parse ID from %(href)s: %(error)s") % locals()) + raise def remove_version_from_href(href): diff --git a/nova/tests/api/openstack/test_common.py b/nova/tests/api/openstack/test_common.py index 5a6e43579..b422bc4d1 100644 --- a/nova/tests/api/openstack/test_common.py +++ b/nova/tests/api/openstack/test_common.py @@ -249,6 +249,10 @@ class MiscFunctionsTest(test.TestCase): common.get_id_from_href, fixture) + def test_get_id_from_href_int(self): + fixture = 1 + self.assertEqual(fixture, common.get_id_from_href(fixture)) + def test_get_version_from_href(self): fixture = 'http://www.testsite.com/v1.1/images' expected = '1.1' diff --git a/nova/tests/api/openstack/test_servers.py b/nova/tests/api/openstack/test_servers.py index b6342ae2f..290f6e990 100644 --- a/nova/tests/api/openstack/test_servers.py +++ b/nova/tests/api/openstack/test_servers.py @@ -1653,6 +1653,22 @@ class ServersTest(test.TestCase): res = req.get_response(fakes.wsgi_app()) self.assertEqual(res.status_int, 400) + def test_create_instance_v1_1_invalid_flavor_id_int(self): + self._setup_for_create_instance() + + image_href = 'http://localhost/v1.1/images/2' + flavor_ref = -1 + body = dict(server=dict( + name='server_test', imageRef=image_href, flavorRef=flavor_ref, + metadata={'hello': 'world', 'open': 'stack'}, + personality={})) + req = webob.Request.blank('/v1.1/servers') + req.method = 'POST' + req.body = json.dumps(body) + req.headers["content-type"] = "application/json" + res = req.get_response(fakes.wsgi_app()) + self.assertEqual(res.status_int, 400) + def test_create_instance_v1_1_bad_flavor_href(self): self._setup_for_create_instance() |
