Throw an user error on creating duplicate keypairs
Fixes bug 902162 Change-Id: I1b73943aab338bde90b4d47bc015964e9981af5d
This commit is contained in:
parent
ed516883fa
commit
999db21e1a
3
.mailmap
3
.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>
|
||||
|
|
2
Authors
2
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>
|
||||
|
|
|
@ -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
|
||||
|
||||
|
|
|
@ -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': {
|
||||
|
|
Loading…
Reference in New Issue