summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorJenkins <jenkins@review.openstack.org>2012-05-01 18:27:05 +0000
committerGerrit Code Review <review@openstack.org>2012-05-01 18:27:05 +0000
commita4ecf32772feea52b89c7bca3d9299b46e02ac41 (patch)
tree93930e51281f4459f1a3b2aa35e1bb7e998d4701
parent19e03e95d354c55df4b9c37712ffc4c56b561826 (diff)
parentb25752b2e742e4bcf872c0dfb9ca59f3e5d51ae9 (diff)
downloadnova-a4ecf32772feea52b89c7bca3d9299b46e02ac41.tar.gz
nova-a4ecf32772feea52b89c7bca3d9299b46e02ac41.tar.xz
nova-a4ecf32772feea52b89c7bca3d9299b46e02ac41.zip
Merge "Return a BadRequest on bad flavors param values."
-rw-r--r--nova/api/openstack/compute/flavors.py6
-rw-r--r--nova/tests/api/openstack/compute/test_flavors.py112
2 files changed, 18 insertions, 100 deletions
diff --git a/nova/api/openstack/compute/flavors.py b/nova/api/openstack/compute/flavors.py
index 8c159c586..6757d8b28 100644
--- a/nova/api/openstack/compute/flavors.py
+++ b/nova/api/openstack/compute/flavors.py
@@ -98,13 +98,15 @@ class Controller(wsgi.Controller):
try:
filters['min_memory_mb'] = int(req.params['minRam'])
except ValueError:
- pass # ignore bogus values per spec
+ msg = _('Invalid minRam filter [%s]') % req.params['minRam']
+ raise webob.exc.HTTPBadRequest(explanation=msg)
if 'minDisk' in req.params:
try:
filters['min_root_gb'] = int(req.params['minDisk'])
except ValueError:
- pass # ignore bogus values per spec
+ msg = _('Invalid minDisk filter [%s]') % req.params['minDisk']
+ raise webob.exc.HTTPBadRequest(explanation=msg)
flavors = instance_types.get_all_types(filters=filters)
flavors_list = flavors.values()
diff --git a/nova/tests/api/openstack/compute/test_flavors.py b/nova/tests/api/openstack/compute/test_flavors.py
index 599e86bc1..2e9a43507 100644
--- a/nova/tests/api/openstack/compute/test_flavors.py
+++ b/nova/tests/api/openstack/compute/test_flavors.py
@@ -358,7 +358,7 @@ class FlavorsTest(test.TestCase):
self.assertEqual(flavors, expected)
def test_get_flavor_list_filter_min_ram(self):
- """Flavor lists may be filtered by minRam"""
+ """Flavor lists may be filtered by minRam."""
req = fakes.HTTPRequest.blank('/v2/fake/flavors?minRam=512')
flavor = self.controller.index(req)
expected = {
@@ -381,8 +381,14 @@ class FlavorsTest(test.TestCase):
}
self.assertEqual(flavor, expected)
+ def test_get_flavor_list_filter_invalid_min_ram(self):
+ """Ensure you cannot list flavors with invalid minRam param."""
+ req = fakes.HTTPRequest.blank('/v2/fake/flavors?minRam=NaN')
+ self.assertRaises(webob.exc.HTTPBadRequest,
+ self.controller.index, req)
+
def test_get_flavor_list_filter_min_disk(self):
- """Flavor lists may be filtered by minRam"""
+ """Flavor lists may be filtered by minDisk."""
req = fakes.HTTPRequest.blank('/v2/fake/flavors?minDisk=20')
flavor = self.controller.index(req)
expected = {
@@ -405,6 +411,12 @@ class FlavorsTest(test.TestCase):
}
self.assertEqual(flavor, expected)
+ def test_get_flavor_list_filter_invalid_min_disk(self):
+ """Ensure you cannot list flavors with invalid minDisk param."""
+ req = fakes.HTTPRequest.blank('/v2/fake/flavors?minDisk=NaN')
+ self.assertRaises(webob.exc.HTTPBadRequest,
+ self.controller.index, req)
+
def test_get_flavor_list_detail_min_ram_and_min_disk(self):
"""Tests that filtering work on flavor details and that minRam and
minDisk filters can be combined
@@ -437,102 +449,6 @@ class FlavorsTest(test.TestCase):
}
self.assertEqual(flavor, expected)
- def test_get_flavor_list_detail_bogus_min_ram(self):
- """Tests that bogus minRam filtering values are ignored"""
- req = fakes.HTTPRequest.blank('/v2/fake/flavors/detail?minRam=16GB')
- flavor = self.controller.detail(req)
- expected = {
- "flavors": [
- {
- "id": "1",
- "name": "flavor 1",
- "ram": "256",
- "disk": "10",
- "rxtx_factor": "",
- "swap": "",
- "vcpus": "",
- "links": [
- {
- "rel": "self",
- "href": "http://localhost/v2/fake/flavors/1",
- },
- {
- "rel": "bookmark",
- "href": "http://localhost/fake/flavors/1",
- },
- ],
- },
- {
- "id": "2",
- "name": "flavor 2",
- "ram": "512",
- "disk": "20",
- "rxtx_factor": "",
- "swap": "",
- "vcpus": "",
- "links": [
- {
- "rel": "self",
- "href": "http://localhost/v2/fake/flavors/2",
- },
- {
- "rel": "bookmark",
- "href": "http://localhost/fake/flavors/2",
- },
- ],
- },
- ],
- }
- self.assertEqual(flavor, expected)
-
- def test_get_flavor_list_detail_bogus_min_disk(self):
- """Tests that bogus minDisk filtering values are ignored"""
- req = fakes.HTTPRequest.blank('/v2/fake/flavors/detail?minDisk=16GB')
- flavor = self.controller.detail(req)
- expected = {
- "flavors": [
- {
- "id": "1",
- "name": "flavor 1",
- "ram": "256",
- "disk": "10",
- "rxtx_factor": "",
- "swap": "",
- "vcpus": "",
- "links": [
- {
- "rel": "self",
- "href": "http://localhost/v2/fake/flavors/1",
- },
- {
- "rel": "bookmark",
- "href": "http://localhost/fake/flavors/1",
- },
- ],
- },
- {
- "id": "2",
- "name": "flavor 2",
- "ram": "512",
- "disk": "20",
- "rxtx_factor": "",
- "swap": "",
- "vcpus": "",
- "links": [
- {
- "rel": "self",
- "href": "http://localhost/v2/fake/flavors/2",
- },
- {
- "rel": "bookmark",
- "href": "http://localhost/fake/flavors/2",
- },
- ],
- },
- ],
- }
- self.assertEqual(flavor, expected)
-
class FlavorsXMLSerializationTest(test.TestCase):