Browse Source

Cache empty branch config to prevent spurious reconfig

There is an edge case in github handling where it's possible to
change a branch from unprotected to protected without Zuul being
notified, therefore if we see an event on a branch which has no
configuration cached, we perform a tenant reconfiguration in order
to catch this case.

We also have an optimization where if we load no configuration from
a repo whatsoever, we don't cache anything for it.

Therefore, every time we see an event on such a repo, we perform
an extra configuration (because the repo has no cached data).

To avoid this, explicitly cache an empty configuration object on
every project-branch we know about.  This way only a branch which
has gone from unprotected to protected will show up with no cached
data and trip the reconfiguration.

Change-Id: I8161b571b03c4d8222abd6f1503190917331f422
tags/3.4.0^2
James E. Blair 5 months ago
parent
commit
aad0e17ddd
2 changed files with 20 additions and 4 deletions
  1. 12
    0
      tests/unit/test_configloader.py
  2. 8
    4
      zuul/configloader.py

+ 12
- 0
tests/unit/test_configloader.py View File

@@ -244,6 +244,18 @@ class TestTenantGroups4(TenantParserTestCase):
244 244
         cat_jobs = [job for job in self.gearman_server.jobs_history
245 245
                     if job.name == b'merger:cat']
246 246
         self.assertEqual(1, len(cat_jobs))
247
+        old_layout = tenant.layout
248
+
249
+        # Check that creating a change in project1 doesn't cause a
250
+        # reconfiguration (due to a mistaken belief that we need to
251
+        # load config from it since there is none in memory).
252
+        A = self.fake_gerrit.addFakeChange('org/project1', 'master', 'A')
253
+        self.fake_gerrit.addEvent(A.getPatchsetCreatedEvent(1))
254
+        self.waitUntilSettled()
255
+        tenant = self.sched.abide.tenants.get('tenant-one')
256
+        new_layout = tenant.layout
257
+
258
+        self.assertEqual(old_layout, new_layout)
247 259
 
248 260
 
249 261
 class TestTenantGroups5(TenantParserTestCase):

+ 8
- 4
zuul/configloader.py View File

@@ -1542,10 +1542,6 @@ class TenantParser(object):
1542 1542
         for project in itertools.chain(
1543 1543
                 tenant.config_projects, tenant.untrusted_projects):
1544 1544
             tpc = tenant.project_configs[project.canonical_name]
1545
-            # If all config classes are excluded then do not request
1546
-            # any getFiles jobs.
1547
-            if not tpc.load_classes:
1548
-                continue
1549 1545
             # For each branch in the repo, get the zuul.yaml for that
1550 1546
             # branch.  Remember the branch and then implicitly add a
1551 1547
             # branch selector to each job there.  This makes the
@@ -1556,6 +1552,14 @@ class TenantParser(object):
1556 1552
                                            branch):
1557 1553
                     # We already have this branch cached.
1558 1554
                     continue
1555
+                if not tpc.load_classes:
1556
+                    # If all config classes are excluded then do not
1557
+                    # request any getFiles jobs, but cache the lack of
1558
+                    # data so we know we've looked at this branch.
1559
+                    abide.cacheUnparsedConfig(
1560
+                        project.canonical_name,
1561
+                        branch, model.UnparsedConfig())
1562
+                    continue
1559 1563
                 job = self.merger.getFiles(
1560 1564
                     project.source.connection.connection_name,
1561 1565
                     project.name, branch,

Loading…
Cancel
Save