94b85f7f17cfbdea36e088462885e41e721c0904
[doctor.git] / 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 import alarm\r
14 import consumer\r
15 import image\r
16 import instance\r
17 import network\r
18 import os_clients\r
19 import user\r
20 \r
21 \r
22 def list_opts():\r
23     return [\r
24         ('consumer', consumer.OPTS),\r
25         ('DEFAULT', itertools.chain(\r
26             os_clients.OPTS,\r
27             image.OPTS,\r
28             user.OPTS,\r
29             network.OPTS,\r
30             instance.OPTS,\r
31             alarm.OPTS))\r
32     ]\r
33 \r
34 \r
35 def prepare_conf(args=None, conf=None, config_files=None):\r
36     if conf is None:\r
37         conf = cfg.ConfigOpts()\r
38 \r
39     for group, options in list_opts():\r
40         conf.register_opts(list(options),\r
41                            group=None if group == 'DEFAULT' else group)\r
42 \r
43     conf(args, project='doctor', validate_default_values=True,\r
44          default_config_files=config_files)\r
45 \r
46     return conf\r