Revision 23b41f6f

b/snf-pithos-app/pithos/api/util.py
1088 1088
            if len(args) > 2 and len(args[2]) > 1024:
1089 1089
                raise faults.BadRequest('Object name too large.')
1090 1090

  
1091
            success_status = False
1092
            try:
1091
            with get_backend() as backend:
1093 1092
                # Add a PithosBackend as attribute of the request object
1094
                request.backend = get_backend()
1095
                request.backend.pre_exec(lock_container_path)
1093
                request.backend = backend
1094
                request.backend.lock_container_path = lock_container_path
1096 1095

  
1097 1096
                # Many API method expect thet X-Auth-Token in request,token
1098 1097
                request.token = request.x_auth_token
......
1100 1099
                response = func(request, *args, **kwargs)
1101 1100
                update_response_headers(request, response)
1102 1101

  
1103
                success_status = True
1104 1102
                return response
1105
            finally:
1106
                # Always close PithosBackend connection
1107
                if getattr(request, "backend", None) is not None:
1108
                    request.backend.post_exec(success_status)
1109
                    request.backend.close()
1110 1103
        return wrapper
1111 1104
    return decorator
1112 1105

  
b/snf-pithos-backend/pithos/backends/modular.py
124 124
logger = logging.getLogger(__name__)
125 125

  
126 126

  
127
def backend_method(func):
128
    @wraps(func)
129
    def wrapper(self, *args, **kw):
130
        self.success_status = getattr(self, 'success_status', False)
131
        try:
132
            result = func(self, *args, **kw)
133
            return result
134
        except:
135
            self.backend.success_status = False
136
            raise
137
    return wrapper
138

  
139

  
127 140
def debug_method(func):
128 141
    @wraps(func)
129 142
    def wrapper(self, *args, **kw):
......
255 268

  
256 269
        self.lock_container_path = False
257 270

  
258
    def pre_exec(self, lock_container_path=False):
259
        self.lock_container_path = lock_container_path
271
    def __enter__(self):
260 272
        self.wrapper.execute()
273
        return self
261 274

  
262
    def post_exec(self, success_status=True):
275
    def __exit__(self, type, value, traceback):
276
        success_status = getattr(self, 'success_status', True)
263 277
        if success_status:
264 278
            # send messages produced
265 279
            for m in self.messages:
......
292 306
                    accept_serials=[],
293 307
                    reject_serials=self.serials)
294 308
            self.wrapper.rollback()
309
        self.close()
295 310

  
296 311
    def close(self):
297 312
        self.wrapper.close()

Also available in: Unified diff