From 52a96f8ce63df1bafcb7fb4915b726d90b0f4b3e Mon Sep 17 00:00:00 2001 From: Dan Mick Date: Mon, 23 May 2016 15:51:57 -0700 Subject: [PATCH] suite: add '--sha1/S' to specify Ceph sha1 directly Check that sha1 exists in the git repo if supplied. Avoid checking that branch exists if sha1 is given (but keep it because other things use branchname...job names, pulpito, etc.) Signed-off-by: Dan Mick --- scripts/suite.py | 4 +++ teuthology/exceptions.py | 15 +++++++++- teuthology/suite.py | 62 ++++++++++++++++++++++++++++++++-------- 3 files changed, 68 insertions(+), 13 deletions(-) diff --git a/scripts/suite.py b/scripts/suite.py index db45c7aedd..1faba07e43 100644 --- a/scripts/suite.py +++ b/scripts/suite.py @@ -31,6 +31,10 @@ Standard arguments: --wait Block until the suite is finished -c , --ceph The ceph branch to run against [default: master] + -S , --sha1 The ceph sha1 to run against (overrides -c) + If both -S and -c are supplied, -S wins, and + there is no validation that sha1 is contained + in branch -k , --kernel The kernel branch to run against; if not supplied, the installed kernel is unchanged diff --git a/teuthology/exceptions.py b/teuthology/exceptions.py index 1d18a28608..e3a92b2655 100644 --- a/teuthology/exceptions.py +++ b/teuthology/exceptions.py @@ -1,4 +1,3 @@ - class BranchNotFoundError(ValueError): def __init__(self, branch, repo=None): self.branch = branch @@ -13,6 +12,20 @@ class BranchNotFoundError(ValueError): branch=self.branch, repo_str=repo_str) +class CommitNotFoundError(ValueError): + def __init__(self, commit, repo=None): + self.commit = commit + self.repo = repo + + def __str__(self): + if self.repo: + repo_str = " in repo: %s" % self.repo + else: + repo_str = "" + return "'{commit}' not found{repo_str}!".format( + commit=self.commit, repo_str=repo_str) + + class GitError(RuntimeError): pass diff --git a/teuthology/suite.py b/teuthology/suite.py index 9d8b0d48e9..6cd04e7041 100644 --- a/teuthology/suite.py +++ b/teuthology/suite.py @@ -23,7 +23,7 @@ import teuthology import matrix from . import lock from .config import config, JobConfig -from .exceptions import BranchNotFoundError, ScheduleFailError +from .exceptions import BranchNotFoundError, CommitNotFoundError, ScheduleFailError from .misc import deep_merge, get_results_url from .repo_utils import fetch_qa_suite, fetch_teuthology from .report import ResultsReporter @@ -42,6 +42,7 @@ def main(args): base_yaml_paths = args[''] suite = args['--suite'].replace('/', ':') ceph_branch = args['--ceph'] + ceph_sha1 = args['--sha1'] kernel_branch = args['--kernel'] kernel_flavor = args['--flavor'] teuthology_branch = args['--teuthology-branch'] @@ -80,9 +81,9 @@ def main(args): machine_type) job_config = create_initial_config(suite, suite_branch, ceph_branch, - teuthology_branch, kernel_branch, - kernel_flavor, distro, machine_type, - name) + ceph_sha1, teuthology_branch, + kernel_branch, kernel_flavor, distro, + machine_type, name) if suite_dir: suite_repo_path = suite_dir @@ -221,9 +222,9 @@ def fetch_repos(branch, test_name): return suite_repo_path -def create_initial_config(suite, suite_branch, ceph_branch, teuthology_branch, - kernel_branch, kernel_flavor, distro, machine_type, - name=None): +def create_initial_config(suite, suite_branch, ceph_branch, ceph_sha1, + teuthology_branch, kernel_branch, kernel_flavor, + distro, machine_type, name=None): """ Put together the config file used as the basis for each job in the run. Grabs hashes for the latest ceph, kernel and teuthology versions in the @@ -252,12 +253,23 @@ def create_initial_config(suite, suite_branch, ceph_branch, teuthology_branch, else: kernel_dict = dict() - # Get the ceph hash - ceph_hash = git_ls_remote('ceph', ceph_branch) + # Get the ceph hash: if --sha1/-S is supplied, use it if + # it is valid, and just keep the ceph_branch around. + # Otherwise use the current git branch tip. + + if ceph_sha1: + ceph_hash = git_validate_sha1('ceph', ceph_sha1) + if not ceph_hash: + exc = CommitNotFoundError(ceph_sha1, 'ceph.git') + schedule_fail(message=str(exc), name=name) + log.info("ceph sha1 explicitly supplied") + + elif ceph_branch: + ceph_hash = git_ls_remote('ceph', ceph_branch) + if not ceph_hash: + exc = BranchNotFoundError(ceph_branch, 'ceph.git') + schedule_fail(message=str(exc), name=name) - if not ceph_hash: - exc = BranchNotFoundError(ceph_branch, 'ceph.git') - schedule_fail(message=str(exc), name=name) log.info("ceph sha1: {hash}".format(hash=ceph_hash)) if config.suite_verify_ceph_hash: @@ -554,6 +566,32 @@ def git_ls_remote(project, branch, project_owner='ceph'): return sha1 +def git_validate_sha1(project, sha1, project_owner='ceph'): + ''' + Use http to validate that project contains sha1 + I can't find a way to do this with git, period, so + we have specific urls to HEAD for github and git.ceph.com/gitweb + for now + ''' + url = build_git_url(project, project_owner) + + if '/github.com/' in url: + url = '/'.join((url, 'commit', sha1)) + elif '/git.ceph.com/' in url: + # kinda specific to knowing git.ceph.com is gitweb + url = ('http://git.ceph.com/?p=%s.git;a=blob_plain;f=.gitignore;hb=%s' + % (project, sha1)) + else: + raise RuntimeError( + 'git_validate_sha1: how do I check %s for a sha1?' % url + ) + + resp = requests.head(url) + if resp.ok: + return sha1 + return None + + def build_git_url(project, project_owner='ceph'): """ Return the git URL to clone the project -- 2.39.5