Merge "Fix zuul-web startup config priming"

This commit is contained in:
Zuul 2021-11-17 01:28:00 +00:00 committed by Gerrit Code Review
commit 144be26419
3 changed files with 78 additions and 2 deletions

View File

@ -21,6 +21,8 @@ import time
import jwt
import sys
import subprocess
import threading
from unittest import skip
import requests
@ -2841,3 +2843,66 @@ class TestCLIViaWebApi(BaseTestWeb):
self.assertEqual(B.reported, 2)
self.assertEqual(C.data['status'], 'MERGED')
self.assertEqual(C.reported, 2)
class TestWebStartup(ZuulTestCase):
tenant_config_file = 'config/single-tenant/main.yaml'
config_ini_data = {}
def _start_web(self):
# Start the web server
self.web = ZuulWebFixture(
self.changes, self.config, self.additional_event_queues,
self.upstream_root, self.rpcclient, self.poller_events,
self.git_url_with_auth, self.addCleanup, self.test_root,
info=zuul.model.WebInfo.fromConfig(self.zuul_ini_config))
self.useFixture(self.web)
def get_url(self, url, *args, **kwargs):
return requests.get(
urllib.parse.urljoin(self.base_url, url), *args, **kwargs)
def createScheduler(self):
pass
def realCreateScheduler(self):
super().createScheduler()
@skip("This test is not reliable in the gate")
def test_web_startup(self):
self.zuul_ini_config = FakeConfig(self.config_ini_data)
self.web = None
t = threading.Thread(target=self._start_web)
t.daemon = True
t.start()
for _ in iterate_timeout(30, 'Wait for web to begin startup'):
if self.web and getattr(self.web, 'web', None):
break
self.web.web.system_config_cache_wake_event.wait()
self.realCreateScheduler()
self.scheds.execute(
lambda app: app.start(self.validate_tenants))
t.join()
self.host = 'localhost'
# Wait until web server is started
while True:
if self.web is None:
time.sleep(0.1)
continue
self.port = self.web.port
try:
with socket.create_connection((self.host, self.port)):
break
except ConnectionRefusedError:
pass
self.base_url = "http://{host}:{port}".format(
host=self.host, port=self.port)
# If the config didn't load correctly, we won't have the jobs
jobs = self.get_url("api/tenant/tenant-one/jobs").json()
self.assertEqual(len(jobs), 10)

View File

@ -246,7 +246,7 @@ class ZKBranchCacheMixin:
if self.read_only:
raise RuntimeError(
"Won't fetch project branches as read-only is set.")
"Will not fetch project branches as read-only is set")
# We need to perform a query
branches = self._fetchProjectBranches(project, exclude_unprotected)

View File

@ -1916,15 +1916,26 @@ class ZuulWeb(object):
if (self.local_layout_state.get(tenant_name)
== self.tenant_layout_state.get(tenant_name)):
continue
self.log.debug("Reloading tenant %s", tenant_name)
with tenant_read_lock(self.zk_client, tenant_name):
layout_state = self.tenant_layout_state.get(tenant_name)
layout_uuid = layout_state and layout_state.uuid
if layout_state:
branch_cache_min_ltimes = (
layout_state.branch_cache_min_ltimes)
else:
# Consider all project branch caches valid if
# we don't have a layout state.
branch_cache_min_ltimes = defaultdict(lambda: -1)
# The tenant will be stored in self.abide.tenants after
# it was loaded.
tenant = loader.loadTenant(
self.abide, tenant_name, self.ansible_manager,
self.unparsed_abide, min_ltimes=min_ltimes,
layout_uuid=layout_uuid)
layout_uuid=layout_uuid,
branch_cache_min_ltimes=branch_cache_min_ltimes)
if tenant is not None:
self.local_layout_state[tenant_name] = layout_state
else: