summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorZuul <zuul@review.openstack.org>2019-02-28 17:09:06 +0000
committerGerrit Code Review <review@openstack.org>2019-02-28 17:09:06 +0000
commitbc83702789450da568f4979e746731eb9529f524 (patch)
treedc6270e9cbddd223e1660a64e3b684a456533ebf
parente70bd50a83c0699ed4545aa034da53a0fac4bc6f (diff)
parent08163359f7bebc13132affb4e3be456b5c9bd973 (diff)
Merge "Fix multiple jobs with provides/requires"
-rw-r--r--tests/fixtures/layouts/provides-requires.yaml10
-rw-r--r--tests/unit/test_v3.py64
-rw-r--r--zuul/model.py11
3 files changed, 71 insertions, 14 deletions
diff --git a/tests/fixtures/layouts/provides-requires.yaml b/tests/fixtures/layouts/provides-requires.yaml
index 3947345..c71c49c 100644
--- a/tests/fixtures/layouts/provides-requires.yaml
+++ b/tests/fixtures/layouts/provides-requires.yaml
@@ -49,11 +49,20 @@
49 name: image-user 49 name: image-user
50 requires: images 50 requires: images
51 51
52- job:
53 name: library-builder
54 provides: libraries
55
56- job:
57 name: library-user
58 requires: libraries
59
52- project: 60- project:
53 name: org/project1 61 name: org/project1
54 check: 62 check:
55 jobs: 63 jobs:
56 - image-builder 64 - image-builder
65 - library-builder
57 gate: 66 gate:
58 queue: integrated 67 queue: integrated
59 jobs: 68 jobs:
@@ -64,6 +73,7 @@
64 check: 73 check:
65 jobs: 74 jobs:
66 - image-user 75 - image-user
76 - library-user
67 gate: 77 gate:
68 queue: integrated 78 queue: integrated
69 jobs: 79 jobs:
diff --git a/tests/unit/test_v3.py b/tests/unit/test_v3.py
index 9da04e4..0f697e3 100644
--- a/tests/unit/test_v3.py
+++ b/tests/unit/test_v3.py
@@ -4967,10 +4967,17 @@ class TestProvidesRequires(ZuulDBTestCase):
4967 {'name': 'image', 'url': 'http://example.com/image'}, 4967 {'name': 'image', 'url': 'http://example.com/image'},
4968 ]}} 4968 ]}}
4969 ) 4969 )
4970 self.executor_server.returnData(
4971 'library-builder', A,
4972 {'zuul':
4973 {'artifacts': [
4974 {'name': 'library', 'url': 'http://example.com/library'},
4975 ]}}
4976 )
4970 self.fake_gerrit.addEvent(A.getPatchsetCreatedEvent(1)) 4977 self.fake_gerrit.addEvent(A.getPatchsetCreatedEvent(1))
4971 self.waitUntilSettled() 4978 self.waitUntilSettled()
4972 4979
4973 self.assertEqual(len(self.builds), 1) 4980 self.assertEqual(len(self.builds), 2)
4974 4981
4975 B = self.fake_gerrit.addFakeChange('org/project2', 'master', 'B') 4982 B = self.fake_gerrit.addFakeChange('org/project2', 'master', 'B')
4976 B.data['commitMessage'] = '%s\n\nDepends-On: %s\n' % ( 4983 B.data['commitMessage'] = '%s\n\nDepends-On: %s\n' % (
@@ -4978,7 +4985,7 @@ class TestProvidesRequires(ZuulDBTestCase):
4978 self.fake_gerrit.addEvent(B.getPatchsetCreatedEvent(1)) 4985 self.fake_gerrit.addEvent(B.getPatchsetCreatedEvent(1))
4979 self.waitUntilSettled() 4986 self.waitUntilSettled()
4980 4987
4981 self.assertEqual(len(self.builds), 1) 4988 self.assertEqual(len(self.builds), 2)
4982 4989
4983 self.executor_server.hold_jobs_in_build = False 4990 self.executor_server.hold_jobs_in_build = False
4984 self.executor_server.release() 4991 self.executor_server.release()
@@ -4986,10 +4993,13 @@ class TestProvidesRequires(ZuulDBTestCase):
4986 4993
4987 self.assertHistory([ 4994 self.assertHistory([
4988 dict(name='image-builder', result='SUCCESS', changes='1,1'), 4995 dict(name='image-builder', result='SUCCESS', changes='1,1'),
4996 dict(name='library-builder', result='SUCCESS', changes='1,1'),
4989 dict(name='image-user', result='SUCCESS', changes='1,1 2,1'), 4997 dict(name='image-user', result='SUCCESS', changes='1,1 2,1'),
4990 ]) 4998 dict(name='library-user', result='SUCCESS', changes='1,1 2,1'),
4999 ], ordered=False)
5000 image_user = self.getJobFromHistory('image-user')
4991 self.assertEqual( 5001 self.assertEqual(
4992 self.history[-1].parameters['zuul']['artifacts'], 5002 image_user.parameters['zuul']['artifacts'],
4993 [{ 5003 [{
4994 'project': 'org/project1', 5004 'project': 'org/project1',
4995 'change': '1', 5005 'change': '1',
@@ -4998,6 +5008,17 @@ class TestProvidesRequires(ZuulDBTestCase):
4998 'url': 'http://example.com/image', 5008 'url': 'http://example.com/image',
4999 'name': 'image', 5009 'name': 'image',
5000 }]) 5010 }])
5011 library_user = self.getJobFromHistory('library-user')
5012 self.assertEqual(
5013 library_user.parameters['zuul']['artifacts'],
5014 [{
5015 'project': 'org/project1',
5016 'change': '1',
5017 'patchset': '1',
5018 'job': 'library-builder',
5019 'url': 'http://example.com/library',
5020 'name': 'library',
5021 }])
5001 5022
5002 @simple_layout('layouts/provides-requires.yaml') 5023 @simple_layout('layouts/provides-requires.yaml')
5003 def test_provides_requires_check_old_success(self): 5024 def test_provides_requires_check_old_success(self):
@@ -5009,11 +5030,19 @@ class TestProvidesRequires(ZuulDBTestCase):
5009 {'name': 'image', 'url': 'http://example.com/image'}, 5030 {'name': 'image', 'url': 'http://example.com/image'},
5010 ]}} 5031 ]}}
5011 ) 5032 )
5033 self.executor_server.returnData(
5034 'library-builder', A,
5035 {'zuul':
5036 {'artifacts': [
5037 {'name': 'library', 'url': 'http://example.com/library'},
5038 ]}}
5039 )
5012 self.fake_gerrit.addEvent(A.getPatchsetCreatedEvent(1)) 5040 self.fake_gerrit.addEvent(A.getPatchsetCreatedEvent(1))
5013 self.waitUntilSettled() 5041 self.waitUntilSettled()
5014 self.assertHistory([ 5042 self.assertHistory([
5015 dict(name='image-builder', result='SUCCESS', changes='1,1'), 5043 dict(name='image-builder', result='SUCCESS', changes='1,1'),
5016 ]) 5044 dict(name='library-builder', result='SUCCESS', changes='1,1'),
5045 ], ordered=False)
5017 5046
5018 B = self.fake_gerrit.addFakeChange('org/project2', 'master', 'B') 5047 B = self.fake_gerrit.addFakeChange('org/project2', 'master', 'B')
5019 B.data['commitMessage'] = '%s\n\nDepends-On: %s\n' % ( 5048 B.data['commitMessage'] = '%s\n\nDepends-On: %s\n' % (
@@ -5023,10 +5052,13 @@ class TestProvidesRequires(ZuulDBTestCase):
5023 5052
5024 self.assertHistory([ 5053 self.assertHistory([
5025 dict(name='image-builder', result='SUCCESS', changes='1,1'), 5054 dict(name='image-builder', result='SUCCESS', changes='1,1'),
5055 dict(name='library-builder', result='SUCCESS', changes='1,1'),
5026 dict(name='image-user', result='SUCCESS', changes='1,1 2,1'), 5056 dict(name='image-user', result='SUCCESS', changes='1,1 2,1'),
5027 ]) 5057 dict(name='library-user', result='SUCCESS', changes='1,1 2,1'),
5058 ], ordered=False)
5059 image_user = self.getJobFromHistory('image-user')
5028 self.assertEqual( 5060 self.assertEqual(
5029 self.history[-1].parameters['zuul']['artifacts'], 5061 image_user.parameters['zuul']['artifacts'],
5030 [{ 5062 [{
5031 'project': 'org/project1', 5063 'project': 'org/project1',
5032 'change': '1', 5064 'change': '1',
@@ -5035,17 +5067,30 @@ class TestProvidesRequires(ZuulDBTestCase):
5035 'url': 'http://example.com/image', 5067 'url': 'http://example.com/image',
5036 'name': 'image', 5068 'name': 'image',
5037 }]) 5069 }])
5070 library_user = self.getJobFromHistory('library-user')
5071 self.assertEqual(
5072 library_user.parameters['zuul']['artifacts'],
5073 [{
5074 'project': 'org/project1',
5075 'change': '1',
5076 'patchset': '1',
5077 'job': 'library-builder',
5078 'url': 'http://example.com/library',
5079 'name': 'library',
5080 }])
5038 5081
5039 @simple_layout('layouts/provides-requires.yaml') 5082 @simple_layout('layouts/provides-requires.yaml')
5040 def test_provides_requires_check_old_failure(self): 5083 def test_provides_requires_check_old_failure(self):
5041 A = self.fake_gerrit.addFakeChange('org/project1', 'master', 'A') 5084 A = self.fake_gerrit.addFakeChange('org/project1', 'master', 'A')
5042 self.executor_server.failJob('image-builder', A) 5085 self.executor_server.failJob('image-builder', A)
5086 self.executor_server.failJob('library-builder', A)
5043 self.fake_gerrit.addEvent(A.getPatchsetCreatedEvent(1)) 5087 self.fake_gerrit.addEvent(A.getPatchsetCreatedEvent(1))
5044 self.waitUntilSettled() 5088 self.waitUntilSettled()
5045 5089
5046 self.assertHistory([ 5090 self.assertHistory([
5047 dict(name='image-builder', result='FAILURE', changes='1,1'), 5091 dict(name='image-builder', result='FAILURE', changes='1,1'),
5048 ]) 5092 dict(name='library-builder', result='FAILURE', changes='1,1'),
5093 ], ordered=False)
5049 5094
5050 B = self.fake_gerrit.addFakeChange('org/project2', 'master', 'B') 5095 B = self.fake_gerrit.addFakeChange('org/project2', 'master', 'B')
5051 B.data['commitMessage'] = '%s\n\nDepends-On: %s\n' % ( 5096 B.data['commitMessage'] = '%s\n\nDepends-On: %s\n' % (
@@ -5055,7 +5100,8 @@ class TestProvidesRequires(ZuulDBTestCase):
5055 5100
5056 self.assertHistory([ 5101 self.assertHistory([
5057 dict(name='image-builder', result='FAILURE', changes='1,1'), 5102 dict(name='image-builder', result='FAILURE', changes='1,1'),
5058 ]) 5103 dict(name='library-builder', result='FAILURE', changes='1,1'),
5104 ], ordered=False)
5059 self.assertIn('image-user : SKIPPED', B.messages[0]) 5105 self.assertIn('image-user : SKIPPED', B.messages[0])
5060 self.assertIn('not met by build', B.messages[0]) 5106 self.assertIn('not met by build', B.messages[0])
5061 5107
diff --git a/zuul/model.py b/zuul/model.py
index feefd68..642f71b 100644
--- a/zuul/model.py
+++ b/zuul/model.py
@@ -2012,7 +2012,7 @@ class QueueItem(object):
2012 self.layout = None 2012 self.layout = None
2013 self.project_pipeline_config = None 2013 self.project_pipeline_config = None
2014 self.job_graph = None 2014 self.job_graph = None
2015 self._cached_sql_results = None 2015 self._cached_sql_results = {}
2016 2016
2017 def __repr__(self): 2017 def __repr__(self):
2018 if self.pipeline: 2018 if self.pipeline:
@@ -2211,7 +2211,8 @@ class QueueItem(object):
2211 2211
2212 def _getRequirementsResultFromSQL(self, requirements): 2212 def _getRequirementsResultFromSQL(self, requirements):
2213 # This either returns data or raises an exception 2213 # This either returns data or raises an exception
2214 if self._cached_sql_results is None: 2214 requirements_tuple = tuple(sorted(requirements))
2215 if requirements_tuple not in self._cached_sql_results:
2215 sql_driver = self.pipeline.manager.sched.connections.drivers['sql'] 2216 sql_driver = self.pipeline.manager.sched.connections.drivers['sql']
2216 conn = sql_driver.tenant_connections.get(self.pipeline.tenant.name) 2217 conn = sql_driver.tenant_connections.get(self.pipeline.tenant.name)
2217 if conn: 2218 if conn:
@@ -2222,16 +2223,16 @@ class QueueItem(object):
2222 change=self.change.number, 2223 change=self.change.number,
2223 branch=self.change.branch, 2224 branch=self.change.branch,
2224 patchset=self.change.patchset, 2225 patchset=self.change.patchset,
2225 provides=list(requirements)) 2226 provides=requirements_tuple)
2226 else: 2227 else:
2227 builds = [] 2228 builds = []
2228 # Just look at the most recent buildset. 2229 # Just look at the most recent buildset.
2229 # TODO: query for a buildset instead of filtering. 2230 # TODO: query for a buildset instead of filtering.
2230 builds = [b for b in builds 2231 builds = [b for b in builds
2231 if b.buildset.uuid == builds[0].buildset.uuid] 2232 if b.buildset.uuid == builds[0].buildset.uuid]
2232 self._cached_sql_results = builds 2233 self._cached_sql_results[requirements_tuple] = builds
2233 2234
2234 builds = self._cached_sql_results 2235 builds = self._cached_sql_results[requirements_tuple]
2235 data = [] 2236 data = []
2236 if not builds: 2237 if not builds:
2237 return data 2238 return data