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
def choose_suite_hash(self, 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, suite_repo_name) util.schedule_fail(message=str(exc), name=self.name) log.info("%s branch: %s %s", suite_repo_name, suite_branch, suite_hash) return suite_hash
def choose_teuthology_branch(self): """Select teuthology branch, check if it is present in repo and return tuple (branch, hash) where hash is commit sha1 corresponding to the HEAD of the branch. The branch name value is determined in the following order: Use ``--teuthology-branch`` argument value if supplied. Use ``TEUTH_BRANCH`` environment variable value if declared. If file ``qa/.teuthology_branch`` can be found in the suite repo supplied with ``--suite-repo`` or ``--suite-dir`` and contains non-empty string then use it as the branch name. Use ``teuthology_branch`` value if it is set in the one of the teuthology config files ``$HOME/teuthology.yaml`` or ``/etc/teuthology.yaml`` correspondingly. Use ``master``. Generate exception if the branch is not present in the repo. """ teuthology_branch = self.args.teuthology_branch if not teuthology_branch: teuthology_branch = os.environ.get('TEUTH_BRANCH', None) if not teuthology_branch: branch_file_path = self.suite_repo_path + '/qa/.teuthology_branch' log.debug('Check file %s exists', branch_file_path) if os.path.exists(branch_file_path): log.debug('Found teuthology branch config file %s', branch_file_path) with open(branch_file_path) as f: teuthology_branch = f.read().strip() if teuthology_branch: log.debug( 'The teuthology branch is overridden with %s', teuthology_branch) else: log.warning( 'The teuthology branch config is empty, skipping') if not teuthology_branch: teuthology_branch = config.get('teuthology_branch', 'master') teuthology_sha1 = util.git_ls_remote( 'teuthology', teuthology_branch ) if not teuthology_sha1: exc = BranchNotFoundError(teuthology_branch, build_git_url('teuthology')) util.schedule_fail(message=str(exc), name=self.name) log.info("teuthology branch: %s %s", teuthology_branch, teuthology_sha1) return teuthology_branch, teuthology_sha1
def choose_teuthology_branch(self): teuthology_branch = self.args.teuthology_branch if teuthology_branch and teuthology_branch != 'master': if not util.git_branch_exists('teuthology', teuthology_branch): exc = BranchNotFoundError(teuthology_branch, 'teuthology.git') util.schedule_fail(message=str(exc), name=self.name) elif not teuthology_branch: # Decide what branch of teuthology to use if util.git_branch_exists('teuthology', self.args.ceph_branch): teuthology_branch = self.args.ceph_branch else: log.info( "branch {0} not in teuthology.git; will use master for" " teuthology".format(self.args.ceph_branch)) teuthology_branch = 'master' teuthology_hash = util.git_ls_remote('teuthology', teuthology_branch) if not teuthology_hash: exc = BranchNotFoundError(teuthology_branch, build_git_url('teuthology')) util.schedule_fail(message=str(exc), name=self.name) log.info("teuthology branch: %s %s", teuthology_branch, teuthology_hash) return teuthology_branch
def test_git_ls_remote(self, m_get_ceph_git_url, git_repository): m_get_ceph_git_url.return_value = git_repository assert util.git_ls_remote('ceph', 'nobranch') is None assert util.git_ls_remote('ceph', 'master') is not None