diff --git a/tests/fixtures/config/git-driver/git/common-config/playbooks/project-test1.yaml b/tests/fixtures/config/git-driver/git/common-config/playbooks/project-test1.yaml new file mode 100644 index 0000000000..f679dceaef --- /dev/null +++ b/tests/fixtures/config/git-driver/git/common-config/playbooks/project-test1.yaml @@ -0,0 +1,2 @@ +- hosts: all + tasks: [] diff --git a/tests/fixtures/config/git-driver/git/common-config/zuul.yaml b/tests/fixtures/config/git-driver/git/common-config/zuul.yaml new file mode 100644 index 0000000000..0e332e4baa --- /dev/null +++ b/tests/fixtures/config/git-driver/git/common-config/zuul.yaml @@ -0,0 +1,22 @@ +- pipeline: + name: check + manager: independent + source: gerrit + trigger: + gerrit: + - event: patchset-created + success: + gerrit: + verified: 1 + failure: + gerrit: + verified: -1 + +- job: + name: project-test1 + +- project: + name: org/project + check: + jobs: + - project-test1 diff --git a/tests/fixtures/config/git-driver/git/org_project/README b/tests/fixtures/config/git-driver/git/org_project/README new file mode 100644 index 0000000000..9daeafb986 --- /dev/null +++ b/tests/fixtures/config/git-driver/git/org_project/README @@ -0,0 +1 @@ +test diff --git a/tests/fixtures/config/git-driver/main.yaml b/tests/fixtures/config/git-driver/main.yaml new file mode 100644 index 0000000000..5b9b3d9ed1 --- /dev/null +++ b/tests/fixtures/config/git-driver/main.yaml @@ -0,0 +1,9 @@ +- tenant: + name: tenant-one + source: + git: + config-repos: + - common-config + gerrit: + project-repos: + - org/project diff --git a/tests/fixtures/zuul-git-driver.conf b/tests/fixtures/zuul-git-driver.conf new file mode 100644 index 0000000000..868e2725f5 --- /dev/null +++ b/tests/fixtures/zuul-git-driver.conf @@ -0,0 +1,43 @@ +[gearman] +server=127.0.0.1 + +[zuul] +tenant_config=config/zuul-connections-same-gerrit/main.yaml +url_pattern=http://logs.example.com/{change.number}/{change.patchset}/{pipeline.name}/{job.name}/{build.number} +job_name_in_report=true + +[merger] +git_dir=/tmp/zuul-test/git +git_user_email=zuul@example.com +git_user_name=zuul +zuul_url=http://zuul.example.com/p + +[launcher] +git_dir=/tmp/zuul-test/launcher-git + +[swift] +authurl=https://identity.api.example.org/v2.0/ +user=username +key=password +tenant_name=" " + +default_container=logs +region_name=EXP +logserver_prefix=http://logs.example.org/server.app/ + +[connection gerrit] +driver=gerrit +server=review.example.com +user=jenkins +sshkey=none + +[connection git] +driver=git +baseurl="" + +[connection outgoing_smtp] +driver=smtp +server=localhost +port=25 +default_from=zuul@example.com +default_to=you@example.com diff --git a/tests/unit/test_git_driver.py b/tests/unit/test_git_driver.py new file mode 100644 index 0000000000..4d75944fe9 --- /dev/null +++ b/tests/unit/test_git_driver.py @@ -0,0 +1,42 @@ +# Copyright 2016 Red Hat, Inc. +# +# Licensed under the Apache License, Version 2.0 (the "License"); you may +# not use this file except in compliance with the License. You may obtain +# a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, WITHOUT +# WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the +# License for the specific language governing permissions and limitations +# under the License. + +from tests.base import ZuulTestCase + + +class TestGitDriver(ZuulTestCase): + config_file = 'zuul-git-driver.conf' + tenant_config_file = 'config/git-driver/main.yaml' + + def setup_config(self): + super(TestGitDriver, self).setup_config() + self.config.set('connection git', 'baseurl', self.upstream_root) + + def test_git_driver(self): + tenant = self.sched.abide.tenants.get('tenant-one') + # Check that we have the git source for common-config and the + # gerrit source for the project. + self.assertEqual('git', tenant.config_repos[0][0].name) + self.assertEqual('common-config', tenant.config_repos[0][1].name) + self.assertEqual('gerrit', tenant.project_repos[0][0].name) + self.assertEqual('org/project', tenant.project_repos[0][1].name) + + # The configuration for this test is accessed via the git + # driver (in common-config), rather than the gerrit driver, so + # if the job runs, it worked. + A = self.fake_gerrit.addFakeChange('org/project', 'master', 'A') + self.fake_gerrit.addEvent(A.getPatchsetCreatedEvent(1)) + self.waitUntilSettled() + self.assertEqual(len(self.history), 1) + self.assertEqual(A.reported, 1) diff --git a/zuul/driver/git/__init__.py b/zuul/driver/git/__init__.py new file mode 100644 index 0000000000..abedf6af21 --- /dev/null +++ b/zuul/driver/git/__init__.py @@ -0,0 +1,27 @@ +# Copyright 2016 Red Hat, Inc. +# +# Licensed under the Apache License, Version 2.0 (the "License"); you may +# not use this file except in compliance with the License. You may obtain +# a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, WITHOUT +# WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the +# License for the specific language governing permissions and limitations +# under the License. + +from zuul.driver import Driver, ConnectionInterface, SourceInterface +import gitconnection +import gitsource + + +class GitDriver(Driver, ConnectionInterface, SourceInterface): + name = 'git' + + def getConnection(self, name, config): + return gitconnection.GitConnection(self, name, config) + + def getSource(self, connection): + return gitsource.GitSource(self, connection) diff --git a/zuul/driver/git/gitconnection.py b/zuul/driver/git/gitconnection.py new file mode 100644 index 0000000000..e72cc77167 --- /dev/null +++ b/zuul/driver/git/gitconnection.py @@ -0,0 +1,54 @@ +# Copyright 2011 OpenStack, LLC. +# Copyright 2012 Hewlett-Packard Development Company, L.P. +# +# Licensed under the Apache License, Version 2.0 (the "License"); you may +# not use this file except in compliance with the License. You may obtain +# a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, WITHOUT +# WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the +# License for the specific language governing permissions and limitations +# under the License. + +import logging +import voluptuous as v + +from zuul.connection import BaseConnection +from zuul.model import Project + + +class GitConnection(BaseConnection): + driver_name = 'git' + log = logging.getLogger("connection.git") + + def __init__(self, driver, connection_name, connection_config): + super(GitConnection, self).__init__(driver, connection_name, + connection_config) + if 'baseurl' not in self.connection_config: + raise Exception('baseurl is required for git connections in ' + '%s' % self.connection_name) + + self.baseurl = self.connection_config.get('baseurl') + self.projects = {} + + def getProject(self, name): + if name not in self.projects: + self.projects[name] = Project(name, self.connection_name) + return self.projects[name] + + def getProjectBranches(self, project): + # TODO(jeblair): implement; this will need to handle local or + # remote git urls. + raise NotImplemented() + + def getGitUrl(self, project): + url = '%s/%s' % (self.baseurl, project.name) + return url + + +def getSchema(): + git_connection = v.Any(str, v.Schema({}, extra=True)) + return git_connection diff --git a/zuul/driver/git/gitsource.py b/zuul/driver/git/gitsource.py new file mode 100644 index 0000000000..bbe799a8c2 --- /dev/null +++ b/zuul/driver/git/gitsource.py @@ -0,0 +1,45 @@ +# Copyright 2012 Hewlett-Packard Development Company, L.P. +# +# Licensed under the Apache License, Version 2.0 (the "License"); you may +# not use this file except in compliance with the License. You may obtain +# a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, WITHOUT +# WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the +# License for the specific language governing permissions and limitations +# under the License. + +import logging +from zuul.source import BaseSource + + +class GitSource(BaseSource): + name = 'git' + log = logging.getLogger("zuul.source.Git") + + def getRefSha(self, project, ref): + raise NotImplemented() + + def isMerged(self, change, head=None): + raise NotImplemented() + + def canMerge(self, change, allow_needs): + raise NotImplemented() + + def getChange(self, event, refresh=False): + raise NotImplemented() + + def getProject(self, name): + return self.connection.getProject(name) + + def getProjectBranches(self, project): + return self.connection.getProjectBranches(project) + + def getGitUrl(self, project): + return self.connection.getGitUrl(project) + + def getProjectOpenChanges(self, project): + raise NotImplemented() diff --git a/zuul/lib/connections.py b/zuul/lib/connections.py index 0a8be03121..c8b61a9d5e 100644 --- a/zuul/lib/connections.py +++ b/zuul/lib/connections.py @@ -16,6 +16,7 @@ import re import zuul.driver.zuul import zuul.driver.gerrit +import zuul.driver.git import zuul.driver.smtp import zuul.driver.timer from zuul.connection import BaseConnection @@ -34,6 +35,7 @@ class ConnectionRegistry(object): self.registerDriver(zuul.driver.zuul.ZuulDriver()) self.registerDriver(zuul.driver.gerrit.GerritDriver()) + self.registerDriver(zuul.driver.git.GitDriver()) self.registerDriver(zuul.driver.smtp.SMTPDriver()) self.registerDriver(zuul.driver.timer.TimerDriver())