dc05c0d875f7c27aaee20b4db25594d24bc22637
[doctor.git] / doctor_tests / config.py
1 ##############################################################################\r
2 # Copyright (c) 2017 ZTE Corporation and others.\r
3 #\r
4 # All rights reserved. This program and the accompanying materials\r
5 # are made available under the terms of the Apache License, Version 2.0\r
6 # which accompanies this distribution, and is available at\r
7 # http://www.apache.org/licenses/LICENSE-2.0\r
8 ##############################################################################\r
9 import itertools\r
10 \r
11 from oslo_config import cfg\r
12 \r
13 from doctor_tests import alarm\r
14 from doctor_tests import consumer\r
15 from doctor_tests import image\r
16 from doctor_tests import instance\r
17 from doctor_tests import installer\r
18 from doctor_tests import network\r
19 from doctor_tests import inspector\r
20 from doctor_tests import monitor\r
21 from doctor_tests import os_clients\r
22 from doctor_tests import profiler_poc\r
23 from doctor_tests import user\r
24 from doctor_tests import scenario\r
25 \r
26 \r
27 def list_opts():\r
28     return [\r
29         ('installer', installer.OPTS),\r
30         ('monitor', monitor.OPTS),\r
31         ('inspector', inspector.OPTS),\r
32         ('consumer', consumer.OPTS),\r
33         ('DEFAULT', itertools.chain(\r
34             os_clients.OPTS,\r
35             image.OPTS,\r
36             user.OPTS,\r
37             network.OPTS,\r
38             instance.OPTS,\r
39             alarm.OPTS,\r
40             profiler_poc.OPTS,\r
41             scenario.OPTS))\r
42     ]\r
43 \r
44 \r
45 def prepare_conf(args=None, conf=None, config_files=None):\r
46     if conf is None:\r
47         conf = cfg.ConfigOpts()\r
48 \r
49     for group, options in list_opts():\r
50         conf.register_opts(list(options),\r
51                            group=None if group == 'DEFAULT' else group)\r
52 \r
53     conf(args, project='doctor', validate_default_values=True,\r
54          default_config_files=config_files)\r
55 \r
56     return conf\r