]> git.apps.os.sepia.ceph.com Git - teuthology.git/commitdiff
suite: split build_git_url out of github_branch_exists
authorLoic Dachary <ldachary@redhat.com>
Thu, 29 Oct 2015 02:57:34 +0000 (11:57 +0900)
committerLoic Dachary <ldachary@redhat.com>
Sat, 31 Oct 2015 01:44:18 +0000 (10:44 +0900)
Signed-off-by: Loic Dachary <ldachary@redhat.com>
teuthology/suite.py
teuthology/test/test_suite.py

index 8c2b82cf15dc8f50626950a37c5e1ecef9f1e180..615a880c9d3284c313f130a7d273d5f003277025 100644 (file)
@@ -465,9 +465,9 @@ def package_version_for_hash(hash, kernel_flavor='basic',
         return resp.text.strip()
 
 
-def github_branch_exists(project, branch, project_owner='ceph'):
+def build_git_url(project, project_owner='ceph'):
     """
-    Query GitHub to check the existence of a project's branch
+    Return the git URL to clone the project
     """
     if project == 'ceph-qa-suite':
         base = config.get_ceph_qa_suite_git_url()
@@ -475,9 +475,14 @@ def github_branch_exists(project, branch, project_owner='ceph'):
         base = config.get_ceph_git_url()
     else:
         base = 'https://github.com/{project_owner}/{project}'
-    url_templ = re.sub('\.git$', '', base) + '/tree/{branch}'
-    url = url_templ.format(project_owner=project_owner, project=project,
-                           branch=branch)
+    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'):
+    """
+    Query GitHub 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
 
index b39ded8129f2bb1b3a03f448ad521cc5d31017ce..fa4bc8684a68c01c4822962cf2769d508e26dd23 100644 (file)
@@ -139,6 +139,22 @@ class TestSuiteOffline(object):
         result = suite.combine_path("/path/to/left", None)
         assert result == "/path/to/left"
 
+    def test_build_git_url_github(self):
+        assert 'project' in suite.build_git_url('project')
+        owner = 'OWNER'
+        assert owner in suite.build_git_url('project', project_owner=owner)
+
+    @patch('teuthology.config.TeuthologyConfig.get_ceph_qa_suite_git_url')
+    def test_build_git_url_ceph_qa_suite_custom(self, m_get_ceph_qa_suite_git_url):
+        url = 'http://foo.com/some'
+        m_get_ceph_qa_suite_git_url.return_value = url + '.git'
+        assert url == suite.build_git_url('ceph-qa-suite')
+
+    @patch('teuthology.config.TeuthologyConfig.get_ceph_git_url')
+    def test_build_git_url_ceph_custom(self, m_get_ceph_git_url):
+        url = 'http://foo.com/some'
+        m_get_ceph_git_url.return_value = url + '.git'
+        assert url == suite.build_git_url('ceph')
 
 class TestFlavor(object):
     def test_get_install_task_flavor_bare(self):
@@ -704,6 +720,9 @@ 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')
 
 class TestSuiteMain(object):