summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorNirmal Ranganathan <rnirmal@gmail.com>2012-02-02 14:19:57 -0600
committerNirmal Ranganathan <rnirmal@gmail.com>2012-02-02 15:35:07 -0600
commit999db21e1a5a0944535e0fb0fd2478ab1647d85b (patch)
tree104afb80425d9c05b95f845132c5fef9ebfa5d13
parented516883faca1976acd6e5a9476d447d39e11ab9 (diff)
downloadnova-999db21e1a5a0944535e0fb0fd2478ab1647d85b.tar.gz
Throw an user error on creating duplicate keypairs
Fixes bug 902162 Change-Id: I1b73943aab338bde90b4d47bc015964e9981af5d
-rw-r--r--.mailmap3
-rw-r--r--Authors2
-rw-r--r--nova/api/openstack/compute/contrib/keypairs.py3
-rw-r--r--nova/tests/api/openstack/compute/contrib/test_keypairs.py14
4 files changed, 19 insertions, 3 deletions
diff --git a/.mailmap b/.mailmap
index e5ced35ebb..e5a9098616 100644
--- a/.mailmap
+++ b/.mailmap
@@ -41,7 +41,8 @@
<matt.dietz@rackspace.com> <mdietz@openstack>
<mordred@inaugust.com> <mordred@hudson>
<naveedm9@gmail.com> <naveed.massjouni@rackspace.com>
-<nirmal.ranganathan@rackspace.com> <nirmal.ranganathan@rackspace.coom>
+<rnirmal@gmail.com> <nirmal.ranganathan@rackspace.com>
+<rnirmal@gmail.com> <nirmal.ranganathan@rackspace.coom>
<paul@openstack.org> <paul.voccio@rackspace.com>
<paul@openstack.org> <pvoccio@castor.local>
<paul@openstack.org> <paul@substation9.com>
diff --git a/Authors b/Authors
index 7930898b95..574a34f308 100644
--- a/Authors
+++ b/Authors
@@ -123,7 +123,7 @@ Muneyuki Noguchi <noguchimn@nttdata.co.jp>
Nachi Ueno <ueno.nachi@lab.ntt.co.jp>
Naveed Massjouni <naveedm9@gmail.com>
Nikolay Sokolov <nsokolov@griddynamics.com>
-Nirmal Ranganathan <nirmal.ranganathan@rackspace.com>
+Nirmal Ranganathan <rnirmal@gmail.com>
Ollie Leahy <oliver.leahy@hp.com>
Pádraig Brady <pbrady@redhat.com>
Paul Voccio <paul@openstack.org>
diff --git a/nova/api/openstack/compute/contrib/keypairs.py b/nova/api/openstack/compute/contrib/keypairs.py
index 57ac48dbc9..0e8a4bb060 100644
--- a/nova/api/openstack/compute/contrib/keypairs.py
+++ b/nova/api/openstack/compute/contrib/keypairs.py
@@ -87,7 +87,8 @@ class KeypairController(object):
# NOTE(ja): generation is slow, so shortcut invalid name exception
try:
db.key_pair_get(context, context.user_id, name)
- raise exception.KeyPairExists(key_name=name)
+ msg = _("Key pair '%s' already exists.") % name
+ raise webob.exc.HTTPConflict(explanation=msg)
except exception.NotFound:
pass
diff --git a/nova/tests/api/openstack/compute/contrib/test_keypairs.py b/nova/tests/api/openstack/compute/contrib/test_keypairs.py
index ff59e174b9..fa04e5efbf 100644
--- a/nova/tests/api/openstack/compute/contrib/test_keypairs.py
+++ b/nova/tests/api/openstack/compute/contrib/test_keypairs.py
@@ -46,6 +46,10 @@ def db_key_pair_destroy(context, user_id, name):
raise Exception()
+def db_key_pair_get(context, user_id, name):
+ pass
+
+
class KeypairsTest(test.TestCase):
def setUp(self):
@@ -130,6 +134,16 @@ class KeypairsTest(test.TestCase):
self.assertTrue(len(res_dict['keypair']['fingerprint']) > 0)
self.assertFalse('private_key' in res_dict['keypair'])
+ def test_keypair_create_duplicate(self):
+ self.stubs.Set(db, "key_pair_get", db_key_pair_get)
+ body = {'keypair': {'name': 'create_duplicate'}}
+ req = webob.Request.blank('/v2/fake/os-keypairs')
+ 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, 409)
+
def test_keypair_import_bad_key(self):
body = {
'keypair': {