Пример #1
0
    def destroy_baymodel(self, baymodel_id):
        session = get_session()
        with session.begin():
            query = model_query(models.BayModel, session=session)
            query = add_identity_filter(query, baymodel_id)

            try:
                baymodel_ref = query.one()
            except NoResultFound:
                raise exception.BayModelNotFound(baymodel=baymodel_id)

            if self._is_baymodel_referenced(session, baymodel_ref['uuid']):
                raise exception.BayModelReferenced(baymodel=baymodel_id)

            query.delete()
Пример #2
0
    def _do_update_baymodel(self, baymodel_id, values):
        session = get_session()
        with session.begin():
            query = model_query(models.BayModel, session=session)
            query = add_identity_filter(query, baymodel_id)
            try:
                ref = query.with_lockmode('update').one()
            except NoResultFound:
                raise exception.BayModelNotFound(baymodel=baymodel_id)

            if self.is_baymodel_referenced(session, ref['uuid']):
                raise exception.BayModelReferenced(baymodel=baymodel_id)

            ref.update(values)
        return ref
Пример #3
0
    def destroy_baymodel(self, baymodel_id):
        def is_baymodel_referenced(session, baymodel_uuid):
            """Checks whether the baymodel is referenced by bay(s)."""
            query = model_query(models.Bay, session=session)
            query = self._add_bays_filters(query,
                                           {'baymodel_id': baymodel_uuid})
            return query.count() != 0

        session = get_session()
        with session.begin():
            query = model_query(models.BayModel, session=session)
            query = add_identity_filter(query, baymodel_id)

            try:
                baymodel_ref = query.one()
            except NoResultFound:
                raise exception.BayModelNotFound(baymodel=baymodel_id)

            if is_baymodel_referenced(session, baymodel_ref['uuid']):
                raise exception.BayModelReferenced(baymodel=baymodel_id)

            query.delete()
Пример #4
0
 def test_BayModelReferenced(self):
     self.assertRaises(exception.BayModelReferenced,
                       lambda: self.raise_(exception.BayModelReferenced()))