Merge "Clean and reorganize the API config options"

This commit is contained in:
Jenkins 2016-05-10 08:35:39 +00:00 committed by Gerrit Code Review
commit b72a247b4f
4 changed files with 28 additions and 35 deletions

View File

@ -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.'),
]

View File

@ -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)

View File

@ -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.evaluator.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),
('evaluator', aodh.service.EVALUATOR_OPTS),

View File

@ -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',
@ -2109,31 +2109,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 = [{