diff --git a/magnum/common/exception.py b/magnum/common/exception.py index 84c125f610..af8a419e8f 100644 --- a/magnum/common/exception.py +++ b/magnum/common/exception.py @@ -351,15 +351,6 @@ class BayAlreadyExists(Conflict): message = _("A node with UUID %(uuid)s already exists.") -class BayLocked(Conflict): - message = _("Bay %(bay)s is locked by host %(host)s, please retry " - "after the current operation is completed.") - - -class BayNotLocked(Invalid): - message = _("Bay %(bay)s found not to be locked on release") - - class BayNotEmpty(Invalid): message = _("Bay %(bay)s is not empty.") @@ -377,15 +368,6 @@ class ContainerAlreadyExists(Conflict): message = _("A node with UUID %(uuid)s already exists.") -class ContainerLocked(Conflict): - message = _("Container %(container)s is locked by host %(host)s, " - "please retry after the current operation is completed.") - - -class ContainerNotLocked(Invalid): - message = _("Container %(container)s found not to be locked on release") - - class PodNotFound(ResourceNotFound): message = _("Pod %(pod)s could not be found.") @@ -398,15 +380,6 @@ class PodAlreadyExists(Conflict): message = _("A node with UUID %(uuid)s already exists.") -class PodLocked(Conflict): - message = _("Pod %(pod)s is locked by host %(host)s, please retry " - "after the current operation is completed.") - - -class PodNotLocked(Invalid): - message = _("Pod %(pod)s found not to be locked on release") - - class ReplicationControllerNotFound(ResourceNotFound): message = _("ReplicationController %(rc)s could not be found.") @@ -428,15 +401,6 @@ class ServiceAlreadyExists(Conflict): message = _("A node with UUID %(uuid)s already exists.") -class ServiceLocked(Conflict): - message = _("Service %(service)s is locked by host %(host)s, please retry " - "after the current operation is completed.") - - -class ServiceNotLocked(Invalid): - message = _("Service %(service)s found not to be locked on release") - - class KeystoneUnauthorized(MagnumException): message = _("Not authorized in Keystone.") diff --git a/magnum/db/api.py b/magnum/db/api.py index 6869bcf40e..132543d4db 100644 --- a/magnum/db/api.py +++ b/magnum/db/api.py @@ -63,32 +63,6 @@ class Connection(object): :returns: A list of tuples of the specified columns. """ - @abc.abstractmethod - def reserve_bay(self, tag, bay_id): - """Reserve a bay. - - To prevent other ManagerServices from manipulating the given - Bay while a Task is performed, mark it reserved by this host. - - :param tag: A string uniquely identifying the reservation holder. - :param bay_id: A bay id or uuid. - :returns: A Bay object. - :raises: BayNotFound if the bay is not found. - :raises: BayLocked if the bay is already reserved. - """ - - @abc.abstractmethod - def release_bay(self, tag, bay_id): - """Release the reservation on a bay. - - :param tag: A string uniquely identifying the reservation holder. - :param bay_id: A bay id or uuid. - :raises: BayNotFound if the bay is not found. - :raises: BayLocked if the bay is reserved by another host. - :raises: BayNotLocked if the bay was found to not have a - reservation at all. - """ - @abc.abstractmethod def create_bay(self, values): """Create a new bay. @@ -123,14 +97,6 @@ class Connection(object): :returns: A bay. """ - @abc.abstractmethod - def get_bay_by_instance(self, instance): - """Return a bay. - - :param instance: The instance name or uuid to search for. - :returns: A bay. - """ - @abc.abstractmethod def destroy_bay(self, bay_id): """Destroy a bay and all associated interfaces. @@ -204,14 +170,6 @@ class Connection(object): :returns: A baymodel. """ - @abc.abstractmethod - def get_baymodel_by_instance(self, instance): - """Return a baymodel. - - :param instance: The instance name or uuid to search for. - :returns: A baymodel. - """ - @abc.abstractmethod def destroy_baymodel(self, baymodel_id): """Destroy a baymodel and all associated interfaces. @@ -249,32 +207,6 @@ class Connection(object): :returns: A list of tuples of the specified columns. """ - @abc.abstractmethod - def reserve_container(self, tag, container_id): - """Reserve a container. - - To prevent other ManagerServices from manipulating the given - Bay while a Task is performed, mark it reserved by this host. - - :param tag: A string uniquely identifying the reservation holder. - :param container_id: A container id or uuid. - :returns: A Bay object. - :raises: BayNotFound if the container is not found. - :raises: BayLocked if the container is already reserved. - """ - - @abc.abstractmethod - def release_container(self, tag, container_id): - """Release the reservation on a container. - - :param tag: A string uniquely identifying the reservation holder. - :param container_id: A container id or uuid. - :raises: BayNotFound if the container is not found. - :raises: BayLocked if the container is reserved by another host. - :raises: BayNotLocked if the container was found to not have a - reservation at all. - """ - @abc.abstractmethod def create_container(self, values): """Create a new container. @@ -311,14 +243,6 @@ class Connection(object): :returns: A container. """ - @abc.abstractmethod - def get_container_by_instance(self, instance): - """Return a container. - - :param instance: The instance name or uuid to search for. - :returns: A container. - """ - @abc.abstractmethod def destroy_container(self, container_id): """Destroy a container and all associated interfaces. @@ -357,32 +281,6 @@ class Connection(object): :returns: A list of tuples of the specified columns. """ - @abc.abstractmethod - def reserve_node(self, tag, node_id): - """Reserve a node. - - To prevent other ManagerServices from manipulating the given - Node while a Task is performed, mark it reserved by this host. - - :param tag: A string uniquely identifying the reservation holder. - :param node_id: A node id or uuid. - :returns: A Node object. - :raises: NodeNotFound if the node is not found. - :raises: NodeLocked if the node is already reserved. - """ - - @abc.abstractmethod - def release_node(self, tag, node_id): - """Release the reservation on a node. - - :param tag: A string uniquely identifying the reservation holder. - :param node_id: A node id or uuid. - :raises: NodeNotFound if the node is not found. - :raises: NodeLocked if the node is reserved by another host. - :raises: NodeNotLocked if the node was found to not have a - reservation at all. - """ - @abc.abstractmethod def create_node(self, values): """Create a new node. @@ -417,14 +315,6 @@ class Connection(object): :returns: A node. """ - @abc.abstractmethod - def get_node_by_instance(self, instance): - """Return a node. - - :param instance: The instance name or uuid to search for. - :returns: A node. - """ - @abc.abstractmethod def destroy_node(self, node_id): """Destroy a node and all associated interfaces. @@ -462,32 +352,6 @@ class Connection(object): :returns: A list of tuples of the specified columns. """ - @abc.abstractmethod - def reserve_pod(self, tag, pod_id): - """Reserve a pod. - - To prevent other ManagerServices from manipulating the given - Bay while a Task is performed, mark it reserved by this host. - - :param tag: A string uniquely identifying the reservation holder. - :param pod_id: A pod id or uuid. - :returns: A Bay object. - :raises: BayNotFound if the pod is not found. - :raises: BayLocked if the pod is already reserved. - """ - - @abc.abstractmethod - def release_pod(self, tag, pod_id): - """Release the reservation on a pod. - - :param tag: A string uniquely identifying the reservation holder. - :param pod_id: A pod id or uuid. - :raises: BayNotFound if the pod is not found. - :raises: BayLocked if the pod is reserved by another host. - :raises: BayNotLocked if the pod was found to not have a - reservation at all. - """ - @abc.abstractmethod def create_pod(self, values): """Create a new pod. @@ -530,14 +394,6 @@ class Connection(object): :returns: A pod. """ - @abc.abstractmethod - def get_pod_by_instance(self, instance): - """Return a pod. - - :param instance: The instance name or uuid to search for. - :returns: A pod. - """ - @abc.abstractmethod def destroy_pod(self, pod_id): """Destroy a pod and all associated interfaces. @@ -576,32 +432,6 @@ class Connection(object): :returns: A list of tuples of the specified columns. """ - @abc.abstractmethod - def reserve_service(self, tag, service_id): - """Reserve a service. - - To prevent other ManagerServices from manipulating the given - Bay while a Task is performed, mark it reserved by this host. - - :param tag: A string uniquely identifying the reservation holder. - :param service_id: A service id or uuid. - :returns: A Bay object. - :raises: BayNotFound if the service is not found. - :raises: BayLocked if the service is already reserved. - """ - - @abc.abstractmethod - def release_service(self, tag, service_id): - """Release the reservation on a service. - - :param tag: A string uniquely identifying the reservation holder. - :param service_id: A service id or uuid. - :raises: BayNotFound if the service is not found. - :raises: BayLocked if the service is reserved by another host. - :raises: BayNotLocked if the service was found to not have a - reservation at all. - """ - @abc.abstractmethod def create_service(self, values): """Create a new service. diff --git a/magnum/db/sqlalchemy/api.py b/magnum/db/sqlalchemy/api.py index af5cd6d1f1..2b6b26fe17 100644 --- a/magnum/db/sqlalchemy/api.py +++ b/magnum/db/sqlalchemy/api.py @@ -160,44 +160,6 @@ class Connection(api.Connection): return _paginate_query(models.Bay, limit, marker, sort_key, sort_dir, query) - def reserve_bay(self, tag, bay_id): - session = get_session() - with session.begin(): - query = model_query(models.Bay, session=session) - query = add_identity_filter(query, bay_id) - # be optimistic and assume we usually create a reservation - count = query.filter_by(reservation=None).update( - {'reservation': tag}, synchronize_session=False) - try: - bay = query.one() - if count != 1: - # Nothing updated and bay exists. Must already be - # locked. - raise exception.BayLocked(bay=bay_id, - host=bay['reservation']) - return bay - except NoResultFound: - raise exception.BayNotFound(bay_id) - - def release_bay(self, tag, bay_id): - session = get_session() - with session.begin(): - query = model_query(models.Bay, session=session) - query = add_identity_filter(query, bay_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: - bay = query.one() - if bay['reservation'] is None: - raise exception.BayNotLocked(bay=bay_id) - else: - raise exception.BayLocked(bay=bay_id, - host=bay['reservation']) - except NoResultFound: - raise exception.BayNotFound(bay_id) - def create_bay(self, values): # ensure defaults are present for new bays if not values.get('uuid'): @@ -229,20 +191,6 @@ class Connection(api.Connection): except NoResultFound: raise exception.BayNotFound(bay=bay_uuid) - def get_bay_by_instance(self, instance): - if not utils.is_uuid_like(instance): - raise exception.InvalidUUID(uuid=instance) - - query = (model_query(models.Bay) - .filter_by(instance_uuid=instance)) - - try: - result = query.one() - except NoResultFound: - raise exception.InstanceNotFound(instance=instance) - - return result - def destroy_bay(self, bay_id): def bay_not_empty(session, bay_uuid): """Checks whether the bay does not have pods or services.""" @@ -388,20 +336,6 @@ class Connection(api.Connection): except NoResultFound: raise exception.BayModelNotFound(baymodel=baymodel_uuid) - def get_baymodel_by_instance(self, instance): - if not utils.is_uuid_like(instance): - raise exception.InvalidUUID(uuid=instance) - - query = (model_query(models.BayModel) - .filter_by(instance_uuid=instance)) - - try: - result = query.one() - except NoResultFound: - raise exception.InstanceNotFound(instance=instance) - - return result - def destroy_baymodel(self, baymodel_id): session = get_session() with session.begin(): @@ -486,45 +420,6 @@ class Connection(api.Connection): return _paginate_query(models.Container, limit, marker, sort_key, sort_dir, query) - def reserve_container(self, tag, container_id): - session = get_session() - with session.begin(): - query = model_query(models.Container, session=session) - query = add_identity_filter(query, container_id) - # be optimistic and assume we usually create a reservation - count = query.filter_by(reservation=None).update( - {'reservation': tag}, synchronize_session=False) - try: - container = query.one() - if count != 1: - # Nothing updated and container exists. Must already be - # locked. - raise exception.ContainerLocked(container=container_id, - host=container['reservation']) - return container - except NoResultFound: - raise exception.ContainerNotFound(container_id) - - def release_container(self, tag, container_id): - session = get_session() - with session.begin(): - query = model_query(models.Container, session=session) - query = add_identity_filter(query, container_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: - container = query.one() - if container['reservation'] is None: - raise exception.ContainerNotLocked( - container=container_id) - else: - raise exception.ContainerLocked(container=container_id, - host=container['reservation']) - except NoResultFound: - raise exception.ContainerNotFound(container_id) - def create_container(self, values): # ensure defaults are present for new containers if not values.get('uuid'): @@ -556,20 +451,6 @@ class Connection(api.Connection): except NoResultFound: raise exception.ContainerNotFound(container=container_uuid) - def get_container_by_instance(self, instance): - if not utils.is_uuid_like(instance): - raise exception.InvalidUUID(uuid=instance) - - query = (model_query(models.Container) - .filter_by(instance_uuid=instance)) - - try: - result = query.one() - except NoResultFound: - raise exception.InstanceNotFound(instance=instance) - - return result - def destroy_container(self, container_id): session = get_session() with session.begin(): @@ -659,44 +540,6 @@ class Connection(api.Connection): return _paginate_query(models.Node, limit, marker, sort_key, sort_dir, query) - def reserve_node(self, tag, node_id): - session = get_session() - with session.begin(): - query = model_query(models.Node, session=session) - query = add_identity_filter(query, node_id) - # be optimistic and assume we usually create a reservation - count = query.filter_by(reservation=None).update( - {'reservation': tag}, synchronize_session=False) - try: - node = query.one() - if count != 1: - # Nothing updated and node exists. Must already be - # locked. - raise exception.NodeLocked(node=node_id, - host=node['reservation']) - return node - except NoResultFound: - raise exception.NodeNotFound(node_id) - - def release_node(self, tag, node_id): - session = get_session() - with session.begin(): - query = model_query(models.Node, session=session) - query = add_identity_filter(query, node_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: - node = query.one() - if node['reservation'] is None: - raise exception.NodeNotLocked(node=node_id) - else: - raise exception.NodeLocked(node=node_id, - host=node['reservation']) - except NoResultFound: - raise exception.NodeNotFound(node_id) - def create_node(self, values): # ensure defaults are present for new nodes if not values.get('uuid'): @@ -728,20 +571,6 @@ class Connection(api.Connection): except NoResultFound: raise exception.NodeNotFound(node=node_uuid) - def get_node_by_instance(self, instance): - if not utils.is_uuid_like(instance): - raise exception.InvalidUUID(uuid=instance) - - query = (model_query(models.Node) - .filter_by(instance_uuid=instance)) - - try: - result = query.one() - except NoResultFound: - raise exception.InstanceNotFound(instance=instance) - - return result - def destroy_node(self, node_id): session = get_session() with session.begin(): @@ -817,44 +646,6 @@ class Connection(api.Connection): return _paginate_query(models.Pod, limit, marker, sort_key, sort_dir, query) - def reserve_pod(self, tag, pod_id): - session = get_session() - with session.begin(): - query = model_query(models.Pod, session=session) - query = add_identity_filter(query, pod_id) - # be optimistic and assume we usually create a reservation - count = query.filter_by(reservation=None).update( - {'reservation': tag}, synchronize_session=False) - try: - pod = query.one() - if count != 1: - # Nothing updated and pod exists. Must already be - # locked. - raise exception.PodLocked(pod=pod_id, - host=pod['reservation']) - return pod - except NoResultFound: - raise exception.PodNotFound(pod_id) - - def release_pod(self, tag, pod_id): - session = get_session() - with session.begin(): - query = model_query(models.Pod, session=session) - query = add_identity_filter(query, pod_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: - pod = query.one() - if pod['reservation'] is None: - raise exception.PodNotLocked(pod=pod_id) - else: - raise exception.PodLocked(pod=pod_id, - host=pod['reservation']) - except NoResultFound: - raise exception.PodNotFound(pod_id) - def create_pod(self, values): # ensure defaults are present for new pods if not values.get('uuid'): @@ -900,20 +691,6 @@ class Connection(api.Connection): except NoResultFound: raise exception.BayNotFound(bay=bay_uuid) - def get_pod_by_instance(self, instance): - if not utils.is_uuid_like(instance): - raise exception.InvalidUUID(uuid=instance) - - query = (model_query(models.Pod) - .filter_by(instance_uuid=instance)) - - try: - result = query.one() - except NoResultFound: - raise exception.InstanceNotFound(instance=instance) - - return result - def destroy_pod(self, pod_id): session = get_session() with session.begin(): @@ -991,44 +768,6 @@ class Connection(api.Connection): return _paginate_query(models.Service, limit, marker, sort_key, sort_dir, query) - def reserve_service(self, tag, service_id): - session = get_session() - with session.begin(): - query = model_query(models.Service, session=session) - query = add_identity_filter(query, service_id) - # be optimistic and assume we usually create a reservation - count = query.filter_by(reservation=None).update( - {'reservation': tag}, synchronize_session=False) - try: - service = query.one() - if count != 1: - # Nothing updated and service exists. Must already be - # locked. - raise exception.ServiceLocked(service=service_id, - host=service['reservation']) - return service - except NoResultFound: - raise exception.ServiceNotFound(service_id) - - def release_service(self, tag, service_id): - session = get_session() - with session.begin(): - query = model_query(models.Service, session=session) - query = add_identity_filter(query, service_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: - service = query.one() - if service['reservation'] is None: - raise exception.ServiceNotLocked(service=service_id) - else: - raise exception.ServiceLocked(service=service_id, - host=service['reservation']) - except NoResultFound: - raise exception.ServiceNotFound(service_id) - def create_service(self, values): # ensure defaults are present for new services if not values.get('uuid'): diff --git a/magnum/tests/common/test_exception.py b/magnum/tests/common/test_exception.py index ca1bdb3fe2..86f66f3ffd 100644 --- a/magnum/tests/common/test_exception.py +++ b/magnum/tests/common/test_exception.py @@ -135,14 +135,6 @@ class TestException(base.BaseTestCase): self.assertRaises(exception.BayAlreadyExists, lambda: self.raise_(exception.BayAlreadyExists())) - def test_BayLocked(self): - self.assertRaises(exception.BayLocked, - lambda: self.raise_(exception.BayLocked())) - - def test_BayNotLocked(self): - self.assertRaises(exception.BayNotLocked, - lambda: self.raise_(exception.BayNotLocked())) - def test_BayNotEmpty(self): self.assertRaises(exception.BayNotEmpty, lambda: self.raise_(exception.BayNotEmpty())) @@ -167,14 +159,6 @@ class TestException(base.BaseTestCase): self.assertRaises(exception.ContainerAlreadyExists, lambda: self.raise_(exception.ContainerAlreadyExists())) - def test_ContainerLocked(self): - self.assertRaises(exception.ContainerLocked, - lambda: self.raise_(exception.ContainerLocked())) - - def test_ContainerNotLocked(self): - self.assertRaises(exception.ContainerNotLocked, - lambda: self.raise_(exception.ContainerNotLocked())) - def test_PodNotFound(self): self.assertRaises(exception.PodNotFound, lambda: self.raise_(exception.PodNotFound())) @@ -187,14 +171,6 @@ class TestException(base.BaseTestCase): self.assertRaises(exception.PodAlreadyExists, lambda: self.raise_(exception.PodAlreadyExists())) - def test_PodLocked(self): - self.assertRaises(exception.PodLocked, - lambda: self.raise_(exception.PodLocked())) - - def test_PodNotLocked(self): - self.assertRaises(exception.PodNotLocked, - lambda: self.raise_(exception.PodNotLocked())) - def test_ReplicationControllerNotFound(self): self.assertRaises(exception.ReplicationControllerNotFound, lambda: self.raise_(exception.ReplicationControllerNotFound())) @@ -214,11 +190,3 @@ class TestException(base.BaseTestCase): def test_ServiceAlreadyExists(self): self.assertRaises(exception.ServiceAlreadyExists, lambda: self.raise_(exception.ServiceAlreadyExists())) - - def test_ServiceLocked(self): - self.assertRaises(exception.ServiceLocked, - lambda: self.raise_(exception.ServiceLocked())) - - def test_ServiceNotLocked(self): - self.assertRaises(exception.ServiceNotLocked, - lambda: self.raise_(exception.ServiceNotLocked()))