diff --git a/.mailmap b/.mailmap index e5ced35ebba..e5a90986168 100644 --- a/.mailmap +++ b/.mailmap @@ -41,7 +41,8 @@ - + + diff --git a/Authors b/Authors index 7930898b950..574a34f3085 100644 --- a/Authors +++ b/Authors @@ -123,7 +123,7 @@ Muneyuki Noguchi Nachi Ueno Naveed Massjouni Nikolay Sokolov -Nirmal Ranganathan +Nirmal Ranganathan Ollie Leahy Pádraig Brady Paul Voccio diff --git a/nova/api/openstack/compute/contrib/keypairs.py b/nova/api/openstack/compute/contrib/keypairs.py index 57ac48dbc91..0e8a4bb060a 100644 --- a/nova/api/openstack/compute/contrib/keypairs.py +++ b/nova/api/openstack/compute/contrib/keypairs.py @@ -87,7 +87,8 @@ def create(self, req, body): # 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 ff59e174b9c..fa04e5efbf1 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 @@ def test_keypair_import(self): 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': {