Fix pep8 issues

The pep8 jobs aren't running in gate at the moment.
Fix up the pep8 issues and remove the tox filter that stopped it
from running.

Also ignore E129 (visually indented line with same indent as next
logical line) as we don't follow it.

Change-Id: I394708ba96797bbc6fcd951e6436a104be0a3746
This commit is contained in:
Joshua Hesketh 2014-08-19 16:27:42 +10:00
parent 7078724d42
commit 29d99b7eb1
15 changed files with 167 additions and 124 deletions

View File

@ -262,14 +262,16 @@ class FakeChange(object):
granted_on=None):
if not granted_on:
granted_on = time.time()
approval = {'description': self.categories[category][0],
'type': category,
'value': str(value),
'by': {
'username': username,
'email': username + '@example.com',
},
'grantedOn': int(granted_on)}
approval = {
'description': self.categories[category][0],
'type': category,
'value': str(value),
'by': {
'username': username,
'email': username + '@example.com',
},
'grantedOn': int(granted_on)
}
for i, x in enumerate(self.patchsets[-1]['approvals'][:]):
if x['by']['username'] == username and x['type'] == category:
del self.patchsets[-1]['approvals'][i]
@ -359,7 +361,7 @@ class FakeChange(object):
def setMerged(self):
if (self.depends_on_change and
self.depends_on_change.data['status'] != 'MERGED'):
self.depends_on_change.data['status'] != 'MERGED'):
return
if self.fail_merge:
return
@ -420,7 +422,7 @@ class FakeGerrit(object):
# project
self.queries.append(query)
l = [change.query() for change in self.changes.values()]
l.append({"type":"stats","rowCount":1,"runTimeMilliseconds":3})
l.append({"type": "stats", "rowCount": 1, "runTimeMilliseconds": 3})
return l
def startWatching(self, *args, **kw):
@ -835,7 +837,8 @@ class ZuulTestCase(testtools.TestCase):
'%(levelname)-8s %(message)s'))
if USE_TEMPDIR:
tmp_root = self.useFixture(fixtures.TempDir(
rootdir=os.environ.get("ZUUL_TEST_ROOT"))).path
rootdir=os.environ.get("ZUUL_TEST_ROOT"))
).path
else:
tmp_root = os.environ.get("ZUUL_TEST_ROOT")
self.test_root = os.path.join(tmp_root, "zuul-test")
@ -934,7 +937,8 @@ class ZuulTestCase(testtools.TestCase):
self.sched.registerTrigger(self.gerrit)
self.timer = zuul.trigger.timer.Timer(self.config, self.sched)
self.sched.registerTrigger(self.timer)
self.zuultrigger = zuul.trigger.zuultrigger.ZuulTrigger(self.config, self.sched)
self.zuultrigger = zuul.trigger.zuultrigger.ZuulTrigger(self.config,
self.sched)
self.sched.registerTrigger(self.zuultrigger)
self.sched.registerReporter(

View File

@ -25,7 +25,6 @@ import git
import zuul.lib.cloner
from tests.base import ZuulTestCase
from tests.base import FIXTURE_DIR
logging.basicConfig(level=logging.DEBUG,
format='%(asctime)s %(name)-32s '
@ -81,11 +80,10 @@ class TestCloner(ZuulTestCase):
B.setMerged()
upstream = self.getUpstreamRepos(projects)
states = [
{'org/project1': self.builds[0].parameters['ZUUL_COMMIT'],
'org/project2': str(upstream['org/project2'].commit('master')),
},
]
states = [{
'org/project1': self.builds[0].parameters['ZUUL_COMMIT'],
'org/project2': str(upstream['org/project2'].commit('master')),
}]
for number, build in enumerate(self.builds):
self.log.debug("Build parameters: %s", build.parameters)
@ -97,7 +95,7 @@ class TestCloner(ZuulTestCase):
zuul_ref=build.parameters['ZUUL_REF'],
zuul_url=self.git_root,
cache_dir=cache_root,
)
)
cloner.execute()
work = self.getWorkspaceRepos(projects)
state = states[number]
@ -110,9 +108,11 @@ class TestCloner(ZuulTestCase):
work = self.getWorkspaceRepos(projects)
upstream_repo_path = os.path.join(self.upstream_root, 'org/project1')
self.assertEquals(work['org/project1'].remotes.origin.url,
upstream_repo_path,
'workspace repo origin should be upstream, not cache')
self.assertEquals(
work['org/project1'].remotes.origin.url,
upstream_repo_path,
'workspace repo origin should be upstream, not cache'
)
self.worker.hold_jobs_in_build = False
self.worker.release()
@ -141,7 +141,7 @@ class TestCloner(ZuulTestCase):
{'org/project1': self.builds[0].parameters['ZUUL_COMMIT'],
'org/project2': self.builds[1].parameters['ZUUL_COMMIT'],
},
]
]
for number, build in enumerate(self.builds):
self.log.debug("Build parameters: %s", build.parameters)
@ -152,7 +152,7 @@ class TestCloner(ZuulTestCase):
zuul_branch=build.parameters['ZUUL_BRANCH'],
zuul_ref=build.parameters['ZUUL_REF'],
zuul_url=self.git_root,
)
)
cloner.execute()
work = self.getWorkspaceRepos(projects)
state = states[number]
@ -177,7 +177,8 @@ class TestCloner(ZuulTestCase):
self.create_branch('org/project2', 'stable/havana')
self.create_branch('org/project4', 'stable/havana')
A = self.fake_gerrit.addFakeChange('org/project1', 'master', 'A')
B = self.fake_gerrit.addFakeChange('org/project2', 'stable/havana', 'B')
B = self.fake_gerrit.addFakeChange('org/project2', 'stable/havana',
'B')
C = self.fake_gerrit.addFakeChange('org/project3', 'master', 'C')
A.addApproval('CRVW', 2)
B.addApproval('CRVW', 2)
@ -210,7 +211,7 @@ class TestCloner(ZuulTestCase):
'org/project4': str(upstream['org/project4'].
commit('master')),
},
]
]
for number, build in enumerate(self.builds):
self.log.debug("Build parameters: %s", build.parameters)
@ -221,7 +222,7 @@ class TestCloner(ZuulTestCase):
zuul_branch=build.parameters['ZUUL_BRANCH'],
zuul_ref=build.parameters['ZUUL_REF'],
zuul_url=self.git_root,
)
)
cloner.execute()
work = self.getWorkspaceRepos(projects)
state = states[number]
@ -249,9 +250,11 @@ class TestCloner(ZuulTestCase):
self.create_branch('org/project5', 'stable/havana')
A = self.fake_gerrit.addFakeChange('org/project1', 'master', 'A')
B = self.fake_gerrit.addFakeChange('org/project2', 'master', 'B')
C = self.fake_gerrit.addFakeChange('org/project3', 'stable/havana', 'C')
C = self.fake_gerrit.addFakeChange('org/project3', 'stable/havana',
'C')
D = self.fake_gerrit.addFakeChange('org/project3', 'master', 'D')
E = self.fake_gerrit.addFakeChange('org/project4', 'stable/havana', 'E')
E = self.fake_gerrit.addFakeChange('org/project4', 'stable/havana',
'E')
A.addApproval('CRVW', 2)
B.addApproval('CRVW', 2)
C.addApproval('CRVW', 2)
@ -271,46 +274,61 @@ class TestCloner(ZuulTestCase):
upstream = self.getUpstreamRepos(projects)
states = [
{'org/project1': self.builds[0].parameters['ZUUL_COMMIT'],
'org/project2': str(upstream['org/project2'].commit('stable/havana')),
'org/project3': str(upstream['org/project3'].commit('stable/havana')),
'org/project4': str(upstream['org/project4'].commit('stable/havana')),
'org/project5': str(upstream['org/project5'].commit('stable/havana')),
'org/project2': str(upstream['org/project2'].commit(
'stable/havana')),
'org/project3': str(upstream['org/project3'].commit(
'stable/havana')),
'org/project4': str(upstream['org/project4'].commit(
'stable/havana')),
'org/project5': str(upstream['org/project5'].commit(
'stable/havana')),
'org/project6': str(upstream['org/project6'].commit('master')),
},
{'org/project1': self.builds[0].parameters['ZUUL_COMMIT'],
'org/project2': str(upstream['org/project2'].commit('stable/havana')),
'org/project3': str(upstream['org/project3'].commit('stable/havana')),
'org/project4': str(upstream['org/project4'].commit('stable/havana')),
'org/project5': str(upstream['org/project5'].commit('stable/havana')),
'org/project2': str(upstream['org/project2'].commit(
'stable/havana')),
'org/project3': str(upstream['org/project3'].commit(
'stable/havana')),
'org/project4': str(upstream['org/project4'].commit(
'stable/havana')),
'org/project5': str(upstream['org/project5'].commit(
'stable/havana')),
'org/project6': str(upstream['org/project6'].commit('master')),
},
{'org/project1': self.builds[0].parameters['ZUUL_COMMIT'],
'org/project2': str(upstream['org/project2'].commit('stable/havana')),
'org/project2': str(upstream['org/project2'].commit(
'stable/havana')),
'org/project3': self.builds[2].parameters['ZUUL_COMMIT'],
'org/project4': str(upstream['org/project4'].commit('stable/havana')),
'org/project4': str(upstream['org/project4'].commit(
'stable/havana')),
'org/project5': str(upstream['org/project5'].commit('stable/havana')),
'org/project5': str(upstream['org/project5'].commit(
'stable/havana')),
'org/project6': str(upstream['org/project6'].commit('master')),
},
{'org/project1': self.builds[0].parameters['ZUUL_COMMIT'],
'org/project2': str(upstream['org/project2'].commit('stable/havana')),
'org/project2': str(upstream['org/project2'].commit(
'stable/havana')),
'org/project3': self.builds[2].parameters['ZUUL_COMMIT'],
'org/project4': str(upstream['org/project4'].commit('stable/havana')),
'org/project5': str(upstream['org/project5'].commit('stable/havana')),
'org/project4': str(upstream['org/project4'].commit(
'stable/havana')),
'org/project5': str(upstream['org/project5'].commit(
'stable/havana')),
'org/project6': str(upstream['org/project6'].commit('master')),
},
{'org/project1': self.builds[0].parameters['ZUUL_COMMIT'],
'org/project2': str(upstream['org/project2'].commit('stable/havana')),
'org/project2': str(upstream['org/project2'].commit(
'stable/havana')),
'org/project3': self.builds[2].parameters['ZUUL_COMMIT'],
'org/project4': self.builds[4].parameters['ZUUL_COMMIT'],
'org/project5': str(upstream['org/project5'].commit('stable/havana')),
'org/project5': str(upstream['org/project5'].commit(
'stable/havana')),
'org/project6': str(upstream['org/project6'].commit('master')),
},
]
]
for number, build in enumerate(self.builds):
self.log.debug("Build parameters: %s", build.parameters)
change_number = int(build.parameters['ZUUL_CHANGE'])
cloner = zuul.lib.cloner.Cloner(
git_base_url=self.upstream_root,
projects=projects,
@ -318,8 +336,8 @@ class TestCloner(ZuulTestCase):
zuul_branch=build.parameters['ZUUL_BRANCH'],
zuul_ref=build.parameters['ZUUL_REF'],
zuul_url=self.git_root,
branch='stable/havana', # Old branch for upgrade
)
branch='stable/havana', # Old branch for upgrade
)
cloner.execute()
work = self.getWorkspaceRepos(projects)
state = states[number]
@ -369,11 +387,10 @@ class TestCloner(ZuulTestCase):
'org/project5': str(upstream['org/project5'].commit('master')),
'org/project6': str(upstream['org/project6'].commit('master')),
},
]
]
for number, build in enumerate(self.builds):
self.log.debug("Build parameters: %s", build.parameters)
change_number = int(build.parameters['ZUUL_CHANGE'])
cloner = zuul.lib.cloner.Cloner(
git_base_url=self.upstream_root,
projects=projects,
@ -381,8 +398,8 @@ class TestCloner(ZuulTestCase):
zuul_branch=build.parameters['ZUUL_BRANCH'],
zuul_ref=build.parameters['ZUUL_REF'],
zuul_url=self.git_root,
branch='master', # New branch for upgrade
)
branch='master', # New branch for upgrade
)
cloner.execute()
work = self.getWorkspaceRepos(projects)
state = states[number]
@ -410,7 +427,8 @@ class TestCloner(ZuulTestCase):
A = self.fake_gerrit.addFakeChange('org/project1', 'master', 'A')
B = self.fake_gerrit.addFakeChange('org/project1', 'master', 'B')
C = self.fake_gerrit.addFakeChange('org/project2', 'master', 'C')
D = self.fake_gerrit.addFakeChange('org/project3', 'stable/havana', 'D')
D = self.fake_gerrit.addFakeChange('org/project3', 'stable/havana',
'D')
A.addApproval('CRVW', 2)
B.addApproval('CRVW', 2)
C.addApproval('CRVW', 2)
@ -452,13 +470,13 @@ class TestCloner(ZuulTestCase):
'org/project3': self.builds[3].parameters['ZUUL_COMMIT'],
'org/project4': str(upstream['org/project4'].commit('master')),
'org/project5': str(upstream['org/project5'].commit('master')),
'org/project6': str(upstream['org/project6'].commit('stable/havana')),
'org/project6': str(upstream['org/project6'].commit(
'stable/havana')),
},
]
]
for number, build in enumerate(self.builds):
self.log.debug("Build parameters: %s", build.parameters)
change_number = int(build.parameters['ZUUL_CHANGE'])
cloner = zuul.lib.cloner.Cloner(
git_base_url=self.upstream_root,
projects=projects,
@ -467,7 +485,7 @@ class TestCloner(ZuulTestCase):
zuul_ref=build.parameters['ZUUL_REF'],
zuul_url=self.git_root,
project_branches={'org/project4': 'master'},
)
)
cloner.execute()
work = self.getWorkspaceRepos(projects)
state = states[number]
@ -514,11 +532,13 @@ class TestCloner(ZuulTestCase):
upstream = self.getUpstreamRepos(projects)
states = [
{'org/project': str(upstream['org/project'].commit('stable/havana')),
{'org/project':
str(upstream['org/project'].commit('stable/havana')),
},
{'org/project': str(upstream['org/project'].commit('stable/havana')),
{'org/project':
str(upstream['org/project'].commit('stable/havana')),
},
]
]
for number, build in enumerate(builds):
self.log.debug("Build parameters: %s", build.parameters)
@ -530,7 +550,7 @@ class TestCloner(ZuulTestCase):
zuul_ref=build.parameters.get('ZUUL_REF', None),
zuul_url=self.git_root,
branch='stable/havana',
)
)
cloner.execute()
work = self.getWorkspaceRepos(projects)
state = states[number]

View File

@ -1427,10 +1427,10 @@ class TestScheduler(ZuulTestCase):
self.waitUntilSettled()
# For debugging purposes...
#for pipeline in self.sched.layout.pipelines.values():
# for queue in pipeline.queues:
# self.log.info("pipepline %s queue %s contents %s" % (
# pipeline.name, queue.name, queue.queue))
# for pipeline in self.sched.layout.pipelines.values():
# for queue in pipeline.queues:
# self.log.info("pipepline %s queue %s contents %s" % (
# pipeline.name, queue.name, queue.queue))
self.worker.release('.*-merge')
self.waitUntilSettled()

View File

@ -15,7 +15,6 @@
# under the License.
import logging
import time
from tests.base import ZuulTestCase
@ -46,9 +45,9 @@ class TestZuulTrigger(ZuulTestCase):
A.addApproval('CRVW', 2)
B1.addApproval('CRVW', 2)
B2.addApproval('CRVW', 2)
A.addApproval('VRFY', 1) # required by gate
B1.addApproval('VRFY', -1) # should go to check
B2.addApproval('VRFY', 1) # should go to gate
A.addApproval('VRFY', 1) # required by gate
B1.addApproval('VRFY', -1) # should go to check
B2.addApproval('VRFY', 1) # should go to gate
B1.addApproval('APRV', 1)
B2.addApproval('APRV', 1)
B1.setDependsOn(A, 1)
@ -106,11 +105,14 @@ class TestZuulTrigger(ZuulTestCase):
self.assertEqual(C.reported, 0)
self.assertEqual(D.reported, 0)
self.assertEqual(E.reported, 0)
self.assertEqual(B.messages[0],
self.assertEqual(
B.messages[0],
"Merge Failed.\n\nThis change was unable to be automatically "
"merged with the current state of the repository. Please rebase "
"your change and upload a new patchset.")
self.assertEqual(self.fake_gerrit.queries[0], "project:org/project status:open")
self.assertEqual(self.fake_gerrit.queries[0],
"project:org/project status:open")
# Reconfigure and run the test again. This is a regression
# check to make sure that we don't end up with a stale trigger
@ -129,8 +131,10 @@ class TestZuulTrigger(ZuulTestCase):
self.assertEqual(C.reported, 0)
self.assertEqual(D.reported, 2)
self.assertEqual(E.reported, 1)
self.assertEqual(E.messages[0],
self.assertEqual(
E.messages[0],
"Merge Failed.\n\nThis change was unable to be automatically "
"merged with the current state of the repository. Please rebase "
"your change and upload a new patchset.")
self.assertEqual(self.fake_gerrit.queries[1], "project:org/project status:open")
self.assertEqual(self.fake_gerrit.queries[1],
"project:org/project status:open")

View File

@ -20,7 +20,7 @@ commands =
downloadcache = ~/cache/pip
[testenv:pep8]
commands = flake8
commands = flake8 {posargs}
[testenv:cover]
commands =
@ -36,7 +36,8 @@ commands = {posargs}
commands = zuul-server -c etc/zuul.conf-sample -t -l {posargs}
[flake8]
ignore = E125,H
select = H231
# These are ignored intentionally in openstack-infra projects;
# please don't submit patches that solely correct them or enable them.
ignore = E125,E129,H
show-source = True
exclude = .venv,.tox,dist,doc,build,*.egg

View File

@ -65,20 +65,20 @@ class Cloner(zuul.cmd.ZuulApp):
project_env = parser.add_argument_group(
'project tuning'
)
)
project_env.add_argument(
'--branch',
help=('branch to checkout instead of Zuul selected branch, '
'for example to specify an alternate branch to test '
'client library compatibility.')
)
)
project_env.add_argument(
'--project-branch', nargs=1, action='append',
metavar='PROJECT=BRANCH',
help=('project-specific branch to checkout which takes precedence '
'over --branch if it is provided; may be specified multiple '
'times.')
)
)
zuul_env = parser.add_argument_group(
'zuul environnement',

View File

@ -165,7 +165,8 @@ class Server(zuul.cmd.ZuulApp):
merger = zuul.merger.client.MergeClient(self.config, self.sched)
gerrit = zuul.trigger.gerrit.Gerrit(self.config, self.sched)
timer = zuul.trigger.timer.Timer(self.config, self.sched)
zuultrigger = zuul.trigger.zuultrigger.ZuulTrigger(self.config, self.sched)
zuultrigger = zuul.trigger.zuultrigger.ZuulTrigger(self.config,
self.sched)
if self.config.has_option('zuul', 'status_expiry'):
cache_expiry = self.config.getint('zuul', 'status_expiry')
else:

View File

@ -20,6 +20,7 @@ import string
from zuul.trigger import gerrit
# Several forms accept either a single item or a list, this makes
# specifying that in the schema easy (and explicit).
def toList(x):
@ -152,11 +153,11 @@ class LayoutSchema(object):
def validateJob(self, value, path=[]):
if isinstance(value, list):
for (i, v) in enumerate(value):
self.validateJob(v, path + [i])
for (i, val) in enumerate(value):
self.validateJob(val, path + [i])
elif isinstance(value, dict):
for k, v in value.items():
self.validateJob(v, path + [k])
for k, val in value.items():
self.validateJob(val, path + [k])
else:
self.job_name.schema(value)
@ -278,4 +279,3 @@ class LayoutValidator(object):
for pipeline in data['pipelines']:
if 'gerrit' in pipeline['trigger']:
gerrit.validate_trigger(pipeline['trigger'])

View File

@ -80,8 +80,7 @@ class Cloner(object):
new_repo = git.Repo.clone_from(git_cache, dest)
self.log.info("Updating origin remote in repo %s to %s",
project, git_upstream)
origin = new_repo.remotes.origin.config_writer.set(
'url', git_upstream)
new_repo.remotes.origin.config_writer.set('url', git_upstream)
else:
self.log.info("Creating repo %s from upstream %s",
project, git_upstream)

View File

@ -45,7 +45,8 @@ class Swift(object):
try:
if self.config.has_section('swift'):
if (not self.config.has_option('swift', 'Send-Temp-Url-Key')
or self.config.getboolean('swift', 'Send-Temp-Url-Key')):
or self.config.getboolean('swift',
'Send-Temp-Url-Key')):
self.connect()
# Tell swift of our key

View File

@ -105,7 +105,7 @@ class Repo(object):
def getCommitFromRef(self, refname):
repo = self.createRepoObject()
if not refname in repo.refs:
if refname not in repo.refs:
return None
ref = repo.refs[refname]
return ref.commit

View File

@ -266,8 +266,8 @@ class Pipeline(object):
j_changes = []
j_changes.append(e.formatJSON())
if (len(j_changes) > 1 and
(j_changes[-2]['remaining_time'] is not None) and
(j_changes[-1]['remaining_time'] is not None)):
(j_changes[-2]['remaining_time'] is not None) and
(j_changes[-1]['remaining_time'] is not None)):
j_changes[-1]['remaining_time'] = max(
j_changes[-2]['remaining_time'],
j_changes[-1]['remaining_time'])
@ -340,7 +340,7 @@ class ChangeQueue(object):
for job in self._jobs:
if job.queue_name:
if (self.assigned_name and
job.queue_name != self.assigned_name):
job.queue_name != self.assigned_name):
raise Exception("More than one name assigned to "
"change queue: %s != %s" %
(self.assigned_name, job.queue_name))
@ -1150,7 +1150,7 @@ class EventFilter(BaseFilter):
matches_email_re = False
for email_re in self.emails:
if (account_email is not None and
email_re.search(account_email)):
email_re.search(account_email)):
matches_email_re = True
if self.emails and not matches_email_re:
return False

View File

@ -235,7 +235,8 @@ class Scheduler(threading.Thread):
pipeline = Pipeline(conf_pipeline['name'])
pipeline.description = conf_pipeline.get('description')
# TODO(jeblair): remove backwards compatibility:
pipeline.source = self.triggers[conf_pipeline.get('source', 'gerrit')]
pipeline.source = self.triggers[conf_pipeline.get('source',
'gerrit')]
precedence = model.PRECEDENCE_MAP[conf_pipeline.get('precedence')]
pipeline.precedence = precedence
pipeline.failure_message = conf_pipeline.get('failure-message',
@ -314,16 +315,19 @@ class Scheduler(threading.Thread):
usernames = toList(trigger.get('username'))
if not usernames:
usernames = toList(trigger.get('username_filter'))
f = EventFilter(trigger=self.triggers['gerrit'],
types=toList(trigger['event']),
branches=toList(trigger.get('branch')),
refs=toList(trigger.get('ref')),
event_approvals=approvals,
comments=comments,
emails=emails,
usernames=usernames,
required_approvals=
toList(trigger.get('require-approval')))
f = EventFilter(
trigger=self.triggers['gerrit'],
types=toList(trigger['event']),
branches=toList(trigger.get('branch')),
refs=toList(trigger.get('ref')),
event_approvals=approvals,
comments=comments,
emails=emails,
usernames=usernames,
required_approvals=toList(
trigger.get('require-approval')
)
)
manager.event_filters.append(f)
if 'timer' in conf_pipeline['trigger']:
for trigger in toList(conf_pipeline['trigger']['timer']):
@ -333,11 +337,14 @@ class Scheduler(threading.Thread):
manager.event_filters.append(f)
if 'zuul' in conf_pipeline['trigger']:
for trigger in toList(conf_pipeline['trigger']['zuul']):
f = EventFilter(trigger=self.triggers['zuul'],
types=toList(trigger['event']),
pipelines=toList(trigger.get('pipeline')),
required_approvals=
toList(trigger.get('require-approval')))
f = EventFilter(
trigger=self.triggers['zuul'],
types=toList(trigger['event']),
pipelines=toList(trigger.get('pipeline')),
required_approvals=toList(
trigger.get('require-approval')
)
)
manager.event_filters.append(f)
for project_template in data.get('project-templates', []):
@ -692,7 +699,7 @@ class Scheduler(threading.Thread):
break
for item in shared_queue.queue:
if (item.change.number == change_ids[0][0] and
item.change.patchset == change_ids[0][1]):
item.change.patchset == change_ids[0][1]):
change_queue = shared_queue
break
if not change_queue:
@ -702,7 +709,7 @@ class Scheduler(threading.Thread):
found = False
for item in change_queue.queue:
if (item.change.number == number and
item.change.patchset == patchset):
item.change.patchset == patchset):
found = True
items_to_enqueue.append(item)
break
@ -1157,7 +1164,8 @@ class BasePipelineManager(object):
item.enqueue_time = enqueue_time
self.reportStats(item)
self.enqueueChangesBehind(change, quiet, ignore_requirements)
self.sched.triggers['zuul'].onChangeEnqueued(item.change, self.pipeline)
self.sched.triggers['zuul'].onChangeEnqueued(item.change,
self.pipeline)
else:
self.log.error("Unable to find change queue for project %s" %
change.project)

View File

@ -250,7 +250,7 @@ class Gerrit(object):
data = change._data
if not data:
return False
if not 'submitRecords' in data:
if 'submitRecords' not in data:
return False
try:
for sr in data['submitRecords']:
@ -328,15 +328,18 @@ class Gerrit(object):
# This is a best-effort function in case Gerrit is unable to return
# a particular change. It happens.
query = "project:%s status:open" % (project.name,)
self.log.debug("Running query %s to get project open changes" % (query,))
self.log.debug("Running query %s to get project open changes" %
(query,))
data = self.gerrit.simpleQuery(query)
changes = []
for record in data:
try:
changes.append(self._getChange(record['number'],
record['currentPatchSet']['number']))
changes.append(
self._getChange(record['number'],
record['currentPatchSet']['number']))
except Exception:
self.log.exception("Unable to query change %s" % (record.get('number'),))
self.log.exception("Unable to query change %s" %
(record.get('number'),))
return changes
def updateChange(self, change):
@ -423,4 +426,3 @@ def validate_trigger(trigger_data):
raise voluptuous.Invalid(
"The event %s does not include ref information, Zuul cannot "
"use ref filter 'ref: %s'" % (event['event'], event['ref']))

View File

@ -47,8 +47,9 @@ class ZuulTrigger(object):
try:
self._createProjectChangeMergedEvents(change)
except Exception:
self.log.exception("Unable to create project-change-merged events for %s" %
(change,))
self.log.exception(
"Unable to create project-change-merged events for "
"%s" % (change,))
def onChangeEnqueued(self, change, pipeline):
# Called each time a change is enqueued in a pipeline
@ -56,11 +57,13 @@ class ZuulTrigger(object):
try:
self._createParentChangeEnqueuedEvents(change, pipeline)
except Exception:
self.log.exception("Unable to create parent-change-enqueued events for %s in %s" %
(change, pipeline))
self.log.exception(
"Unable to create parent-change-enqueued events for "
"%s in %s" % (change, pipeline))
def _createProjectChangeMergedEvents(self, change):
changes = self.sched.triggers['gerrit'].getProjectOpenChanges(change.project)
changes = self.sched.triggers['gerrit'].getProjectOpenChanges(
change.project)
for open_change in changes:
self._createProjectChangeMergedEvent(open_change)