Merge "improve OptGroup consistency across configuration"

This commit is contained in:
Zuul
2019-07-03 11:45:00 +00:00
committed by Gerrit Code Review
20 changed files with 62 additions and 50 deletions

View File

@@ -22,6 +22,7 @@ from watcher.conf import api as conf_api
from watcher.conf import applier as conf_applier
from watcher.conf import ceilometer_client as conf_ceilometer_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 decision_engine as conf_de
from watcher.conf import exception
@@ -39,19 +40,22 @@ def list_opts():
(conf_api.AUTH_OPTS +
exception.EXC_LOG_OPTS +
paths.PATH_OPTS)),
('api', conf_api.API_SERVICE_OPTS),
('database', db.SQL_OPTS),
('watcher_planner', conf_planner.WATCHER_PLANNER_OPTS),
('watcher_applier', conf_applier.APPLIER_MANAGER_OPTS),
('watcher_decision_engine',
(conf_de.WATCHER_DECISION_ENGINE_OPTS +
conf_de.WATCHER_CONTINUOUS_OPTS)),
('nova_client', conf_nova_client.NOVA_CLIENT_OPTS),
('glance_client', conf_glance_client.GLANCE_CLIENT_OPTS),
('cinder_client', conf_cinder_client.CINDER_CLIENT_OPTS),
('ceilometer_client', conf_ceilometer_client.CEILOMETER_CLIENT_OPTS),
('neutron_client', conf_neutron_client.NEUTRON_CLIENT_OPTS),
('watcher_clients_auth',
(conf_api.api, conf_api.API_SERVICE_OPTS),
(db.database, db.SQL_OPTS),
(conf_planner.watcher_planner, conf_planner.WATCHER_PLANNER_OPTS),
(conf_applier.watcher_applier, conf_applier.APPLIER_MANAGER_OPTS),
(conf_de.watcher_decision_engine,
(conf_de.WATCHER_DECISION_ENGINE_OPTS)),
(conf_nova_client.nova_client, conf_nova_client.NOVA_CLIENT_OPTS),
(conf_glance_client.glance_client,
conf_glance_client.GLANCE_CLIENT_OPTS),
(conf_cinder_client.cinder_client,
conf_cinder_client.CINDER_CLIENT_OPTS),
(conf_ceilometer_client.ceilometer_client,
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_plugin_conf_options('password') +
ka_loading.get_session_conf_options()))

View File

@@ -65,4 +65,4 @@ def register_opts(conf):
def list_opts():
return [('api', API_SERVICE_OPTS), ('DEFAULT', AUTH_OPTS)]
return [(api, API_SERVICE_OPTS), ('DEFAULT', AUTH_OPTS)]

View File

@@ -50,4 +50,4 @@ def register_opts(conf):
def list_opts():
return [('watcher_applier', APPLIER_MANAGER_OPTS)]
return [(watcher_applier, APPLIER_MANAGER_OPTS)]

View File

@@ -60,4 +60,4 @@ def register_opts(conf):
def list_opts():
return [('ceilometer_client', CEILOMETER_CLIENT_OPTS)]
return [(ceilometer_client, CEILOMETER_CLIENT_OPTS)]

View File

@@ -41,4 +41,4 @@ def register_opts(conf):
def list_opts():
return [('cinder_client', CINDER_CLIENT_OPTS)]
return [(cinder_client, CINDER_CLIENT_OPTS)]

View File

@@ -27,5 +27,5 @@ def register_opts(conf):
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())]

View File

@@ -45,4 +45,4 @@ def register_opts(conf):
def list_opts():
return [('collector', COLLECTOR_OPTS)]
return [(collector, COLLECTOR_OPTS)]

View File

@@ -56,4 +56,4 @@ def register_opts(conf):
def list_opts():
return [('watcher_datasources', DATASOURCES_OPTS)]
return [(datasources, DATASOURCES_OPTS)]

View File

@@ -41,4 +41,4 @@ def register_opts(conf):
def list_opts():
return [('database', SQL_OPTS)]
return [(database, SQL_OPTS)]

View File

@@ -68,24 +68,19 @@ WATCHER_DECISION_ENGINE_OPTS = [
' instance_cpu_usage: VM_CPU\n'
' gnocchi:\n'
' instance_cpu_usage: cpu_vm_util\n\n'
'This file is optional.')]
WATCHER_CONTINUOUS_OPTS = [
'This file is optional.'),
cfg.IntOpt('continuous_audit_interval',
default=10,
mutable=True,
help='Interval (in seconds) for checking newly created '
'continuous audits.')
]
'continuous audits.')]
def register_opts(conf):
conf.register_group(watcher_decision_engine)
conf.register_opts(WATCHER_DECISION_ENGINE_OPTS,
group=watcher_decision_engine)
conf.register_opts(WATCHER_CONTINUOUS_OPTS, group=watcher_decision_engine)
def list_opts():
return [('watcher_decision_engine', WATCHER_DECISION_ENGINE_OPTS),
('watcher_decision_engine', WATCHER_CONTINUOUS_OPTS)]
return [(watcher_decision_engine, WATCHER_DECISION_ENGINE_OPTS)]

View File

@@ -41,4 +41,4 @@ def register_opts(conf):
def list_opts():
return [('glance_client', GLANCE_CLIENT_OPTS)]
return [(glance_client, GLANCE_CLIENT_OPTS)]

View File

@@ -42,4 +42,4 @@ def register_opts(conf):
def list_opts():
return [('gnocchi_client', GNOCCHI_CLIENT_OPTS)]
return [(gnocchi_client, GNOCCHI_CLIENT_OPTS)]

View File

@@ -41,4 +41,4 @@ def register_opts(conf):
def list_opts():
return [('grafana_translators', GRAFANA_TRANSLATOR_INFLUX_OPTS)]
return [(grafana_translators, GRAFANA_TRANSLATOR_INFLUX_OPTS)]

View File

@@ -41,4 +41,4 @@ def register_opts(conf):
def list_opts():
return [('ironic_client', IRONIC_CLIENT_OPTS)]
return [(ironic_client, IRONIC_CLIENT_OPTS)]

View File

@@ -35,4 +35,4 @@ def register_opts(conf):
def list_opts():
return [('keystone_client', KEYSTONE_CLIENT_OPTS)]
return [(keystone_client, KEYSTONE_CLIENT_OPTS)]

View File

@@ -41,4 +41,4 @@ def register_opts(conf):
def list_opts():
return [('monasca_client', MONASCA_CLIENT_OPTS)]
return [(monasca_client, MONASCA_CLIENT_OPTS)]

View File

@@ -41,4 +41,4 @@ def register_opts(conf):
def list_opts():
return [('neutron_client', NEUTRON_CLIENT_OPTS)]
return [(neutron_client, NEUTRON_CLIENT_OPTS)]

View File

@@ -52,4 +52,4 @@ def register_opts(conf):
def list_opts():
return [('nova_client', NOVA_CLIENT_OPTS)]
return [(nova_client, NOVA_CLIENT_OPTS)]

View File

@@ -38,4 +38,4 @@ def register_opts(conf):
def list_opts():
return [('watcher_planner', WATCHER_PLANNER_OPTS)]
return [(watcher_planner, WATCHER_PLANNER_OPTS)]

View File

@@ -28,6 +28,11 @@ from watcher.tests.decision_engine import fake_strategies
class TestListOpts(base.TestCase):
def setUp(self):
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 = [
'DEFAULT', 'api', 'database', 'watcher_decision_engine',
'watcher_applier', 'watcher_datasources', 'watcher_planner',
@@ -38,6 +43,24 @@ class TestListOpts(base.TestCase):
'placement_client']
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):
expected_sections = self.opt_sections
@@ -73,14 +96,9 @@ class TestListOpts(base.TestCase):
with mock.patch.object(extension, "ExtensionManager") as m_ext_manager:
m_ext_manager.side_effect = m_list_available
result = opts.list_opts()
self._assert_name_or_group(result, expected_sections)
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):
expected_sections = self.base_sections + [
@@ -110,12 +128,7 @@ class TestListOpts(base.TestCase):
result = opts.list_opts()
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))
self._assert_name_or_group(result, expected_sections)
result_map = dict(result)
strategy_opts = result_map['watcher_strategies.strategy_1']