]> git-server-git.apps.pok.os.sepia.ceph.com Git - teuthology.git/commitdiff
suite: implement git_branch_exists with ls-remote 684/head
authorLoic Dachary <ldachary@redhat.com>
Thu, 29 Oct 2015 22:40:00 +0000 (07:40 +0900)
committerloic <ldachary@redhat.com>
Sat, 31 Oct 2015 01:49:02 +0000 (10:49 +0900)
Use git ls-remote to verify the existence of a branch instead of a
github specific interface so that it plays well with all valid git
remote URL.

Rename github_branch_exists into git_branch_exists.

Signed-off-by: Loic Dachary <ldachary@redhat.com>
teuthology/suite.py
teuthology/test/test_suite.py

index 5b77bd62798ff328b981277749d46f4edc544e8f..4b9b4b3d4992e873f84a6e591324356ef10f375f 100644 (file)
@@ -216,12 +216,12 @@ def create_initial_config(suite, suite_branch, ceph_branch, teuthology_branch,
     log.info("ceph version: {ver}".format(ver=ceph_version))
 
     if teuthology_branch and teuthology_branch != 'master':
-        if not github_branch_exists('teuthology', teuthology_branch):
+        if not git_branch_exists('teuthology', teuthology_branch):
             exc = BranchNotFoundError(teuthology_branch, 'teuthology.git')
             schedule_fail(message=str(exc), name=name)
     elif not teuthology_branch:
         # Decide what branch of teuthology to use
-        if github_branch_exists('teuthology', ceph_branch):
+        if git_branch_exists('teuthology', ceph_branch):
             teuthology_branch = ceph_branch
         else:
             log.info("branch {0} not in teuthology.git; will use master for"
@@ -230,12 +230,12 @@ def create_initial_config(suite, suite_branch, ceph_branch, teuthology_branch,
     log.info("teuthology branch: %s", teuthology_branch)
 
     if suite_branch and suite_branch != 'master':
-        if not github_branch_exists('ceph-qa-suite', suite_branch):
+        if not git_branch_exists('ceph-qa-suite', suite_branch):
             exc = BranchNotFoundError(suite_branch, 'ceph-qa-suite.git')
             schedule_fail(message=str(exc), name=name)
     elif not suite_branch:
         # Decide what branch of ceph-qa-suite to use
-        if github_branch_exists('ceph-qa-suite', ceph_branch):
+        if git_branch_exists('ceph-qa-suite', ceph_branch):
             suite_branch = ceph_branch
         else:
             log.info("branch {0} not in ceph-qa-suite.git; will use master for"
@@ -486,14 +486,11 @@ def build_git_url(project, project_owner='ceph'):
     url_templ = re.sub('\.git$', '', base)
     return url_templ.format(project_owner=project_owner, project=project)
 
-def github_branch_exists(project, branch, project_owner='ceph'):
+def git_branch_exists(project, branch, project_owner='ceph'):
     """
-    Query GitHub to check the existence of a project's branch
+    Query the git repository to check the existence of a project's branch
     """
-    url = build_git_url(project, project_owner) + '/tree/' + branch
-    resp = requests.head(url)
-    return resp.ok
-
+    return git_ls_remote(project, branch, project_owner) != None
 
 def get_branch_info(project, branch, project_owner='ceph'):
     """
index abf7a87e35dd81fd43858c563c2a09d9135245d6..87405ee57927c65d9e1411172bbfa1cd43b3bb75 100644 (file)
@@ -746,9 +746,12 @@ class TestBuildMatrix(object):
         assert fragments[0] == 'thrash/ceph/base.yaml'
         assert fragments[1] == 'thrash/ceph-thrash/default.yaml'
 
-def test_github_branch_exists():
-    assert False == suite.github_branch_exists('ceph', 'nobranchnowaycanthappen')
-    assert True == suite.github_branch_exists('ceph', 'master')
+@patch('subprocess.check_output')
+def test_git_branch_exists(m_check_output):
+    m_check_output.return_value = ''
+    assert False == suite.git_branch_exists('ceph', 'nobranchnowaycanthappen')
+    m_check_output.return_value = 'HHH branch'
+    assert True == suite.git_branch_exists('ceph', 'master')
 
 class TestSuiteMain(object):