Browse Source

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
tags/3.4.0
Brendan Jackman 5 months ago
parent
commit
f605862a4d
2 changed files with 25 additions and 7 deletions
  1. 24
    7
      tests/unit/test_gerrit_crd.py
  2. 1
    0
      zuul/driver/gerrit/gerritconnection.py

+ 24
- 7
tests/unit/test_gerrit_crd.py View File

@@ -18,6 +18,12 @@ from tests.base import (
18 18
     simple_layout,
19 19
 )
20 20
 
21
+URL_FORMATS = [
22
+    '{baseurl}/{change_no}',
23
+    '{baseurl}/#/c/{change_no}',
24
+    '{baseurl}/c/{project}/+/{change_no}/',
25
+]
26
+
21 27
 
22 28
 class TestGerritCRD(ZuulTestCase):
23 29
     tenant_config_file = 'config/single-tenant/main.yaml'
@@ -95,15 +101,14 @@ class TestGerritCRD(ZuulTestCase):
95 101
     # changes - repeat the simple test on each of the 3 to ensure they can be
96 102
     # parsed, the other tests just use the default URL schema provided in
97 103
     # FakeGerritChange.data['url'] .
104
+    def test_crd_gate_url_schema0(self):
105
+        self._test_crd_gate(URL_FORMATS[0])
98 106
 
99 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 110
     def test_crd_gate_url_schema2(self):
103
-        self._test_crd_gate('{baseurl}/#/c/{change_no}')
104
-
105
-    def test_crd_gate_url_schema3(self):
106
-        self._test_crd_gate('{baseurl}/c/{project}/+/{change_no}/')
111
+        self._test_crd_gate(URL_FORMATS[2])
107 112
 
108 113
     def test_crd_gate_triangle(self):
109 114
         A = self.fake_gerrit.addFakeChange('org/project1', 'master', 'A')
@@ -260,7 +265,7 @@ class TestGerritCRD(ZuulTestCase):
260 265
         self.assertEqual(A.data['status'], 'MERGED')
261 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 269
         "Test reverse cross-repo dependencies"
265 270
         A = self.fake_gerrit.addFakeChange('org/project1', 'master', 'A')
266 271
         B = self.fake_gerrit.addFakeChange('org/project2', 'master', 'B')
@@ -269,8 +274,11 @@ class TestGerritCRD(ZuulTestCase):
269 274
 
270 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 280
         A.data['commitMessage'] = '%s\n\nDepends-On: %s\n' % (
273
-            A.subject, B.data['url'])
281
+            A.subject, url)
274 282
 
275 283
         self.fake_gerrit.addEvent(A.addApproval('Approved', 1))
276 284
         self.waitUntilSettled()
@@ -300,6 +308,15 @@ class TestGerritCRD(ZuulTestCase):
300 308
             'project-merge', 'org/project1').changes
301 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 320
     def test_crd_cycle(self):
304 321
         "Test cross-repo dependency cycles"
305 322
         A = self.fake_gerrit.addFakeChange('org/project1', 'master', 'A')

+ 1
- 0
zuul/driver/gerrit/gerritconnection.py View File

@@ -558,6 +558,7 @@ class GerritConnection(BaseConnection):
558 558
         change.uris = [
559 559
             '%s/%s' % (baseurl, change.number),
560 560
             '%s/#/c/%s' % (baseurl, change.number),
561
+            '%s/c/%s/+/%s' % (baseurl, change.project.name, change.number),
561 562
         ]
562 563
 
563 564
         max_ps = 0

Loading…
Cancel
Save