Add Git driver

This adds a very basic git driver, essentially so that Zuul can
use it to load its configuration from a non-subject system.  This
facilitates third-party testing (where the configuration is under
the control of the zuul operator in a git repo, but the subject
system is otherwise unrelated).

Change-Id: I26829dbcbeeb23fec3a7978767071d9d28ea5597
This commit is contained in:
James E. Blair 2017-02-14 13:23:14 -08:00
parent 1f8ee7f550
commit 45de61c2fa
10 changed files with 247 additions and 0 deletions

View File

@ -0,0 +1,2 @@
- hosts: all
tasks: []

View File

@ -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

View File

@ -0,0 +1 @@
test

View File

@ -0,0 +1,9 @@
- tenant:
name: tenant-one
source:
git:
config-repos:
- common-config
gerrit:
project-repos:
- org/project

43
tests/fixtures/zuul-git-driver.conf vendored Normal file
View File

@ -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

View File

@ -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)

View File

@ -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)

View File

@ -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

View File

@ -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()

View File

@ -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())