Show More
@@ -152,6 +152,28 b' OUTPUT::' | |||
|
152 | 152 | error : null |
|
153 | 153 | |
|
154 | 154 | |
|
155 | invalidate_cache | |
|
156 | ---------------- | |
|
157 | ||
|
158 | Invalidate cache for repository. | |
|
159 | This command can be executed only using api_key belonging to user with admin | |
|
160 | rights or regular user that have write or admin or write access to repository. | |
|
161 | ||
|
162 | INPUT:: | |
|
163 | ||
|
164 | id : <id_for_response> | |
|
165 | api_key : "<api_key>" | |
|
166 | method : "invalidate_cache" | |
|
167 | args : { | |
|
168 | "repoid" : "<reponame or repo_id>" | |
|
169 | } | |
|
170 | ||
|
171 | OUTPUT:: | |
|
172 | ||
|
173 | id : <id_given_in_input> | |
|
174 | result : "Cache for repository `<reponame>` was invalidated: invalidated cache keys: <list_of_cache_keys>" | |
|
175 | error : null | |
|
176 | ||
|
155 | 177 | lock |
|
156 | 178 | ---- |
|
157 | 179 |
@@ -202,6 +202,32 b' class ApiController(JSONRPCController):' | |||
|
202 | 202 | 'Error occurred during rescan repositories action' |
|
203 | 203 | ) |
|
204 | 204 | |
|
205 | def invalidate_cache(self, apiuser, repoid): | |
|
206 | """ | |
|
207 | Dispatch cache invalidation action on given repo | |
|
208 | ||
|
209 | :param apiuser: | |
|
210 | :param repoid: | |
|
211 | """ | |
|
212 | repo = get_repo_or_error(repoid) | |
|
213 | if HasPermissionAnyApi('hg.admin')(user=apiuser) is False: | |
|
214 | # check if we have admin permission for this repo ! | |
|
215 | if HasRepoPermissionAnyApi('repository.admin', | |
|
216 | 'repository.write')(user=apiuser, | |
|
217 | repo_name=repo.repo_name) is False: | |
|
218 | raise JSONRPCError('repository `%s` does not exist' % (repoid)) | |
|
219 | ||
|
220 | try: | |
|
221 | invalidated_keys = ScmModel().mark_for_invalidation(repo.repo_name) | |
|
222 | Session().commit() | |
|
223 | return ('Cache for repository `%s` was invalidated: ' | |
|
224 | 'invalidated cache keys: %s' % (repoid, invalidated_keys)) | |
|
225 | except Exception: | |
|
226 | log.error(traceback.format_exc()) | |
|
227 | raise JSONRPCError( | |
|
228 | 'Error occurred during cache invalidation action' | |
|
229 | ) | |
|
230 | ||
|
205 | 231 | def lock(self, apiuser, repoid, locked, userid=Optional(OAttr('apiuser'))): |
|
206 | 232 | """ |
|
207 | 233 | Set locking state on particular repository by given user, if |
@@ -286,6 +286,25 b' class BaseTestApi(object):' | |||
|
286 | 286 | expected = 'Error occurred during rescan repositories action' |
|
287 | 287 | self._compare_error(id_, expected, given=response.body) |
|
288 | 288 | |
|
289 | def test_api_invalidate_cache(self): | |
|
290 | id_, params = _build_data(self.apikey, 'invalidate_cache', | |
|
291 | repoid=self.REPO) | |
|
292 | response = api_call(self, params) | |
|
293 | ||
|
294 | expected = ("Cache for repository `%s` was invalidated: " | |
|
295 | "invalidated cache keys: %s" % (self.REPO, | |
|
296 | [unicode(self.REPO)])) | |
|
297 | self._compare_ok(id_, expected, given=response.body) | |
|
298 | ||
|
299 | @mock.patch.object(ScmModel, 'mark_for_invalidation', crash) | |
|
300 | def test_api_invalidate_cache_error(self): | |
|
301 | id_, params = _build_data(self.apikey, 'invalidate_cache', | |
|
302 | repoid=self.REPO) | |
|
303 | response = api_call(self, params) | |
|
304 | ||
|
305 | expected = 'Error occurred during cache invalidation action' | |
|
306 | self._compare_error(id_, expected, given=response.body) | |
|
307 | ||
|
289 | 308 | def test_api_lock_repo_lock_aquire(self): |
|
290 | 309 | id_, params = _build_data(self.apikey, 'lock', |
|
291 | 310 | userid=TEST_USER_ADMIN_LOGIN, |
General Comments 0
You need to be logged in to leave comments.
Login now