Browse Source

Merge "Fix multiple jobs with provides/requires"

tags/3.6.0
Zuul 2 months ago
parent
commit
bc83702789
3 changed files with 71 additions and 14 deletions
  1. 10
    0
      tests/fixtures/layouts/provides-requires.yaml
  2. 55
    9
      tests/unit/test_v3.py
  3. 6
    5
      zuul/model.py

+ 10
- 0
tests/fixtures/layouts/provides-requires.yaml View File

@@ -49,11 +49,20 @@
49 49
     name: image-user
50 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 60
 - project:
53 61
     name: org/project1
54 62
     check:
55 63
       jobs:
56 64
         - image-builder
65
+        - library-builder
57 66
     gate:
58 67
       queue: integrated
59 68
       jobs:
@@ -64,6 +73,7 @@
64 73
     check:
65 74
       jobs:
66 75
         - image-user
76
+        - library-user
67 77
     gate:
68 78
       queue: integrated
69 79
       jobs:

+ 55
- 9
tests/unit/test_v3.py View File

@@ -4967,10 +4967,17 @@ class TestProvidesRequires(ZuulDBTestCase):
4967 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 4977
         self.fake_gerrit.addEvent(A.getPatchsetCreatedEvent(1))
4971 4978
         self.waitUntilSettled()
4972 4979
 
4973
-        self.assertEqual(len(self.builds), 1)
4980
+        self.assertEqual(len(self.builds), 2)
4974 4981
 
4975 4982
         B = self.fake_gerrit.addFakeChange('org/project2', 'master', 'B')
4976 4983
         B.data['commitMessage'] = '%s\n\nDepends-On: %s\n' % (
@@ -4978,7 +4985,7 @@ class TestProvidesRequires(ZuulDBTestCase):
4978 4985
         self.fake_gerrit.addEvent(B.getPatchsetCreatedEvent(1))
4979 4986
         self.waitUntilSettled()
4980 4987
 
4981
-        self.assertEqual(len(self.builds), 1)
4988
+        self.assertEqual(len(self.builds), 2)
4982 4989
 
4983 4990
         self.executor_server.hold_jobs_in_build = False
4984 4991
         self.executor_server.release()
@@ -4986,10 +4993,13 @@ class TestProvidesRequires(ZuulDBTestCase):
4986 4993
 
4987 4994
         self.assertHistory([
4988 4995
             dict(name='image-builder', result='SUCCESS', changes='1,1'),
4996
+            dict(name='library-builder', result='SUCCESS', changes='1,1'),
4989 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 5001
         self.assertEqual(
4992
-            self.history[-1].parameters['zuul']['artifacts'],
5002
+            image_user.parameters['zuul']['artifacts'],
4993 5003
             [{
4994 5004
                 'project': 'org/project1',
4995 5005
                 'change': '1',
@@ -4998,6 +5008,17 @@ class TestProvidesRequires(ZuulDBTestCase):
4998 5008
                 'url': 'http://example.com/image',
4999 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 5023
     @simple_layout('layouts/provides-requires.yaml')
5003 5024
     def test_provides_requires_check_old_success(self):
@@ -5009,11 +5030,19 @@ class TestProvidesRequires(ZuulDBTestCase):
5009 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 5040
         self.fake_gerrit.addEvent(A.getPatchsetCreatedEvent(1))
5013 5041
         self.waitUntilSettled()
5014 5042
         self.assertHistory([
5015 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 5047
         B = self.fake_gerrit.addFakeChange('org/project2', 'master', 'B')
5019 5048
         B.data['commitMessage'] = '%s\n\nDepends-On: %s\n' % (
@@ -5023,10 +5052,13 @@ class TestProvidesRequires(ZuulDBTestCase):
5023 5052
 
5024 5053
         self.assertHistory([
5025 5054
             dict(name='image-builder', result='SUCCESS', changes='1,1'),
5055
+            dict(name='library-builder', result='SUCCESS', changes='1,1'),
5026 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 5060
         self.assertEqual(
5029
-            self.history[-1].parameters['zuul']['artifacts'],
5061
+            image_user.parameters['zuul']['artifacts'],
5030 5062
             [{
5031 5063
                 'project': 'org/project1',
5032 5064
                 'change': '1',
@@ -5035,17 +5067,30 @@ class TestProvidesRequires(ZuulDBTestCase):
5035 5067
                 'url': 'http://example.com/image',
5036 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 5082
     @simple_layout('layouts/provides-requires.yaml')
5040 5083
     def test_provides_requires_check_old_failure(self):
5041 5084
         A = self.fake_gerrit.addFakeChange('org/project1', 'master', 'A')
5042 5085
         self.executor_server.failJob('image-builder', A)
5086
+        self.executor_server.failJob('library-builder', A)
5043 5087
         self.fake_gerrit.addEvent(A.getPatchsetCreatedEvent(1))
5044 5088
         self.waitUntilSettled()
5045 5089
 
5046 5090
         self.assertHistory([
5047 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 5095
         B = self.fake_gerrit.addFakeChange('org/project2', 'master', 'B')
5051 5096
         B.data['commitMessage'] = '%s\n\nDepends-On: %s\n' % (
@@ -5055,7 +5100,8 @@ class TestProvidesRequires(ZuulDBTestCase):
5055 5100
 
5056 5101
         self.assertHistory([
5057 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 5105
         self.assertIn('image-user : SKIPPED', B.messages[0])
5060 5106
         self.assertIn('not met by build', B.messages[0])
5061 5107
 

+ 6
- 5
zuul/model.py View File

@@ -2012,7 +2012,7 @@ class QueueItem(object):
2012 2012
         self.layout = None
2013 2013
         self.project_pipeline_config = None
2014 2014
         self.job_graph = None
2015
-        self._cached_sql_results = None
2015
+        self._cached_sql_results = {}
2016 2016
 
2017 2017
     def __repr__(self):
2018 2018
         if self.pipeline:
@@ -2211,7 +2211,8 @@ class QueueItem(object):
2211 2211
 
2212 2212
     def _getRequirementsResultFromSQL(self, requirements):
2213 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 2216
             sql_driver = self.pipeline.manager.sched.connections.drivers['sql']
2216 2217
             conn = sql_driver.tenant_connections.get(self.pipeline.tenant.name)
2217 2218
             if conn:
@@ -2222,16 +2223,16 @@ class QueueItem(object):
2222 2223
                     change=self.change.number,
2223 2224
                     branch=self.change.branch,
2224 2225
                     patchset=self.change.patchset,
2225
-                    provides=list(requirements))
2226
+                    provides=requirements_tuple)
2226 2227
             else:
2227 2228
                 builds = []
2228 2229
             # Just look at the most recent buildset.
2229 2230
             # TODO: query for a buildset instead of filtering.
2230 2231
             builds = [b for b in builds
2231 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 2236
         data = []
2236 2237
         if not builds:
2237 2238
             return data

Loading…
Cancel
Save