Example #1
0
    def choose_ceph_hash(self):
        """
        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.
        """
        repo_name = self.ceph_repo_name

        if self.args.ceph_sha1:
            ceph_hash = self.args.ceph_sha1
            if self.args.validate_sha1:
                ceph_hash = util.git_validate_sha1(repo_name, ceph_hash)
            if not ceph_hash:
                exc = CommitNotFoundError(self.args.ceph_sha1,
                                          '%s.git' % repo_name)
                util.schedule_fail(message=str(exc), name=self.name)
            log.info("ceph sha1 explicitly supplied")

        elif self.args.ceph_branch:
            ceph_hash = util.git_ls_remote(repo_name, self.args.ceph_branch)
            if not ceph_hash:
                exc = BranchNotFoundError(self.args.ceph_branch,
                                          '%s.git' % repo_name)
                util.schedule_fail(message=str(exc), name=self.name)

        log.info("ceph sha1: {hash}".format(hash=ceph_hash))
        return ceph_hash
Example #2
0
def reset_repo(repo_url, dest_path, branch, commit=None):
    """

    :param repo_url:  The full URL to the repo (not including the branch)
    :param dest_path: The full path to the destination directory
    :param branch:    The branch.
    :param commit:    The sha1 to checkout. Defaults to None, which uses HEAD of the branch.
    :raises:          BranchNotFoundError if the branch is not found;
                      CommitNotFoundError if the commit is not found;
                      GitError for other errors
    """
    validate_branch(branch)
    if '/' in branch:
        reset_branch = lsstrip(remote_ref_from_ref(branch), 'refs/remotes/')
    else:
        reset_branch = 'origin/%s' % branch
    reset_ref = commit or reset_branch
    log.info('Resetting repo at %s to %s', dest_path, reset_ref)
    # This try/except block will notice if the requested branch doesn't
    # exist, whether it was cloned or fetched.
    try:
        subprocess.check_output(
            ('git', 'reset', '--hard', reset_ref),
            cwd=dest_path,
        )
    except subprocess.CalledProcessError:
        if commit:
            raise CommitNotFoundError(commit, repo_url)
        raise BranchNotFoundError(branch, repo_url)
Example #3
0
    def _tag_to_sha1(self):
        """
        Shaman doesn't know about tags. Use git ls-remote to query the remote
        repo in order to map tags to their sha1 value.

        This method will also retry against ceph.git if the original request
        uses ceph-ci.git and fails.
        """
        def get_sha1(url):
            # Ceph (and other projects) uses annotated tags for releases. This
            # has the side-effect of making git ls-remote return the sha1 for
            # the annotated tag object and not the last "real" commit in that
            # tag. By contrast, when a person (or a build system) issues a
            # "git checkout <tag>" command, HEAD will be the last "real" commit
            # and not the tag.
            # Below we have to append "^{}" to the tag value to work around
            # this in order to query for the sha1 that the build system uses.
            return repo_utils.ls_remote(url, "%s^{}" % self.tag)

        git_url = repo_utils.build_git_url(self.project)
        result = get_sha1(git_url)
        # For upgrade tests that are otherwise using ceph-ci.git, we need to
        # also look in ceph.git to lookup released tags.
        if result is None and 'ceph-ci' in git_url:
            alt_git_url = git_url.replace('ceph-ci', 'ceph')
            log.info(
                "Tag '%s' not found in %s; will also look in %s",
                self.tag,
                git_url,
                alt_git_url,
            )
            result = get_sha1(alt_git_url)

        if result is None:
            raise CommitNotFoundError(self.tag, git_url)
        return result