From: Zack Cerza Date: Wed, 30 Nov 2016 20:58:42 +0000 (-0700) Subject: suite: add --suite-repo option X-Git-Tag: 1.1.0~487^2~4 X-Git-Url: http://git-server-git.apps.pok.os.sepia.ceph.com/?a=commitdiff_plain;h=eb0d56b8b7c94d6b560663d590d7f4a3e3bf7c9c;p=teuthology.git suite: add --suite-repo option Signed-off-by: Zack Cerza --- diff --git a/scripts/suite.py b/scripts/suite.py index c5a49bc5..76d1e5d1 100644 --- a/scripts/suite.py +++ b/scripts/suite.py @@ -57,6 +57,8 @@ Standard arguments: Distribution to run against -D , --distro-version Distro version to run against + --suite-repo Use tasks and suite definition in this repository + [default: {default_suite_repo}] --suite-branch Use this suite branch instead of the ceph branch --suite-dir Use this alternative directory as-is when @@ -117,8 +119,11 @@ Scheduler arguments: 'fail', 'pass', 'queued', 'running', 'waiting' [default: fail,dead] -""".format(default_machine_type=config.default_machine_type, - default_results_timeout=config.results_timeout) +""".format( + default_machine_type=config.default_machine_type, + default_results_timeout=config.results_timeout, + default_suite_repo=config.get_ceph_qa_suite_git_url(), +) def main(argv=sys.argv[1:]): diff --git a/teuthology/suite/placeholder.py b/teuthology/suite/placeholder.py index d10a0d08..fe068c94 100644 --- a/teuthology/suite/placeholder.py +++ b/teuthology/suite/placeholder.py @@ -96,6 +96,7 @@ dict_templ = { } }, 'suite': Placeholder('suite'), + 'suite_repo': Placeholder('suite_repo'), 'suite_branch': Placeholder('suite_branch'), 'suite_sha1': Placeholder('suite_hash'), 'tasks': [], diff --git a/teuthology/suite/run.py b/teuthology/suite/run.py index 0763cab7..13225f70 100644 --- a/teuthology/suite/run.py +++ b/teuthology/suite/run.py @@ -36,6 +36,10 @@ class Run(object): """ self.args = args self.name = self.make_run_name() + + if self.args.suite_repo: + config.ceph_qa_suite_git_url = self.args.suite_repo + self.base_config = self.create_initial_config() # caches package versions to minimize requests to gbs self.package_versions = dict() @@ -102,6 +106,7 @@ class Run(object): distro_version=self.args.distro_version, archive_upload=config.archive_upload, archive_upload_key=config.archive_upload_key, + suite_repo=config.get_ceph_qa_suite_git_url(), ) return self.build_base_config() @@ -189,30 +194,50 @@ class Run(object): log.info("teuthology branch: %s", teuthology_branch) return teuthology_branch + @property + def suite_repo_name(self): + if self.args.suite_repo: + return self.args.suite_repo.split('/')[-1].rstrip('.git') + else: + return 'ceph-qa-suite' + def choose_suite_branch(self): + suite_repo_name = self.suite_repo_name + suite_repo_project_or_url = self.args.suite_repo or 'ceph-qa-suite' suite_branch = self.args.suite_branch ceph_branch = self.args.ceph_branch if suite_branch and suite_branch != 'master': - if not util.git_branch_exists('ceph-qa-suite', suite_branch): - exc = BranchNotFoundError(suite_branch, 'ceph-qa-suite.git') + if not util.git_branch_exists( + suite_repo_project_or_url, + suite_branch + ): + exc = BranchNotFoundError(suite_branch, suite_repo_name) util.schedule_fail(message=str(exc), name=self.name) elif not suite_branch: - # Decide what branch of ceph-qa-suite to use - if util.git_branch_exists('ceph-qa-suite', ceph_branch): + # Decide what branch of the suite repo to use + if util.git_branch_exists(suite_repo_project_or_url, ceph_branch): suite_branch = ceph_branch else: log.info( - "branch {0} not in ceph-qa-suite.git; will use master for" - " ceph-qa-suite".format(ceph_branch)) + "branch {0} not in {1}; will use master for" + " ceph-qa-suite".format( + ceph_branch, + suite_repo_name + )) suite_branch = 'master' return suite_branch def choose_suite_hash(self, suite_branch): - suite_hash = util.git_ls_remote('ceph-qa-suite', suite_branch) + suite_repo_name = self.suite_repo_name + suite_repo_project_or_url = self.args.suite_repo or 'ceph-qa-suite' + suite_hash = util.git_ls_remote( + suite_repo_project_or_url, + suite_branch + ) if not suite_hash: - exc = BranchNotFoundError(suite_branch, 'ceph-qa-suite.git') + exc = BranchNotFoundError(suite_branch, suite_repo_name) util.schedule_fail(message=str(exc), name=self.name) - log.info("ceph-qa-suite branch: %s %s", suite_branch, suite_hash) + log.info("%s branch: %s %s", suite_repo_name, suite_branch, suite_hash) return suite_hash def build_base_config(self): diff --git a/teuthology/suite/test/test_placeholder.py b/teuthology/suite/test/test_placeholder.py index 51683e64..03d04d35 100644 --- a/teuthology/suite/test/test_placeholder.py +++ b/teuthology/suite/test/test_placeholder.py @@ -18,6 +18,7 @@ class TestPlaceholder(object): distro_version='distro_version', archive_upload='archive_upload', archive_upload_key='archive_upload_key', + suite_repo='https://example.com/ceph/suite.git', ) output_dict = substitute_placeholders(dict_templ, input_dict) assert output_dict['suite'] == 'suite' @@ -40,6 +41,7 @@ class TestPlaceholder(object): archive_upload_key='archive_upload_key', distro=None, distro_version=None, + suite_repo='https://example.com/ceph/suite.git', ) output_dict = substitute_placeholders(dict_templ, input_dict) assert 'os_type' not in output_dict diff --git a/teuthology/suite/test/test_util.py b/teuthology/suite/test/test_util.py index ae46dc9f..c587a205 100644 --- a/teuthology/suite/test/test_util.py +++ b/teuthology/suite/test/test_util.py @@ -10,12 +10,20 @@ from teuthology.orchestra.opsys import OS from teuthology.suite import util +REPO_PROJECTS_AND_URLS = [ + 'ceph', + 'https://github.com/not_ceph/ceph.git', +] + + +@pytest.mark.parametrize('project_or_url', REPO_PROJECTS_AND_URLS) @patch('subprocess.check_output') -def test_git_branch_exists(m_check_output): +def test_git_branch_exists(m_check_output, project_or_url): m_check_output.return_value = '' - assert False == util.git_branch_exists('ceph', 'nobranchnowaycanthappen') + assert False == util.git_branch_exists( + project_or_url, 'nobranchnowaycanthappen') m_check_output.return_value = 'HHH branch' - assert True == util.git_branch_exists('ceph', 'master') + assert True == util.git_branch_exists(project_or_url, 'master') @pytest.fixture diff --git a/teuthology/suite/util.py b/teuthology/suite/util.py index 8d372769..2538c12b 100644 --- a/teuthology/suite/util.py +++ b/teuthology/suite/util.py @@ -169,13 +169,20 @@ def get_distro_defaults(distro, machine_type): ) -def git_ls_remote(project, branch, project_owner='ceph'): +def git_ls_remote(project_or_url, branch, project_owner='ceph'): """ Find the latest sha1 for a given project's branch. + :param project_or_url: Either a project name or a full URL + :param branch: The branch to query + :param project_owner: The GitHub project owner. Only used when a project + name is passed; not when a URL is passed :returns: The sha1 if found; else None """ - url = build_git_url(project, project_owner) + if '://' in project_or_url: + url = project_or_url + else: + url = build_git_url(project_or_url, project_owner) return repo_utils.ls_remote(url, branch) @@ -205,11 +212,16 @@ def git_validate_sha1(project, sha1, project_owner='ceph'): return None -def git_branch_exists(project, branch, project_owner='ceph'): +def git_branch_exists(project_or_url, branch, project_owner='ceph'): """ Query the git repository to check the existence of a project's branch + + :param project_or_url: Either a project name or a full URL + :param branch: The branch to query + :param project_owner: The GitHub project owner. Only used when a project + name is passed; not when a URL is passed """ - return git_ls_remote(project, branch, project_owner) is not None + return git_ls_remote(project_or_url, branch, project_owner) is not None def get_branch_info(project, branch, project_owner='ceph'):