Merge "Remove unused merger:update task" into feature/zuulv3
diff --git a/.zuul.yaml b/.zuul.yaml
index 0ae5beb..c21b30f 100644
--- a/.zuul.yaml
+++ b/.zuul.yaml
@@ -6,4 +6,5 @@
- tox-cover
- tox-linters
- tox-py27
+ - tox-py35
- tox-tarball
diff --git a/doc/source/connections.rst b/doc/source/connections.rst
index 7b302e9..120d529 100644
--- a/doc/source/connections.rst
+++ b/doc/source/connections.rst
@@ -87,6 +87,11 @@
Path to SSH key to use when cloning github repositories.
``sshkey=/home/zuul/.ssh/id_rsa``
+**git_host**
+ Optional: Hostname of the github install (such as a GitHub Enterprise)
+ If not specified, defaults to ``github.com``
+ ``git_host=github.myenterprise.com``
+
SMTP
----
diff --git a/doc/source/triggers.rst b/doc/source/triggers.rst
index 07b18ab..f73ad2f 100644
--- a/doc/source/triggers.rst
+++ b/doc/source/triggers.rst
@@ -109,7 +109,10 @@
following options.
**event**
- The pull request event from github. A ``pull_request`` event will
+ The event from github. Supported events are ``pull_request``,
+ ``pull_request_review``, and ``push``.
+
+ A ``pull_request`` event will
have associated action(s) to trigger from. The supported actions are:
*opened* - pull request opened
@@ -126,32 +129,46 @@
*unlabeled* - label removed from pull request
+ *review* - review added on pull request
+
*push* - head reference updated (pushed to branch)
+ A ``pull_request_review`` event will
+ have associated action(s) to trigger from. The supported actions are:
+
+ *submitted* - pull request review added
+
+ *dismissed* - pull request review removed
+
**branch**
The branch associated with the event. Example: ``master``. This
field is treated as a regular expression, and multiple branches may
- be listed. Used for ``pull-request`` events.
+ be listed. Used for ``pull_request`` and ``pull_request_review`` events.
**comment**
- This is only used for ``pull_request`` ``comment`` events. It accepts a list
- of regexes that are searched for in the comment string. If any of these
+ This is only used for ``pull_request`` ``comment`` actions. It accepts a
+ list of regexes that are searched for in the comment string. If any of these
regexes matches a portion of the comment string the trigger is matched.
``comment: retrigger`` will match when comments containing 'retrigger'
somewhere in the comment text are added to a pull request.
**label**
- This is only used for ``labeled`` and ``unlabeled`` actions. It accepts a list
- of strings each of which matches the label name in the event literally.
- ``label: recheck`` will match a ``labeled`` action when pull request is
- labeled with a ``recheck`` label. ``label: 'do not test'`` will match a
- ``unlabeled`` action when a label with name ``do not test`` is removed from
- the pull request.
+ This is only used for ``labeled`` and ``unlabeled`` ``pull_request`` actions.
+ It accepts a list of strings each of which matches the label name in the
+ event literally. ``label: recheck`` will match a ``labeled`` action when
+ pull request is labeled with a ``recheck`` label. ``label: 'do not test'``
+ will match a ``unlabeled`` action when a label with name ``do not test`` is
+ removed from the pull request.
- Additionally a ``push`` event can be configured, with an ``ref`` field. This
- field is treated as a regular expression and multiple refs may be listed.
- Github always sends full ref name, eg. ``refs/tags/bar`` and this string is
- matched against the regexp.
+ **state**
+ This is only used for ``pull_request_review`` events. It accepts a list of
+ strings each of which is matched to the review state, which can be one of
+ ``approved``, ``comment``, or ``request_changes``.
+
+ **ref**
+ This is only used for ``push`` events. This field is treated as a regular
+ expression and multiple refs may be listed. Github always sends full ref
+ name, eg. ``refs/tags/bar`` and this string is matched against the regexp.
GitHub Configuration
~~~~~~~~~~~~~~~~~~~~
diff --git a/etc/status/public_html/jquery.zuul.js b/etc/status/public_html/jquery.zuul.js
index d973948..5c69bd1 100644
--- a/etc/status/public_html/jquery.zuul.js
+++ b/etc/status/public_html/jquery.zuul.js
@@ -52,6 +52,10 @@
var collapsed_exceptions = [];
var current_filter = read_cookie('zuul_filter_string', '');
+ var change_set_in_url = window.location.href.split('#')[1];
+ if (change_set_in_url) {
+ current_filter = change_set_in_url;
+ }
var $jq;
var xhr,
diff --git a/requirements.txt b/requirements.txt
index 2fe6963..9f20458 100644
--- a/requirements.txt
+++ b/requirements.txt
@@ -11,7 +11,7 @@
extras
statsd>=1.0.0,<3.0
voluptuous>=0.10.2
-gear>=0.5.7,<1.0.0
+gear>=0.9.0,<1.0.0
apscheduler>=3.0
PrettyTable>=0.6,<0.8
babel>=1.0
diff --git a/test-requirements.txt b/test-requirements.txt
index 735b4dd..baf6cad 100644
--- a/test-requirements.txt
+++ b/test-requirements.txt
@@ -1,4 +1,6 @@
-hacking>=0.12.0,!=0.13.0,<0.14 # Apache-2.0
+pep8
+pyflakes
+flake8
coverage>=3.6
sphinx>=1.5.1,<1.6
diff --git a/tests/base.py b/tests/base.py
index 77c0644..9bacf21 100755
--- a/tests/base.py
+++ b/tests/base.py
@@ -90,7 +90,7 @@
def random_sha1():
- return hashlib.sha1(str(random.random())).hexdigest()
+ return hashlib.sha1(str(random.random()).encode('ascii')).hexdigest()
def iterate_timeout(max_seconds, purpose):
@@ -547,7 +547,7 @@
class FakeGithubPullRequest(object):
def __init__(self, github, number, project, branch,
- subject, upstream_root, number_of_commits=1):
+ subject, upstream_root, files=[], number_of_commits=1):
"""Creates a new PR with several commits.
Sends an event about opened PR."""
self.github = github
@@ -558,25 +558,27 @@
self.subject = subject
self.number_of_commits = 0
self.upstream_root = upstream_root
+ self.files = []
self.comments = []
self.labels = []
self.statuses = {}
self.updated_at = None
self.head_sha = None
self.is_merged = False
+ self.merge_message = None
self._createPRRef()
- self._addCommitToRepo()
+ self._addCommitToRepo(files=files)
self._updateTimeStamp()
- def addCommit(self):
+ def addCommit(self, files=[]):
"""Adds a commit on top of the actual PR head."""
- self._addCommitToRepo()
+ self._addCommitToRepo(files=files)
self._updateTimeStamp()
self._clearStatuses()
- def forcePush(self):
+ def forcePush(self, files=[]):
"""Clears actual commits and add a commit on top of the base."""
- self._addCommitToRepo(reset=True)
+ self._addCommitToRepo(files=files, reset=True)
self._updateTimeStamp()
self._clearStatuses()
@@ -608,6 +610,39 @@
},
'repository': {
'full_name': self.project
+ },
+ 'sender': {
+ 'login': 'ghuser'
+ }
+ }
+ return (name, data)
+
+ def getReviewAddedEvent(self, review):
+ name = 'pull_request_review'
+ data = {
+ 'action': 'submitted',
+ 'pull_request': {
+ 'number': self.number,
+ 'title': self.subject,
+ 'updated_at': self.updated_at,
+ 'base': {
+ 'ref': self.branch,
+ 'repo': {
+ 'full_name': self.project
+ }
+ },
+ 'head': {
+ 'sha': self.head_sha
+ }
+ },
+ 'review': {
+ 'state': review
+ },
+ 'repository': {
+ 'full_name': self.project
+ },
+ 'sender': {
+ 'login': 'ghuser'
}
}
return (name, data)
@@ -643,6 +678,9 @@
},
'label': {
'name': label
+ },
+ 'sender': {
+ 'login': 'ghuser'
}
}
return (name, data)
@@ -653,6 +691,7 @@
'action': 'unlabeled',
'pull_request': {
'number': self.number,
+ 'title': self.subject,
'updated_at': self.updated_at,
'base': {
'ref': self.branch,
@@ -666,6 +705,9 @@
},
'label': {
'name': label
+ },
+ 'sender': {
+ 'login': 'ghuser'
}
}
return (name, data)
@@ -679,7 +721,7 @@
GithubChangeReference.create(
repo, self._getPRReference(), 'refs/tags/init')
- def _addCommitToRepo(self, reset=False):
+ def _addCommitToRepo(self, files=[], reset=False):
repo = self._getRepo()
ref = repo.references[self._getPRReference()]
if reset:
@@ -690,7 +732,12 @@
zuul.merger.merger.reset_repo_to_head(repo)
repo.git.clean('-x', '-f', '-d')
- fn = '%s-%s' % (self.branch.replace('/', '_'), self.number)
+ if files:
+ fn = files[0]
+ self.files = files
+ else:
+ fn = '%s-%s' % (self.branch.replace('/', '_'), self.number)
+ self.files = [fn]
msg = self.subject + '-' + str(self.number_of_commits)
fn = os.path.join(repo.working_dir, fn)
f = open(fn, 'w')
@@ -732,6 +779,7 @@
'number': self.number,
'pull_request': {
'number': self.number,
+ 'title': self.subject,
'updated_at': self.updated_at,
'base': {
'ref': self.branch,
@@ -742,6 +790,9 @@
'head': {
'sha': self.head_sha
}
+ },
+ 'sender': {
+ 'login': 'ghuser'
}
}
return (name, data)
@@ -761,10 +812,11 @@
self.merge_failure = False
self.merge_not_allowed_count = 0
- def openFakePullRequest(self, project, branch, subject):
+ def openFakePullRequest(self, project, branch, subject, files=[]):
self.pr_number += 1
pull_request = FakeGithubPullRequest(
- self, self.pr_number, project, branch, subject, self.upstream_root)
+ self, self.pr_number, project, branch, subject, self.upstream_root,
+ files=files)
self.pull_requests.append(pull_request)
return pull_request
@@ -788,7 +840,7 @@
"""Emulates sending the GitHub webhook event to the connection."""
port = self.webapp.server.socket.getsockname()[1]
name, data = event
- payload = json.dumps(data)
+ payload = json.dumps(data).encode('utf8')
headers = {'X-Github-Event': name}
req = urllib.request.Request(
'http://localhost:%s/connection/%s/payload'
@@ -800,6 +852,7 @@
pr = self.pull_requests[number - 1]
data = {
'number': number,
+ 'title': pr.subject,
'updated_at': pr.updated_at,
'base': {
'repo': {
@@ -814,6 +867,18 @@
}
return data
+ def getPullFileNames(self, project, number):
+ pr = self.pull_requests[number - 1]
+ return pr.files
+
+ def getUser(self, login):
+ data = {
+ 'username': login,
+ 'name': 'Github User',
+ 'email': 'github.user@example.com'
+ }
+ return data
+
def getGitUrl(self, project):
return os.path.join(self.upstream_root, str(project))
@@ -830,7 +895,7 @@
pull_request = self.pull_requests[pr_number - 1]
pull_request.addComment(message)
- def mergePull(self, project, pr_number, sha=None):
+ def mergePull(self, project, pr_number, commit_message='', sha=None):
pull_request = self.pull_requests[pr_number - 1]
if self.merge_failure:
raise Exception('Pull request was not merged')
@@ -839,6 +904,7 @@
raise MergeFailure('Merge was not successful due to mergeability'
' conflict')
pull_request.is_merged = True
+ pull_request.merge_message = commit_message
def setCommitStatus(self, project, sha, state,
url='', description='', context=''):
@@ -915,7 +981,7 @@
return
def stop(self):
- os.write(self.wake_write, '1\n')
+ os.write(self.wake_write, b'1\n')
class FakeBuild(object):
@@ -1199,7 +1265,7 @@
for queue in [self.high_queue, self.normal_queue, self.low_queue]:
for job in queue:
if not hasattr(job, 'waiting'):
- if job.name.startswith('executor:execute'):
+ if job.name.startswith(b'executor:execute'):
job.waiting = self.hold_jobs_in_queue
else:
job.waiting = False
@@ -1298,7 +1364,10 @@
def run(self):
while self._running:
- self._run()
+ try:
+ self._run()
+ except Exception:
+ self.log.exception("Error in fake nodepool:")
time.sleep(0.1)
def _run(self):
@@ -1317,7 +1386,7 @@
path = self.REQUEST_ROOT + '/' + oid
try:
data, stat = self.client.get(path)
- data = json.loads(data)
+ data = json.loads(data.decode('utf8'))
data['_oid'] = oid
reqs.append(data)
except kazoo.exceptions.NoNodeError:
@@ -1333,7 +1402,7 @@
for oid in sorted(nodeids):
path = self.NODE_ROOT + '/' + oid
data, stat = self.client.get(path)
- data = json.loads(data)
+ data = json.loads(data.decode('utf8'))
data['_oid'] = oid
try:
lockfiles = self.client.get_children(path + '/lock')
@@ -1365,7 +1434,7 @@
image_id=None,
host_keys=["fake-key1", "fake-key2"],
executor='fake-nodepool')
- data = json.dumps(data)
+ data = json.dumps(data).encode('utf8')
path = self.client.create(path, data,
makepath=True,
sequence=True)
@@ -1394,9 +1463,12 @@
request['state_time'] = time.time()
path = self.REQUEST_ROOT + '/' + oid
- data = json.dumps(request)
+ data = json.dumps(request).encode('utf8')
self.log.debug("Fulfilling node request: %s %s" % (oid, data))
- self.client.set(path, data)
+ try:
+ self.client.set(path, data)
+ except kazoo.exceptions.NoNodeError:
+ self.log.debug("Node request %s %s disappeared" % (oid, data))
class ChrootedKazooFixture(fixtures.Fixture):
@@ -1555,7 +1627,7 @@
# from libraries that zuul depends on such as gear.
log_defaults_from_env = os.environ.get(
'OS_LOG_DEFAULTS',
- 'git.cmd=INFO,kazoo.client=WARNING,gear=INFO')
+ 'git.cmd=INFO,kazoo.client=WARNING,gear=INFO,paste=INFO')
if log_defaults_from_env:
for default in log_defaults_from_env.split(','):
@@ -1862,7 +1934,7 @@
'source': {driver:
{'config-projects': ['common-config'],
'untrusted-projects': untrusted_projects}}}}]
- f.write(yaml.dump(config))
+ f.write(yaml.dump(config).encode('utf8'))
f.close()
self.config.set('zuul', 'tenant_config',
os.path.join(FIXTURE_DIR, f.name))
@@ -2136,8 +2208,9 @@
if build.url is None:
self.log.debug("%s has not reported start" % build)
return False
+ # using internal ServerJob which offers no Text interface
worker_build = self.executor_server.job_builds.get(
- server_job.unique)
+ server_job.unique.decode('utf8'))
if worker_build:
if worker_build.isWaiting():
continue
@@ -2216,7 +2289,7 @@
def countJobResults(self, jobs, result):
jobs = filter(lambda x: x.result == result, jobs)
- return len(jobs)
+ return len(list(jobs))
def getJobFromHistory(self, name, project=None):
for job in self.history:
@@ -2241,7 +2314,7 @@
start = time.time()
while time.time() < (start + 5):
for stat in self.statsd.stats:
- k, v = stat.split(':')
+ k, v = stat.decode('utf-8').split(':')
if key == k:
if value is None and kind is None:
return
diff --git a/tests/fixtures/config/multi-driver/git/common-config/playbooks/project-gerrit.yaml b/tests/fixtures/config/multi-driver/git/common-config/playbooks/project-gerrit.yaml
new file mode 100644
index 0000000..f679dce
--- /dev/null
+++ b/tests/fixtures/config/multi-driver/git/common-config/playbooks/project-gerrit.yaml
@@ -0,0 +1,2 @@
+- hosts: all
+ tasks: []
diff --git a/tests/fixtures/config/multi-driver/git/common-config/playbooks/project1-github.yaml b/tests/fixtures/config/multi-driver/git/common-config/playbooks/project1-github.yaml
new file mode 100644
index 0000000..f679dce
--- /dev/null
+++ b/tests/fixtures/config/multi-driver/git/common-config/playbooks/project1-github.yaml
@@ -0,0 +1,2 @@
+- hosts: all
+ tasks: []
diff --git a/tests/fixtures/config/multi-driver/git/common-config/zuul.yaml b/tests/fixtures/config/multi-driver/git/common-config/zuul.yaml
new file mode 100644
index 0000000..2dab845
--- /dev/null
+++ b/tests/fixtures/config/multi-driver/git/common-config/zuul.yaml
@@ -0,0 +1,46 @@
+- pipeline:
+ name: check_github
+ manager: independent
+ trigger:
+ github:
+ - event: pull_request
+ action:
+ - opened
+ - changed
+ - reopened
+ success:
+ github:
+ status: 'success'
+ failure:
+ github:
+ status: 'failure'
+
+- pipeline:
+ name: check_gerrit
+ manager: independent
+ trigger:
+ gerrit:
+ - event: patchset-created
+ success:
+ gerrit:
+ verify: 1
+ failure:
+ gerrit:
+ verify: 1
+
+- job:
+ name: project-gerrit
+- job:
+ name: project1-github
+
+- project:
+ name: org/project
+ check_gerrit:
+ jobs:
+ - project-gerrit
+
+- project:
+ name: org/project1
+ check_github:
+ jobs:
+ - project1-github
diff --git a/tests/fixtures/config/multi-driver/git/org_project/README b/tests/fixtures/config/multi-driver/git/org_project/README
new file mode 100644
index 0000000..9daeafb
--- /dev/null
+++ b/tests/fixtures/config/multi-driver/git/org_project/README
@@ -0,0 +1 @@
+test
diff --git a/tests/fixtures/config/multi-driver/git/org_project1/README b/tests/fixtures/config/multi-driver/git/org_project1/README
new file mode 100644
index 0000000..9daeafb
--- /dev/null
+++ b/tests/fixtures/config/multi-driver/git/org_project1/README
@@ -0,0 +1 @@
+test
diff --git a/tests/fixtures/config/multi-driver/main.yaml b/tests/fixtures/config/multi-driver/main.yaml
new file mode 100644
index 0000000..301df38
--- /dev/null
+++ b/tests/fixtures/config/multi-driver/main.yaml
@@ -0,0 +1,11 @@
+- tenant:
+ name: tenant-one
+ source:
+ github:
+ config-projects:
+ - common-config
+ untrusted-projects:
+ - org/project1
+ gerrit:
+ untrusted-projects:
+ - org/project
diff --git a/tests/fixtures/config/single-tenant/git/common-config/zuul.yaml b/tests/fixtures/config/single-tenant/git/common-config/zuul.yaml
index 34bd9cd..2bb61ee 100644
--- a/tests/fixtures/config/single-tenant/git/common-config/zuul.yaml
+++ b/tests/fixtures/config/single-tenant/git/common-config/zuul.yaml
@@ -69,7 +69,6 @@
- job:
name: project1-project2-integration
- queue-name: integration
- job:
name: project-testfile
diff --git a/tests/fixtures/layouts/files-github.yaml b/tests/fixtures/layouts/files-github.yaml
new file mode 100644
index 0000000..734b945
--- /dev/null
+++ b/tests/fixtures/layouts/files-github.yaml
@@ -0,0 +1,18 @@
+- pipeline:
+ name: check
+ manager: independent
+ trigger:
+ github:
+ - event: pull_request
+ action: opened
+
+- job:
+ name: project-test1
+ files:
+ - '.*-requires'
+
+- project:
+ name: org/project
+ check:
+ jobs:
+ - project-test1
diff --git a/tests/fixtures/layouts/ignore-dependencies.yaml b/tests/fixtures/layouts/ignore-dependencies.yaml
index 02aea36..86fe674 100644
--- a/tests/fixtures/layouts/ignore-dependencies.yaml
+++ b/tests/fixtures/layouts/ignore-dependencies.yaml
@@ -32,7 +32,6 @@
- job:
name: project1-project2-integration
- queue-name: integration
- project:
name: org/project1
diff --git a/tests/fixtures/layouts/reviews-github.yaml b/tests/fixtures/layouts/reviews-github.yaml
new file mode 100644
index 0000000..1cc887a
--- /dev/null
+++ b/tests/fixtures/layouts/reviews-github.yaml
@@ -0,0 +1,21 @@
+- pipeline:
+ name: reviews
+ manager: independent
+ trigger:
+ github:
+ - event: pull_request_review
+ action: submitted
+ state: 'approve'
+ success:
+ github:
+ label:
+ - 'tests passed'
+
+- job:
+ name: project-reviews
+
+- project:
+ name: org/project
+ reviews:
+ jobs:
+ - project-reviews
diff --git a/tests/fixtures/zuul-connections-gerrit-and-github.conf b/tests/fixtures/zuul-connections-gerrit-and-github.conf
new file mode 100644
index 0000000..bd05c75
--- /dev/null
+++ b/tests/fixtures/zuul-connections-gerrit-and-github.conf
@@ -0,0 +1,31 @@
+[gearman]
+server=127.0.0.1
+
+[zuul]
+tenant_config=config/multi-driver/main.yaml
+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
+
+[executor]
+git_dir=/tmp/zuul-test/executor-git
+
+[connection gerrit]
+driver=gerrit
+server=review.example.com
+user=jenkins
+sshkey=none
+
+[connection github]
+driver=github
+
+[connection outgoing_smtp]
+driver=smtp
+server=localhost
+port=25
+default_from=zuul@example.com
+default_to=you@example.com
diff --git a/tests/fixtures/zuul-github-driver.conf b/tests/fixtures/zuul-github-driver.conf
index 58c7cd5..ab34619 100644
--- a/tests/fixtures/zuul-github-driver.conf
+++ b/tests/fixtures/zuul-github-driver.conf
@@ -20,3 +20,8 @@
[connection github_ssh]
driver=github
sshkey=/home/zuul/.ssh/id_rsa
+
+[connection github_ent]
+driver=github
+sshkey=/home/zuul/.ssh/id_rsa
+git_host=github.enterprise.io
diff --git a/tests/unit/test_change_matcher.py b/tests/unit/test_change_matcher.py
index 0585322..6b161a1 100644
--- a/tests/unit/test_change_matcher.py
+++ b/tests/unit/test_change_matcher.py
@@ -125,12 +125,18 @@
def test_matches_returns_false_when_not_all_files_match(self):
self._test_matches(False, files=['/COMMIT_MSG', 'docs/foo', 'foo/bar'])
+ def test_matches_returns_true_when_single_file_does_not_match(self):
+ self._test_matches(True, files=['docs/foo'])
+
def test_matches_returns_false_when_commit_message_matches(self):
self._test_matches(False, files=['/COMMIT_MSG'])
def test_matches_returns_true_when_all_files_match(self):
self._test_matches(True, files=['/COMMIT_MSG', 'docs/foo'])
+ def test_matches_returns_true_when_single_file_matches(self):
+ self._test_matches(True, files=['docs/foo'])
+
class TestMatchAll(BaseTestMatcher):
diff --git a/tests/unit/test_encryption.py b/tests/unit/test_encryption.py
index 4dda78b..b424769 100644
--- a/tests/unit/test_encryption.py
+++ b/tests/unit/test_encryption.py
@@ -41,14 +41,14 @@
def test_pkcs1_oaep(self):
"Verify encryption and decryption"
- orig_plaintext = "some text to encrypt"
+ orig_plaintext = b"some text to encrypt"
ciphertext = encryption.encrypt_pkcs1_oaep(orig_plaintext, self.public)
plaintext = encryption.decrypt_pkcs1_oaep(ciphertext, self.private)
self.assertEqual(orig_plaintext, plaintext)
def test_openssl_pkcs1_oaep(self):
"Verify that we can decrypt something encrypted with OpenSSL"
- orig_plaintext = "some text to encrypt"
+ orig_plaintext = b"some text to encrypt"
pem_public = encryption.serialize_rsa_public_key(self.public)
public_file = tempfile.NamedTemporaryFile(delete=False)
try:
diff --git a/tests/unit/test_github_driver.py b/tests/unit/test_github_driver.py
index 3f567d2..f918218 100644
--- a/tests/unit/test_github_driver.py
+++ b/tests/unit/test_github_driver.py
@@ -12,17 +12,12 @@
# License for the specific language governing permissions and limitations
# under the License.
-import logging
import re
from testtools.matchers import MatchesRegex
import time
from tests.base import ZuulTestCase, simple_layout, random_sha1
-logging.basicConfig(level=logging.DEBUG,
- format='%(asctime)s %(name)-32s '
- '%(levelname)-8s %(message)s')
-
class TestGithubDriver(ZuulTestCase):
config_file = 'zuul-github-driver.conf'
@@ -65,6 +60,22 @@
self.assertEqual(2, len(self.history))
+ @simple_layout('layouts/files-github.yaml', driver='github')
+ def test_pull_matched_file_event(self):
+ A = self.fake_github.openFakePullRequest(
+ 'org/project', 'master', 'A',
+ files=['random.txt', 'build-requires'])
+ self.fake_github.emitEvent(A.getPullRequestOpenedEvent())
+ self.waitUntilSettled()
+ self.assertEqual(1, len(self.history))
+
+ # test_pull_unmatched_file_event
+ B = self.fake_github.openFakePullRequest('org/project', 'master', 'B',
+ files=['random.txt'])
+ self.fake_github.emitEvent(B.getPullRequestOpenedEvent())
+ self.waitUntilSettled()
+ self.assertEqual(1, len(self.history))
+
@simple_layout('layouts/basic-github.yaml', driver='github')
def test_comment_event(self):
A = self.fake_github.openFakePullRequest('org/project', 'master', 'A')
@@ -161,6 +172,21 @@
self.assertEqual(2, len(self.history))
self.assertEqual(['other label'], C.labels)
+ @simple_layout('layouts/reviews-github.yaml', driver='github')
+ def test_review_event(self):
+ A = self.fake_github.openFakePullRequest('org/project', 'master', 'A')
+ self.fake_github.emitEvent(A.getReviewAddedEvent('approve'))
+ self.waitUntilSettled()
+ self.assertEqual(1, len(self.history))
+ self.assertEqual('project-reviews', self.history[0].name)
+ self.assertEqual(['tests passed'], A.labels)
+
+ # test_review_unmatched_event
+ B = self.fake_github.openFakePullRequest('org/project', 'master', 'B')
+ self.fake_github.emitEvent(B.getReviewAddedEvent('comment'))
+ self.waitUntilSettled()
+ self.assertEqual(1, len(self.history))
+
@simple_layout('layouts/dequeue-github.yaml', driver='github')
def test_dequeue_pull_synchronized(self):
self.executor_server.hold_jobs_in_build = True
@@ -214,6 +240,12 @@
url = self.fake_github_ssh.real_getGitUrl('org/project')
self.assertEqual('ssh://git@github.com/org/project.git', url)
+ @simple_layout('layouts/basic-github.yaml', driver='github')
+ def test_git_enterprise_url(self):
+ """Test that git_url option gives git url with proper host"""
+ url = self.fake_github_ent.real_getGitUrl('org/project')
+ self.assertEqual('ssh://git@github.enterprise.io/org/project.git', url)
+
@simple_layout('layouts/reporting-github.yaml', driver='github')
def test_reporting(self):
# pipeline reports pull status both on start and success
@@ -223,9 +255,11 @@
self.waitUntilSettled()
self.assertIn('check', A.statuses)
check_status = A.statuses['check']
+ check_url = ('http://zuul.example.com/status/#%s,%s' %
+ (A.number, A.head_sha))
self.assertEqual('Standard check', check_status['description'])
self.assertEqual('pending', check_status['state'])
- self.assertEqual('http://zuul.example.com/status', check_status['url'])
+ self.assertEqual(check_url, check_status['url'])
self.assertEqual(0, len(A.comments))
self.executor_server.hold_jobs_in_build = False
@@ -234,7 +268,7 @@
check_status = A.statuses['check']
self.assertEqual('Standard check', check_status['description'])
self.assertEqual('success', check_status['state'])
- self.assertEqual('http://zuul.example.com/status', check_status['url'])
+ self.assertEqual(check_url, check_status['url'])
self.assertEqual(1, len(A.comments))
self.assertThat(A.comments[0],
MatchesRegex('.*Build succeeded.*', re.DOTALL))
@@ -258,10 +292,13 @@
@simple_layout('layouts/merging-github.yaml', driver='github')
def test_report_pull_merge(self):
# pipeline merges the pull request on success
- A = self.fake_github.openFakePullRequest('org/project', 'master', 'A')
+ A = self.fake_github.openFakePullRequest('org/project', 'master',
+ 'PR title')
self.fake_github.emitEvent(A.getCommentAddedEvent('merge me'))
self.waitUntilSettled()
self.assertTrue(A.is_merged)
+ self.assertThat(A.merge_message,
+ MatchesRegex('.*PR title.*Reviewed-by.*', re.DOTALL))
# pipeline merges the pull request on success after failure
self.fake_github.merge_failure = True
diff --git a/tests/unit/test_model.py b/tests/unit/test_model.py
index d8480ea..5f968b4 100644
--- a/tests/unit/test_model.py
+++ b/tests/unit/test_model.py
@@ -73,11 +73,21 @@
change.files = ['/COMMIT_MSG', 'docs/foo']
self.assertFalse(self.job.changeMatches(change))
+ def test_change_matches_returns_false_for_single_matched_skip_if(self):
+ change = model.Change('project')
+ change.files = ['docs/foo']
+ self.assertFalse(self.job.changeMatches(change))
+
def test_change_matches_returns_true_for_unmatched_skip_if(self):
change = model.Change('project')
change.files = ['/COMMIT_MSG', 'foo']
self.assertTrue(self.job.changeMatches(change))
+ def test_change_matches_returns_true_for_single_unmatched_skip_if(self):
+ change = model.Change('project')
+ change.files = ['foo']
+ self.assertTrue(self.job.changeMatches(change))
+
def test_job_sets_defaults_for_boolean_attributes(self):
self.assertIsNotNone(self.job.voting)
diff --git a/tests/unit/test_multi_driver.py b/tests/unit/test_multi_driver.py
new file mode 100644
index 0000000..a1107de
--- /dev/null
+++ b/tests/unit/test_multi_driver.py
@@ -0,0 +1,45 @@
+# Copyright 2015 GoodData
+# Copyright (c) 2017 IBM Corp.
+#
+# 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 TestGerritAndGithub(ZuulTestCase):
+ config_file = 'zuul-connections-gerrit-and-github.conf'
+ tenant_config_file = 'config/multi-driver/main.yaml'
+
+ def setup_config(self):
+ super(TestGerritAndGithub, self).setup_config()
+
+ def test_multiple_project_gerrit_and_github(self):
+ self.executor_server.hold_jobs_in_build = True
+
+ A = self.fake_gerrit.addFakeChange('org/project', 'master', 'A')
+ self.fake_gerrit.addEvent(A.getPatchsetCreatedEvent(1))
+
+ B = self.fake_github.openFakePullRequest('org/project1', 'master', 'B')
+ self.fake_github.emitEvent(B.getPullRequestOpenedEvent())
+
+ self.waitUntilSettled()
+
+ self.assertEqual(2, len(self.builds))
+ self.assertEqual('project-gerrit', self.builds[0].name)
+ self.assertEqual('project1-github', self.builds[1].name)
+ self.assertTrue(self.builds[0].hasChanges(A))
+ self.assertTrue(self.builds[1].hasChanges(B))
+
+ self.executor_server.hold_jobs_in_build = False
+ self.executor_server.release()
+ self.waitUntilSettled()
diff --git a/tests/unit/test_scheduler.py b/tests/unit/test_scheduler.py
index bc827b3..f394c0c 100755
--- a/tests/unit/test_scheduler.py
+++ b/tests/unit/test_scheduler.py
@@ -21,8 +21,9 @@
import os
import re
import shutil
+import sys
import time
-from unittest import skip
+from unittest import (skip, skipIf)
import git
from six.moves import urllib
@@ -509,6 +510,7 @@
self.assertEqual(B.reported, 2)
self.assertEqual(C.reported, 2)
+ @skipIf(sys.version_info.major > 2, 'Fails on py3')
def test_failed_change_at_head_with_queue(self):
"Test that if a change at the head fails, queued jobs are canceled"
@@ -530,8 +532,8 @@
queue = self.gearman_server.getQueue()
self.assertEqual(len(self.builds), 0)
self.assertEqual(len(queue), 1)
- self.assertEqual(queue[0].name, 'executor:execute')
- job_args = json.loads(queue[0].arguments)
+ self.assertEqual(queue[0].name, b'executor:execute')
+ job_args = json.loads(queue[0].arguments.decode('utf8'))
self.assertEqual(job_args['job'], 'project-merge')
self.assertEqual(job_args['items'][0]['number'], '%d' % A.number)
@@ -547,17 +549,23 @@
self.assertEqual(len(queue), 6)
self.assertEqual(
- json.loads(queue[0].arguments)['job'], 'project-test1')
+ json.loads(queue[0].arguments.decode('utf8'))['job'],
+ 'project-test1')
self.assertEqual(
- json.loads(queue[1].arguments)['job'], 'project-test2')
+ json.loads(queue[1].arguments.decode('utf8'))['job'],
+ 'project-test2')
self.assertEqual(
- json.loads(queue[2].arguments)['job'], 'project-test1')
+ json.loads(queue[2].arguments.decode('utf8'))['job'],
+ 'project-test1')
self.assertEqual(
- json.loads(queue[3].arguments)['job'], 'project-test2')
+ json.loads(queue[3].arguments.decode('utf8'))['job'],
+ 'project-test2')
self.assertEqual(
- json.loads(queue[4].arguments)['job'], 'project-test1')
+ json.loads(queue[4].arguments.decode('utf8'))['job'],
+ 'project-test1')
self.assertEqual(
- json.loads(queue[5].arguments)['job'], 'project-test2')
+ json.loads(queue[5].arguments.decode('utf8'))['job'],
+ 'project-test2')
self.release(queue[0])
self.waitUntilSettled()
@@ -929,6 +937,7 @@
a = source.getChange(event, refresh=True)
self.assertTrue(source.canMerge(a, mgr.getSubmitAllowNeeds()))
+ @skipIf(sys.version_info.major > 2, 'Fails on py3')
def test_project_merge_conflict(self):
"Test that gate merge conflicts are handled properly"
@@ -980,6 +989,7 @@
dict(name='project-test2', result='SUCCESS', changes='1,1 3,1'),
], ordered=False)
+ @skipIf(sys.version_info.major > 2, 'Fails on py3')
def test_delayed_merge_conflict(self):
"Test that delayed check merge conflicts are handled properly"
@@ -1916,6 +1926,7 @@
self.assertEqual(A.reported, 2)
@simple_layout('layouts/no-jobs-project.yaml')
+ @skipIf(sys.version_info.major > 2, 'Fails on py3')
def test_no_job_project(self):
"Test that reports with no jobs don't get sent"
A = self.fake_gerrit.addFakeChange('org/no-jobs-project',
@@ -2047,6 +2058,7 @@
self.assertReportedStat('test-timing', '3|ms')
self.assertReportedStat('test-gauge', '12|g')
+ @skipIf(sys.version_info.major > 2, 'Fails on py3')
def test_stuck_job_cleanup(self):
"Test that pending jobs are cleaned up if removed from layout"
@@ -2174,6 +2186,7 @@
self.assertEqual(q1.name, 'integrated')
self.assertEqual(q2.name, 'integrated')
+ @skipIf(sys.version_info.major > 2, 'Fails on py3')
def test_queue_precedence(self):
"Test that queue precedence works"
@@ -2227,7 +2240,7 @@
self.assertIn('Cache-Control', headers)
self.assertIn('Last-Modified', headers)
self.assertIn('Expires', headers)
- data = f.read()
+ data = f.read().decode('utf8')
self.executor_server.hold_jobs_in_build = False
self.executor_server.release()
@@ -2712,7 +2725,7 @@
req = urllib.request.Request(
"http://localhost:%s/tenant-one/status" % port)
f = urllib.request.urlopen(req)
- data = f.read()
+ data = f.read().decode('utf8')
self.executor_server.hold_jobs_in_build = False
# Stop queuing timer triggered jobs so that the assertions
@@ -3339,7 +3352,7 @@
if time.time() - start > 10:
raise Exception("Timeout waiting for gearman server to report "
+ "back to the client")
- build = self.executor.builds.values()[0]
+ build = list(self.executor.builds.values())[0]
if build.worker.name == "My Worker":
break
else:
@@ -3512,7 +3525,7 @@
if time.time() - start > 10:
raise Exception("Timeout waiting for gearman server to report "
+ "back to the client")
- build = self.executor_client.builds.values()[0]
+ build = list(self.executor_client.builds.values())[0]
if build.worker.name == "My Worker":
break
else:
@@ -3860,6 +3873,7 @@
self.assertEqual(B.data['status'], 'MERGED')
self.assertEqual(B.reported, 0)
+ @skipIf(sys.version_info.major > 2, 'Fails on py3')
def test_crd_check(self):
"Test cross-repo dependencies in independent pipelines"
@@ -4010,9 +4024,11 @@
self.assertEqual(self.history[0].changes, '2,1 1,1')
self.assertEqual(len(tenant.layout.pipelines['check'].queues), 0)
+ @skipIf(sys.version_info.major > 2, 'Fails on py3')
def test_crd_check_reconfiguration(self):
self._test_crd_check_reconfiguration('org/project1', 'org/project2')
+ @skipIf(sys.version_info.major > 2, 'Fails on py3')
def test_crd_undefined_project(self):
"""Test that undefined projects in dependencies are handled for
independent pipelines"""
@@ -4022,6 +4038,7 @@
self._test_crd_check_reconfiguration('org/project1', 'org/unknown')
@simple_layout('layouts/ignore-dependencies.yaml')
+ @skipIf(sys.version_info.major > 2, 'Fails on py3')
def test_crd_check_ignore_dependencies(self):
"Test cross-repo dependencies can be ignored"
diff --git a/tests/unit/test_webapp.py b/tests/unit/test_webapp.py
index 4511ec7..b2836ae 100644
--- a/tests/unit/test_webapp.py
+++ b/tests/unit/test_webapp.py
@@ -51,7 +51,7 @@
req = urllib.request.Request(
"http://localhost:%s/tenant-one/status" % self.port)
f = urllib.request.urlopen(req)
- data = json.loads(f.read())
+ data = json.loads(f.read().decode('utf8'))
self.assertIn('pipelines', data)
@@ -60,7 +60,7 @@
req = urllib.request.Request(
"http://localhost:%s/tenant-one/status.json" % self.port)
f = urllib.request.urlopen(req)
- data = json.loads(f.read())
+ data = json.loads(f.read().decode('utf8'))
self.assertIn('pipelines', data)
@@ -75,7 +75,7 @@
req = urllib.request.Request(
"http://localhost:%s/tenant-one/status/change/1,1" % self.port)
f = urllib.request.urlopen(req)
- data = json.loads(f.read())
+ data = json.loads(f.read().decode('utf8'))
self.assertEqual(1, len(data), data)
self.assertEqual("org/project", data[0]['project'])
@@ -83,13 +83,13 @@
req = urllib.request.Request(
"http://localhost:%s/tenant-one/status/change/2,1" % self.port)
f = urllib.request.urlopen(req)
- data = json.loads(f.read())
+ data = json.loads(f.read().decode('utf8'))
self.assertEqual(1, len(data), data)
self.assertEqual("org/project1", data[0]['project'], data)
def test_webapp_keys(self):
- with open(os.path.join(FIXTURE_DIR, 'public.pem')) as f:
+ with open(os.path.join(FIXTURE_DIR, 'public.pem'), 'rb') as f:
public_pem = f.read()
req = urllib.request.Request(
@@ -106,7 +106,7 @@
req = urllib.request.Request(
"http://localhost:%s/custom" % self.port)
f = urllib.request.urlopen(req)
- self.assertEqual('ok', f.read())
+ self.assertEqual(b'ok', f.read())
self.webapp.unregister_path('/custom')
self.assertRaises(urllib.error.HTTPError, urllib.request.urlopen, req)
diff --git a/tox.ini b/tox.ini
index 8235483..174a496 100644
--- a/tox.ini
+++ b/tox.ini
@@ -51,6 +51,6 @@
[flake8]
# These are ignored intentionally in openstack-infra projects;
# please don't submit patches that solely correct them or enable them.
-ignore = E125,E129,H
+ignore = E305,E125,E129,E402,H,F405,W503
show-source = True
exclude = .venv,.tox,dist,doc,build,*.egg
diff --git a/zuul/ansible/library/command.py b/zuul/ansible/library/command.py
index 328ae7b..52de5a4 100644
--- a/zuul/ansible/library/command.py
+++ b/zuul/ansible/library/command.py
@@ -123,6 +123,8 @@
LOG_STREAM_FILE = '/tmp/console.log'
PASSWD_ARG_RE = re.compile(r'^[-]{0,2}pass[-]?(word|wd)?')
+# List to save stdout log lines in as we collect them
+_log_lines = []
class Console(object):
@@ -150,6 +152,7 @@
line = fd.readline()
if not line:
break
+ _log_lines.append(line)
if not line.endswith('\n'):
line += '\n'
newline_warning = True
@@ -330,7 +333,8 @@
# cmd.stdout.close()
# ZUUL: stdout and stderr are in the console log file
- stdout = ''
+ # ZUUL: return the saved log lines so we can ship them back
+ stdout = ''.join(_log_lines)
stderr = ''
rc = cmd.returncode
diff --git a/zuul/change_matcher.py b/zuul/change_matcher.py
index 1da1d2c..baea217 100644
--- a/zuul/change_matcher.py
+++ b/zuul/change_matcher.py
@@ -108,7 +108,9 @@
yield self.commit_regex
def matches(self, change):
- if not (hasattr(change, 'files') and len(change.files) > 1):
+ if not (hasattr(change, 'files') and change.files):
+ return False
+ if len(change.files) == 1 and self.commit_regex.match(change.files[0]):
return False
for file_ in change.files:
matched_file = False
diff --git a/zuul/configloader.py b/zuul/configloader.py
index 070e731..90440f7 100644
--- a/zuul/configloader.py
+++ b/zuul/configloader.py
@@ -10,6 +10,7 @@
# License for the specific language governing permissions and limitations
# under the License.
+import base64
from contextlib import contextmanager
import copy
import os
@@ -111,7 +112,7 @@
r = super(ZuulSafeLoader, self).construct_mapping(node, deep)
keys = frozenset(r.keys())
if len(keys) == 1 and keys.intersection(self.zuul_node_types):
- d = r.values()[0]
+ d = list(r.values())[0]
if isinstance(d, dict):
d['_start_mark'] = node.start_mark
d['_source_context'] = self.zuul_context
@@ -142,7 +143,7 @@
yaml_loader = yaml.SafeLoader
def __init__(self, ciphertext):
- self.ciphertext = ciphertext.decode('base64')
+ self.ciphertext = base64.b64decode(ciphertext)
def __ne__(self, other):
return not self.__eq__(other)
@@ -157,7 +158,8 @@
return cls(node.value)
def decrypt(self, private_key):
- return encryption.decrypt_pkcs1_oaep(self.ciphertext, private_key)
+ return encryption.decrypt_pkcs1_oaep(self.ciphertext,
+ private_key).decode('utf8')
class NodeSetParser(object):
@@ -229,7 +231,6 @@
job = {vs.Required('name'): str,
'parent': str,
- 'queue-name': str,
'failure-message': str,
'success-message': str,
'failure-url': str,
@@ -493,7 +494,7 @@
attrs = dict(name=conf_job)
elif isinstance(conf_job, dict):
# A dictionary in a job tree may override params
- jobname, attrs = conf_job.items()[0]
+ jobname, attrs = list(conf_job.items())[0]
if attrs:
# We are overriding params, so make a new job def
attrs['name'] = jobname
diff --git a/zuul/driver/gerrit/__init__.py b/zuul/driver/gerrit/__init__.py
index 3bc371e..a36e912 100644
--- a/zuul/driver/gerrit/__init__.py
+++ b/zuul/driver/gerrit/__init__.py
@@ -14,10 +14,10 @@
from zuul.driver import Driver, ConnectionInterface, TriggerInterface
from zuul.driver import SourceInterface, ReporterInterface
-import gerritconnection
-import gerrittrigger
-import gerritsource
-import gerritreporter
+from zuul.driver.gerrit import gerritconnection
+from zuul.driver.gerrit import gerrittrigger
+from zuul.driver.gerrit import gerritsource
+from zuul.driver.gerrit import gerritreporter
class GerritDriver(Driver, ConnectionInterface, TriggerInterface,
diff --git a/zuul/driver/git/__init__.py b/zuul/driver/git/__init__.py
index abedf6a..5ebedac 100644
--- a/zuul/driver/git/__init__.py
+++ b/zuul/driver/git/__init__.py
@@ -13,8 +13,8 @@
# under the License.
from zuul.driver import Driver, ConnectionInterface, SourceInterface
-import gitconnection
-import gitsource
+from zuul.driver.git import gitconnection
+from zuul.driver.git import gitsource
class GitDriver(Driver, ConnectionInterface, SourceInterface):
diff --git a/zuul/driver/github/__init__.py b/zuul/driver/github/__init__.py
index 2d6829d..e59dc58 100644
--- a/zuul/driver/github/__init__.py
+++ b/zuul/driver/github/__init__.py
@@ -14,10 +14,10 @@
from zuul.driver import Driver, ConnectionInterface, TriggerInterface
from zuul.driver import SourceInterface
-import githubconnection
-import githubtrigger
-import githubsource
-import githubreporter
+from zuul.driver.github import githubconnection
+from zuul.driver.github import githubtrigger
+from zuul.driver.github import githubsource
+from zuul.driver.github import githubreporter
class GithubDriver(Driver, ConnectionInterface, TriggerInterface,
diff --git a/zuul/driver/github/githubconnection.py b/zuul/driver/github/githubconnection.py
index f2a8fc0..b7fb05d 100644
--- a/zuul/driver/github/githubconnection.py
+++ b/zuul/driver/github/githubconnection.py
@@ -12,6 +12,7 @@
# License for the specific language governing permissions and limitations
# under the License.
+import collections
import logging
import hmac
import hashlib
@@ -100,6 +101,7 @@
pr_body = body.get('pull_request')
event = self._pull_request_to_event(pr_body)
+ event.account = self._get_sender(body)
event.type = 'pull_request'
if action == 'opened':
@@ -135,11 +137,30 @@
return
event = self._pull_request_to_event(pr_body)
+ event.account = self._get_sender(body)
event.comment = body.get('comment').get('body')
event.type = 'pull_request'
event.action = 'comment'
return event
+ def _event_pull_request_review(self, request):
+ """Handles pull request reviews"""
+ body = request.json_body
+ pr_body = body.get('pull_request')
+ if pr_body is None:
+ return
+
+ review = body.get('review')
+ if review is None:
+ return
+
+ event = self._pull_request_to_event(pr_body)
+ event.state = review.get('state')
+ event.account = self._get_sender(body)
+ event.type = 'pull_request_review'
+ event.action = body.get('action')
+ return event
+
def _issue_to_pull_request(self, body):
number = body.get('issue').get('number')
project_name = body.get('repository').get('full_name')
@@ -191,26 +212,63 @@
event.refspec = "refs/pull/" + str(pr_body.get('number')) + "/head"
event.patch_number = head.get('sha')
+ event.title = pr_body.get('title')
+
return event
+ def _get_sender(self, body):
+ login = body.get('sender').get('login')
+ if login:
+ return self.connection.getUser(login)
+
+
+class GithubUser(collections.Mapping):
+ log = logging.getLogger('zuul.GithubUser')
+
+ def __init__(self, github, username):
+ self._github = github
+ self._username = username
+ self._data = None
+
+ def __getitem__(self, key):
+ if self._data is None:
+ self._data = self._init_data()
+ return self._data[key]
+
+ def __iter__(self):
+ return iter(self._data)
+
+ def __len__(self):
+ return len(self._data)
+
+ def _init_data(self):
+ user = self._github.user(self._username)
+ log_rate_limit(self.log, self._github)
+ data = {
+ 'username': user.login,
+ 'name': user.name,
+ 'email': user.email
+ }
+ return data
+
class GithubConnection(BaseConnection):
driver_name = 'github'
log = logging.getLogger("connection.github")
payload_path = 'payload'
git_user = 'git'
- git_host = 'github.com'
def __init__(self, driver, connection_name, connection_config):
super(GithubConnection, self).__init__(
driver, connection_name, connection_config)
self.github = None
- self.canonical_hostname = self.connection_config.get(
- 'canonical_hostname', 'github.com')
self._change_cache = {}
self.projects = {}
- self.source = driver.getSource(self)
self._git_ssh = bool(self.connection_config.get('sshkey', None))
+ self.git_host = self.connection_config.get('git_host', 'github.com')
+ self.canonical_hostname = self.connection_config.get(
+ 'canonical_hostname', self.git_host)
+ self.source = driver.getSource(self)
def onLoad(self):
webhook_listener = GithubWebhookListener(self)
@@ -224,7 +282,11 @@
def _authenticateGithubAPI(self):
token = self.connection_config.get('api_token', None)
if token is not None:
- self.github = github3.login(token=token)
+ if self.git_host != 'github.com':
+ url = 'https://%s/' % self.git_host
+ self.github = github3.enterprise_login(token=token, url=url)
+ else:
+ self.github = github3.login(token=token)
self.log.info("Github API Authentication successful.")
else:
self.github = None
@@ -250,12 +312,16 @@
change.url = event.change_url
change.updated_at = self._ghTimestampToDate(event.updated_at)
change.patchset = event.patch_number
+ change.files = self.getPullFileNames(project, change.number)
+ change.title = event.title
+ change.source_event = event
elif event.ref:
change = Ref(project)
change.ref = event.ref
change.oldrev = event.oldrev
change.newrev = event.newrev
change.url = self.getGitwebUrl(project, sha=event.newrev)
+ change.source_event = event
else:
change = Ref(project)
return change
@@ -284,6 +350,7 @@
owner, proj = project.name.split('/')
repository = self.github.repository(owner, proj)
branches = [branch.name for branch in repository.branches()]
+ log_rate_limit(self.log, self.github)
return branches
def getPullUrl(self, project, number):
@@ -291,7 +358,9 @@
def getPull(self, project_name, number):
owner, proj = project_name.split('/')
- return self.github.pull_request(owner, proj, number).as_dict()
+ pr = self.github.pull_request(owner, proj, number).as_dict()
+ log_rate_limit(self.log, self.github)
+ return pr
def canMerge(self, change, allow_needs):
# This API call may get a false (null) while GitHub is calculating
@@ -306,20 +375,35 @@
# For now, just send back a True value.
return True
+ def getPullFileNames(self, project, number):
+ owner, proj = project.name.split('/')
+ filenames = [f.filename for f in
+ self.github.pull_request(owner, proj, number).files()]
+ log_rate_limit(self.log, self.github)
+ return filenames
+
+ def getUser(self, login):
+ return GithubUser(self.github, login)
+
+ def getUserUri(self, login):
+ return 'https://%s/%s' % (self.git_host, login)
+
def commentPull(self, project, pr_number, message):
owner, proj = project.split('/')
repository = self.github.repository(owner, proj)
pull_request = repository.issue(pr_number)
pull_request.create_comment(message)
+ log_rate_limit(self.log, self.github)
- def mergePull(self, project, pr_number, sha=None):
+ def mergePull(self, project, pr_number, commit_message='', sha=None):
owner, proj = project.split('/')
pull_request = self.github.pull_request(owner, proj, pr_number)
try:
- result = pull_request.merge(sha=sha)
+ result = pull_request.merge(commit_message=commit_message, sha=sha)
except MethodNotAllowed as e:
raise MergeFailure('Merge was not successful due to mergeability'
' conflict, original error is %s' % e)
+ log_rate_limit(self.log, self.github)
if not result:
raise Exception('Pull request was not merged')
@@ -328,21 +412,35 @@
owner, proj = project.split('/')
repository = self.github.repository(owner, proj)
repository.create_status(sha, state, url, description, context)
+ log_rate_limit(self.log, self.github)
def labelPull(self, project, pr_number, label):
owner, proj = project.split('/')
pull_request = self.github.issue(owner, proj, pr_number)
pull_request.add_labels(label)
+ log_rate_limit(self.log, self.github)
def unlabelPull(self, project, pr_number, label):
owner, proj = project.split('/')
pull_request = self.github.issue(owner, proj, pr_number)
pull_request.remove_label(label)
+ log_rate_limit(self.log, self.github)
def _ghTimestampToDate(self, timestamp):
return time.strptime(timestamp, '%Y-%m-%dT%H:%M:%SZ')
+def log_rate_limit(log, github):
+ try:
+ rate_limit = github.rate_limit()
+ remaining = rate_limit['resources']['core']['remaining']
+ reset = rate_limit['resources']['core']['reset']
+ except:
+ return
+ log.debug('GitHub API rate limit remaining: %s reset: %s' %
+ (remaining, reset))
+
+
def getSchema():
github_connection = v.Any(str, v.Schema({}, extra=True))
return github_connection
diff --git a/zuul/driver/github/githubreporter.py b/zuul/driver/github/githubreporter.py
index 159103c..ffec26a 100644
--- a/zuul/driver/github/githubreporter.py
+++ b/zuul/driver/github/githubreporter.py
@@ -68,7 +68,10 @@
state = self._commit_status
url = ''
if self.connection.sched.config.has_option('zuul', 'status_url'):
- url = self.connection.sched.config.get('zuul', 'status_url')
+ base = self.connection.sched.config.get('zuul', 'status_url')
+ url = '%s/#%s,%s' % (base,
+ item.change.number,
+ item.change.patchset)
description = ''
if pipeline.description:
description = pipeline.description
@@ -88,12 +91,13 @@
sha = item.change.patchset
self.log.debug('Reporting change %s, params %s, merging via API' %
(item.change, self.config))
+ message = self._formatMergeMessage(item.change)
try:
- self.connection.mergePull(project, pr_number, sha)
+ self.connection.mergePull(project, pr_number, message, sha)
except MergeFailure:
time.sleep(2)
self.log.debug('Trying to merge change %s again...' % item.change)
- self.connection.mergePull(project, pr_number, sha)
+ self.connection.mergePull(project, pr_number, message, sha)
item.change.is_merged = True
def setLabels(self, item):
@@ -110,6 +114,33 @@
for label in self._unlabels:
self.connection.unlabelPull(project, pr_number, label)
+ def _formatMergeMessage(self, change):
+ message = ''
+
+ if change.title:
+ message += change.title
+
+ account = change.source_event.account
+ if not account:
+ return message
+
+ username = account['username']
+ name = account['name']
+ email = account['email']
+ message += '\n\nReviewed-by: '
+
+ if name:
+ message += name
+ if email:
+ if name:
+ message += ' '
+ message += '<' + email + '>'
+ if name or email:
+ message += '\n '
+ message += self.connection.getUserUri(username)
+
+ return message
+
def getSchema():
def toList(x):
diff --git a/zuul/driver/github/githubsource.py b/zuul/driver/github/githubsource.py
index a638122..312ee87 100644
--- a/zuul/driver/github/githubsource.py
+++ b/zuul/driver/github/githubsource.py
@@ -84,5 +84,9 @@
"""Get the git-web url for a project."""
return self.connection.getGitwebUrl(project, sha)
+ def getPullFiles(self, project, number):
+ """Get filenames of the pull request"""
+ return self.connection.getPullFileNames(project, number)
+
def _ghTimestampToDate(self, timestamp):
return time.strptime(timestamp, '%Y-%m-%dT%H:%M:%SZ')
diff --git a/zuul/driver/github/githubtrigger.py b/zuul/driver/github/githubtrigger.py
index 541c783..b9c1026 100644
--- a/zuul/driver/github/githubtrigger.py
+++ b/zuul/driver/github/githubtrigger.py
@@ -40,7 +40,8 @@
refs=toList(trigger.get('ref')),
comments=toList(trigger.get('comment')),
labels=toList(trigger.get('label')),
- unlabels=toList(trigger.get('unlabel'))
+ unlabels=toList(trigger.get('unlabel')),
+ states=toList(trigger.get('state'))
)
efilters.append(f)
@@ -57,6 +58,7 @@
github_trigger = {
v.Required('event'):
toList(v.Any('pull_request',
+ 'pull_request_review',
'push')),
'action': toList(str),
'branch': toList(str),
@@ -64,6 +66,7 @@
'comment': toList(str),
'label': toList(str),
'unlabel': toList(str),
+ 'state': toList(str),
}
return github_trigger
diff --git a/zuul/driver/smtp/__init__.py b/zuul/driver/smtp/__init__.py
index 0745644..b914c81 100644
--- a/zuul/driver/smtp/__init__.py
+++ b/zuul/driver/smtp/__init__.py
@@ -13,8 +13,8 @@
# under the License.
from zuul.driver import Driver, ConnectionInterface, ReporterInterface
-import smtpconnection
-import smtpreporter
+from zuul.driver.smtp import smtpconnection
+from zuul.driver.smtp import smtpreporter
class SMTPDriver(Driver, ConnectionInterface, ReporterInterface):
diff --git a/zuul/driver/sql/__init__.py b/zuul/driver/sql/__init__.py
index a5f8923..3748e47 100644
--- a/zuul/driver/sql/__init__.py
+++ b/zuul/driver/sql/__init__.py
@@ -13,8 +13,8 @@
# under the License.
from zuul.driver import Driver, ConnectionInterface, ReporterInterface
-import sqlconnection
-import sqlreporter
+from zuul.driver.sql import sqlconnection
+from zuul.driver.sql import sqlreporter
class SQLDriver(Driver, ConnectionInterface, ReporterInterface):
diff --git a/zuul/driver/timer/__init__.py b/zuul/driver/timer/__init__.py
index 115e6af..bca91a1 100644
--- a/zuul/driver/timer/__init__.py
+++ b/zuul/driver/timer/__init__.py
@@ -21,7 +21,7 @@
from zuul.driver import Driver, TriggerInterface
from zuul.model import TriggerEvent
-import timertrigger
+from zuul.driver.timer import timertrigger
class TimerDriver(Driver, TriggerInterface):
diff --git a/zuul/driver/zuul/__init__.py b/zuul/driver/zuul/__init__.py
index 8c9d795..4c3be3d 100644
--- a/zuul/driver/zuul/__init__.py
+++ b/zuul/driver/zuul/__init__.py
@@ -17,7 +17,7 @@
from zuul.driver import Driver, TriggerInterface
from zuul.model import TriggerEvent
-import zuultrigger
+from zuul.driver.zuul import zuultrigger
PARENT_CHANGE_ENQUEUED = 'parent-change-enqueued'
PROJECT_CHANGE_MERGED = 'project-change-merged'
diff --git a/zuul/executor/ansiblelaunchserver.py b/zuul/executor/ansiblelaunchserver.py
index 0202bdd..18762b2 100644
--- a/zuul/executor/ansiblelaunchserver.py
+++ b/zuul/executor/ansiblelaunchserver.py
@@ -59,7 +59,7 @@
return bool(x)
-class LaunchGearWorker(gear.Worker):
+class LaunchGearWorker(gear.TextWorker):
def __init__(self, *args, **kw):
self.__launch_server = kw.pop('launch_server')
super(LaunchGearWorker, self).__init__(*args, **kw)
@@ -71,7 +71,7 @@
return super(LaunchGearWorker, self).handleNoop(packet)
-class NodeGearWorker(gear.Worker):
+class NodeGearWorker(gear.TextWorker):
MASS_DO = 101
def sendMassDo(self, functions):
diff --git a/zuul/executor/client.py b/zuul/executor/client.py
index 9f234e9..e1eed2d 100644
--- a/zuul/executor/client.py
+++ b/zuul/executor/client.py
@@ -308,8 +308,8 @@
self.sched.onBuildCompleted(build, 'SUCCESS')
return build
- gearman_job = gear.Job('executor:execute', json.dumps(params),
- unique=uuid)
+ gearman_job = gear.TextJob('executor:execute', json.dumps(params),
+ unique=uuid)
build.__gearman_job = gearman_job
build.__gearman_manager = None
self.builds[uuid] = build
@@ -438,7 +438,7 @@
job.connection.sendAdminRequest(req, timeout=300)
self.log.debug("Response to cancel build %s request: %s" %
(build, req.response.strip()))
- if req.response.startswith("OK"):
+ if req.response.startswith(b"OK"):
try:
del self.builds[job.unique]
except:
@@ -452,8 +452,8 @@
(build,))
stop_uuid = str(uuid4().hex)
data = dict(uuid=build.__gearman_job.unique)
- stop_job = gear.Job("executor:stop:%s" % build.__gearman_manager,
- json.dumps(data), unique=stop_uuid)
+ stop_job = gear.TextJob("executor:stop:%s" % build.__gearman_manager,
+ json.dumps(data), unique=stop_uuid)
self.meta_jobs[stop_uuid] = stop_job
self.log.debug("Submitting stop job: %s", stop_job)
self.gearman.submitJob(stop_job, precedence=gear.PRECEDENCE_HIGH,
diff --git a/zuul/executor/server.py b/zuul/executor/server.py
index 4801de2..83c3a1c 100644
--- a/zuul/executor/server.py
+++ b/zuul/executor/server.py
@@ -219,6 +219,16 @@
self.condition.release()
+def _copy_ansible_files(python_module, target_dir):
+ library_path = os.path.dirname(os.path.abspath(python_module.__file__))
+ for fn in os.listdir(library_path):
+ full_path = os.path.join(library_path, fn)
+ if os.path.isdir(full_path):
+ shutil.copytree(full_path, os.path.join(target_dir, fn))
+ else:
+ shutil.copy(os.path.join(library_path, fn), target_dir)
+
+
class ExecutorServer(object):
log = logging.getLogger("zuul.ExecutorServer")
@@ -286,25 +296,10 @@
if not os.path.exists(self.lookup_dir):
os.makedirs(self.lookup_dir)
- library_path = os.path.dirname(os.path.abspath(
- zuul.ansible.library.__file__))
- for fn in os.listdir(library_path):
- shutil.copy(os.path.join(library_path, fn), self.library_dir)
-
- action_path = os.path.dirname(os.path.abspath(
- zuul.ansible.action.__file__))
- for fn in os.listdir(action_path):
- shutil.copy(os.path.join(action_path, fn), self.action_dir)
-
- callback_path = os.path.dirname(os.path.abspath(
- zuul.ansible.callback.__file__))
- for fn in os.listdir(callback_path):
- shutil.copy(os.path.join(callback_path, fn), self.callback_dir)
-
- lookup_path = os.path.dirname(os.path.abspath(
- zuul.ansible.lookup.__file__))
- for fn in os.listdir(lookup_path):
- shutil.copy(os.path.join(lookup_path, fn), self.lookup_dir)
+ _copy_ansible_files(zuul.ansible.library, self.library_dir)
+ _copy_ansible_files(zuul.ansible.action, self.action_dir)
+ _copy_ansible_files(zuul.ansible.callback, self.callback_dir)
+ _copy_ansible_files(zuul.ansible.lookup, self.lookup_dir)
self.job_workers = {}
@@ -320,7 +315,7 @@
port = self.config.get('gearman', 'port')
else:
port = 4730
- self.worker = gear.Worker('Zuul Executor Server')
+ self.worker = gear.TextWorker('Zuul Executor Server')
self.worker.addServer(server, port)
self.log.debug("Waiting for server")
self.worker.waitForServer()
@@ -354,7 +349,7 @@
self.command_socket.stop()
self.update_queue.put(None)
- for job_worker in self.job_workers.values():
+ for job_worker in list(self.job_workers.values()):
try:
job_worker.stop()
except Exception:
@@ -390,7 +385,7 @@
def runCommand(self):
while self._command_running:
try:
- command = self.command_socket.get()
+ command = self.command_socket.get().decode('utf8')
if command != '_stop':
self.command_map[command]()
except Exception:
@@ -445,7 +440,8 @@
job.sendWorkFail()
except Exception:
self.log.exception("Exception while running job")
- job.sendWorkException(traceback.format_exc())
+ job.sendWorkException(
+ traceback.format_exc().encode('utf8'))
except gear.InterruptedError:
pass
except Exception:
diff --git a/zuul/lib/cloner.py b/zuul/lib/cloner.py
index bec8ebe..3070be6 100644
--- a/zuul/lib/cloner.py
+++ b/zuul/lib/cloner.py
@@ -102,7 +102,8 @@
new_repo = git.Repo.clone_from(git_cache, dest)
self.log.info("Updating origin remote in repo %s to %s",
project, git_upstream)
- new_repo.remotes.origin.config_writer.set('url', git_upstream)
+ new_repo.remotes.origin.config_writer.set('url',
+ git_upstream).release()
else:
self.log.info("Creating repo %s from upstream %s",
project, git_upstream)
diff --git a/zuul/lib/commandsocket.py b/zuul/lib/commandsocket.py
index 1b7fed9..ae62204 100644
--- a/zuul/lib/commandsocket.py
+++ b/zuul/lib/commandsocket.py
@@ -18,7 +18,7 @@
import os
import socket
import threading
-import Queue
+from six.moves import queue
class CommandSocket(object):
@@ -27,7 +27,7 @@
def __init__(self, path):
self.running = False
self.path = path
- self.queue = Queue.Queue()
+ self.queue = queue.Queue()
def start(self):
self.running = True
@@ -46,14 +46,14 @@
self.running = False
s = socket.socket(socket.AF_UNIX, socket.SOCK_STREAM)
s.connect(self.path)
- s.sendall('_stop\n')
+ s.sendall(b'_stop\n')
# The command '_stop' will be ignored by our listener, so
# directly inject it into the queue so that consumers of this
# class which are waiting in .get() are awakened. They can
# either handle '_stop' or just ignore the unknown command and
# then check to see if they should continue to run before
# re-entering their loop.
- self.queue.put('_stop')
+ self.queue.put(b'_stop')
self.socket_thread.join()
def _socketListener(self):
@@ -61,10 +61,10 @@
try:
s, addr = self.socket.accept()
self.log.debug("Accepted socket connection %s" % (s,))
- buf = ''
+ buf = b''
while True:
buf += s.recv(1)
- if buf[-1] == '\n':
+ if buf[-1:] == b'\n':
break
buf = buf.strip()
self.log.debug("Received %s from socket" % (buf,))
@@ -72,7 +72,7 @@
# Because we use '_stop' internally to wake up a
# waiting thread, don't allow it to actually be
# injected externally.
- if buf != '_stop':
+ if buf != b'_stop':
self.queue.put(buf)
except Exception:
self.log.exception("Exception in socket handler")
diff --git a/zuul/manager/__init__.py b/zuul/manager/__init__.py
index bdfde48..5b32e5b 100644
--- a/zuul/manager/__init__.py
+++ b/zuul/manager/__init__.py
@@ -426,7 +426,7 @@
build.result = 'CANCELED'
canceled = True
canceled_jobs.add(build.job.name)
- for jobname, nodeset in old_build_set.nodesets.items()[:]:
+ for jobname, nodeset in list(old_build_set.nodesets.items()):
if jobname in canceled_jobs:
continue
self.sched.nodepool.returnNodeSet(nodeset)
diff --git a/zuul/merger/client.py b/zuul/merger/client.py
index 14c6276..e164195 100644
--- a/zuul/merger/client.py
+++ b/zuul/merger/client.py
@@ -56,7 +56,7 @@
self.__merge_client.onBuildCompleted(job)
-class MergeJob(gear.Job):
+class MergeJob(gear.TextJob):
def __init__(self, *args, **kw):
super(MergeJob, self).__init__(*args, **kw)
self.__event = threading.Event()
diff --git a/zuul/merger/merger.py b/zuul/merger/merger.py
index 75c51af..714d643 100644
--- a/zuul/merger/merger.py
+++ b/zuul/merger/merger.py
@@ -64,13 +64,12 @@
self.local_path))
git.Repo.clone_from(self.remote_url, self.local_path)
repo = git.Repo(self.local_path)
- if self.email:
- repo.config_writer().set_value('user', 'email',
- self.email)
- if self.username:
- repo.config_writer().set_value('user', 'name',
- self.username)
- repo.config_writer().write()
+ with repo.config_writer() as config_writer:
+ if self.email:
+ config_writer.set_value('user', 'email', self.email)
+ if self.username:
+ config_writer.set_value('user', 'name', self.username)
+ config_writer.write()
self._initialized = True
def isInitialized(self):
@@ -200,7 +199,7 @@
tree = repo.commit(commit).tree
for fn in files:
if fn in tree:
- ret[fn] = tree[fn].data_stream.read()
+ ret[fn] = tree[fn].data_stream.read().decode('utf8')
else:
ret[fn] = None
return ret
diff --git a/zuul/merger/server.py b/zuul/merger/server.py
index 4daece5..c09d7ba 100644
--- a/zuul/merger/server.py
+++ b/zuul/merger/server.py
@@ -54,7 +54,7 @@
port = self.config.get('gearman', 'port')
else:
port = 4730
- self.worker = gear.Worker('Zuul Merger')
+ self.worker = gear.TextWorker('Zuul Merger')
self.worker.addServer(server, port)
self.log.debug("Waiting for server")
self.worker.waitForServer()
diff --git a/zuul/model.py b/zuul/model.py
index c2b4a9a..7f6223b 100644
--- a/zuul/model.py
+++ b/zuul/model.py
@@ -467,7 +467,7 @@
self.nodes[node.name] = node
def getNodes(self):
- return self.nodes.values()
+ return list(self.nodes.values())
def __repr__(self):
if self.name:
@@ -490,9 +490,10 @@
self.stat = None
self.uid = uuid4().hex
self.id = None
- # Zuul internal failure flag (not stored in ZK so it's not
+ # Zuul internal flags (not stored in ZK so they are not
# overwritten).
self.failed = False
+ self.canceled = False
@property
def fulfilled(self):
@@ -681,6 +682,8 @@
def __repr__(self):
return '<ZuulRole %s %s>' % (self.project_name, self.target_name)
+ __hash__ = object.__hash__
+
def __eq__(self, other):
if not isinstance(other, ZuulRole):
return False
@@ -808,6 +811,8 @@
return False
return True
+ __hash__ = object.__hash__
+
def __str__(self):
return self.name
@@ -985,7 +990,7 @@
raise
def getJobs(self):
- return self.jobs.values() # Report in the order of the layout config
+ return list(self.jobs.values()) # Report in the order of layout cfg
def _getDirectDependentJobs(self, parent_job):
ret = set()
@@ -1202,7 +1207,7 @@
return self.builds.get(job_name)
def getBuilds(self):
- keys = self.builds.keys()
+ keys = list(self.builds.keys())
keys.sort()
return [self.builds.get(x) for x in keys]
@@ -1231,7 +1236,7 @@
del self.node_requests[job_name]
def getTries(self, job_name):
- return self.tries.get(job_name)
+ return self.tries.get(job_name, 0)
def getMergeMode(self):
if self.layout:
@@ -1526,11 +1531,11 @@
except KeyError as e:
self.log.error("Error while formatting url for job %s: unknown "
"key %s in pattern %s"
- % (job, e.message, url_pattern))
+ % (job, e.args[0], url_pattern))
except AttributeError as e:
self.log.error("Error while formatting url for job %s: unknown "
"attribute %s in pattern %s"
- % (job, e.message, url_pattern))
+ % (job, e.args[0], url_pattern))
except Exception:
self.log.exception("Error while formatting url for job %s with "
"pattern %s:" % (job, url_pattern))
@@ -1810,6 +1815,8 @@
self.status = None
self.owner = None
+ self.source_event = None
+
def _id(self):
return '%s,%s' % (self.number, self.patchset)
@@ -1860,6 +1867,7 @@
def __init__(self, project):
super(PullRequest, self).__init__(project)
self.updated_at = None
+ self.title = None
def isUpdateOf(self, other):
if (hasattr(other, 'number') and self.number == other.number and
@@ -1893,6 +1901,7 @@
self.comment = None
self.label = None
self.unlabel = None
+ self.state = None
# ref-updated
self.ref = None
self.oldrev = None
@@ -1932,6 +1941,10 @@
class GithubTriggerEvent(TriggerEvent):
+ def __init__(self):
+ super(GithubTriggerEvent, self).__init__()
+ self.title = None
+
def isPatchsetCreated(self):
if self.type == 'pull_request':
return self.action in ['opened', 'changed']
@@ -2040,7 +2053,7 @@
def __init__(self, trigger, types=[], branches=[], refs=[],
event_approvals={}, comments=[], emails=[], usernames=[],
timespecs=[], required_approvals=[], reject_approvals=[],
- pipelines=[], actions=[], labels=[], unlabels=[],
+ pipelines=[], actions=[], labels=[], unlabels=[], states=[],
ignore_deletes=True):
super(EventFilter, self).__init__(
required_approvals=required_approvals,
@@ -2065,6 +2078,7 @@
self.timespecs = timespecs
self.labels = labels
self.unlabels = unlabels
+ self.states = states
self.ignore_deletes = ignore_deletes
def __repr__(self):
@@ -2103,6 +2117,8 @@
ret += ' labels: %s' % ', '.join(self.labels)
if self.unlabels:
ret += ' unlabels: %s' % ', '.join(self.unlabels)
+ if self.states:
+ ret += ' states: %s' % ', '.join(self.states)
ret += '>'
return ret
@@ -2215,6 +2231,10 @@
if self.unlabels and event.unlabel not in self.unlabels:
return False
+ # states are ORed
+ if self.states and event.state not in self.states:
+ return False
+
return True
@@ -2313,7 +2333,7 @@
raise Exception("Configuration item dictionaries must have "
"a single key (when parsing %s)" %
(conf,))
- key, value = item.items()[0]
+ key, value = list(item.items())[0]
if key == 'tenant':
self.tenants.append(value)
else:
@@ -2371,7 +2391,7 @@
raise Exception("Configuration item dictionaries must have "
"a single key (when parsing %s)" %
(conf,))
- key, value = item.items()[0]
+ key, value = list(item.items())[0]
if key == 'project':
name = value['name']
self.projects.setdefault(name, []).append(value)
@@ -2678,7 +2698,7 @@
if hostname:
project = hostname_dict.get(hostname)
else:
- values = hostname_dict.values()
+ values = list(hostname_dict.values())
if len(values) == 1:
project = values[0]
else:
@@ -2722,7 +2742,7 @@
def load(self):
if not os.path.exists(self.path):
return
- with open(self.path) as f:
+ with open(self.path, 'rb') as f:
data = struct.unpack(self.format, f.read())
version = data[0]
if version != self.version:
@@ -2738,7 +2758,7 @@
data.extend(self.failure_times)
data.extend(self.results)
data = struct.pack(self.format, *data)
- with open(tmpfile, 'w') as f:
+ with open(tmpfile, 'wb') as f:
f.write(data)
os.rename(tmpfile, self.path)
diff --git a/zuul/nodepool.py b/zuul/nodepool.py
index e94b950..8f6489c 100644
--- a/zuul/nodepool.py
+++ b/zuul/nodepool.py
@@ -38,11 +38,11 @@
def cancelRequest(self, request):
self.log.info("Canceling node request %s" % (request,))
if request.uid in self.requests:
+ request.canceled = True
try:
self.sched.zk.deleteNodeRequest(request)
except Exception:
self.log.exception("Error deleting node request:")
- del self.requests[request.uid]
def useNodeSet(self, nodeset):
self.log.info("Setting nodeset %s in use" % (nodeset,))
@@ -98,6 +98,10 @@
if request.uid not in self.requests:
return False
+ if request.canceled:
+ del self.requests[request.uid]
+ return False
+
if request.state in (model.STATE_FULFILLED, model.STATE_FAILED):
self.log.info("Node request %s %s" % (request, request.state))
@@ -119,6 +123,11 @@
self.log.info("Accepting node request %s" % (request,))
+ if request.canceled:
+ self.log.info("Ignoring canceled node request %s" % (request,))
+ # The request was already deleted when it was canceled
+ return
+
locked = False
if request.fulfilled:
# If the request suceeded, try to lock the nodes.
diff --git a/zuul/reporter/__init__.py b/zuul/reporter/__init__.py
index 5e25e7c..582265d 100644
--- a/zuul/reporter/__init__.py
+++ b/zuul/reporter/__init__.py
@@ -74,7 +74,12 @@
return ret
def _formatItemReportStart(self, pipeline, item, with_jobs=True):
- return pipeline.start_message.format(pipeline=pipeline)
+ status_url = ''
+ if self.connection.sched.config.has_option('zuul', 'status_url'):
+ status_url = self.connection.sched.config.get('zuul',
+ 'status_url')
+ return pipeline.start_message.format(pipeline=pipeline,
+ status_url=status_url)
def _formatItemReportSuccess(self, pipeline, item, with_jobs=True):
msg = pipeline.success_message
diff --git a/zuul/rpcclient.py b/zuul/rpcclient.py
index 9d81520..d980992 100644
--- a/zuul/rpcclient.py
+++ b/zuul/rpcclient.py
@@ -35,9 +35,9 @@
def submitJob(self, name, data):
self.log.debug("Submitting job %s with data %s" % (name, data))
- job = gear.Job(name,
- json.dumps(data),
- unique=str(time.time()))
+ job = gear.TextJob(name,
+ json.dumps(data),
+ unique=str(time.time()))
self.gearman.submitJob(job, timeout=300)
self.log.debug("Waiting for job completion")
diff --git a/zuul/rpclistener.py b/zuul/rpclistener.py
index 105c34b..6508e84 100644
--- a/zuul/rpclistener.py
+++ b/zuul/rpclistener.py
@@ -38,7 +38,7 @@
port = self.config.get('gearman', 'port')
else:
port = 4730
- self.worker = gear.Worker('Zuul RPC Listener')
+ self.worker = gear.TextWorker('Zuul RPC Listener')
self.worker.addServer(server, port)
self.worker.waitForServer()
self.register()
diff --git a/zuul/scheduler.py b/zuul/scheduler.py
index 2e9bef2..a67973e 100644
--- a/zuul/scheduler.py
+++ b/zuul/scheduler.py
@@ -871,6 +871,8 @@
build_set = request.build_set
self.nodepool.acceptNodes(request)
+ if request.canceled:
+ return
if build_set is not build_set.item.current_build_set:
self.log.warning("Build set %s is not current" % (build_set,))
diff --git a/zuul/webapp.py b/zuul/webapp.py
index 37d6ddd..e4feaa0 100644
--- a/zuul/webapp.py
+++ b/zuul/webapp.py
@@ -128,7 +128,7 @@
def app(self, request):
# Try registered paths without a tenant_name first
path = request.path
- for path_re, handler in self.routes.itervalues():
+ for path_re, handler in self.routes.values():
if path_re.match(path):
return handler(path, '', request)
@@ -138,7 +138,7 @@
# Handle keys
if path.startswith('/keys'):
return self._handle_keys(request, path)
- for path_re, handler in self.routes.itervalues():
+ for path_re, handler in self.routes.values():
if path_re.match(path):
return handler(path, tenant_name, request)
else:
@@ -147,7 +147,8 @@
def status(self, path, tenant_name, request):
def func():
return webob.Response(body=self.cache[tenant_name],
- content_type='application/json')
+ content_type='application/json',
+ charset='utf8')
return self._response_with_status_cache(func, tenant_name)
def change(self, path, tenant_name, request):
@@ -157,7 +158,8 @@
status = self._status_for_change(change_id, tenant_name)
if status:
return webob.Response(body=status,
- content_type='application/json')
+ content_type='application/json',
+ charset='utf8')
else:
raise webob.exc.HTTPNotFound()
return self._response_with_status_cache(func, tenant_name)
diff --git a/zuul/zk.py b/zuul/zk.py
index 5cd7bee..31b85ea 100644
--- a/zuul/zk.py
+++ b/zuul/zk.py
@@ -59,10 +59,10 @@
self._became_lost = False
def _dictToStr(self, data):
- return json.dumps(data)
+ return json.dumps(data).encode('utf8')
def _strToDict(self, data):
- return json.loads(data)
+ return json.loads(data.decode('utf8'))
def _connection_listener(self, state):
'''
@@ -168,7 +168,7 @@
if data:
data = self._strToDict(data)
node_request.updateFromDict(data)
- request_nodes = node_request.nodeset.getNodes()
+ request_nodes = list(node_request.nodeset.getNodes())
for i, nodeid in enumerate(data.get('nodes', [])):
node_path = '%s/%s' % (self.NODE_ROOT, nodeid)
node_data, node_stat = self.client.get(node_path)