summaryrefslogtreecommitdiff
path: root/zuul
diff options
context:
space:
mode:
authorJames E. Blair <jeblair@redhat.com>2017-03-28 16:16:34 -0700
committerJames E. Blair <jeblair@redhat.com>2017-04-06 13:45:17 -0700
commit1c7744207c304582e84a97c4416d06496be996c7 (patch)
treeea397f3c923e2aaa8cf2c64b77fc4173967cb010 /zuul
parentf43b53a67f5ce283da11d1c26e9c5730af53bd23 (diff)
downloadzuul-1c7744207c304582e84a97c4416d06496be996c7.tar.gz
Add canonical hostname to source object
This is the start of the implementation of: http://lists.openstack.org/pipermail/openstack-infra/2017-March/005208.html It lets us associate a canonical hostname with every connection that we will later use to uniquely identify source code repos. Story: 2000953 Change-Id: I7f2e64944d46f304e63a54078e682fd5e1682f27
Diffstat (limited to 'zuul')
-rw-r--r--zuul/driver/gerrit/gerritconnection.py2
-rw-r--r--zuul/driver/gerrit/gerritsource.py5
-rw-r--r--zuul/driver/git/gitconnection.py11
-rw-r--r--zuul/driver/git/gitsource.py5
-rw-r--r--zuul/source/__init__.py3
5 files changed, 24 insertions, 2 deletions
diff --git a/zuul/driver/gerrit/gerritconnection.py b/zuul/driver/gerrit/gerritconnection.py
index e3c726ff6..e18daa93a 100644
--- a/zuul/driver/gerrit/gerritconnection.py
+++ b/zuul/driver/gerrit/gerritconnection.py
@@ -253,6 +253,8 @@ class GerritConnection(BaseConnection):
self.user = self.connection_config.get('user')
self.server = self.connection_config.get('server')
+ self.canonical_hostname = self.connection_config.get(
+ 'canonical_hostname', self.server)
self.port = int(self.connection_config.get('port', 29418))
self.keyfile = self.connection_config.get('sshkey', None)
self.keepalive = int(self.connection_config.get('keepalive', 60))
diff --git a/zuul/driver/gerrit/gerritsource.py b/zuul/driver/gerrit/gerritsource.py
index c5e46b1a6..2271cde53 100644
--- a/zuul/driver/gerrit/gerritsource.py
+++ b/zuul/driver/gerrit/gerritsource.py
@@ -20,6 +20,11 @@ class GerritSource(BaseSource):
name = 'gerrit'
log = logging.getLogger("zuul.source.Gerrit")
+ def __init__(self, driver, connection, config=None):
+ hostname = connection.canonical_hostname
+ super(GerritSource, self).__init__(driver, connection,
+ hostname, config)
+
def getRefSha(self, project, ref):
return self.connection.getRefSha(project, ref)
diff --git a/zuul/driver/git/gitconnection.py b/zuul/driver/git/gitconnection.py
index e72cc7716..9c8d65855 100644
--- a/zuul/driver/git/gitconnection.py
+++ b/zuul/driver/git/gitconnection.py
@@ -14,6 +14,8 @@
# under the License.
import logging
+from six.moves import urllib
+
import voluptuous as v
from zuul.connection import BaseConnection
@@ -30,8 +32,15 @@ class GitConnection(BaseConnection):
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.canonical_hostname = self.connection_config.get(
+ 'canonical_hostname')
+ if not self.canonical_hostname:
+ r = urllib.parse.urlparse(self.baseurl)
+ if r.hostname:
+ self.canonical_hostname = r.hostname
+ else:
+ self.canonical_hostname = 'localhost'
self.projects = {}
def getProject(self, name):
diff --git a/zuul/driver/git/gitsource.py b/zuul/driver/git/gitsource.py
index bbe799a8c..076e8b735 100644
--- a/zuul/driver/git/gitsource.py
+++ b/zuul/driver/git/gitsource.py
@@ -20,6 +20,11 @@ class GitSource(BaseSource):
name = 'git'
log = logging.getLogger("zuul.source.Git")
+ def __init__(self, driver, connection, config=None):
+ hostname = connection.canonical_hostname
+ super(GitSource, self).__init__(driver, connection,
+ hostname, config)
+
def getRefSha(self, project, ref):
raise NotImplemented()
diff --git a/zuul/source/__init__.py b/zuul/source/__init__.py
index 0fc9dd3c0..f0eeba6e9 100644
--- a/zuul/source/__init__.py
+++ b/zuul/source/__init__.py
@@ -27,9 +27,10 @@ class BaseSource(object):
Defines the exact public methods that must be supplied."""
- def __init__(self, driver, connection, config=None):
+ def __init__(self, driver, connection, canonical_hostname, config=None):
self.driver = driver
self.connection = connection
+ self.canonical_hostname = canonical_hostname
self.config = config or {}
@abc.abstractmethod