zuul tenant-conf-check: disable scheduler creation

This change prevents the tenant-conf-check from failing when
running without a ZooKeeper service.

Change-Id: Ib4f96268e40afd46eb531f84e0d20751bb985fc3
This commit is contained in:
Tristan Cacqueray 2021-06-01 19:10:13 +00:00
parent dd45f931b6
commit 6a8ca2d07b
3 changed files with 22 additions and 3 deletions

View File

@ -0,0 +1,5 @@
---
fixes:
- |
The zuul tenant-conf-check command no longer needs a ZooKeeper connection
to validate the tenants configuration file is valid.

View File

@ -28,6 +28,7 @@ from tests.base import FIXTURE_DIR
class BaseClientTestCase(BaseTestCase):
config_file = 'zuul.conf'
config_with_zk = True
def setUp(self):
super(BaseClientTestCase, self).setUp()
@ -35,6 +36,10 @@ class BaseClientTestCase(BaseTestCase):
rootdir=os.environ.get("ZUUL_TEST_ROOT"))).path
self.config = configparser.ConfigParser()
self.config.read(os.path.join(FIXTURE_DIR, self.config_file))
if self.config_with_zk:
self.config_add_zk()
def config_add_zk(self):
self.setupZK()
self.config.add_section('zookeeper')
self.config.set('zookeeper', 'hosts', self.zk_chroot_fixture.zk_hosts)
@ -48,8 +53,9 @@ class BaseClientTestCase(BaseTestCase):
class TestTenantValidationClient(BaseClientTestCase):
def test_client_tenant_conf_check(self):
config_with_zk = False
def test_client_tenant_conf_check(self):
self.config.set(
'scheduler', 'tenant_config',
os.path.join(FIXTURE_DIR, 'config/tenant-parser/simple.yaml'))

View File

@ -718,8 +718,16 @@ class Client(zuul.cmd.ZuulApp):
from zuul import scheduler
from zuul import configloader
self.configure_connections(source_only=True)
sched = scheduler.Scheduler(self.config, self.connections,
self, testonly=True)
class SchedulerConfig(scheduler.Scheduler):
# A custom scheduler constructor adapted for config check
# to avoid loading runtime clients.
def __init__(self, config, connections):
self.config = config
self.connections = connections
self.unparsed_config_cache = None
sched = SchedulerConfig(self.config, self.connections)
loader = configloader.ConfigLoader(
sched.connections, sched, None, None)
tenant_config, script = sched._checkTenantSourceConf(self.config)