Add config file flag to javelin

Instead of playing around with environmental variables, since javelin
is a CLI, add a flag to set the config file path.

Change-Id: I1e82e0a8e72117ba55048b2dab7aa9a8ba00c1cb
This commit is contained in:
Joe Gordon
2014-07-17 15:38:28 +00:00
parent 246353a958
commit 28a84ae570
3 changed files with 25 additions and 8 deletions

View File

@@ -28,6 +28,7 @@ import yaml
import argparse
import tempest.auth
from tempest import config
from tempest import exceptions
from tempest.services.compute.json import flavors_client
from tempest.services.compute.json import servers_client
@@ -452,11 +453,17 @@ def get_options():
required=True,
metavar='resourcefile.yaml',
help='Resources definition yaml file')
parser.add_argument(
'-d', '--devstack-base',
required=True,
metavar='/opt/stack/old',
help='Devstack base directory for retrieving artifacts')
parser.add_argument(
'-c', '--config-file',
metavar='/etc/tempest.conf',
help='path to javelin2(tempest) config file')
# auth bits, letting us also just source the devstack openrc
parser.add_argument('--os-username',
metavar='<auth-user-name>',
@@ -476,6 +483,8 @@ def get_options():
print("ERROR: Unknown mode -m %s\n" % OPTS.mode)
parser.print_help()
sys.exit(1)
if OPTS.config_file:
config.CONF.set_config_path(OPTS.config_file)
def setup_logging(debug=True):

View File

@@ -1085,18 +1085,22 @@ class TempestConfigPrivate(object):
cfg.CONF.set_default('domain_name', self.identity.admin_domain_name,
group='compute-admin')
def __init__(self, parse_conf=True):
def __init__(self, parse_conf=True, config_path=None):
"""Initialize a configuration from a conf directory and conf file."""
super(TempestConfigPrivate, self).__init__()
config_files = []
failsafe_path = "/etc/tempest/" + self.DEFAULT_CONFIG_FILE
# Environment variables override defaults...
conf_dir = os.environ.get('TEMPEST_CONFIG_DIR',
self.DEFAULT_CONFIG_DIR)
conf_file = os.environ.get('TEMPEST_CONFIG', self.DEFAULT_CONFIG_FILE)
if config_path:
path = config_path
else:
# Environment variables override defaults...
conf_dir = os.environ.get('TEMPEST_CONFIG_DIR',
self.DEFAULT_CONFIG_DIR)
conf_file = os.environ.get('TEMPEST_CONFIG',
self.DEFAULT_CONFIG_FILE)
path = os.path.join(conf_dir, conf_file)
path = os.path.join(conf_dir, conf_file)
if not os.path.isfile(path):
path = failsafe_path
@@ -1118,6 +1122,7 @@ class TempestConfigPrivate(object):
class TempestConfigProxy(object):
_config = None
_path = None
_extra_log_defaults = [
'keystoneclient.session=INFO',
@@ -1134,9 +1139,12 @@ class TempestConfigProxy(object):
def __getattr__(self, attr):
if not self._config:
self._fix_log_levels()
self._config = TempestConfigPrivate()
self._config = TempestConfigPrivate(config_path=self._path)
return getattr(self._config, attr)
def set_config_path(self, path):
self._path = path
CONF = TempestConfigProxy()

View File

@@ -58,6 +58,6 @@ class ConfigFixture(conf_fixture.Config):
class FakePrivate(config.TempestConfigPrivate):
def __init__(self):
def __init__(self, parse_conf=True, config_path=None):
cfg.CONF([], default_config_files=[])
self._set_attrs()