Fix config.py
This commit is contained in:
parent
2814653559
commit
9658eed822
|
@ -12,10 +12,13 @@
|
||||||
# WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
|
# WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
|
||||||
# License for the specific language governing permissions and limitations
|
# License for the specific language governing permissions and limitations
|
||||||
# under the License.
|
# under the License.
|
||||||
|
import logging as std_logging
|
||||||
|
import os
|
||||||
|
|
||||||
from oslo_config import cfg
|
from oslo_config import cfg
|
||||||
|
from oslo_log import log as logging
|
||||||
|
|
||||||
from tempest import config # noqa
|
LOG = logging.getLogger('tempest_stress')
|
||||||
|
|
||||||
stress_group = cfg.OptGroup(name='stress', title='Stress Test Options')
|
stress_group = cfg.OptGroup(name='stress', title='Stress Test Options')
|
||||||
|
|
||||||
|
@ -58,41 +61,46 @@ class StressConfigPrivate(object):
|
||||||
|
|
||||||
DEFAULT_CONFIG_FILE = "stress_tests.conf"
|
DEFAULT_CONFIG_FILE = "stress_tests.conf"
|
||||||
|
|
||||||
def __init__(self):
|
def __init__(self, config_path=None):
|
||||||
"""Initialize a configuration from a conf directory and conf file."""
|
"""Initialize a configuration from a conf directory and conf file."""
|
||||||
super(StressConfigPrivate, self).__init__()
|
super(StressConfigPrivate, self).__init__()
|
||||||
|
|
||||||
# Environment variables override defaults.
|
# Environment variables override defaults.
|
||||||
conf_file = os.environ.get('STRESS_TEST_CONFIG', self.DEFAULT_CONFIG_FILE)
|
conf_file = os.environ.get('STRESS_TEST_CONFIG', self.DEFAULT_CONFIG_FILE)
|
||||||
conf_dirs = list()
|
conf_path = ''
|
||||||
conf_dir = os.path.dirname(os.path.dirname(__file__))
|
if config_path:
|
||||||
conf_path = os.path.join(conf_dir, conf_file)
|
config_path + '/' + self.DEFAULT_CONFIG_FILE
|
||||||
if not os.path.isfile(conf_path):
|
if not os.path.isfile(conf_path):
|
||||||
if os.environ.get('STRESS_TEST_CONFIG_DIR'):
|
if os.environ.get('STRESS_TEST_CONFIG_DIR'):
|
||||||
conf_dir = os.environ.get('STRESS_TEST_CONFIG_DIR')
|
conf_dir = os.environ.get('STRESS_TEST_CONFIG_DIR')
|
||||||
conf_path = os.path.join(conf_dir, conf_file)
|
conf_path = os.path.join(conf_dir, conf_file)
|
||||||
if not os.path.isfile(conf_path):
|
if not os.path.isfile(conf_path):
|
||||||
raise Exception('Config file: %s could not be found'
|
conf_path = "/etc/tempest/" + self.DEFAULT_CONFIG_FILE
|
||||||
% self.DEFAULT_CONFIG_FILE)
|
|
||||||
LOG.info("Using tempest_stress config file %s" % conf_path)
|
LOG.info("Using tempest_stress config file %s" % conf_path)
|
||||||
conf = cfg.CONF
|
conf = cfg.CONF
|
||||||
conf([], project='tempest_stress', default_config_files=[conf_path])
|
if os.path.isfile(conf_path):
|
||||||
assert False, conf_path
|
conf([], project='stress', default_config_files=[conf_path])
|
||||||
|
else:
|
||||||
|
conf([], project='stress')
|
||||||
conf.register_group(stress_group)
|
conf.register_group(stress_group)
|
||||||
group_name = stress_group.name
|
group_name = stress_group.name
|
||||||
for opt in StressGroup:
|
for opt in StressGroup:
|
||||||
conf.register_opt(opt, group=group_name)
|
conf.register_opt(opt, group=group_name)
|
||||||
self.stress = cfg.CONF.stress
|
self.stress = conf.stress
|
||||||
conf.log_opt_values(LOG, std_logging.DEBUG)
|
conf.log_opt_values(LOG, std_logging.DEBUG)
|
||||||
|
|
||||||
|
|
||||||
class StressConfigProxy(object):
|
class StressConfigProxy(object):
|
||||||
_config = None
|
_config = None
|
||||||
|
_path = None
|
||||||
def __getattr__(self, attr):
|
def __getattr__(self, attr):
|
||||||
if not self._config:
|
if not self._config:
|
||||||
self._config = StressConfigPrivate()
|
self._config = StressConfigPrivate(config_path=self._path)
|
||||||
|
|
||||||
return getattr(self._config, attr)
|
return getattr(self._config, attr)
|
||||||
|
|
||||||
|
def set_config_path(self, path):
|
||||||
|
self._path = path
|
||||||
|
|
||||||
|
|
||||||
CONF = StressConfigProxy()
|
CONF = StressConfigProxy()
|
||||||
|
|
Loading…
Reference in New Issue