Merge "improve OptGroup consistency across configuration"
This commit is contained in:
@@ -22,6 +22,7 @@ from watcher.conf import api as conf_api
|
|||||||
from watcher.conf import applier as conf_applier
|
from watcher.conf import applier as conf_applier
|
||||||
from watcher.conf import ceilometer_client as conf_ceilometer_client
|
from watcher.conf import ceilometer_client as conf_ceilometer_client
|
||||||
from watcher.conf import cinder_client as conf_cinder_client
|
from watcher.conf import cinder_client as conf_cinder_client
|
||||||
|
from watcher.conf import clients_auth as conf_auth
|
||||||
from watcher.conf import db
|
from watcher.conf import db
|
||||||
from watcher.conf import decision_engine as conf_de
|
from watcher.conf import decision_engine as conf_de
|
||||||
from watcher.conf import exception
|
from watcher.conf import exception
|
||||||
@@ -39,19 +40,22 @@ def list_opts():
|
|||||||
(conf_api.AUTH_OPTS +
|
(conf_api.AUTH_OPTS +
|
||||||
exception.EXC_LOG_OPTS +
|
exception.EXC_LOG_OPTS +
|
||||||
paths.PATH_OPTS)),
|
paths.PATH_OPTS)),
|
||||||
('api', conf_api.API_SERVICE_OPTS),
|
(conf_api.api, conf_api.API_SERVICE_OPTS),
|
||||||
('database', db.SQL_OPTS),
|
(db.database, db.SQL_OPTS),
|
||||||
('watcher_planner', conf_planner.WATCHER_PLANNER_OPTS),
|
(conf_planner.watcher_planner, conf_planner.WATCHER_PLANNER_OPTS),
|
||||||
('watcher_applier', conf_applier.APPLIER_MANAGER_OPTS),
|
(conf_applier.watcher_applier, conf_applier.APPLIER_MANAGER_OPTS),
|
||||||
('watcher_decision_engine',
|
(conf_de.watcher_decision_engine,
|
||||||
(conf_de.WATCHER_DECISION_ENGINE_OPTS +
|
(conf_de.WATCHER_DECISION_ENGINE_OPTS)),
|
||||||
conf_de.WATCHER_CONTINUOUS_OPTS)),
|
(conf_nova_client.nova_client, conf_nova_client.NOVA_CLIENT_OPTS),
|
||||||
('nova_client', conf_nova_client.NOVA_CLIENT_OPTS),
|
(conf_glance_client.glance_client,
|
||||||
('glance_client', conf_glance_client.GLANCE_CLIENT_OPTS),
|
conf_glance_client.GLANCE_CLIENT_OPTS),
|
||||||
('cinder_client', conf_cinder_client.CINDER_CLIENT_OPTS),
|
(conf_cinder_client.cinder_client,
|
||||||
('ceilometer_client', conf_ceilometer_client.CEILOMETER_CLIENT_OPTS),
|
conf_cinder_client.CINDER_CLIENT_OPTS),
|
||||||
('neutron_client', conf_neutron_client.NEUTRON_CLIENT_OPTS),
|
(conf_ceilometer_client.ceilometer_client,
|
||||||
('watcher_clients_auth',
|
conf_ceilometer_client.CEILOMETER_CLIENT_OPTS),
|
||||||
|
(conf_neutron_client.neutron_client,
|
||||||
|
conf_neutron_client.NEUTRON_CLIENT_OPTS),
|
||||||
|
(conf_auth.WATCHER_CLIENTS_AUTH,
|
||||||
(ka_loading.get_auth_common_conf_options() +
|
(ka_loading.get_auth_common_conf_options() +
|
||||||
ka_loading.get_auth_plugin_conf_options('password') +
|
ka_loading.get_auth_plugin_conf_options('password') +
|
||||||
ka_loading.get_session_conf_options()))
|
ka_loading.get_session_conf_options()))
|
||||||
|
|||||||
@@ -65,4 +65,4 @@ def register_opts(conf):
|
|||||||
|
|
||||||
|
|
||||||
def list_opts():
|
def list_opts():
|
||||||
return [('api', API_SERVICE_OPTS), ('DEFAULT', AUTH_OPTS)]
|
return [(api, API_SERVICE_OPTS), ('DEFAULT', AUTH_OPTS)]
|
||||||
|
|||||||
@@ -50,4 +50,4 @@ def register_opts(conf):
|
|||||||
|
|
||||||
|
|
||||||
def list_opts():
|
def list_opts():
|
||||||
return [('watcher_applier', APPLIER_MANAGER_OPTS)]
|
return [(watcher_applier, APPLIER_MANAGER_OPTS)]
|
||||||
|
|||||||
@@ -60,4 +60,4 @@ def register_opts(conf):
|
|||||||
|
|
||||||
|
|
||||||
def list_opts():
|
def list_opts():
|
||||||
return [('ceilometer_client', CEILOMETER_CLIENT_OPTS)]
|
return [(ceilometer_client, CEILOMETER_CLIENT_OPTS)]
|
||||||
|
|||||||
@@ -41,4 +41,4 @@ def register_opts(conf):
|
|||||||
|
|
||||||
|
|
||||||
def list_opts():
|
def list_opts():
|
||||||
return [('cinder_client', CINDER_CLIENT_OPTS)]
|
return [(cinder_client, CINDER_CLIENT_OPTS)]
|
||||||
|
|||||||
@@ -27,5 +27,5 @@ def register_opts(conf):
|
|||||||
|
|
||||||
|
|
||||||
def list_opts():
|
def list_opts():
|
||||||
return [('watcher_clients_auth', ka_loading.get_session_conf_options() +
|
return [(WATCHER_CLIENTS_AUTH, ka_loading.get_session_conf_options() +
|
||||||
ka_loading.get_auth_common_conf_options())]
|
ka_loading.get_auth_common_conf_options())]
|
||||||
|
|||||||
@@ -45,4 +45,4 @@ def register_opts(conf):
|
|||||||
|
|
||||||
|
|
||||||
def list_opts():
|
def list_opts():
|
||||||
return [('collector', COLLECTOR_OPTS)]
|
return [(collector, COLLECTOR_OPTS)]
|
||||||
|
|||||||
@@ -56,4 +56,4 @@ def register_opts(conf):
|
|||||||
|
|
||||||
|
|
||||||
def list_opts():
|
def list_opts():
|
||||||
return [('watcher_datasources', DATASOURCES_OPTS)]
|
return [(datasources, DATASOURCES_OPTS)]
|
||||||
|
|||||||
@@ -41,4 +41,4 @@ def register_opts(conf):
|
|||||||
|
|
||||||
|
|
||||||
def list_opts():
|
def list_opts():
|
||||||
return [('database', SQL_OPTS)]
|
return [(database, SQL_OPTS)]
|
||||||
|
|||||||
@@ -68,24 +68,19 @@ WATCHER_DECISION_ENGINE_OPTS = [
|
|||||||
' instance_cpu_usage: VM_CPU\n'
|
' instance_cpu_usage: VM_CPU\n'
|
||||||
' gnocchi:\n'
|
' gnocchi:\n'
|
||||||
' instance_cpu_usage: cpu_vm_util\n\n'
|
' instance_cpu_usage: cpu_vm_util\n\n'
|
||||||
'This file is optional.')]
|
'This file is optional.'),
|
||||||
|
|
||||||
WATCHER_CONTINUOUS_OPTS = [
|
|
||||||
cfg.IntOpt('continuous_audit_interval',
|
cfg.IntOpt('continuous_audit_interval',
|
||||||
default=10,
|
default=10,
|
||||||
mutable=True,
|
mutable=True,
|
||||||
help='Interval (in seconds) for checking newly created '
|
help='Interval (in seconds) for checking newly created '
|
||||||
'continuous audits.')
|
'continuous audits.')]
|
||||||
]
|
|
||||||
|
|
||||||
|
|
||||||
def register_opts(conf):
|
def register_opts(conf):
|
||||||
conf.register_group(watcher_decision_engine)
|
conf.register_group(watcher_decision_engine)
|
||||||
conf.register_opts(WATCHER_DECISION_ENGINE_OPTS,
|
conf.register_opts(WATCHER_DECISION_ENGINE_OPTS,
|
||||||
group=watcher_decision_engine)
|
group=watcher_decision_engine)
|
||||||
conf.register_opts(WATCHER_CONTINUOUS_OPTS, group=watcher_decision_engine)
|
|
||||||
|
|
||||||
|
|
||||||
def list_opts():
|
def list_opts():
|
||||||
return [('watcher_decision_engine', WATCHER_DECISION_ENGINE_OPTS),
|
return [(watcher_decision_engine, WATCHER_DECISION_ENGINE_OPTS)]
|
||||||
('watcher_decision_engine', WATCHER_CONTINUOUS_OPTS)]
|
|
||||||
|
|||||||
@@ -41,4 +41,4 @@ def register_opts(conf):
|
|||||||
|
|
||||||
|
|
||||||
def list_opts():
|
def list_opts():
|
||||||
return [('glance_client', GLANCE_CLIENT_OPTS)]
|
return [(glance_client, GLANCE_CLIENT_OPTS)]
|
||||||
|
|||||||
@@ -42,4 +42,4 @@ def register_opts(conf):
|
|||||||
|
|
||||||
|
|
||||||
def list_opts():
|
def list_opts():
|
||||||
return [('gnocchi_client', GNOCCHI_CLIENT_OPTS)]
|
return [(gnocchi_client, GNOCCHI_CLIENT_OPTS)]
|
||||||
|
|||||||
@@ -41,4 +41,4 @@ def register_opts(conf):
|
|||||||
|
|
||||||
|
|
||||||
def list_opts():
|
def list_opts():
|
||||||
return [('grafana_translators', GRAFANA_TRANSLATOR_INFLUX_OPTS)]
|
return [(grafana_translators, GRAFANA_TRANSLATOR_INFLUX_OPTS)]
|
||||||
|
|||||||
@@ -41,4 +41,4 @@ def register_opts(conf):
|
|||||||
|
|
||||||
|
|
||||||
def list_opts():
|
def list_opts():
|
||||||
return [('ironic_client', IRONIC_CLIENT_OPTS)]
|
return [(ironic_client, IRONIC_CLIENT_OPTS)]
|
||||||
|
|||||||
@@ -35,4 +35,4 @@ def register_opts(conf):
|
|||||||
|
|
||||||
|
|
||||||
def list_opts():
|
def list_opts():
|
||||||
return [('keystone_client', KEYSTONE_CLIENT_OPTS)]
|
return [(keystone_client, KEYSTONE_CLIENT_OPTS)]
|
||||||
|
|||||||
@@ -41,4 +41,4 @@ def register_opts(conf):
|
|||||||
|
|
||||||
|
|
||||||
def list_opts():
|
def list_opts():
|
||||||
return [('monasca_client', MONASCA_CLIENT_OPTS)]
|
return [(monasca_client, MONASCA_CLIENT_OPTS)]
|
||||||
|
|||||||
@@ -41,4 +41,4 @@ def register_opts(conf):
|
|||||||
|
|
||||||
|
|
||||||
def list_opts():
|
def list_opts():
|
||||||
return [('neutron_client', NEUTRON_CLIENT_OPTS)]
|
return [(neutron_client, NEUTRON_CLIENT_OPTS)]
|
||||||
|
|||||||
@@ -52,4 +52,4 @@ def register_opts(conf):
|
|||||||
|
|
||||||
|
|
||||||
def list_opts():
|
def list_opts():
|
||||||
return [('nova_client', NOVA_CLIENT_OPTS)]
|
return [(nova_client, NOVA_CLIENT_OPTS)]
|
||||||
|
|||||||
@@ -38,4 +38,4 @@ def register_opts(conf):
|
|||||||
|
|
||||||
|
|
||||||
def list_opts():
|
def list_opts():
|
||||||
return [('watcher_planner', WATCHER_PLANNER_OPTS)]
|
return [(watcher_planner, WATCHER_PLANNER_OPTS)]
|
||||||
|
|||||||
@@ -28,6 +28,11 @@ from watcher.tests.decision_engine import fake_strategies
|
|||||||
class TestListOpts(base.TestCase):
|
class TestListOpts(base.TestCase):
|
||||||
def setUp(self):
|
def setUp(self):
|
||||||
super(TestListOpts, self).setUp()
|
super(TestListOpts, self).setUp()
|
||||||
|
# These option groups will be registered using strings instead of
|
||||||
|
# OptGroup objects this should be avoided if possible.
|
||||||
|
self.none_objects = ['DEFAULT', 'watcher_clients_auth',
|
||||||
|
'watcher_strategies.strategy_1']
|
||||||
|
|
||||||
self.base_sections = [
|
self.base_sections = [
|
||||||
'DEFAULT', 'api', 'database', 'watcher_decision_engine',
|
'DEFAULT', 'api', 'database', 'watcher_decision_engine',
|
||||||
'watcher_applier', 'watcher_datasources', 'watcher_planner',
|
'watcher_applier', 'watcher_datasources', 'watcher_planner',
|
||||||
@@ -38,6 +43,24 @@ class TestListOpts(base.TestCase):
|
|||||||
'placement_client']
|
'placement_client']
|
||||||
self.opt_sections = list(dict(opts.list_opts()).keys())
|
self.opt_sections = list(dict(opts.list_opts()).keys())
|
||||||
|
|
||||||
|
def _assert_name_or_group(self, actual_sections, expected_sections):
|
||||||
|
for name_or_group, options in actual_sections:
|
||||||
|
section_name = name_or_group
|
||||||
|
if isinstance(name_or_group, cfg.OptGroup):
|
||||||
|
section_name = name_or_group.name
|
||||||
|
elif section_name in self.none_objects:
|
||||||
|
pass
|
||||||
|
else:
|
||||||
|
# All option groups should be added to list_otps with an
|
||||||
|
# OptGroup object for some exceptions this is not possible but
|
||||||
|
# new groups should use OptGroup
|
||||||
|
raise Exception(
|
||||||
|
"Invalid option group: {0} should be of type OptGroup not "
|
||||||
|
"string.".format(section_name))
|
||||||
|
|
||||||
|
self.assertIn(section_name, expected_sections)
|
||||||
|
self.assertTrue(len(options))
|
||||||
|
|
||||||
def test_run_list_opts(self):
|
def test_run_list_opts(self):
|
||||||
expected_sections = self.opt_sections
|
expected_sections = self.opt_sections
|
||||||
|
|
||||||
@@ -73,14 +96,9 @@ class TestListOpts(base.TestCase):
|
|||||||
with mock.patch.object(extension, "ExtensionManager") as m_ext_manager:
|
with mock.patch.object(extension, "ExtensionManager") as m_ext_manager:
|
||||||
m_ext_manager.side_effect = m_list_available
|
m_ext_manager.side_effect = m_list_available
|
||||||
result = opts.list_opts()
|
result = opts.list_opts()
|
||||||
|
self._assert_name_or_group(result, expected_sections)
|
||||||
|
|
||||||
self.assertIsNotNone(result)
|
self.assertIsNotNone(result)
|
||||||
for name_or_group, options in result:
|
|
||||||
section_name = name_or_group
|
|
||||||
if isinstance(name_or_group, cfg.OptGroup):
|
|
||||||
section_name = name_or_group.name
|
|
||||||
self.assertIn(section_name, expected_sections)
|
|
||||||
self.assertTrue(len(options))
|
|
||||||
|
|
||||||
def test_list_opts_with_opts(self):
|
def test_list_opts_with_opts(self):
|
||||||
expected_sections = self.base_sections + [
|
expected_sections = self.base_sections + [
|
||||||
@@ -110,12 +128,7 @@ class TestListOpts(base.TestCase):
|
|||||||
result = opts.list_opts()
|
result = opts.list_opts()
|
||||||
|
|
||||||
self.assertIsNotNone(result)
|
self.assertIsNotNone(result)
|
||||||
for name_or_group, options in result:
|
self._assert_name_or_group(result, expected_sections)
|
||||||
section_name = name_or_group
|
|
||||||
if isinstance(name_or_group, cfg.OptGroup):
|
|
||||||
section_name = name_or_group.name
|
|
||||||
self.assertIn(section_name, expected_sections)
|
|
||||||
self.assertTrue(len(options))
|
|
||||||
|
|
||||||
result_map = dict(result)
|
result_map = dict(result)
|
||||||
strategy_opts = result_map['watcher_strategies.strategy_1']
|
strategy_opts = result_map['watcher_strategies.strategy_1']
|
||||||
|
|||||||
Reference in New Issue
Block a user