Enable test_one_branch cloner test
This alters test_cloner to test the behavior of the executor, which,
in v3, performs the git repo preparation that is performed by the
cloner in v2. These tests represent all of the ways we expect zuul
to be used with git repos in different kinds of jobs, so the test
is altered as little as possible.
A future change will rename the test file and class.
Change-Id: I4dc9aeb325e38c54b4150bcc8ac672096e2cadbc
diff --git a/tests/base.py b/tests/base.py
index d229604..e03e6cf 100755
--- a/tests/base.py
+++ b/tests/base.py
@@ -1103,6 +1103,25 @@
self.log.debug(" OK")
return True
+ def getWorkspaceRepos(self, projects):
+ """Return workspace git repo objects for the listed projects
+
+ :arg list projects: A list of strings, each the canonical name
+ of a project.
+
+ :returns: A dictionary of {name: repo} for every listed
+ project.
+ :rtype: dict
+
+ """
+
+ repos = {}
+ for project in projects:
+ path = os.path.join(self.jobdir.src_root, project)
+ repo = git.Repo(path)
+ repos[project] = repo
+ return repos
+
class RecordingExecutorServer(zuul.executor.server.ExecutorServer):
"""An Ansible executor to be used in tests.
@@ -2516,6 +2535,29 @@
specified_conn.server == conn.server):
conn.addEvent(event)
+ def getUpstreamRepos(self, projects):
+ """Return upstream git repo objects for the listed projects
+
+ :arg list projects: A list of strings, each the canonical name
+ of a project.
+
+ :returns: A dictionary of {name: repo} for every listed
+ project.
+ :rtype: dict
+
+ """
+
+ repos = {}
+ for project in projects:
+ # FIXME(jeblair): the upstream root does not yet have a
+ # hostname component; that needs to be added, and this
+ # line removed:
+ tmp_project_name = '/'.join(project.split('/')[1:])
+ path = os.path.join(self.upstream_root, tmp_project_name)
+ repo = git.Repo(path)
+ repos[project] = repo
+ return repos
+
class AnsibleZuulTestCase(ZuulTestCase):
"""ZuulTestCase but with an actual ansible executor running"""
diff --git a/tests/fixtures/layouts/repo-checkout-two-project.yaml b/tests/fixtures/layouts/repo-checkout-two-project.yaml
new file mode 100644
index 0000000..239d80c
--- /dev/null
+++ b/tests/fixtures/layouts/repo-checkout-two-project.yaml
@@ -0,0 +1,59 @@
+- pipeline:
+ name: check
+ manager: independent
+ trigger:
+ gerrit:
+ - event: patchset-created
+ success:
+ gerrit:
+ verified: 1
+ failure:
+ gerrit:
+ verified: -1
+
+- pipeline:
+ name: gate
+ manager: dependent
+ success-message: Build succeeded (gate).
+ trigger:
+ gerrit:
+ - event: comment-added
+ approval:
+ - approved: 1
+ success:
+ gerrit:
+ verified: 2
+ submit: true
+ failure:
+ gerrit:
+ verified: -2
+ start:
+ gerrit:
+ verified: 0
+ precedence: high
+
+- job:
+ name: integration
+ required-projects:
+ - org/project1
+ - org/project2
+
+- project:
+ name: org/project1
+ check:
+ jobs:
+ - integration
+ gate:
+ queue: integrated
+ jobs:
+ - integration
+
+- project:
+ name: org/project2
+ check:
+ jobs:
+ - integration
+ gate:
+ queue: integrated
+ jobs:
+ - integration
diff --git a/tests/unit/test_cloner.py b/tests/unit/test_cloner.py
index e65904b..430f24e 100644
--- a/tests/unit/test_cloner.py
+++ b/tests/unit/test_cloner.py
@@ -19,44 +19,21 @@
import os
import shutil
import time
+from unittest import skip
import git
import zuul.lib.cloner
-from tests.base import ZuulTestCase
+from tests.base import ZuulTestCase, simple_layout
class TestCloner(ZuulTestCase):
+ tenant_config_file = 'config/single-tenant/main.yaml'
log = logging.getLogger("zuul.test.cloner")
- workspace_root = None
- def setUp(self):
- self.skip("Disabled for early v3 development")
-
- super(TestCloner, self).setUp()
- self.workspace_root = os.path.join(self.test_root, 'workspace')
-
- self.updateConfigLayout(
- 'tests/fixtures/layout-cloner.yaml')
- self.sched.reconfigure(self.config)
- self.registerJobs()
-
- def getWorkspaceRepos(self, projects):
- repos = {}
- for project in projects:
- repos[project] = git.Repo(
- os.path.join(self.workspace_root, project))
- return repos
-
- def getUpstreamRepos(self, projects):
- repos = {}
- for project in projects:
- repos[project] = git.Repo(
- os.path.join(self.upstream_root, project))
- return repos
-
+ @skip("Disabled for early v3 development")
def test_cache_dir(self):
projects = ['org/project1', 'org/project2']
cache_root = os.path.join(self.test_root, "cache")
@@ -140,16 +117,19 @@
self.worker.release()
self.waitUntilSettled()
+ @simple_layout('layouts/repo-checkout-two-project.yaml')
def test_one_branch(self):
- self.worker.hold_jobs_in_build = True
+ self.executor_server.hold_jobs_in_build = True
- projects = ['org/project1', 'org/project2']
+ p1 = 'review.example.com/org/project1'
+ p2 = 'review.example.com/org/project2'
+ projects = [p1, p2]
A = self.fake_gerrit.addFakeChange('org/project1', 'master', 'A')
B = self.fake_gerrit.addFakeChange('org/project2', 'master', 'B')
- A.addApproval('CRVW', 2)
- B.addApproval('CRVW', 2)
- self.fake_gerrit.addEvent(A.addApproval('APRV', 1))
- self.fake_gerrit.addEvent(B.addApproval('APRV', 1))
+ A.addApproval('code-review', 2)
+ B.addApproval('code-review', 2)
+ self.fake_gerrit.addEvent(A.addApproval('approved', 1))
+ self.fake_gerrit.addEvent(B.addApproval('approved', 1))
self.waitUntilSettled()
@@ -157,27 +137,17 @@
upstream = self.getUpstreamRepos(projects)
states = [
- {'org/project1': self.builds[0].parameters['ZUUL_COMMIT'],
- 'org/project2': str(upstream['org/project2'].commit('master')),
+ {p1: self.builds[0].parameters['ZUUL_COMMIT'],
+ p2: str(upstream[p2].commit('master')),
},
- {'org/project1': self.builds[0].parameters['ZUUL_COMMIT'],
- 'org/project2': self.builds[1].parameters['ZUUL_COMMIT'],
+ {p1: self.builds[0].parameters['ZUUL_COMMIT'],
+ p2: self.builds[1].parameters['ZUUL_COMMIT'],
},
]
for number, build in enumerate(self.builds):
self.log.debug("Build parameters: %s", build.parameters)
- cloner = zuul.lib.cloner.Cloner(
- git_base_url=self.upstream_root,
- projects=projects,
- workspace=self.workspace_root,
- zuul_project=build.parameters.get('ZUUL_PROJECT', None),
- zuul_branch=build.parameters['ZUUL_BRANCH'],
- zuul_ref=build.parameters['ZUUL_REF'],
- zuul_url=self.src_root,
- )
- cloner.execute()
- work = self.getWorkspaceRepos(projects)
+ work = build.getWorkspaceRepos(projects)
state = states[number]
for project in projects:
@@ -186,12 +156,11 @@
'Project %s commit for build %s should '
'be correct' % (project, number))
- shutil.rmtree(self.workspace_root)
-
- self.worker.hold_jobs_in_build = False
- self.worker.release()
+ self.executor_server.hold_jobs_in_build = False
+ self.executor_server.release()
self.waitUntilSettled()
+ @skip("Disabled for early v3 development")
def test_multi_branch(self):
self.worker.hold_jobs_in_build = True
projects = ['org/project1', 'org/project2',
@@ -262,6 +231,7 @@
self.worker.release()
self.waitUntilSettled()
+ @skip("Disabled for early v3 development")
def test_upgrade(self):
# Simulates an upgrade test
self.worker.hold_jobs_in_build = True
@@ -442,6 +412,7 @@
self.worker.release()
self.waitUntilSettled()
+ @skip("Disabled for early v3 development")
def test_project_override(self):
self.worker.hold_jobs_in_build = True
projects = ['org/project1', 'org/project2', 'org/project3',
@@ -528,6 +499,7 @@
self.worker.release()
self.waitUntilSettled()
+ @skip("Disabled for early v3 development")
def test_periodic(self):
self.worker.hold_jobs_in_build = True
self.create_branch('org/project', 'stable/havana')
@@ -595,6 +567,7 @@
self.worker.release()
self.waitUntilSettled()
+ @skip("Disabled for early v3 development")
def test_periodic_update(self):
# Test that the merger correctly updates its local repository
# before running a periodic job.
@@ -676,6 +649,7 @@
self.worker.release()
self.waitUntilSettled()
+ @skip("Disabled for early v3 development")
def test_post_checkout(self):
self.worker.hold_jobs_in_build = True
project = "org/project1"
@@ -710,6 +684,7 @@
'be correct' % (project, 0))
shutil.rmtree(self.workspace_root)
+ @skip("Disabled for early v3 development")
def test_post_and_master_checkout(self):
self.worker.hold_jobs_in_build = True
projects = ["org/project1", "org/project2"]