diff --git a/rhodecode/api/tests/conftest.py b/rhodecode/api/tests/conftest.py --- a/rhodecode/api/tests/conftest.py +++ b/rhodecode/api/tests/conftest.py @@ -21,12 +21,12 @@ import pytest from rhodecode.model.meta import Session from rhodecode.model.user import UserModel from rhodecode.model.auth_token import AuthTokenModel -from rhodecode.tests import TEST_USER_ADMIN_LOGIN @pytest.fixture(scope="class") def testuser_api(request, baseapp): cls = request.cls + from rhodecode.tests import TEST_USER_ADMIN_LOGIN # ADMIN USER cls.usr = UserModel().get_by_username(TEST_USER_ADMIN_LOGIN) diff --git a/rhodecode/api/views/server_api.py b/rhodecode/api/views/server_api.py --- a/rhodecode/api/views/server_api.py +++ b/rhodecode/api/views/server_api.py @@ -213,6 +213,62 @@ def rescan_repos(request, apiuser, remov 'Error occurred during rescan repositories action' ) +@jsonrpc_method() +def cleanup_repos(request, apiuser, remove_obsolete=Optional(False)): + """ + Triggers a rescan of the specified repositories. + + * If the ``remove_obsolete`` option is set, it also deletes repositories + that are found in the database but not on the file system, so called + "clean zombies". + + This command can only be run using an |authtoken| with admin rights to + the specified repository. + + This command takes the following options: + + :param apiuser: This is filled automatically from the |authtoken|. + :type apiuser: AuthUser + :param remove_obsolete: Deletes repositories from the database that + are not found on the filesystem. + :type remove_obsolete: Optional(``True`` | ``False``) + + Example output: + + .. code-block:: bash + + id : + result : { + 'added': [,...] + 'removed': [,...] + } + error : null + + Example error output: + + .. code-block:: bash + + id : + result : null + error : { + 'Error occurred during rescan repositories action' + } + + """ + if not has_superadmin_permission(apiuser): + raise JSONRPCForbidden() + + try: + rm_obsolete = Optional.extract(remove_obsolete) + added, removed = repo2db_mapper(ScmModel().repo_scan(), + remove_obsolete=rm_obsolete, force_hooks_rebuild=True) + return {'added': added, 'removed': removed} + except Exception: + log.exception('Failed to run repo rescann') + raise JSONRPCError( + 'Error occurred during rescan repositories action' + ) + @jsonrpc_method() def cleanup_sessions(request, apiuser, older_then=Optional(60)): diff --git a/rhodecode/bootstrap.py b/rhodecode/bootstrap.py new file mode 100644 --- /dev/null +++ b/rhodecode/bootstrap.py @@ -0,0 +1,41 @@ +# Copyright (C) 2010-2024 RhodeCode GmbH +# +# This program is free software: you can redistribute it and/or modify +# it under the terms of the GNU Affero General Public License, version 3 +# (only), as published by the Free Software Foundation. +# +# This program is distributed in the hope that it will be useful, +# but WITHOUT ANY WARRANTY; without even the implied warranty of +# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +# GNU General Public License for more details. +# +# You should have received a copy of the GNU Affero General Public License +# along with this program. If not, see . +# +# This program is dual-licensed. If you wish to learn more about the +# RhodeCode Enterprise Edition, including its added features, Support services, +# and proprietary license terms, please see https://rhodecode.com/licenses/ + +# bootstrap data available for tests and setup clean install + +TEST_USER_ADMIN_LOGIN = 'test_admin' +TEST_USER_ADMIN_PASS = 'test12' +TEST_USER_ADMIN_EMAIL = 'test_admin@mail.com' + +TEST_USER_REGULAR_LOGIN = 'test_regular' +TEST_USER_REGULAR_PASS = 'test12' +TEST_USER_REGULAR_EMAIL = 'test_regular@mail.com' + +TEST_USER_REGULAR2_LOGIN = 'test_regular2' +TEST_USER_REGULAR2_PASS = 'test12' +TEST_USER_REGULAR2_EMAIL = 'test_regular2@mail.com' + +HG_REPO = 'vcs_test_hg' +GIT_REPO = 'vcs_test_git' +SVN_REPO = 'vcs_test_svn' + +NEW_HG_REPO = 'vcs_test_hg_new' +NEW_GIT_REPO = 'vcs_test_git_new' + +HG_FORK = 'vcs_test_hg_fork' +GIT_FORK = 'vcs_test_git_fork' diff --git a/rhodecode/lib/db_manage.py b/rhodecode/lib/db_manage.py --- a/rhodecode/lib/db_manage.py +++ b/rhodecode/lib/db_manage.py @@ -307,7 +307,7 @@ class DbManage(object): def create_test_admin_and_users(self): log.info('creating admin and regular test users') - from rhodecode.tests import TEST_USER_ADMIN_LOGIN, \ + from rhodecode.bootstrap import TEST_USER_ADMIN_LOGIN, \ TEST_USER_ADMIN_PASS, TEST_USER_ADMIN_EMAIL, \ TEST_USER_REGULAR_LOGIN, TEST_USER_REGULAR_PASS, \ TEST_USER_REGULAR_EMAIL, TEST_USER_REGULAR2_LOGIN, \ diff --git a/rhodecode/tests/__init__.py b/rhodecode/tests/__init__.py --- a/rhodecode/tests/__init__.py +++ b/rhodecode/tests/__init__.py @@ -33,49 +33,20 @@ from rhodecode.lib import helpers as h from rhodecode.lib.helpers import flash from rhodecode.lib.str_utils import safe_str from rhodecode.lib.hash_utils import sha1_safe +from rhodecode.bootstrap import \ + TEST_USER_ADMIN_LOGIN, TEST_USER_ADMIN_PASS, TEST_USER_ADMIN_EMAIL, \ + TEST_USER_REGULAR_LOGIN, TEST_USER_REGULAR_PASS, TEST_USER_REGULAR_EMAIL, \ + TEST_USER_REGULAR2_LOGIN, TEST_USER_REGULAR2_PASS, TEST_USER_REGULAR2_EMAIL,\ + HG_REPO, GIT_REPO, SVN_REPO,\ + NEW_HG_REPO, NEW_GIT_REPO,\ + HG_FORK, GIT_FORK log = logging.getLogger(__name__) -__all__ = [ - 'get_new_dir', 'TestController', 'console_printer', - 'clear_cache_regions', - 'assert_session_flash', 'login_user', 'no_newline_id_generator', - 'TESTS_TMP_PATH', 'HG_REPO', 'GIT_REPO', 'SVN_REPO', - 'NEW_HG_REPO', 'NEW_GIT_REPO', - 'HG_FORK', 'GIT_FORK', 'TEST_USER_ADMIN_LOGIN', 'TEST_USER_ADMIN_PASS', - 'TEST_USER_REGULAR_LOGIN', 'TEST_USER_REGULAR_PASS', - 'TEST_USER_REGULAR_EMAIL', 'TEST_USER_REGULAR2_LOGIN', - 'TEST_USER_REGULAR2_PASS', 'TEST_USER_REGULAR2_EMAIL', 'TEST_HG_REPO', - 'TEST_HG_REPO_CLONE', 'TEST_HG_REPO_PULL', 'TEST_GIT_REPO', - 'TEST_GIT_REPO_CLONE', 'TEST_GIT_REPO_PULL', 'SCM_TESTS', -] - # SOME GLOBALS FOR TESTS TEST_DIR = tempfile.gettempdir() -TEST_USER_ADMIN_LOGIN = 'test_admin' -TEST_USER_ADMIN_PASS = 'test12' -TEST_USER_ADMIN_EMAIL = 'test_admin@mail.com' - -TEST_USER_REGULAR_LOGIN = 'test_regular' -TEST_USER_REGULAR_PASS = 'test12' -TEST_USER_REGULAR_EMAIL = 'test_regular@mail.com' - -TEST_USER_REGULAR2_LOGIN = 'test_regular2' -TEST_USER_REGULAR2_PASS = 'test12' -TEST_USER_REGULAR2_EMAIL = 'test_regular2@mail.com' - -HG_REPO = 'vcs_test_hg' -GIT_REPO = 'vcs_test_git' -SVN_REPO = 'vcs_test_svn' - -NEW_HG_REPO = 'vcs_test_hg_new' -NEW_GIT_REPO = 'vcs_test_git_new' - -HG_FORK = 'vcs_test_hg_fork' -GIT_FORK = 'vcs_test_git_fork' - ## VCS SCM_TESTS = ['hg', 'git'] uniq_suffix = str(int(time.mktime(datetime.datetime.now().timetuple())))