Remove inappropriate exceptions and their usages
Change-Id: Iab8c035cca32190a8be9b68a180ebe752582a51b
This commit is contained in:
parent
d8df3b3a4c
commit
45343d34cc
@ -363,10 +363,6 @@ class BayNotFound(ResourceNotFound):
|
||||
message = _("Bay %(bay)s could not be found.")
|
||||
|
||||
|
||||
class BayAssociated(InvalidState):
|
||||
message = _("Bay %(bay)s is associated with instance %(instance)s.")
|
||||
|
||||
|
||||
class BayAlreadyExists(Conflict):
|
||||
message = _("A node with UUID %(uuid)s already exists.")
|
||||
|
||||
@ -379,11 +375,6 @@ class ContainerNotFound(ResourceNotFound):
|
||||
message = _("Container %(container)s could not be found.")
|
||||
|
||||
|
||||
class ContainerAssociated(InvalidState):
|
||||
message = _("Container %(container)s is associated with "
|
||||
"instance %(instance)s.")
|
||||
|
||||
|
||||
class ContainerAlreadyExists(Conflict):
|
||||
message = _("A container with UUID %(uuid)s already exists.")
|
||||
|
||||
@ -392,10 +383,6 @@ class PodNotFound(ResourceNotFound):
|
||||
message = _("Pod %(pod)s could not be found.")
|
||||
|
||||
|
||||
class PodAssociated(InvalidState):
|
||||
message = _("Pod %(pod)s is associated with instance %(instance)s.")
|
||||
|
||||
|
||||
class PodAlreadyExists(Conflict):
|
||||
message = _("A node with UUID %(uuid)s already exists.")
|
||||
|
||||
@ -412,11 +399,6 @@ class ServiceNotFound(ResourceNotFound):
|
||||
message = _("Service %(service)s could not be found.")
|
||||
|
||||
|
||||
class ServiceAssociated(InvalidState):
|
||||
message = _("Service %(service)s is associated with "
|
||||
"instance %(instance)s.")
|
||||
|
||||
|
||||
class ServiceAlreadyExists(Conflict):
|
||||
message = _("A node with UUID %(uuid)s already exists.")
|
||||
|
||||
|
@ -110,7 +110,6 @@ class Connection(object):
|
||||
|
||||
:param bay_id: The id or uuid of a bay.
|
||||
:returns: A bay.
|
||||
:raises: BayAssociated
|
||||
:raises: BayNotFound
|
||||
"""
|
||||
|
||||
@ -256,7 +255,6 @@ class Connection(object):
|
||||
|
||||
:param container_id: The id or uuid of a container.
|
||||
:returns: A container.
|
||||
:raises: BayAssociated
|
||||
:raises: BayNotFound
|
||||
"""
|
||||
|
||||
@ -415,7 +413,6 @@ class Connection(object):
|
||||
|
||||
:param pod_id: The id or uuid of a pod.
|
||||
:returns: A pod.
|
||||
:raises: BayAssociated
|
||||
:raises: BayNotFound
|
||||
"""
|
||||
|
||||
@ -496,7 +493,6 @@ class Connection(object):
|
||||
|
||||
:param service_id: The id or uuid of a service.
|
||||
:returns: A service.
|
||||
:raises: BayAssociated
|
||||
:raises: BayNotFound
|
||||
"""
|
||||
|
||||
|
@ -156,12 +156,7 @@ class Connection(api.Connection):
|
||||
bay.update(values)
|
||||
try:
|
||||
bay.save()
|
||||
except db_exc.DBDuplicateEntry as exc:
|
||||
if 'instance_uuid' in exc.columns:
|
||||
raise exception.InstanceAssociated(
|
||||
instance_uuid=values['instance_uuid'],
|
||||
bay=values['uuid'])
|
||||
|
||||
except db_exc.DBDuplicateEntry:
|
||||
raise exception.BayAlreadyExists(uuid=values['uuid'])
|
||||
return bay
|
||||
|
||||
@ -217,12 +212,7 @@ class Connection(api.Connection):
|
||||
msg = _("Cannot overwrite UUID for an existing Bay.")
|
||||
raise exception.InvalidParameterValue(err=msg)
|
||||
|
||||
try:
|
||||
return self._do_update_bay(bay_id, values)
|
||||
except db_exc.DBDuplicateEntry:
|
||||
raise exception.InstanceAssociated(
|
||||
instance_uuid=values['instance_uuid'],
|
||||
bay=bay_id)
|
||||
return self._do_update_bay(bay_id, values)
|
||||
|
||||
def _do_update_bay(self, bay_id, values):
|
||||
session = get_session()
|
||||
@ -234,11 +224,6 @@ class Connection(api.Connection):
|
||||
except NoResultFound:
|
||||
raise exception.BayNotFound(bay=bay_id)
|
||||
|
||||
# Prevent instance_uuid overwriting
|
||||
if values.get("instance_uuid") and ref.instance_uuid:
|
||||
raise exception.BayAssociated(bay=bay_id,
|
||||
instance=ref.instance_uuid)
|
||||
|
||||
if 'provision_state' in values:
|
||||
values['provision_updated_at'] = timeutils.utcnow()
|
||||
|
||||
@ -295,11 +280,7 @@ class Connection(api.Connection):
|
||||
baymodel.update(values)
|
||||
try:
|
||||
baymodel.save()
|
||||
except db_exc.DBDuplicateEntry as exc:
|
||||
if 'instance_uuid' in exc.columns:
|
||||
raise exception.InstanceAssociated(
|
||||
instance_uuid=values['instance_uuid'],
|
||||
baymodel=values['uuid'])
|
||||
except db_exc.DBDuplicateEntry:
|
||||
raise exception.BayModelAlreadyExists(uuid=values['uuid'])
|
||||
return baymodel
|
||||
|
||||
@ -346,12 +327,7 @@ class Connection(api.Connection):
|
||||
msg = _("Cannot overwrite UUID for an existing BayModel.")
|
||||
raise exception.InvalidParameterValue(err=msg)
|
||||
|
||||
try:
|
||||
return self._do_update_baymodel(baymodel_id, values)
|
||||
except db_exc.DBDuplicateEntry:
|
||||
raise exception.InstanceAssociated(
|
||||
instance_uuid=values['instance_uuid'],
|
||||
baymodel=baymodel_id)
|
||||
return self._do_update_baymodel(baymodel_id, values)
|
||||
|
||||
def _do_update_baymodel(self, baymodel_id, values):
|
||||
session = get_session()
|
||||
@ -407,11 +383,7 @@ class Connection(api.Connection):
|
||||
container.update(values)
|
||||
try:
|
||||
container.save()
|
||||
except db_exc.DBDuplicateEntry as exc:
|
||||
if 'instance_uuid' in exc.columns:
|
||||
raise exception.InstanceAssociated(
|
||||
instance_uuid=values['instance_uuid'],
|
||||
container=values['uuid'])
|
||||
except db_exc.DBDuplicateEntry:
|
||||
raise exception.ContainerAlreadyExists(uuid=values['uuid'])
|
||||
return container
|
||||
|
||||
@ -444,12 +416,7 @@ class Connection(api.Connection):
|
||||
msg = _("Cannot overwrite UUID for an existing Container.")
|
||||
raise exception.InvalidParameterValue(err=msg)
|
||||
|
||||
try:
|
||||
return self._do_update_container(container_id, values)
|
||||
except db_exc.DBDuplicateEntry:
|
||||
raise exception.InstanceAssociated(
|
||||
instance_uuid=values['instance_uuid'],
|
||||
container=container_id)
|
||||
return self._do_update_container(container_id, values)
|
||||
|
||||
def _do_update_container(self, container_id, values):
|
||||
session = get_session()
|
||||
@ -461,11 +428,6 @@ class Connection(api.Connection):
|
||||
except NoResultFound:
|
||||
raise exception.ContainerNotFound(container=container_id)
|
||||
|
||||
# Prevent instance_uuid overwriting
|
||||
if values.get("instance_uuid") and ref.instance_uuid:
|
||||
raise exception.ContainerAssociated(container=container_id,
|
||||
instance=ref.instance_uuid)
|
||||
|
||||
if 'provision_state' in values:
|
||||
values['provision_updated_at'] = timeutils.utcnow()
|
||||
|
||||
@ -623,11 +585,7 @@ class Connection(api.Connection):
|
||||
pod.update(values)
|
||||
try:
|
||||
pod.save()
|
||||
except db_exc.DBDuplicateEntry as exc:
|
||||
if 'instance_uuid' in exc.columns:
|
||||
raise exception.InstanceAssociated(
|
||||
instance_uuid=values['instance_uuid'],
|
||||
pod=values['uuid'])
|
||||
except db_exc.DBDuplicateEntry:
|
||||
raise exception.PodAlreadyExists(uuid=values['uuid'])
|
||||
return pod
|
||||
|
||||
@ -674,12 +632,7 @@ class Connection(api.Connection):
|
||||
msg = _("Cannot overwrite UUID for an existing Pod.")
|
||||
raise exception.InvalidParameterValue(err=msg)
|
||||
|
||||
try:
|
||||
return self._do_update_pod(pod_id, values)
|
||||
except db_exc.DBDuplicateEntry:
|
||||
raise exception.InstanceAssociated(
|
||||
instance_uuid=values['instance_uuid'],
|
||||
pod=pod_id)
|
||||
return self._do_update_pod(pod_id, values)
|
||||
|
||||
def _do_update_pod(self, pod_id, values):
|
||||
session = get_session()
|
||||
@ -691,11 +644,6 @@ class Connection(api.Connection):
|
||||
except NoResultFound:
|
||||
raise exception.PodNotFound(pod=pod_id)
|
||||
|
||||
# Prevent instance_uuid overwriting
|
||||
if values.get("instance_uuid") and ref.instance_uuid:
|
||||
raise exception.PodAssociated(pod=pod_id,
|
||||
instance=ref.instance_uuid)
|
||||
|
||||
if 'provision_state' in values:
|
||||
values['provision_updated_at'] = timeutils.utcnow()
|
||||
|
||||
@ -747,11 +695,7 @@ class Connection(api.Connection):
|
||||
service.update(values)
|
||||
try:
|
||||
service.save()
|
||||
except db_exc.DBDuplicateEntry as exc:
|
||||
if 'instance_uuid' in exc.columns:
|
||||
raise exception.InstanceAssociated(
|
||||
instance_uuid=values['instance_uuid'],
|
||||
service=values['uuid'])
|
||||
except db_exc.DBDuplicateEntry:
|
||||
raise exception.ServiceAlreadyExists(uuid=values['uuid'])
|
||||
return service
|
||||
|
||||
@ -791,12 +735,7 @@ class Connection(api.Connection):
|
||||
msg = _("Cannot overwrite UUID for an existing Service.")
|
||||
raise exception.InvalidParameterValue(err=msg)
|
||||
|
||||
try:
|
||||
return self._do_update_service(service_id, values)
|
||||
except db_exc.DBDuplicateEntry:
|
||||
raise exception.InstanceAssociated(
|
||||
instance_uuid=values['instance_uuid'],
|
||||
service=service_id)
|
||||
return self._do_update_service(service_id, values)
|
||||
|
||||
def _do_update_service(self, service_id, values):
|
||||
session = get_session()
|
||||
@ -808,11 +747,6 @@ class Connection(api.Connection):
|
||||
except NoResultFound:
|
||||
raise exception.ServiceNotFound(service=service_id)
|
||||
|
||||
# Prevent instance_uuid overwriting
|
||||
if values.get("instance_uuid") and ref.instance_uuid:
|
||||
raise exception.ServiceAssociated(service=service_id,
|
||||
instance=ref.instance_uuid)
|
||||
|
||||
if 'provision_state' in values:
|
||||
values['provision_updated_at'] = timeutils.utcnow()
|
||||
|
||||
@ -861,11 +795,7 @@ class Connection(api.Connection):
|
||||
rc.update(values)
|
||||
try:
|
||||
rc.save()
|
||||
except db_exc.DBDuplicateEntry as exc:
|
||||
if 'instance_uuid' in exc.columns:
|
||||
raise exception.InstanceAssociated(
|
||||
instance_uuid=values['instance_uuid'],
|
||||
pod=values['uuid'])
|
||||
except db_exc.DBDuplicateEntry:
|
||||
raise exception.ReplicationControllerAlreadyExists(
|
||||
uuid=values['uuid'])
|
||||
return rc
|
||||
@ -915,12 +845,7 @@ class Connection(api.Connection):
|
||||
msg = _("Cannot overwrite UUID for an existing rc.")
|
||||
raise exception.InvalidParameterValue(err=msg)
|
||||
|
||||
try:
|
||||
return self._do_update_rc(rc_id, values)
|
||||
except db_exc.DBDuplicateEntry:
|
||||
raise exception.InstanceAssociated(
|
||||
instance_uuid=values['instance_uuid'],
|
||||
rc=rc_id)
|
||||
return self._do_update_rc(rc_id, values)
|
||||
|
||||
def _do_update_rc(self, rc_id, values):
|
||||
session = get_session()
|
||||
|
@ -127,10 +127,6 @@ class TestException(base.BaseTestCase):
|
||||
self.assertRaises(exception.BayNotFound,
|
||||
lambda: self.raise_(exception.BayNotFound()))
|
||||
|
||||
def test_BayAssociated(self):
|
||||
self.assertRaises(exception.BayAssociated,
|
||||
lambda: self.raise_(exception.BayAssociated()))
|
||||
|
||||
def test_BayAlreadyExists(self):
|
||||
self.assertRaises(exception.BayAlreadyExists,
|
||||
lambda: self.raise_(exception.BayAlreadyExists()))
|
||||
@ -155,10 +151,6 @@ class TestException(base.BaseTestCase):
|
||||
self.assertRaises(exception.ContainerNotFound,
|
||||
lambda: self.raise_(exception.ContainerNotFound()))
|
||||
|
||||
def test_ContainerAssociated(self):
|
||||
self.assertRaises(exception.ContainerAssociated,
|
||||
lambda: self.raise_(exception.ContainerAssociated()))
|
||||
|
||||
def test_ContainerAlreadyExists(self):
|
||||
self.assertRaises(exception.ContainerAlreadyExists,
|
||||
lambda: self.raise_(exception.ContainerAlreadyExists()))
|
||||
@ -167,10 +159,6 @@ class TestException(base.BaseTestCase):
|
||||
self.assertRaises(exception.PodNotFound,
|
||||
lambda: self.raise_(exception.PodNotFound()))
|
||||
|
||||
def test_PodAssociated(self):
|
||||
self.assertRaises(exception.PodAssociated,
|
||||
lambda: self.raise_(exception.PodAssociated()))
|
||||
|
||||
def test_PodAlreadyExists(self):
|
||||
self.assertRaises(exception.PodAlreadyExists,
|
||||
lambda: self.raise_(exception.PodAlreadyExists()))
|
||||
@ -187,10 +175,6 @@ class TestException(base.BaseTestCase):
|
||||
self.assertRaises(exception.ServiceNotFound,
|
||||
lambda: self.raise_(exception.ServiceNotFound()))
|
||||
|
||||
def test_ServiceAssociated(self):
|
||||
self.assertRaises(exception.ServiceAssociated,
|
||||
lambda: self.raise_(exception.ServiceAssociated()))
|
||||
|
||||
def test_ServiceAlreadyExists(self):
|
||||
self.assertRaises(exception.ServiceAlreadyExists,
|
||||
lambda: self.raise_(exception.ServiceAlreadyExists()))
|
||||
|
Loading…
Reference in New Issue
Block a user