From 9230658b952677f98e18b97beff76cca5f31ab38 Mon Sep 17 00:00:00 2001 From: liusheng Date: Fri, 22 Apr 2016 09:52:21 +0800 Subject: [PATCH] Clean and reorganize the API config options Clean the deprecations and move the ALARM_API_OPTS options to api group. Change-Id: If5831f83dea0bebaf83b726410fa92ad8544cd4e Signed-off-by: liusheng --- aodh/api/__init__.py | 10 ++++++++- aodh/api/controllers/v2/alarms.py | 9 +++++--- aodh/opts.py | 22 ++----------------- .../functional/api/v2/test_alarm_scenarios.py | 22 +++++++++---------- 4 files changed, 28 insertions(+), 35 deletions(-) diff --git a/aodh/api/__init__.py b/aodh/api/__init__.py index 7c4a5424e..68b67aa11 100644 --- a/aodh/api/__init__.py +++ b/aodh/api/__init__.py @@ -19,11 +19,19 @@ from oslo_config import cfg OPTS = [ cfg.PortOpt('port', default=8042, - deprecated_group='DEFAULT', help='The port for the aodh API server.', ), cfg.StrOpt('host', default='0.0.0.0', help='The listen IP for the aodh API server.', ), + cfg.StrOpt('paste_config', + default="api_paste.ini", + help="Configuration file for WSGI definition of API."), + cfg.IntOpt('workers', default=1, + min=1, + help='Number of workers for aodh API server.'), + cfg.BoolOpt('pecan_debug', + default=False, + help='Toggle Pecan Debug Middleware.'), ] diff --git a/aodh/api/controllers/v2/alarms.py b/aodh/api/controllers/v2/alarms.py index 15c5e4beb..287f5bfa1 100644 --- a/aodh/api/controllers/v2/alarms.py +++ b/aodh/api/controllers/v2/alarms.py @@ -54,13 +54,16 @@ LOG = log.getLogger(__name__) ALARM_API_OPTS = [ cfg.IntOpt('user_alarm_quota', + deprecated_group='DEFAULT', help='Maximum number of alarms defined for a user.' ), cfg.IntOpt('project_alarm_quota', + deprecated_group='DEFAULT', help='Maximum number of alarms defined for a project.' ), cfg.IntOpt('alarm_max_actions', default=-1, + deprecated_group='DEFAULT', help='Maximum count of actions for each state of an alarm, ' 'non-positive number means no limit.'), ] @@ -93,14 +96,14 @@ def is_over_quota(conn, project_id, user_id): over_quota = False # Start by checking for user quota - user_alarm_quota = pecan.request.cfg.user_alarm_quota + user_alarm_quota = pecan.request.cfg.api.user_alarm_quota if user_alarm_quota is not None: user_alarms = list(conn.get_alarms(user=user_id)) over_quota = len(user_alarms) >= user_alarm_quota # If the user quota isn't reached, we check for the project quota if not over_quota: - project_alarm_quota = pecan.request.cfg.project_alarm_quota + project_alarm_quota = pecan.request.cfg.api.project_alarm_quota if project_alarm_quota is not None: project_alarms = list(conn.get_alarms(project=project_id)) over_quota = len(project_alarms) >= project_alarm_quota @@ -305,7 +308,7 @@ class Alarm(base.Base): @staticmethod def check_alarm_actions(alarm): - max_actions = pecan.request.cfg.alarm_max_actions + max_actions = pecan.request.cfg.api.alarm_max_actions for state in state_kind: actions_name = state.replace(" ", "_") + '_actions' actions = getattr(alarm, actions_name) diff --git a/aodh/opts.py b/aodh/opts.py index bc985e57f..eec0c4472 100644 --- a/aodh/opts.py +++ b/aodh/opts.py @@ -14,7 +14,6 @@ import itertools from keystoneauth1 import loading -from oslo_config import cfg import aodh.api import aodh.api.controllers.v2.alarms @@ -38,28 +37,11 @@ def list_opts(): aodh.event.OPTS, aodh.notifier.rest.OPTS, aodh.queue.OPTS, - aodh.service.OPTS, - aodh.api.controllers.v2.alarms.ALARM_API_OPTS)), + aodh.service.OPTS)), ('api', itertools.chain( aodh.api.OPTS, - [ - cfg.StrOpt( - 'paste_config', - deprecated_name='api_paste_config', - deprecated_group='DEFAULT', - default="api_paste.ini", - help="Configuration file for WSGI definition of API."), - cfg.IntOpt( - 'workers', default=1, - deprecated_name='api_workers', - deprecated_group='DEFAULT', - min=1, - help='Number of workers for aodh API server.'), - cfg.BoolOpt('pecan_debug', - default=False, - help='Toggle Pecan Debug Middleware.'), - ])), + aodh.api.controllers.v2.alarms.ALARM_API_OPTS)), ('coordination', aodh.coordination.OPTS), ('database', aodh.storage.OPTS), ('service_credentials', aodh.keystone_client.OPTS), diff --git a/aodh/tests/functional/api/v2/test_alarm_scenarios.py b/aodh/tests/functional/api/v2/test_alarm_scenarios.py index ea81256a3..da8226c9c 100644 --- a/aodh/tests/functional/api/v2/test_alarm_scenarios.py +++ b/aodh/tests/functional/api/v2/test_alarm_scenarios.py @@ -1219,7 +1219,7 @@ class TestAlarms(TestAlarmsBase): self.assertEqual(['http://no.where'], alarms[0].alarm_actions) def test_post_alarm_with_too_many_actions(self): - self.CONF.set_override('alarm_max_actions', 1) + self.CONF.set_override('alarm_max_actions', 1, group='api') body = { 'name': 'alarm-with-many-actions', 'type': 'combination', @@ -2111,31 +2111,31 @@ class TestAlarmsQuotas(TestAlarmsBase): self.assertEqual(1, len(alarms)) def test_alarms_quotas(self): - self.CONF.set_override('user_alarm_quota', 1) - self.CONF.set_override('project_alarm_quota', 1) + self.CONF.set_override('user_alarm_quota', 1, 'api') + self.CONF.set_override('project_alarm_quota', 1, 'api') self._test_alarm_quota() def test_project_alarms_quotas(self): - self.CONF.set_override('project_alarm_quota', 1) + self.CONF.set_override('project_alarm_quota', 1, 'api') self._test_alarm_quota() def test_user_alarms_quotas(self): - self.CONF.set_override('user_alarm_quota', 1) + self.CONF.set_override('user_alarm_quota', 1, 'api') self._test_alarm_quota() def test_larger_limit_project_alarms_quotas(self): - self.CONF.set_override('user_alarm_quota', 1) - self.CONF.set_override('project_alarm_quota', 2) + self.CONF.set_override('user_alarm_quota', 1, 'api') + self.CONF.set_override('project_alarm_quota', 2, 'api') self._test_alarm_quota() def test_larger_limit_user_alarms_quotas(self): - self.CONF.set_override('user_alarm_quota', 2) - self.CONF.set_override('project_alarm_quota', 1) + self.CONF.set_override('user_alarm_quota', 2, 'api') + self.CONF.set_override('project_alarm_quota', 1, 'api') self._test_alarm_quota() def test_larger_limit_user_alarm_quotas_multitenant_user(self): - self.CONF.set_override('user_alarm_quota', 2) - self.CONF.set_override('project_alarm_quota', 1) + self.CONF.set_override('user_alarm_quota', 2, 'api') + self.CONF.set_override('project_alarm_quota', 1, 'api') def _test(field, value): query = [{