summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorBrendan Jackman <bhenryj0117@gmail.com>2018-11-29 16:20:02 +0700
committerBrendan Jackman <bhenryj0117@gmail.com>2018-11-30 11:02:32 +0700
commitf605862a4d6824b6c9ea5b907c2ca3feb7793adc (patch)
treeb02b2e6dff1793cdccdf75b3baa8be1dbbcf9a94
parentfff02ace694de41da98240083588e02d4670d7e9 (diff)
Fix "reverse" Depends-On detection with new Gerrit URL schema
The regex to detect Depends-On relations between Gerrit changes was recently updated for the new URL schema. However because the change.uris attribute was not also updated, getChangesDependingOn was not working, and the functionality that this enables ("reverse" dependency processing, where a dependee change triggers a test for an already-approved dependent) was not covered by the test. Update the attribute and add test coverage. Change-Id: I400445093beda390aa9ce19af31e50820f7c56df
Notes
Notes (review): Code-Review+1: Tristan Cacqueray <tdecacqu@redhat.com> Code-Review+2: Monty Taylor <mordred@inaugust.com> Code-Review+1: Artem Goncharov <artem.goncharov@gmail.com> Code-Review+2: Tobias Henkel <tobias.henkel@bmw.de> Workflow+1: Tobias Henkel <tobias.henkel@bmw.de> Verified+2: Zuul Submitted-by: Zuul Submitted-at: Wed, 05 Dec 2018 12:04:40 +0000 Reviewed-on: https://review.openstack.org/620838 Project: openstack-infra/zuul Branch: refs/heads/master
-rw-r--r--tests/unit/test_gerrit_crd.py31
-rw-r--r--zuul/driver/gerrit/gerritconnection.py1
2 files changed, 25 insertions, 7 deletions
diff --git a/tests/unit/test_gerrit_crd.py b/tests/unit/test_gerrit_crd.py
index cabaf7c..5f796ac 100644
--- a/tests/unit/test_gerrit_crd.py
+++ b/tests/unit/test_gerrit_crd.py
@@ -18,6 +18,12 @@ from tests.base import (
18 simple_layout, 18 simple_layout,
19) 19)
20 20
21URL_FORMATS = [
22 '{baseurl}/{change_no}',
23 '{baseurl}/#/c/{change_no}',
24 '{baseurl}/c/{project}/+/{change_no}/',
25]
26
21 27
22class TestGerritCRD(ZuulTestCase): 28class TestGerritCRD(ZuulTestCase):
23 tenant_config_file = 'config/single-tenant/main.yaml' 29 tenant_config_file = 'config/single-tenant/main.yaml'
@@ -95,15 +101,14 @@ class TestGerritCRD(ZuulTestCase):
95 # changes - repeat the simple test on each of the 3 to ensure they can be 101 # changes - repeat the simple test on each of the 3 to ensure they can be
96 # parsed, the other tests just use the default URL schema provided in 102 # parsed, the other tests just use the default URL schema provided in
97 # FakeGerritChange.data['url'] . 103 # FakeGerritChange.data['url'] .
104 def test_crd_gate_url_schema0(self):
105 self._test_crd_gate(URL_FORMATS[0])
98 106
99 def test_crd_gate_url_schema1(self): 107 def test_crd_gate_url_schema1(self):
100 self._test_crd_gate('{baseurl}/{change_no}') 108 self._test_crd_gate(URL_FORMATS[1])
101 109
102 def test_crd_gate_url_schema2(self): 110 def test_crd_gate_url_schema2(self):
103 self._test_crd_gate('{baseurl}/#/c/{change_no}') 111 self._test_crd_gate(URL_FORMATS[2])
104
105 def test_crd_gate_url_schema3(self):
106 self._test_crd_gate('{baseurl}/c/{project}/+/{change_no}/')
107 112
108 def test_crd_gate_triangle(self): 113 def test_crd_gate_triangle(self):
109 A = self.fake_gerrit.addFakeChange('org/project1', 'master', 'A') 114 A = self.fake_gerrit.addFakeChange('org/project1', 'master', 'A')
@@ -260,7 +265,7 @@ class TestGerritCRD(ZuulTestCase):
260 self.assertEqual(A.data['status'], 'MERGED') 265 self.assertEqual(A.data['status'], 'MERGED')
261 self.assertEqual(A.reported, 2) 266 self.assertEqual(A.reported, 2)
262 267
263 def test_crd_gate_reverse(self): 268 def _test_crd_gate_reverse(self, url_fmt):
264 "Test reverse cross-repo dependencies" 269 "Test reverse cross-repo dependencies"
265 A = self.fake_gerrit.addFakeChange('org/project1', 'master', 'A') 270 A = self.fake_gerrit.addFakeChange('org/project1', 'master', 'A')
266 B = self.fake_gerrit.addFakeChange('org/project2', 'master', 'B') 271 B = self.fake_gerrit.addFakeChange('org/project2', 'master', 'B')
@@ -269,8 +274,11 @@ class TestGerritCRD(ZuulTestCase):
269 274
270 # A Depends-On: B 275 # A Depends-On: B
271 276
277 url = url_fmt.format(baseurl=B.gerrit.baseurl.rstrip('/'),
278 project=B.project,
279 change_no=B.number)
272 A.data['commitMessage'] = '%s\n\nDepends-On: %s\n' % ( 280 A.data['commitMessage'] = '%s\n\nDepends-On: %s\n' % (
273 A.subject, B.data['url']) 281 A.subject, url)
274 282
275 self.fake_gerrit.addEvent(A.addApproval('Approved', 1)) 283 self.fake_gerrit.addEvent(A.addApproval('Approved', 1))
276 self.waitUntilSettled() 284 self.waitUntilSettled()
@@ -300,6 +308,15 @@ class TestGerritCRD(ZuulTestCase):
300 'project-merge', 'org/project1').changes 308 'project-merge', 'org/project1').changes
301 self.assertEqual(changes, '2,1 1,1') 309 self.assertEqual(changes, '2,1 1,1')
302 310
311 def test_crd_gate_reverse_schema0(self):
312 self._test_crd_gate_reverse(URL_FORMATS[0])
313
314 def test_crd_gate_reverse_schema1(self):
315 self._test_crd_gate_reverse(URL_FORMATS[1])
316
317 def test_crd_gate_reverse_schema2(self):
318 self._test_crd_gate_reverse(URL_FORMATS[2])
319
303 def test_crd_cycle(self): 320 def test_crd_cycle(self):
304 "Test cross-repo dependency cycles" 321 "Test cross-repo dependency cycles"
305 A = self.fake_gerrit.addFakeChange('org/project1', 'master', 'A') 322 A = self.fake_gerrit.addFakeChange('org/project1', 'master', 'A')
diff --git a/zuul/driver/gerrit/gerritconnection.py b/zuul/driver/gerrit/gerritconnection.py
index 63d1d3d..64f9308 100644
--- a/zuul/driver/gerrit/gerritconnection.py
+++ b/zuul/driver/gerrit/gerritconnection.py
@@ -558,6 +558,7 @@ class GerritConnection(BaseConnection):
558 change.uris = [ 558 change.uris = [
559 '%s/%s' % (baseurl, change.number), 559 '%s/%s' % (baseurl, change.number),
560 '%s/#/c/%s' % (baseurl, change.number), 560 '%s/#/c/%s' % (baseurl, change.number),
561 '%s/c/%s/+/%s' % (baseurl, change.project.name, change.number),
561 ] 562 ]
562 563
563 max_ps = 0 564 max_ps = 0