Extend config API with getSupportedLabels()

New config API method to get all labels that are supported by a
configured provider. Used in the launcher to not have to know
what driver is used and the configuration of its config data
structure.

Change-Id: Ib792e84c546bc52507141835ed57bd72ad9f09d3
This commit is contained in:
David Shrewsbury 2018-03-07 21:42:19 -05:00
parent f19f89777d
commit c204313801
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