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