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