From 6023c50ca1a02808703ffb5a3cb18375a1c5a8fa Mon Sep 17 00:00:00 2001 From: dongwenjuan Date: Thu, 22 Jun 2017 19:26:05 +0800 Subject: support config file Change-Id: Ib8e696acfe21787904fce6838341f3a256aa0267 Signed-off-by: dongwenjuan --- etc/doctor.sample.conf | 26 ++++++++++++++++++++++++++ tests/config.py | 6 +++++- tests/main.py | 10 +++++++++- 3 files changed, 40 insertions(+), 2 deletions(-) create mode 100644 etc/doctor.sample.conf diff --git a/etc/doctor.sample.conf b/etc/doctor.sample.conf new file mode 100644 index 00000000..8a1ddc3e --- /dev/null +++ b/etc/doctor.sample.conf @@ -0,0 +1,26 @@ +############################################################################## +# Copyright (c) 2017 ZTE Corporation and others. +# +# All rights reserved. This program and the accompanying materials +# are made available under the terms of the Apache License, Version 2.0 +# which accompanies this distribution, and is available at +# http://www.apache.org/licenses/LICENSE-2.0 +############################################################################## +[DEFAULT] +image_name = cirros +image_format = qcow2 +image_filename = cirros.img +image_download_url = https://launchpad.net/cirros/trunk/0.3.0/+download/cirros-0.3.0-x86_64-disk.img + +glance_version = 2 +nova_version = 2.34 + +doctor_user = doctor +doctor_passwd = doctor +doctor_project = doctor +doctor_role = _member_ +quota_instances = 1 +quota_cores = 1 + + + diff --git a/tests/config.py b/tests/config.py index 7a0bef2d..3cacd0a2 100644 --- a/tests/config.py +++ b/tests/config.py @@ -7,6 +7,7 @@ # http://www.apache.org/licenses/LICENSE-2.0 ############################################################################## import itertools + from oslo_config import cfg import image @@ -23,7 +24,7 @@ def list_opts(): ] -def prepare_conf(conf=None): +def prepare_conf(args=None, conf=None, config_files=None): if conf is None: conf = cfg.ConfigOpts() @@ -31,4 +32,7 @@ def prepare_conf(conf=None): conf.register_opts(list(options), group=None if group == 'DEFAULT' else group) + conf(args, project='doctor', validate_default_values=True, + default_config_files=config_files) + return conf diff --git a/tests/main.py b/tests/main.py index 46f0c894..bb2c912d 100644 --- a/tests/main.py +++ b/tests/main.py @@ -6,6 +6,8 @@ # which accompanies this distribution, and is available at # http://www.apache.org/licenses/LICENSE-2.0 ############################################################################## +import os +from os.path import isfile, join import sys import config @@ -58,7 +60,13 @@ class DoctorTest(object): def main(): """doctor main""" - conf = config.prepare_conf() + doctor_root_dir = os.path.dirname(os.getcwd()) + config_file_dir = '{0}/{1}'.format(doctor_root_dir, 'etc/') + config_files = [join(config_file_dir, f) for f in os.listdir(config_file_dir) + if isfile(join(config_file_dir, f))] + + conf = config.prepare_conf(args=sys.argv[1:], + config_files=config_files) doctor = DoctorTest(conf) doctor.run() -- cgit 1.2.3-korg