Rename instance type exceptions to flavors

Change-Id: I731ae3a2d5490b0824d3c90fb67902b60fa8f437
This commit is contained in:
Zhenguo Niu 2017-04-25 10:00:10 +08:00
parent a7224e4ba9
commit 6fe3d0d43d
7 changed files with 25 additions and 25 deletions

View File

@ -172,7 +172,7 @@ class FlavorsController(rest.RestController):
try: try:
flavor_in_db = objects.InstanceType.get( flavor_in_db = objects.InstanceType.get(
pecan.request.context, flavor_uuid) pecan.request.context, flavor_uuid)
except exception.InstanceTypeNotFound: except exception.FlavorTypeNotFound:
msg = (_("InstanceType %s could not be found") % msg = (_("InstanceType %s could not be found") %
flavor_uuid) flavor_uuid)
raise wsme.exc.ClientSideError( raise wsme.exc.ClientSideError(

View File

@ -609,8 +609,8 @@ class InstanceController(InstanceControllerBase):
key_name=key_name, key_name=key_name,
min_count=min_count, min_count=min_count,
max_count=max_count) max_count=max_count)
except exception.InstanceTypeNotFound: except exception.FlavorNotFound:
msg = (_("InstanceType %s could not be found") % msg = (_("Flavor %s could not be found") %
instance_type_uuid) instance_type_uuid)
raise wsme.exc.ClientSideError( raise wsme.exc.ClientSideError(
msg, status_code=http_client.BAD_REQUEST) msg, status_code=http_client.BAD_REQUEST)

View File

@ -148,12 +148,12 @@ class InvalidUUID(Invalid):
_msg_fmt = _("Expected a uuid but received %(uuid)s.") _msg_fmt = _("Expected a uuid but received %(uuid)s.")
class InstanceTypeAlreadyExists(MoganException): class FlavorAlreadyExists(MoganException):
_msg_fmt = _("InstanceType with uuid %(uuid)s already exists.") _msg_fmt = _("Flavor with uuid %(uuid)s already exists.")
class InstanceTypeNotFound(NotFound): class FlavorNotFound(NotFound):
_msg_fmt = _("InstanceType %(type_id)s could not be found.") _msg_fmt = _("Flavor %(type_id)s could not be found.")
class InstanceAlreadyExists(MoganException): class InstanceAlreadyExists(MoganException):
@ -241,13 +241,13 @@ class NoValidNode(MoganException):
message = _("No valid node was found. %(reason)s") message = _("No valid node was found. %(reason)s")
class TypeExtraSpecUpdateCreateFailed(MoganException): class FlavorExtraSpecUpdateCreateFailed(MoganException):
_msg_fmt = _("Instance Type %(id)s extra spec cannot be updated or" _msg_fmt = _("Flavor %(id)s extra spec cannot be updated or"
"created after %(retries)d retries.") "created after %(retries)d retries.")
class InstanceTypeExtraSpecsNotFound(NotFound): class FlavorExtraSpecsNotFound(NotFound):
_msg_fmt = _("Instance Type %(type_id)s has no extra specs with " _msg_fmt = _("Flavor %(flavor_id)s has no extra specs with "
"key %(extra_specs_key)s.") "key %(extra_specs_key)s.")

View File

@ -125,7 +125,7 @@ class Connection(api.Connection):
session.add(instance_type) session.add(instance_type)
session.flush() session.flush()
except db_exc.DBDuplicateEntry: except db_exc.DBDuplicateEntry:
raise exception.InstanceTypeAlreadyExists(uuid=values['uuid']) raise exception.FlavorAlreadyExists(uuid=values['uuid'])
return _dict_with_extra_specs(instance_type) return _dict_with_extra_specs(instance_type)
def instance_type_get(self, context, instance_type_uuid): def instance_type_get(self, context, instance_type_uuid):
@ -134,7 +134,7 @@ class Connection(api.Connection):
try: try:
return _dict_with_extra_specs(query.one()) return _dict_with_extra_specs(query.one())
except NoResultFound: except NoResultFound:
raise exception.InstanceTypeNotFound( raise exception.FlavorNotFound(
type_id=instance_type_uuid) type_id=instance_type_uuid)
def instance_type_update(self, context, instance_type_id, values): def instance_type_update(self, context, instance_type_id, values):
@ -144,7 +144,7 @@ class Connection(api.Connection):
try: try:
ref = query.with_lockmode('update').one() ref = query.with_lockmode('update').one()
except NoResultFound: except NoResultFound:
raise exception.InstanceTypeNotFound( raise exception.FlavorNotFound(
type_id=instance_type_id) type_id=instance_type_id)
ref.update(values) ref.update(values)
@ -170,7 +170,7 @@ class Connection(api.Connection):
count = query.delete() count = query.delete()
if count != 1: if count != 1:
raise exception.InstanceTypeNotFound( raise exception.FlavorNotFound(
type_id=instance_type_uuid) type_id=instance_type_uuid)
def instance_create(self, context, values): def instance_create(self, context, values):
@ -454,7 +454,7 @@ class Connection(api.Connection):
# a concurrent transaction has been committed, # a concurrent transaction has been committed,
# try again unless this was the last attempt # try again unless this was the last attempt
if attempt == max_retries - 1: if attempt == max_retries - 1:
raise exception.TypeExtraSpecUpdateCreateFailed( raise exception.FlavorExtraSpecUpdateCreateFailed(
id=instance_type_uuid, retries=max_retries) id=instance_type_uuid, retries=max_retries)
def instance_type_extra_specs_get(self, context, type_id): def instance_type_extra_specs_get(self, context, type_id):
@ -467,8 +467,8 @@ class Connection(api.Connection):
delete(synchronize_session=False) delete(synchronize_session=False)
# did not find the extra spec # did not find the extra spec
if result == 0: if result == 0:
raise exception.InstanceTypeExtraSpecsNotFound( raise exception.FlavorExtraSpecsNotFound(
extra_specs_key=key, type_id=type_id) extra_specs_key=key, flavor_id=type_id)
def instance_nic_update_or_create(self, context, port_id, values): def instance_nic_update_or_create(self, context, port_id, values):
with _session_for_write() as session: with _session_for_write() as session:
@ -877,7 +877,7 @@ def _type_get_id_from_type_query(context, type_id):
def _type_get_id_from_type(context, type_id): def _type_get_id_from_type(context, type_id):
result = _type_get_id_from_type_query(context, type_id).first() result = _type_get_id_from_type_query(context, type_id).first()
if not result: if not result:
raise exception.InstanceTypeNotFound(type_id=type_id) raise exception.FlavorNotFound(type_id=type_id)
return result.uuid return result.uuid

View File

@ -57,7 +57,7 @@ class BaseBaremetalComputeTest(tempest.test.BaseTestCase):
else: else:
# TODO(liusheng) we shouldn't depend on the default # TODO(liusheng) we shouldn't depend on the default
# type created by devstack # type created by devstack
raise exception.InstanceTypeNotFound("'small' type not found.") raise exception.FlavorNotFound("'small' flavor not found.")
@classmethod @classmethod
def _get_net_id(cls): def _get_net_id(cls):

View File

@ -60,7 +60,7 @@ class DbInstanceTypeExtraSpecsTestCase(base.DbTestCase):
def test_delete_extra_specs_does_not_exist(self): def test_delete_extra_specs_does_not_exist(self):
self.dbapi.extra_specs_update_or_create( self.dbapi.extra_specs_update_or_create(
self.context, self.instance_type['uuid'], self.specs) self.context, self.instance_type['uuid'], self.specs)
self.assertRaises(exception.InstanceTypeExtraSpecsNotFound, self.assertRaises(exception.FlavorExtraSpecsNotFound,
self.dbapi.type_extra_specs_delete, self.dbapi.type_extra_specs_delete,
self.context, self.context,
self.instance_type['uuid'], self.instance_type['uuid'],

View File

@ -34,7 +34,7 @@ class DbInstanceTypeTestCase(base.DbTestCase):
utils.create_test_instance_type(name='testing') utils.create_test_instance_type(name='testing')
def test_create_instance_type_already_exists(self): def test_create_instance_type_already_exists(self):
self.assertRaises(exception.InstanceTypeAlreadyExists, self.assertRaises(exception.FlavorAlreadyExists,
utils.create_test_instance_type, utils.create_test_instance_type,
uuid=self.instance_type['uuid']) uuid=self.instance_type['uuid'])
@ -56,7 +56,7 @@ class DbInstanceTypeTestCase(base.DbTestCase):
self.assertEqual(self.instance_type['uuid'], instance_type['uuid']) self.assertEqual(self.instance_type['uuid'], instance_type['uuid'])
def test_get_instance_type_that_does_not_exist(self): def test_get_instance_type_that_does_not_exist(self):
self.assertRaises(exception.InstanceTypeNotFound, self.assertRaises(exception.FlavorNotFound,
self.dbapi.instance_type_get, self.dbapi.instance_type_get,
self.context, self.context,
uuidutils.generate_uuid()) uuidutils.generate_uuid())
@ -65,13 +65,13 @@ class DbInstanceTypeTestCase(base.DbTestCase):
self.dbapi.instance_type_destroy(self.context, self.dbapi.instance_type_destroy(self.context,
self.instance_type['uuid']) self.instance_type['uuid'])
self.assertRaises(exception.InstanceTypeNotFound, self.assertRaises(exception.FlavorNotFound,
self.dbapi.instance_type_destroy, self.dbapi.instance_type_destroy,
self.context, self.context,
self.instance_type['uuid']) self.instance_type['uuid'])
def test_destroy_instance_type_that_does_not_exist(self): def test_destroy_instance_type_that_does_not_exist(self):
self.assertRaises(exception.InstanceTypeNotFound, self.assertRaises(exception.FlavorNotFound,
self.dbapi.instance_type_destroy, self.dbapi.instance_type_destroy,
self.context, self.context,
uuidutils.generate_uuid()) uuidutils.generate_uuid())