diff --git a/magnum/common/exception.py b/magnum/common/exception.py index e2f7310e9b..dfda3c4568 100644 --- a/magnum/common/exception.py +++ b/magnum/common/exception.py @@ -331,6 +331,14 @@ class FileSystemNotSupported(MagnumException): "File system %(fs)s is not supported.") +class BayModelNotFound(ResourceNotFound): + message = _("Baymodel %(baymodel)s could not be found.") + + +class BayModelAlreadyExists(Conflict): + message = _("A baymodel with UUID %(uuid)s already exists.") + + class BayNotFound(ResourceNotFound): message = _("Bay %(bay)s could not be found.") diff --git a/magnum/db/api.py b/magnum/db/api.py index fc15520174..fcb7ede0f7 100644 --- a/magnum/db/api.py +++ b/magnum/db/api.py @@ -169,32 +169,6 @@ class Connection(object): :returns: A list of tuples of the specified columns. """ - @abc.abstractmethod - def reserve_baymodel(self, tag, baymodel_id): - """Reserve a baymodel. - - To prevent other ManagerServices from manipulating the given - BayModel while a Task is performed, mark it reserved by this host. - - :param tag: A string uniquely identifying the reservation holder. - :param baymodel_id: A baymodel id or uuid. - :returns: A BayModel object. - :raises: BayModelNotFound if the baymodel is not found. - :raises: BayModelLocked if the baymodel is already reserved. - """ - - @abc.abstractmethod - def release_baymodel(self, tag, baymodel_id): - """Release the reservation on a baymodel. - - :param tag: A string uniquely identifying the reservation holder. - :param baymodel_id: A baymodel id or uuid. - :raises: BayModelNotFound if the baymodel is not found. - :raises: BayModelLocked if the baymodel is reserved by another host. - :raises: BayModelNotLocked if the baymodel was found to not have a - reservation at all. - """ - @abc.abstractmethod def create_baymodel(self, values): """Create a new baymodel. @@ -251,7 +225,6 @@ class Connection(object): :param baymodel_id: The id or uuid of a baymodel. :returns: A baymodel. - :raises: BayModelAssociated :raises: BayModelNotFound """ diff --git a/magnum/db/sqlalchemy/api.py b/magnum/db/sqlalchemy/api.py index 98fa0a872c..b2591b7b37 100644 --- a/magnum/db/sqlalchemy/api.py +++ b/magnum/db/sqlalchemy/api.py @@ -340,44 +340,6 @@ class Connection(api.Connection): return _paginate_query(models.BayModel, limit, marker, sort_key, sort_dir, query) - def reserve_baymodel(self, tag, baymodel_id): - session = get_session() - with session.begin(): - query = model_query(models.BayModel, session=session) - query = add_identity_filter(query, baymodel_id) - # be optimistic and assume we usually create a reservation - count = query.filter_by(reservation=None).update( - {'reservation': tag}, synchronize_session=False) - try: - baymodel = query.one() - if count != 1: - # Nothing updated and baymodel exists. Must already be - # locked. - raise exception.BayModelLocked(baymodel=baymodel_id, - host=baymodel['reservation']) - return baymodel - except NoResultFound: - raise exception.BayModelNotFound(baymodel_id) - - def release_baymodel(self, tag, baymodel_id): - session = get_session() - with session.begin(): - query = model_query(models.BayModel, session=session) - query = add_identity_filter(query, baymodel_id) - # be optimistic and assume we usually release a reservation - count = query.filter_by(reservation=tag).update( - {'reservation': None}, synchronize_session=False) - try: - if count != 1: - baymodel = query.one() - if baymodel['reservation'] is None: - raise exception.BayModelNotLocked(baymodel=baymodel_id) - else: - raise exception.BayModelLocked(baymodel=baymodel_id, - host=baymodel['reservation']) - except NoResultFound: - raise exception.BayModelNotFound(baymodel_id) - def create_baymodel(self, values): # ensure defaults are present for new baymodels if not values.get('uuid'): @@ -453,14 +415,6 @@ class Connection(api.Connection): except NoResultFound: raise exception.BayModelNotFound(baymodel=baymodel_id) - # Prevent instance_uuid overwriting - if values.get("instance_uuid") and ref.instance_uuid: - raise exception.BayModelAssociated(baymodel=baymodel_id, - instance=ref.instance_uuid) - - if 'provision_state' in values: - values['provision_updated_at'] = timeutils.utcnow() - ref.update(values) return ref diff --git a/magnum/tests/common/test_exception.py b/magnum/tests/common/test_exception.py index 526ab59b23..5e54a9b3da 100644 --- a/magnum/tests/common/test_exception.py +++ b/magnum/tests/common/test_exception.py @@ -143,6 +143,14 @@ class TestException(base.BaseTestCase): self.assertRaises(exception.BayNotLocked, lambda: self.raise_(exception.BayNotLocked())) + def test_BayModelNotFound(self): + self.assertRaises(exception.BayModelNotFound, + lambda: self.raise_(exception.BayModelNotFound())) + + def test_BayModelAlreadyExists(self): + self.assertRaises(exception.BayModelAlreadyExists, + lambda: self.raise_(exception.BayModelAlreadyExists())) + def test_ContainerNotFound(self): self.assertRaises(exception.ContainerNotFound, lambda: self.raise_(exception.ContainerNotFound()))