Add labels option for cluster template

Add a config option `labels`, which is passed to create cluster template

Change-Id: Ic44f8e9e7d09d5f3d4d7b2bcc24d16d03c14673e
This commit is contained in:
Jake Yip 2018-09-13 17:19:15 +10:00 committed by Jake Yip
parent 7762c6e801
commit fc301ca240
3 changed files with 22 additions and 2 deletions

View File

@ -15,6 +15,7 @@ import warnings
from tempest import config
from oslo_config import cfg
from oslo_utils import strutils
CONF = config.CONF
@ -95,6 +96,21 @@ class Config(object):
raise Exception('config missing image_id key')
cls.image_id = CONF.magnum.image_id
@classmethod
def set_labels(cls, config):
labels = {}
ls = strutils.split_by_commas(CONF.magnum.get('labels', None))
for l in ls:
try:
(k, v) = l.split(('='), 1)
except ValueError:
raise Exception('labels must be in format key1=val1,key2-val2')
if k not in labels:
labels[k] = v
else:
raise Exception('key %s in labels defined multiple times')
cls.labels = labels
@classmethod
def set_nic_id(cls, config):
if 'nic_id' not in CONF.magnum:
@ -168,6 +184,7 @@ class Config(object):
cls.set_docker_storage_driver(config)
cls.set_region(config)
cls.set_image_id(config)
cls.set_labels(config)
cls.set_nic_id(config)
cls.set_keypair_name(config)
cls.set_flavor_id(config)

View File

@ -225,7 +225,8 @@ def valid_kubernetes_baymodel(is_public=False):
cluster_distro=None,
external_network_id=config.Config.nic_id,
http_proxy=None, https_proxy=None, no_proxy=None,
network_driver=None, volume_driver=None, labels={},
network_driver=None, volume_driver=None,
labels=config.Config.labels,
tls_disabled=False)
@ -505,7 +506,7 @@ def valid_cluster_template(is_public=False):
external_network_id=config.Config.nic_id,
http_proxy=None, https_proxy=None,
no_proxy=None, network_driver=config.Config.network_driver,
volume_driver=None, labels={},
volume_driver=None, labels=config.Config.labels,
docker_storage_driver=config.Config.docker_storage_driver,
tls_disabled=False)

View File

@ -31,6 +31,8 @@ MagnumGroup = [
cfg.StrOpt("image_id",
default="fedora-coreos-latest",
help="Image id to be used for ClusterTemplate."),
cfg.StrOpt("labels",
help="Labels in format key1=value1,key2=value2."),
cfg.StrOpt("nic_id",
default="public",
help="NIC id."),