From a5cdd3236ed212c0f7b2a95d9bad35730b18eaba Mon Sep 17 00:00:00 2001 From: Loic Dachary Date: Thu, 29 Oct 2015 11:59:08 +0900 Subject: [PATCH] suite: add the git_ls_remote function It was inlined and used as a fallback when not extracting the ceph hash from gitbuilders. Signed-off-by: Loic Dachary --- teuthology/suite.py | 8 ++++++++ teuthology/test/test_suite.py | 26 ++++++++++++++++++++++++++ 2 files changed, 34 insertions(+) diff --git a/teuthology/suite.py b/teuthology/suite.py index 615a880c9d..5b77bd6279 100644 --- a/teuthology/suite.py +++ b/teuthology/suite.py @@ -464,6 +464,14 @@ def package_version_for_hash(hash, kernel_flavor='basic', if resp.ok: return resp.text.strip() +def git_ls_remote(project, branch, project_owner='ceph'): + ls_remote = subprocess.check_output( + "git ls-remote " + build_git_url(project, project_owner) + " " + + branch, shell=True).split() + if ls_remote: + return ls_remote[0] + else: + return None def build_git_url(project, project_owner='ceph'): """ diff --git a/teuthology/test/test_suite.py b/teuthology/test/test_suite.py index fa4bc8684a..abf7a87e35 100644 --- a/teuthology/test/test_suite.py +++ b/teuthology/test/test_suite.py @@ -7,6 +7,26 @@ from teuthology import suite from scripts.suite import main from teuthology.config import config +import os +import pytest +import tempfile + +@pytest.fixture +def git_repository(request): + d = tempfile.mkdtemp() + os.system(""" + cd {d} + git init + touch A + git config user.email 'you@example.com' + git config user.name 'Your Name' + git add A + git commit -m 'A' A + """.format(d=d)) + def fin(): + os.system("rm -fr " + d) + request.addfinalizer(fin) + return d class TestSuiteOffline(object): def test_name_timestamp_passed(self): @@ -156,6 +176,12 @@ class TestSuiteOffline(object): m_get_ceph_git_url.return_value = url + '.git' assert url == suite.build_git_url('ceph') + @patch('teuthology.config.TeuthologyConfig.get_ceph_git_url') + def test_git_ls_remote(self, m_get_ceph_git_url, git_repository): + m_get_ceph_git_url.return_value = git_repository + assert None == suite.git_ls_remote('ceph', 'nobranch') + assert suite.git_ls_remote('ceph', 'master') is not None + class TestFlavor(object): def test_get_install_task_flavor_bare(self): config = dict( -- 2.39.5