Move timer tests to commitConfigUpdate

These can't use simple_layout because they need to make changes
before loading the timer configuration, so use the new
commitConfigUpdate method to swap in their configuration.  Update
it to ensure that all necessary playbooks are created.

Change-Id: I3ad25d6db2030c2aae884700115b095e8f481f2c
This commit is contained in:
James E. Blair
2017-04-20 10:19:20 -07:00
parent 9ea0d0b937
commit dfdfcfceaa
18 changed files with 38 additions and 45 deletions

View File

@@ -2069,12 +2069,18 @@ class ZuulTestCase(BaseTestCase):
"""
source_path = os.path.join(FIXTURE_DIR, source_name)
commit_data = {}
with open(source_path, 'r') as nt:
commit_data['zuul.yaml'] = nt.read()
files = {}
with open(source_path, 'r') as f:
data = f.read()
layout = yaml.safe_load(data)
files['zuul.yaml'] = data
for item in layout:
if 'job' in item:
jobname = item['job']['name']
files['playbooks/%s.yaml' % jobname] = ''
before = self.addCommitToRepo(
project_name, 'Pulling content from %s' % source_name,
commit_data)
files)
return before
def addEvent(self, connection, event):

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

@@ -1742,11 +1742,13 @@ class TestScheduler(ZuulTestCase):
def test_abandoned_not_timer(self):
"Test that an abandoned change does not cancel timer jobs"
# This test can not use simple_layout because it must start
# with a configuration which does not include a
# timer-triggered job so that we have an opportunity to set
# the hold flag before the first job.
self.executor_server.hold_jobs_in_build = True
# Start timer trigger - also org/project
self.updateConfigLayout('layout-idle')
self.commitConfigUpdate('common-config', 'layouts/idle.yaml')
self.sched.reconfigure(self.config)
# The pipeline triggers every second, so we should have seen
# several by now.
@@ -1755,9 +1757,9 @@ class TestScheduler(ZuulTestCase):
# Stop queuing timer triggered jobs so that the assertions
# below don't race against more jobs being queued.
# Must be in same repo, so overwrite config with another one
self.commitLayoutUpdate('layout-idle', 'layout-no-timer')
self.commitConfigUpdate('common-config', 'layouts/no-timer.yaml')
self.sched.reconfigure(self.config)
self.assertEqual(len(self.builds), 2, "Two timer jobs")
A = self.fake_gerrit.addFakeChange('org/project', 'master', 'A')
@@ -2695,8 +2697,12 @@ class TestScheduler(ZuulTestCase):
def test_timer(self):
"Test that a periodic job is triggered"
# This test can not use simple_layout because it must start
# with a configuration which does not include a
# timer-triggered job so that we have an opportunity to set
# the hold flag before the first job.
self.executor_server.hold_jobs_in_build = True
self.updateConfigLayout('layout-timer')
self.commitConfigUpdate('common-config', 'layouts/timer.yaml')
self.sched.reconfigure(self.config)
# The pipeline triggers every second, so we should have seen
@@ -2709,14 +2715,14 @@ class TestScheduler(ZuulTestCase):
port = self.webapp.server.socket.getsockname()[1]
req = urllib.request.Request(
"http://localhost:%s/openstack/status" % port)
"http://localhost:%s/tenant-one/status" % port)
f = urllib.request.urlopen(req)
data = f.read()
self.executor_server.hold_jobs_in_build = False
# Stop queuing timer triggered jobs so that the assertions
# below don't race against more jobs being queued.
self.commitLayoutUpdate('layout-timer', 'layout-no-timer')
self.commitConfigUpdate('common-config', 'layouts/no-timer.yaml')
self.sched.reconfigure(self.config)
self.executor_server.release()
self.waitUntilSettled()
@@ -2739,13 +2745,18 @@ class TestScheduler(ZuulTestCase):
def test_idle(self):
"Test that frequent periodic jobs work"
# This test can not use simple_layout because it must start
# with a configuration which does not include a
# timer-triggered job so that we have an opportunity to set
# the hold flag before the first job.
self.executor_server.hold_jobs_in_build = True
self.updateConfigLayout('layout-idle')
for x in range(1, 3):
# Test that timer triggers periodic jobs even across
# layout config reloads.
# Start timer trigger
self.commitConfigUpdate('common-config',
'layouts/idle.yaml')
self.sched.reconfigure(self.config)
self.waitUntilSettled()
@@ -2755,7 +2766,8 @@ class TestScheduler(ZuulTestCase):
# Stop queuing timer triggered jobs so that the assertions
# below don't race against more jobs being queued.
before = self.commitLayoutUpdate('layout-idle', 'layout-no-timer')
self.commitConfigUpdate('common-config',
'layouts/no-timer.yaml')
self.sched.reconfigure(self.config)
self.waitUntilSettled()
self.assertEqual(len(self.builds), 2,
@@ -2764,11 +2776,6 @@ class TestScheduler(ZuulTestCase):
self.waitUntilSettled()
self.assertEqual(len(self.builds), 0)
self.assertEqual(len(self.history), x * 2)
# Revert back to layout-idle
repo = git.Repo(os.path.join(self.test_root,
'upstream',
'layout-idle'))
repo.git.reset('--hard', before)
@simple_layout('layouts/smtp.yaml')
def test_check_smtp_pool(self):
@@ -2800,8 +2807,12 @@ class TestScheduler(ZuulTestCase):
def test_timer_smtp(self):
"Test that a periodic job is triggered"
# This test can not use simple_layout because it must start
# with a configuration which does not include a
# timer-triggered job so that we have an opportunity to set
# the hold flag before the first job.
self.executor_server.hold_jobs_in_build = True
self.updateConfigLayout('layout-timer-smtp')
self.commitConfigUpdate('common-config', 'layouts/timer-smtp.yaml')
self.sched.reconfigure(self.config)
# The pipeline triggers every second, so we should have seen
@@ -2834,7 +2845,7 @@ class TestScheduler(ZuulTestCase):
# Stop queuing timer triggered jobs and let any that may have
# queued through so that end of test assertions pass.
self.commitLayoutUpdate('layout-timer-smtp', 'layout-no-timer')
self.commitConfigUpdate('common-config', 'layouts/no-timer.yaml')
self.sched.reconfigure(self.config)
self.waitUntilSettled()
self.executor_server.release('.*')