Merge "Use a temp ZK config cache for tenant validation"

This commit is contained in:
Zuul 2021-07-23 15:48:05 +00:00 committed by Gerrit Code Review
commit 35e4745b09
2 changed files with 20 additions and 10 deletions

View File

@ -24,6 +24,7 @@ import threading
import time import time
import traceback import traceback
import urllib import urllib
import uuid
from collections import defaultdict from collections import defaultdict
from apscheduler.schedulers.background import BackgroundScheduler from apscheduler.schedulers.background import BackgroundScheduler
@ -855,12 +856,20 @@ class Scheduler(threading.Thread):
invalid = tenants_to_load.difference(available_tenants) invalid = tenants_to_load.difference(available_tenants)
raise RuntimeError(f"Invalid tenant(s) found: {invalid}") raise RuntimeError(f"Invalid tenant(s) found: {invalid}")
abide = Abide() # Use a temporary config cache for the validation
loader.loadAdminRules(abide, unparsed_abide) validate_root = f"/zuul/validate/{uuid.uuid4().hex}"
loader.loadTPCs(abide, unparsed_abide) self.unparsed_config_cache = UnparsedConfigCache(self.zk_client,
for tenant_name in tenants_to_load: validate_root)
loader.loadTenant(abide, tenant_name, self.ansible_manager,
unparsed_abide, min_ltimes=None) try:
abide = Abide()
loader.loadAdminRules(abide, unparsed_abide)
loader.loadTPCs(abide, unparsed_abide)
for tenant_name in tenants_to_load:
loader.loadTenant(abide, tenant_name, self.ansible_manager,
unparsed_abide, min_ltimes=None)
finally:
self.zk_client.client.delete(validate_root, recursive=True)
loading_errors = [] loading_errors = []
for tenant in abide.tenants.values(): for tenant in abide.tenants.values():

View File

@ -23,6 +23,8 @@ from kazoo.exceptions import NoNodeError
from zuul.zk import sharding, ZooKeeperSimpleBase from zuul.zk import sharding, ZooKeeperSimpleBase
CONFIG_ROOT = "/zuul/config"
def _safe_path(root_path, *keys): def _safe_path(root_path, *keys):
return "/".join((root_path, *(quote_plus(k) for k in keys))) return "/".join((root_path, *(quote_plus(k) for k in keys)))
@ -134,13 +136,12 @@ class FilesCache(ZooKeeperSimpleBase, MutableMapping):
class UnparsedConfigCache(ZooKeeperSimpleBase): class UnparsedConfigCache(ZooKeeperSimpleBase):
"""Zookeeper cache for unparsed config files.""" """Zookeeper cache for unparsed config files."""
CONFIG_ROOT = "/zuul/config"
log = logging.getLogger("zuul.zk.config_cache.UnparsedConfigCache") log = logging.getLogger("zuul.zk.config_cache.UnparsedConfigCache")
def __init__(self, client): def __init__(self, client, config_root=CONFIG_ROOT):
super().__init__(client) super().__init__(client)
self.cache_path = f"{self.CONFIG_ROOT}/cache" self.cache_path = f"{config_root}/cache"
self.lock_path = f"{self.CONFIG_ROOT}/lock" self.lock_path = f"{config_root}/lock"
def readLock(self, project_cname): def readLock(self, project_cname):
return self.kazoo_client.ReadLock( return self.kazoo_client.ReadLock(