Merge "Extend config API with getSupportedLabels()"

This commit is contained in:
Zuul 2018-03-08 14:24:09 +00:00 committed by Gerrit Code Review
commit 90f702f60f
5 changed files with 25 additions and 11 deletions

View File

@ -451,3 +451,10 @@ class ProviderConfig(ConfigValue):
@abc.abstractmethod
def getSchema(self):
pass
@abc.abstractmethod
def getSupportedLabels(self):
'''
Return a set of label names supported by this provider.
'''
pass

View File

@ -275,3 +275,9 @@ class OpenStackProviderConfig(ProviderConfig):
'diskimages': [provider_diskimage],
'cloud-images': [provider_cloud_images],
})
def getSupportedLabels(self):
labels = set()
for pool in self.pools.values():
labels.update(pool.labels.keys())
return labels

View File

@ -80,3 +80,9 @@ class StaticProviderConfig(ProviderConfig):
'nodes': [pool_node],
}
return v.Schema({'pools': [pool]})
def getSupportedLabels(self):
labels = set()
for pool in self.pools.values():
labels.update(pool.labels)
return labels

View File

@ -288,17 +288,7 @@ class PoolWorker(threading.Thread):
launcher = zk.Launcher()
launcher.id = self.launcher_id
for prov_cfg in self.nodepool.config.providers.values():
if prov_cfg.driver.name in ('openstack', 'fake'):
for pool_cfg in prov_cfg.pools.values():
launcher.supported_labels.update(
set(pool_cfg.labels.keys()))
elif prov_cfg.driver.name == 'static':
for pool_cfg in prov_cfg.pools.values():
launcher.supported_labels.update(pool_cfg.labels)
else:
self.log.error(
"Launcher registration unhandled driver: %s",
prov_cfg.driver.name)
launcher.supported_labels.update(prov_cfg.getSupportedLabels())
self.zk.registerLauncher(launcher)
try:

View File

@ -33,12 +33,14 @@ class TestConfig(ProviderConfig):
def load(self, newconfig):
self.pools = {}
self.labels = set()
for pool in self.provider.get('pools', []):
testpool = TestPool()
testpool.name = pool['name']
testpool.provider = self
testpool.max_servers = pool.get('max-servers', math.inf)
for label in pool['labels']:
self.labels.add(label)
newconfig.labels[label].pools.append(testpool)
self.pools[pool['name']] = testpool
@ -46,3 +48,6 @@ class TestConfig(ProviderConfig):
pool = {'name': str,
'labels': [str]}
return v.Schema({'pools': [pool]})
def getSupportedLabels(self):
return self.labels