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