Make all params configurable via system env
Change-Id: I7cc86ef8abd429fbd0028507b2bde8bd11bdffea
This commit is contained in:
parent
a8e50eacc4
commit
d73c8ad2d4
@ -87,7 +87,8 @@
|
|||||||
# From shaker.engine.config
|
# From shaker.engine.config
|
||||||
#
|
#
|
||||||
|
|
||||||
# Address for server connections (host:port) (string value)
|
# Address for server connections (host:port), defaults to
|
||||||
|
# env[SHAKER_SERVER_ENDPOINT]. (string value)
|
||||||
#server_endpoint = <None>
|
#server_endpoint = <None>
|
||||||
|
|
||||||
#
|
#
|
||||||
@ -109,15 +110,16 @@
|
|||||||
# Authentication region name, defaults to env[OS_REGION_NAME]. (string value)
|
# Authentication region name, defaults to env[OS_REGION_NAME]. (string value)
|
||||||
#os_region_name = RegionOne
|
#os_region_name = RegionOne
|
||||||
|
|
||||||
# Name or ID of external network. If not set the network is chosen randomly.
|
# Name or ID of external network, defaults to env[SHAKER_EXTERNAL_NET]. If no
|
||||||
# (string value)
|
# value provided then Shaker picks any of available external networks. (string
|
||||||
|
# value)
|
||||||
#external_net = <None>
|
#external_net = <None>
|
||||||
|
|
||||||
# Name of image to use. The default is created by shaker-image-builder (string
|
# Name of image to use. The default is created by shaker-image-builder. (string
|
||||||
# value)
|
# value)
|
||||||
#image_name = shaker-image
|
#image_name = shaker-image
|
||||||
|
|
||||||
# Name of image flavor. The default is created by shaker-image-builder (string
|
# Name of image flavor. The default is created by shaker-image-builder. (string
|
||||||
# value)
|
# value)
|
||||||
#flavor_name = shaker-flavor
|
#flavor_name = shaker-flavor
|
||||||
|
|
||||||
@ -125,20 +127,21 @@
|
|||||||
# From shaker.engine.config
|
# From shaker.engine.config
|
||||||
#
|
#
|
||||||
|
|
||||||
# Scenario file name (string value)
|
# Scenario file name, defaults to env[SHAKER_SCENARIO]. (string value)
|
||||||
#scenario = <None>
|
#scenario = <None>
|
||||||
|
|
||||||
# Report template in Jinja format (string value)
|
# Report template in Jinja format (string value)
|
||||||
#report_template = shaker/resources/report_template.jinja2
|
#report_template = shaker/resources/report_template.jinja2
|
||||||
|
|
||||||
# Report file name. If not specified print to stdout (string value)
|
# Report file name, defaults to env[SHAKER_REPORT]. If no value provided the
|
||||||
|
# report is printed to stdout. (string value)
|
||||||
#report = <None>
|
#report = <None>
|
||||||
|
|
||||||
#
|
#
|
||||||
# From shaker.engine.config
|
# From shaker.engine.config
|
||||||
#
|
#
|
||||||
|
|
||||||
# Agent unique id (string value)
|
# Agent unique id, defaults to env[SHAKER_AGENT_ID]. (string value)
|
||||||
#agent_id = <None>
|
#agent_id = <None>
|
||||||
|
|
||||||
#
|
#
|
||||||
|
@ -21,64 +21,84 @@ from shaker.engine import utils
|
|||||||
|
|
||||||
COMMON_OPTS = [
|
COMMON_OPTS = [
|
||||||
cfg.StrOpt('server-endpoint',
|
cfg.StrOpt('server-endpoint',
|
||||||
|
default=utils.env('SHAKER_SERVER_ENDPOINT'),
|
||||||
required=True,
|
required=True,
|
||||||
help='Address for server connections (host:port)'),
|
help='Address for server connections (host:port), '
|
||||||
|
'defaults to env[SHAKER_SERVER_ENDPOINT].'),
|
||||||
]
|
]
|
||||||
|
|
||||||
OPENSTACK_OPTS = [
|
OPENSTACK_OPTS = [
|
||||||
cfg.StrOpt('os-auth-url', metavar='<auth-url>',
|
cfg.StrOpt('os-auth-url', metavar='<auth-url>',
|
||||||
default=utils.env('OS_AUTH_URL'),
|
default=utils.env('OS_AUTH_URL'),
|
||||||
|
sample_default='',
|
||||||
|
required=True,
|
||||||
help='Authentication URL, defaults to env[OS_AUTH_URL].'),
|
help='Authentication URL, defaults to env[OS_AUTH_URL].'),
|
||||||
cfg.StrOpt('os-tenant-name', metavar='<auth-tenant-name>',
|
cfg.StrOpt('os-tenant-name', metavar='<auth-tenant-name>',
|
||||||
default=utils.env('OS_TENANT_NAME'),
|
default=utils.env('OS_TENANT_NAME'),
|
||||||
|
sample_default='',
|
||||||
|
required=True,
|
||||||
help='Authentication tenant name, defaults to '
|
help='Authentication tenant name, defaults to '
|
||||||
'env[OS_TENANT_NAME].'),
|
'env[OS_TENANT_NAME].'),
|
||||||
cfg.StrOpt('os-username', metavar='<auth-username>',
|
cfg.StrOpt('os-username', metavar='<auth-username>',
|
||||||
default=utils.env('OS_USERNAME'),
|
default=utils.env('OS_USERNAME'),
|
||||||
|
sample_default='',
|
||||||
|
required=True,
|
||||||
help='Authentication username, defaults to env[OS_USERNAME].'),
|
help='Authentication username, defaults to env[OS_USERNAME].'),
|
||||||
cfg.StrOpt('os-password', metavar='<auth-password>',
|
cfg.StrOpt('os-password', metavar='<auth-password>',
|
||||||
default=utils.env('OS_PASSWORD'),
|
default=utils.env('OS_PASSWORD'),
|
||||||
|
sample_default='',
|
||||||
|
required=True,
|
||||||
help='Authentication password, defaults to env[OS_PASSWORD].'),
|
help='Authentication password, defaults to env[OS_PASSWORD].'),
|
||||||
cfg.StrOpt('os-region-name', metavar='<auth-region-name>',
|
cfg.StrOpt('os-region-name', metavar='<auth-region-name>',
|
||||||
default=utils.env('OS_REGION_NAME') or 'RegionOne',
|
default=utils.env('OS_REGION_NAME') or 'RegionOne',
|
||||||
|
required=True,
|
||||||
help='Authentication region name, defaults to '
|
help='Authentication region name, defaults to '
|
||||||
'env[OS_REGION_NAME].'),
|
'env[OS_REGION_NAME].'),
|
||||||
|
|
||||||
cfg.StrOpt('external-net',
|
cfg.StrOpt('external-net',
|
||||||
help='Name or ID of external network. If not set the network '
|
default=utils.env('SHAKER_EXTERNAL_NET'),
|
||||||
'is chosen randomly.'),
|
help='Name or ID of external network, defaults to '
|
||||||
|
'env[SHAKER_EXTERNAL_NET]. If no value provided then '
|
||||||
|
'Shaker picks any of available external networks.'),
|
||||||
|
|
||||||
cfg.StrOpt('image-name',
|
cfg.StrOpt('image-name',
|
||||||
default='shaker-image',
|
default=utils.env('SHAKER_IMAGE') or 'shaker-image',
|
||||||
help='Name of image to use. The default is created by '
|
help='Name of image to use. The default is created by '
|
||||||
'shaker-image-builder'),
|
'shaker-image-builder.'),
|
||||||
cfg.StrOpt('flavor-name',
|
cfg.StrOpt('flavor-name',
|
||||||
default='shaker-flavor',
|
default=utils.env('SHAKER_FLAVOR') or 'shaker-flavor',
|
||||||
help='Name of image flavor. The default is created by '
|
help='Name of image flavor. The default is created by '
|
||||||
'shaker-image-builder'),
|
'shaker-image-builder.'),
|
||||||
]
|
]
|
||||||
|
|
||||||
SERVER_OPTS = [
|
SERVER_OPTS = [
|
||||||
cfg.StrOpt('scenario',
|
cfg.StrOpt('scenario',
|
||||||
|
default=utils.env('SHAKER_SCENARIO'),
|
||||||
required=True,
|
required=True,
|
||||||
help='Scenario file name'),
|
help='Scenario file name, defaults to env[SHAKER_SCENARIO].'),
|
||||||
|
|
||||||
cfg.StrOpt('report-template',
|
cfg.StrOpt('report-template',
|
||||||
default='shaker/resources/report_template.jinja2',
|
default=(utils.env('SHAKER_REPORT_TEMPLATE') or
|
||||||
|
'shaker/resources/report_template.jinja2'),
|
||||||
help='Report template in Jinja format'),
|
help='Report template in Jinja format'),
|
||||||
cfg.StrOpt('report',
|
cfg.StrOpt('report',
|
||||||
help='Report file name. If not specified print to stdout'),
|
default=utils.env('SHAKER_REPORT'),
|
||||||
|
help='Report file name, defaults to env[SHAKER_REPORT]. '
|
||||||
|
'If no value provided the report is printed to stdout.'),
|
||||||
]
|
]
|
||||||
|
|
||||||
|
|
||||||
AGENT_OPTS = [
|
AGENT_OPTS = [
|
||||||
cfg.StrOpt('agent-id',
|
cfg.StrOpt('agent-id',
|
||||||
|
default=utils.env('SHAKER_AGENT_ID'),
|
||||||
required=True,
|
required=True,
|
||||||
help='Agent unique id'),
|
help='Agent unique id, defaults to env[SHAKER_AGENT_ID].'),
|
||||||
]
|
]
|
||||||
|
|
||||||
IMAGE_BUILDER_OPTS = [
|
IMAGE_BUILDER_OPTS = [
|
||||||
cfg.StrOpt('image-builder-template',
|
cfg.StrOpt('image-builder-template',
|
||||||
default='shaker/resources/image_builder_template.yaml',
|
default=(utils.env('SHAKER_IMAGE_BUILDER_TEMPLATE') or
|
||||||
|
'shaker/resources/image_builder_template.yaml'),
|
||||||
help='Heat template for the image builder.'),
|
help='Heat template for the image builder.'),
|
||||||
]
|
]
|
||||||
|
|
||||||
|
@ -13,6 +13,7 @@
|
|||||||
# See the License for the specific language governing permissions and
|
# See the License for the specific language governing permissions and
|
||||||
# limitations under the License.
|
# limitations under the License.
|
||||||
|
|
||||||
|
import logging as std_logging
|
||||||
import uuid
|
import uuid
|
||||||
|
|
||||||
from oslo_config import cfg
|
from oslo_config import cfg
|
||||||
@ -33,16 +34,23 @@ LOG = logging.getLogger(__name__)
|
|||||||
def init():
|
def init():
|
||||||
# init conf and logging
|
# init conf and logging
|
||||||
conf = cfg.CONF
|
conf = cfg.CONF
|
||||||
conf.register_cli_opts(config.OPENSTACK_OPTS)
|
opts = config.OPENSTACK_OPTS + config.IMAGE_BUILDER_OPTS
|
||||||
conf.register_cli_opts(config.IMAGE_BUILDER_OPTS)
|
conf.register_cli_opts(opts)
|
||||||
conf.register_opts(config.OPENSTACK_OPTS)
|
conf.register_opts(opts)
|
||||||
conf.register_opts(config.IMAGE_BUILDER_OPTS)
|
|
||||||
logging.register_options(conf)
|
logging.register_options(conf)
|
||||||
logging.set_defaults()
|
logging.set_defaults()
|
||||||
|
|
||||||
|
try:
|
||||||
conf(project='shaker')
|
conf(project='shaker')
|
||||||
|
utils.validate_required_opts(conf, opts)
|
||||||
|
except cfg.RequiredOptError as e:
|
||||||
|
print('Error: %s' % e)
|
||||||
|
conf.print_usage()
|
||||||
|
exit(1)
|
||||||
|
|
||||||
logging.setup(conf, 'shaker')
|
logging.setup(conf, 'shaker')
|
||||||
LOG.info('Logging enabled')
|
LOG.info('Logging enabled')
|
||||||
|
conf.log_opt_values(LOG, std_logging.DEBUG)
|
||||||
|
|
||||||
openstack_client = openstack.OpenStackClient(
|
openstack_client = openstack.OpenStackClient(
|
||||||
username=cfg.CONF.os_username, password=cfg.CONF.os_password,
|
username=cfg.CONF.os_username, password=cfg.CONF.os_password,
|
||||||
|
@ -13,6 +13,7 @@
|
|||||||
# See the License for the specific language governing permissions and
|
# See the License for the specific language governing permissions and
|
||||||
# limitations under the License.
|
# limitations under the License.
|
||||||
|
|
||||||
|
import logging as std_logging
|
||||||
import time
|
import time
|
||||||
import uuid
|
import uuid
|
||||||
|
|
||||||
@ -197,17 +198,15 @@ def execute(execution, agents):
|
|||||||
def main():
|
def main():
|
||||||
# init conf and logging
|
# init conf and logging
|
||||||
conf = cfg.CONF
|
conf = cfg.CONF
|
||||||
conf.register_cli_opts(config.COMMON_OPTS)
|
opts = config.COMMON_OPTS + config.OPENSTACK_OPTS + config.SERVER_OPTS
|
||||||
conf.register_cli_opts(config.OPENSTACK_OPTS)
|
conf.register_cli_opts(opts)
|
||||||
conf.register_cli_opts(config.SERVER_OPTS)
|
conf.register_opts(opts)
|
||||||
conf.register_opts(config.COMMON_OPTS)
|
|
||||||
conf.register_opts(config.OPENSTACK_OPTS)
|
|
||||||
conf.register_opts(config.SERVER_OPTS)
|
|
||||||
logging.register_options(conf)
|
logging.register_options(conf)
|
||||||
logging.set_defaults()
|
logging.set_defaults()
|
||||||
|
|
||||||
try:
|
try:
|
||||||
conf(project='shaker')
|
conf(project='shaker')
|
||||||
|
utils.validate_required_opts(conf, opts)
|
||||||
except cfg.RequiredOptError as e:
|
except cfg.RequiredOptError as e:
|
||||||
print('Error: %s' % e)
|
print('Error: %s' % e)
|
||||||
conf.print_usage()
|
conf.print_usage()
|
||||||
@ -215,6 +214,7 @@ def main():
|
|||||||
|
|
||||||
logging.setup(conf, 'shaker')
|
logging.setup(conf, 'shaker')
|
||||||
LOG.info('Logging enabled')
|
LOG.info('Logging enabled')
|
||||||
|
conf.log_opt_values(LOG, std_logging.DEBUG)
|
||||||
|
|
||||||
scenario = read_scenario()
|
scenario = read_scenario()
|
||||||
deployment = deploy.Deployment(cfg.CONF.os_username,
|
deployment = deploy.Deployment(cfg.CONF.os_username,
|
||||||
|
@ -16,6 +16,7 @@
|
|||||||
import os
|
import os
|
||||||
import random
|
import random
|
||||||
|
|
||||||
|
from oslo_config import cfg
|
||||||
from oslo_log import log as logging
|
from oslo_log import log as logging
|
||||||
import six
|
import six
|
||||||
|
|
||||||
@ -32,7 +33,15 @@ def env(*_vars, **kwargs):
|
|||||||
value = os.environ.get(v)
|
value = os.environ.get(v)
|
||||||
if value:
|
if value:
|
||||||
return value
|
return value
|
||||||
return kwargs.get('default', '')
|
return kwargs.get('default', None)
|
||||||
|
|
||||||
|
|
||||||
|
def validate_required_opts(conf, opts):
|
||||||
|
# all config parameters default to ENV values, that's why standard
|
||||||
|
# check of required options doesn't work and needs to be done manually
|
||||||
|
for opt in opts:
|
||||||
|
if opt.required and not conf[opt.dest]:
|
||||||
|
raise cfg.RequiredOptError(opt.name)
|
||||||
|
|
||||||
|
|
||||||
def read_file(file_name):
|
def read_file(file_name):
|
||||||
|
Loading…
Reference in New Issue
Block a user