summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorJenkins <jenkins@review.openstack.org>2012-02-22 22:05:58 +0000
committerGerrit Code Review <review@openstack.org>2012-02-22 22:05:58 +0000
commitbeb49b664cde757784f4f93d2a0ea5346288ed37 (patch)
treeb842626a74fcae868c15749e6b09f71cbb772361
parent1ef939bf40e18a73cfce2d8bc039211ae044c379 (diff)
parent1767e0ae9595003c22facc86e590b7c9b1ed6a75 (diff)
downloadnova-beb49b664cde757784f4f93d2a0ea5346288ed37.tar.gz
nova-beb49b664cde757784f4f93d2a0ea5346288ed37.tar.xz
nova-beb49b664cde757784f4f93d2a0ea5346288ed37.zip
Merge "Return 40x for flavor.create duplicate."
-rw-r--r--nova/api/openstack/compute/contrib/flavormanage.py9
-rw-r--r--nova/tests/api/openstack/compute/contrib/test_flavor_manage.py27
2 files changed, 33 insertions, 3 deletions
diff --git a/nova/api/openstack/compute/contrib/flavormanage.py b/nova/api/openstack/compute/contrib/flavormanage.py
index 3fe9bc669..547760e94 100644
--- a/nova/api/openstack/compute/contrib/flavormanage.py
+++ b/nova/api/openstack/compute/contrib/flavormanage.py
@@ -66,9 +66,12 @@ class FlavorManageController(wsgi.Controller):
swap = vals.get('swap')
rxtx_factor = vals.get('rxtx_factor')
- flavor = instance_types.create(name, memory_mb, vcpus,
- root_gb, ephemeral_gb, flavorid,
- swap, rxtx_factor)
+ try:
+ flavor = instance_types.create(name, memory_mb, vcpus,
+ root_gb, ephemeral_gb, flavorid,
+ swap, rxtx_factor)
+ except exception.InstanceTypeExists as err:
+ raise webob.exc.HTTPConflict(explanation=str(err))
return self._view_builder.show(req, flavor)
diff --git a/nova/tests/api/openstack/compute/contrib/test_flavor_manage.py b/nova/tests/api/openstack/compute/contrib/test_flavor_manage.py
index e825aa4bd..8a18c1ab2 100644
--- a/nova/tests/api/openstack/compute/contrib/test_flavor_manage.py
+++ b/nova/tests/api/openstack/compute/contrib/test_flavor_manage.py
@@ -115,3 +115,30 @@ class FlavorManageTest(test.TestCase):
body = json.loads(res.body)
for key in expected["flavor"]:
self.assertEquals(body["flavor"][key], expected["flavor"][key])
+
+ def test_instance_type_exists_exception_returns_409(self):
+ expected = {
+ "flavor": {
+ "name": "test",
+ "ram": 512,
+ "vcpus": 2,
+ "disk": 1,
+ "OS-FLV-EXT-DATA:ephemeral": 1,
+ "id": 1235,
+ "swap": 512,
+ "rxtx_factor": 1,
+ }
+ }
+
+ def fake_create(name, memory_mb, vcpus, root_gb, ephemeral_gb,
+ flavorid, swap, rxtx_factor):
+ raise exception.InstanceTypeExists()
+
+ self.stubs.Set(instance_types, "create", fake_create)
+ url = '/v2/fake/flavors'
+ req = webob.Request.blank(url)
+ req.headers['Content-Type'] = 'application/json'
+ req.method = 'POST'
+ req.body = json.dumps(expected)
+ res = req.get_response(fakes.wsgi_app())
+ self.assertEqual(res.status_int, 409)