Use EntityNotFound instead of UserKeyPairMissing

Replace and remove UserKeyPairMissing.
Partial-Bug: #1515603

Change-Id: I47859c0cd85e77a56e663198a9eb492c9cbfecac
This commit is contained in:
ricolin 2015-11-19 11:28:13 +08:00 committed by Rico Lin
parent 17851c88c9
commit 743f470f10
3 changed files with 4 additions and 8 deletions

View File

@ -127,10 +127,6 @@ class InvalidTemplateReference(HeatException):
' is incorrect.')
class UserKeyPairMissing(HeatException):
msg_fmt = _("The Key (%(key_name)s) could not be found.")
class FlavorMissing(HeatException):
msg_fmt = _("The Flavor ID (%(flavor_id)s) could not be found.")

View File

@ -265,12 +265,12 @@ class NovaClientPlugin(client_plugin.ClientPlugin):
:param key_name: the name of the key to look for
:returns: the keypair (name, public_key) for :key_name:
:raises: exception.UserKeyPairMissing
:raises: exception.EntityNotFound
"""
try:
return self.client().keypairs.get(key_name)
except exceptions.NotFound:
raise exception.UserKeyPairMissing(key_name=key_name)
raise exception.EntityNotFound(entity='Key', name=key_name)
def build_userdata(self, metadata, userdata=None, instance_user=None,
user_data_format='HEAT_CFNTOOLS'):
@ -690,7 +690,7 @@ class ServerConstraint(constraints.BaseCustomConstraint):
class KeypairConstraint(constraints.BaseCustomConstraint):
expected_exceptions = (exception.UserKeyPairMissing,)
expected_exceptions = (exception.EntityNotFound,)
def validate_with_client(self, client, key_name):
if not key_name:

View File

@ -123,7 +123,7 @@ class NovaClientPluginTests(NovaClientPluginTestCase):
self.nova_client.keypairs.get.side_effect = [
my_key, nova_exceptions.NotFound(404)]
self.assertEqual(my_key, self.nova_plugin.get_keypair(my_key_name))
self.assertRaises(exception.UserKeyPairMissing,
self.assertRaises(exception.EntityNotFound,
self.nova_plugin.get_keypair, 'notakey')
calls = [mock.call(my_key_name),
mock.call('notakey')]