Stop using global conf object
This patch completely replaces the global conf object with a local one built by aodh.service.prepare_service(). Change-Id: Ia5d37db7e3d5ddb858dd7ef30394bfb148109291
This commit is contained in:
parent
d4a678184c
commit
28dd79c383
@ -27,9 +27,3 @@ OPTS = [
|
||||
help='The listen IP for the aodh API server.',
|
||||
),
|
||||
]
|
||||
|
||||
CONF = cfg.CONF
|
||||
opt_group = cfg.OptGroup(name='api',
|
||||
title='Options for the aodh-api service')
|
||||
CONF.register_group(opt_group)
|
||||
CONF.register_opts(OPTS, opt_group)
|
||||
|
@ -27,32 +27,11 @@ from aodh.api import hooks
|
||||
from aodh.api import middleware
|
||||
from aodh.i18n import _
|
||||
from aodh.i18n import _LW
|
||||
from aodh import service
|
||||
from aodh import storage
|
||||
|
||||
|
||||
LOG = log.getLogger(__name__)
|
||||
|
||||
CONF = cfg.CONF
|
||||
|
||||
OPTS = [
|
||||
cfg.StrOpt('api_paste_config',
|
||||
default="api_paste.ini",
|
||||
help="Configuration file for WSGI definition of API."
|
||||
),
|
||||
cfg.IntOpt('api_workers', default=1,
|
||||
min=1,
|
||||
help='Number of workers for aodh API server.'),
|
||||
]
|
||||
|
||||
API_OPTS = [
|
||||
cfg.BoolOpt('pecan_debug',
|
||||
default=False,
|
||||
help='Toggle Pecan Debug Middleware.'),
|
||||
]
|
||||
|
||||
CONF.register_opts(OPTS)
|
||||
CONF.register_opts(API_OPTS, group='api')
|
||||
|
||||
PECAN_CONFIG = {
|
||||
'app': {
|
||||
'root': 'aodh.api.controllers.root.RootController',
|
||||
@ -128,7 +107,8 @@ def build_server(conf):
|
||||
|
||||
|
||||
def _app():
|
||||
return setup_app(conf=cfg.CONF)
|
||||
conf = service.prepare_service()
|
||||
return setup_app(conf=conf)
|
||||
|
||||
|
||||
def app_factory(global_config, **local_conf):
|
||||
|
@ -18,11 +18,10 @@
|
||||
|
||||
See http://pecan.readthedocs.org/en/latest/deployment.html for details.
|
||||
"""
|
||||
from oslo_config import cfg
|
||||
|
||||
from aodh.api import app
|
||||
from aodh import service
|
||||
|
||||
|
||||
# Initialize the oslo configuration library and logging
|
||||
service.prepare_service([])
|
||||
application = app.load_app(cfg.CONF)
|
||||
conf = service.prepare_service([])
|
||||
application = app.load_app(conf)
|
||||
|
@ -13,7 +13,6 @@
|
||||
# License for the specific language governing permissions and limitations
|
||||
# under the License.
|
||||
|
||||
from oslo_config import cfg
|
||||
from oslo_serialization import jsonutils
|
||||
import pecan
|
||||
import requests
|
||||
@ -25,9 +24,6 @@ from aodh.api.controllers.v2 import utils as v2_utils
|
||||
from aodh import keystone_client
|
||||
|
||||
|
||||
cfg.CONF.import_opt('gnocchi_url', 'aodh.evaluator.gnocchi')
|
||||
|
||||
|
||||
class GnocchiUnavailable(Exception):
|
||||
code = 503
|
||||
|
||||
|
@ -72,9 +72,6 @@ ALARM_API_OPTS = [
|
||||
'non-positive number means no limit.'),
|
||||
]
|
||||
|
||||
cfg.CONF.register_opts(ALARM_API_OPTS)
|
||||
cfg.CONF.import_opt('record_history', 'aodh.evaluator')
|
||||
|
||||
state_kind = ["ok", "alarm", "insufficient data"]
|
||||
state_kind_enum = wtypes.Enum(str, *state_kind)
|
||||
severity_kind = ["low", "moderate", "critical"]
|
||||
|
@ -15,12 +15,10 @@
|
||||
# License for the specific language governing permissions and limitations
|
||||
# under the License.
|
||||
|
||||
from oslo_config import cfg
|
||||
|
||||
from aodh.api import app
|
||||
from aodh import service
|
||||
|
||||
|
||||
def main():
|
||||
service.prepare_service()
|
||||
app.build_server(cfg.CONF)
|
||||
conf = service.prepare_service()
|
||||
app.build_server(conf)
|
||||
|
@ -15,21 +15,18 @@
|
||||
# License for the specific language governing permissions and limitations
|
||||
# under the License.
|
||||
|
||||
from oslo_config import cfg
|
||||
from oslo_service import service as os_service
|
||||
|
||||
from aodh import evaluator as evaluator_svc
|
||||
from aodh import notifier as notifier_svc
|
||||
from aodh import service
|
||||
|
||||
CONF = cfg.CONF
|
||||
|
||||
|
||||
def notifier():
|
||||
service.prepare_service()
|
||||
os_service.launch(CONF, notifier_svc.AlarmNotifierService(CONF)).wait()
|
||||
conf = service.prepare_service()
|
||||
os_service.launch(conf, notifier_svc.AlarmNotifierService(conf)).wait()
|
||||
|
||||
|
||||
def evaluator():
|
||||
service.prepare_service()
|
||||
os_service.launch(CONF, evaluator_svc.AlarmEvaluationService(CONF)).wait()
|
||||
conf = service.prepare_service()
|
||||
os_service.launch(conf, evaluator_svc.AlarmEvaluationService(conf)).wait()
|
||||
|
@ -16,8 +16,6 @@
|
||||
|
||||
import logging
|
||||
|
||||
from oslo_config import cfg
|
||||
|
||||
from aodh.i18n import _LI
|
||||
from aodh import service
|
||||
from aodh import storage
|
||||
@ -27,18 +25,18 @@ LOG = logging.getLogger(__name__)
|
||||
|
||||
|
||||
def dbsync():
|
||||
service.prepare_service()
|
||||
storage.get_connection_from_config(cfg.CONF).upgrade()
|
||||
conf = service.prepare_service()
|
||||
storage.get_connection_from_config(conf).upgrade()
|
||||
|
||||
|
||||
def expirer():
|
||||
service.prepare_service()
|
||||
conf = service.prepare_service()
|
||||
|
||||
if cfg.CONF.database.alarm_history_time_to_live > 0:
|
||||
if conf.database.alarm_history_time_to_live > 0:
|
||||
LOG.debug("Clearing expired alarm history data")
|
||||
storage_conn = storage.get_connection_from_config(cfg.CONF)
|
||||
storage_conn = storage.get_connection_from_config(conf)
|
||||
storage_conn.clear_expired_alarm_history_data(
|
||||
cfg.CONF.database.alarm_history_time_to_live)
|
||||
conf.database.alarm_history_time_to_live)
|
||||
else:
|
||||
LOG.info(_LI("Nothing to clean, database alarm history time to live "
|
||||
"is disabled"))
|
||||
|
@ -42,7 +42,6 @@ OPTS = [
|
||||
'membership has changed')
|
||||
|
||||
]
|
||||
cfg.CONF.register_opts(OPTS, group='coordination')
|
||||
|
||||
|
||||
class PartitionCoordinator(object):
|
||||
|
@ -55,8 +55,6 @@ OPTS = [
|
||||
),
|
||||
]
|
||||
|
||||
cfg.CONF.register_opts(OPTS)
|
||||
|
||||
|
||||
@six.add_metaclass(abc.ABCMeta)
|
||||
class Evaluator(object):
|
||||
|
@ -29,9 +29,6 @@ OPTS = [
|
||||
help='URL to Gnocchi.'),
|
||||
]
|
||||
|
||||
cfg.CONF.register_opts(OPTS)
|
||||
cfg.CONF.import_opt('http_timeout', 'aodh.service')
|
||||
|
||||
|
||||
class GnocchiThresholdEvaluator(threshold.ThresholdEvaluator):
|
||||
|
||||
|
@ -1,5 +1,5 @@
|
||||
#
|
||||
# Copyright 2013 Red Hat, Inc
|
||||
# Copyright 2013-2015 Red Hat, Inc
|
||||
#
|
||||
# Licensed under the Apache License, Version 2.0 (the "License"); you may
|
||||
# not use this file except in compliance with the License. You may obtain
|
||||
@ -19,7 +19,6 @@ import operator
|
||||
import six
|
||||
|
||||
from ceilometerclient import client as ceiloclient
|
||||
from oslo_config import cfg
|
||||
from oslo_log import log
|
||||
from oslo_utils import timeutils
|
||||
|
||||
@ -29,9 +28,6 @@ from aodh.i18n import _, _LW
|
||||
|
||||
LOG = log.getLogger(__name__)
|
||||
|
||||
cfg.CONF.import_opt('http_timeout', 'aodh.service')
|
||||
cfg.CONF.import_group('service_credentials', 'aodh.service')
|
||||
|
||||
COMPARATORS = {
|
||||
'gt': operator.gt,
|
||||
'lt': operator.lt,
|
||||
|
@ -52,8 +52,6 @@ OPTS = [
|
||||
|
||||
]
|
||||
|
||||
cfg.CONF.register_opts(OPTS)
|
||||
|
||||
|
||||
class RestAlarmNotifier(notifier.AlarmNotifier):
|
||||
"""Rest alarm notifier."""
|
||||
|
39
aodh/opts.py
39
aodh/opts.py
@ -13,10 +13,12 @@
|
||||
# under the License.
|
||||
import itertools
|
||||
|
||||
from oslo_config import cfg
|
||||
|
||||
import aodh.api
|
||||
import aodh.api.app
|
||||
import aodh.api.controllers.v2.alarms
|
||||
import aodh.coordination
|
||||
import aodh.evaluator
|
||||
import aodh.evaluator.gnocchi
|
||||
import aodh.notifier.rest
|
||||
import aodh.rpc
|
||||
@ -27,16 +29,33 @@ import aodh.storage
|
||||
def list_opts():
|
||||
return [
|
||||
('DEFAULT',
|
||||
itertools.chain(aodh.api.app.OPTS,
|
||||
aodh.evaluator.gnocchi.OPTS,
|
||||
aodh.notifier.rest.OPTS,
|
||||
aodh.service.OPTS,
|
||||
aodh.rpc.OPTS,
|
||||
aodh.storage.OLD_OPTS,
|
||||
aodh.api.controllers.v2.alarms.ALARM_API_OPTS)),
|
||||
itertools.chain(
|
||||
[
|
||||
cfg.StrOpt(
|
||||
'api_paste_config',
|
||||
default="api_paste.ini",
|
||||
help="Configuration file for WSGI definition of API."),
|
||||
cfg.IntOpt(
|
||||
'api_workers', default=1,
|
||||
min=1,
|
||||
help='Number of workers for aodh API server.'),
|
||||
],
|
||||
aodh.evaluator.OPTS,
|
||||
aodh.evaluator.gnocchi.OPTS,
|
||||
aodh.notifier.rest.OPTS,
|
||||
aodh.service.OPTS,
|
||||
aodh.rpc.OPTS,
|
||||
aodh.storage.OLD_OPTS,
|
||||
aodh.api.controllers.v2.alarms.ALARM_API_OPTS,
|
||||
aodh.storage.CLI_OPTS)),
|
||||
('api',
|
||||
itertools.chain(aodh.api.OPTS,
|
||||
aodh.api.app.API_OPTS,)),
|
||||
itertools.chain(
|
||||
aodh.api.OPTS,
|
||||
[
|
||||
cfg.BoolOpt('pecan_debug',
|
||||
default=False,
|
||||
help='Toggle Pecan Debug Middleware.'),
|
||||
])),
|
||||
('coordination', aodh.coordination.OPTS),
|
||||
('database', aodh.storage.OPTS),
|
||||
('service_credentials', aodh.service.CLI_OPTS),
|
||||
|
@ -32,8 +32,6 @@ OPTS = [
|
||||
'messages.'),
|
||||
]
|
||||
|
||||
cfg.CONF.register_opts(OPTS)
|
||||
|
||||
LOG = log.getLogger(__name__)
|
||||
|
||||
|
||||
|
@ -16,13 +16,17 @@
|
||||
# under the License.
|
||||
import os
|
||||
import socket
|
||||
import sys
|
||||
|
||||
from keystonemiddleware import opts as ks_opts
|
||||
from oslo_config import cfg
|
||||
from oslo_db import options as db_options
|
||||
import oslo_i18n
|
||||
from oslo_log import log
|
||||
from oslo_messaging import opts as msg_opts
|
||||
from oslo_policy import opts as policy_opts
|
||||
|
||||
from aodh import messaging
|
||||
from aodh import opts
|
||||
|
||||
|
||||
OPTS = [
|
||||
@ -48,7 +52,6 @@ OPTS = [
|
||||
deprecated_opts=[cfg.DeprecatedOpt(
|
||||
'threshold_evaluation_interval', group='alarm')]),
|
||||
]
|
||||
cfg.CONF.register_opts(OPTS)
|
||||
|
||||
|
||||
CLI_OPTS = [
|
||||
@ -99,17 +102,30 @@ CLI_OPTS = [
|
||||
default=os.environ.get('OS_PROJECT_NAME', 'admin'),
|
||||
help='The user project name'),
|
||||
]
|
||||
cfg.CONF.register_cli_opts(CLI_OPTS, group="service_credentials")
|
||||
|
||||
|
||||
def prepare_service(argv=None):
|
||||
conf = cfg.ConfigOpts()
|
||||
oslo_i18n.enable_lazy()
|
||||
log.register_options(cfg.CONF)
|
||||
log_levels = (cfg.CONF.default_log_levels +
|
||||
log.register_options(conf)
|
||||
log_levels = (conf.default_log_levels +
|
||||
['stevedore=INFO', 'keystoneclient=INFO'])
|
||||
log.set_defaults(default_log_levels=log_levels)
|
||||
if argv is None:
|
||||
argv = sys.argv
|
||||
cfg.CONF(argv[1:], project='aodh', validate_default_values=True)
|
||||
log.setup(cfg.CONF, 'aodh')
|
||||
db_options.set_defaults(conf)
|
||||
policy_opts.set_defaults(conf)
|
||||
for group, options in ks_opts.list_auth_token_opts():
|
||||
conf.register_opts(list(options), group=group)
|
||||
# FIXME(jd) We can use that with oslo.messaging>2.0.0:
|
||||
# msg_opts.set_defaults(conf)
|
||||
for group, options in msg_opts.list_opts():
|
||||
conf.register_opts(list(options),
|
||||
group=None if group == "DEFAULT" else group)
|
||||
# Register our own Aodh options
|
||||
for group, options in opts.list_opts():
|
||||
conf.register_opts(list(options),
|
||||
group=None if group == "DEFAULT" else group)
|
||||
|
||||
conf(argv, project='aodh', validate_default_values=True)
|
||||
log.setup(conf, 'aodh')
|
||||
messaging.setup()
|
||||
return conf
|
||||
|
@ -16,7 +16,6 @@
|
||||
"""
|
||||
|
||||
from oslo_config import cfg
|
||||
from oslo_db import options as db_options
|
||||
from oslo_log import log
|
||||
import retrying
|
||||
import six.moves.urllib.parse as urlparse
|
||||
@ -36,9 +35,6 @@ OLD_OPTS = [
|
||||
),
|
||||
]
|
||||
|
||||
cfg.CONF.register_opts(OLD_OPTS)
|
||||
|
||||
|
||||
OPTS = [
|
||||
cfg.IntOpt('alarm_history_time_to_live',
|
||||
default=-1,
|
||||
@ -56,8 +52,6 @@ OPTS = [
|
||||
"as compute node's resource id is <hostname>_<nodename>."),
|
||||
]
|
||||
|
||||
cfg.CONF.register_opts(OPTS, group='database')
|
||||
|
||||
CLI_OPTS = [
|
||||
cfg.BoolOpt('sql-expire-samples-only',
|
||||
default=False,
|
||||
@ -67,10 +61,6 @@ CLI_OPTS = [
|
||||
),
|
||||
]
|
||||
|
||||
cfg.CONF.register_cli_opts(CLI_OPTS)
|
||||
|
||||
db_options.set_defaults(cfg.CONF)
|
||||
|
||||
|
||||
class StorageUnknownWriteError(Exception):
|
||||
"""Error raised when an unknown error occurs while recording."""
|
||||
|
@ -1,7 +1,7 @@
|
||||
#
|
||||
# Copyright 2012 New Dream Network, LLC (DreamHost)
|
||||
# Copyright 2013 eNovance
|
||||
# Copyright 2014 Red Hat, Inc
|
||||
# Copyright 2014-2015 Red Hat, Inc
|
||||
#
|
||||
# Authors: Doug Hellmann <doug.hellmann@dreamhost.com>
|
||||
# Julien Danjou <julien@danjou.info>
|
||||
@ -20,7 +20,6 @@
|
||||
# under the License.
|
||||
"""MongoDB storage backend"""
|
||||
|
||||
from oslo_config import cfg
|
||||
from oslo_log import log
|
||||
import pymongo
|
||||
|
||||
@ -28,9 +27,6 @@ from aodh import storage
|
||||
from aodh.storage.mongo import utils as pymongo_utils
|
||||
from aodh.storage import pymongo_base
|
||||
|
||||
cfg.CONF.import_opt('alarm_history_time_to_live', 'aodh.storage',
|
||||
group="database")
|
||||
|
||||
LOG = log.getLogger(__name__)
|
||||
|
||||
|
||||
|
@ -18,7 +18,6 @@
|
||||
|
||||
import weakref
|
||||
|
||||
from oslo_config import cfg
|
||||
from oslo_log import log
|
||||
from oslo_utils import netutils
|
||||
import pymongo
|
||||
@ -28,11 +27,6 @@ from aodh.i18n import _
|
||||
|
||||
LOG = log.getLogger(__name__)
|
||||
|
||||
# FIXME(dhellmann): Configuration options are not part of the Oslo
|
||||
# library APIs, and should not be used like this.
|
||||
cfg.CONF.import_opt('max_retries', 'oslo_db.options', group="database")
|
||||
cfg.CONF.import_opt('retry_interval', 'oslo_db.options', group="database")
|
||||
|
||||
|
||||
def make_timestamp_range(start, end,
|
||||
start_timestamp_op=None, end_timestamp_op=None):
|
||||
|
@ -1,5 +1,6 @@
|
||||
#
|
||||
# Copyright 2012 New Dream Network, LLC (DreamHost)
|
||||
# Copyright 2015 Red Hat, Inc.
|
||||
#
|
||||
# Licensed under the Apache License, Version 2.0 (the "License"); you may
|
||||
# not use this file except in compliance with the License. You may obtain
|
||||
@ -15,17 +16,13 @@
|
||||
"""Base classes for API tests.
|
||||
"""
|
||||
|
||||
from oslo_config import cfg
|
||||
from oslo_config import fixture as fixture_config
|
||||
from oslo_policy import opts
|
||||
import pecan
|
||||
import pecan.testing
|
||||
|
||||
from aodh import service
|
||||
from aodh.tests import db as db_test_base
|
||||
|
||||
OPT_GROUP_NAME = 'keystone_authtoken'
|
||||
cfg.CONF.import_group(OPT_GROUP_NAME, "keystonemiddleware.auth_token")
|
||||
|
||||
|
||||
class FunctionalTest(db_test_base.TestBase):
|
||||
"""Used for functional tests of Pecan controllers.
|
||||
@ -38,12 +35,11 @@ class FunctionalTest(db_test_base.TestBase):
|
||||
|
||||
def setUp(self):
|
||||
super(FunctionalTest, self).setUp()
|
||||
self.CONF = self.useFixture(fixture_config.Config()).conf
|
||||
conf = service.prepare_service([])
|
||||
self.CONF = self.useFixture(fixture_config.Config(conf)).conf
|
||||
self.setup_messaging(self.CONF)
|
||||
opts.set_defaults(self.CONF)
|
||||
|
||||
self.CONF.set_override("auth_version", "v2.0",
|
||||
group=OPT_GROUP_NAME)
|
||||
self.CONF.set_override("auth_version", "v2.0", 'keystone_authtoken')
|
||||
self.CONF.set_override("policy_file",
|
||||
self.path_get('etc/aodh/policy.json'),
|
||||
group='oslo_policy')
|
||||
|
@ -1,7 +1,7 @@
|
||||
# vim: tabstop=4 shiftwidth=4 softtabstop=4
|
||||
|
||||
# Copyright 2014 IBM Corp.
|
||||
# All Rights Reserved.
|
||||
# Copyright 2014 IBM Corp. All Rights Reserved.
|
||||
# Copyright 2015 Red Hat, Inc.
|
||||
#
|
||||
# Licensed under the Apache License, Version 2.0 (the "License"); you may
|
||||
# not use this file except in compliance with the License. You may obtain
|
||||
@ -18,9 +18,9 @@
|
||||
import mock
|
||||
from oslo_config import cfg
|
||||
from oslo_config import fixture as fixture_config
|
||||
from oslo_log import log
|
||||
|
||||
from aodh.api import app
|
||||
from aodh import service
|
||||
from aodh.tests import base
|
||||
|
||||
|
||||
@ -28,8 +28,8 @@ class TestApp(base.BaseTestCase):
|
||||
|
||||
def setUp(self):
|
||||
super(TestApp, self).setUp()
|
||||
self.CONF = self.useFixture(fixture_config.Config()).conf
|
||||
log.register_options(cfg.CONF)
|
||||
conf = service.prepare_service([])
|
||||
self.CONF = self.useFixture(fixture_config.Config(conf)).conf
|
||||
|
||||
def test_api_paste_file_not_exist(self):
|
||||
self.CONF.set_override('api_paste_config', 'non-existent-file')
|
||||
|
@ -1,5 +1,6 @@
|
||||
#
|
||||
# Copyright 2012 New Dream Network, LLC (DreamHost)
|
||||
# Copyright 2015 Red Hat, Inc.
|
||||
#
|
||||
# Licensed under the Apache License, Version 2.0 (the "License"); you may
|
||||
# not use this file except in compliance with the License. You may obtain
|
||||
@ -18,11 +19,11 @@ import datetime
|
||||
import hashlib
|
||||
import json
|
||||
|
||||
import mock
|
||||
from oslo_utils import timeutils
|
||||
import webtest
|
||||
|
||||
from aodh.api import app
|
||||
from aodh.tests import api as acl
|
||||
from aodh.tests.api import v2
|
||||
from aodh.tests import db as tests_db
|
||||
|
||||
@ -89,10 +90,14 @@ class TestAPIACL(v2.FunctionalTest,
|
||||
**params)
|
||||
|
||||
def _make_app(self):
|
||||
self.CONF.set_override("cache", "fake.cache", group=acl.OPT_GROUP_NAME)
|
||||
self.CONF.set_override("cache", "fake.cache", 'keystone_authtoken')
|
||||
file_name = self.path_get('etc/aodh/api_paste.ini')
|
||||
self.CONF.set_override("api_paste_config", file_name)
|
||||
return webtest.TestApp(app.load_app(conf=self.CONF))
|
||||
# We need the other call to prepare_service in app.py to return the
|
||||
# same tweaked conf object.
|
||||
with mock.patch('aodh.service.prepare_service') as ps:
|
||||
ps.return_value = self.CONF
|
||||
return webtest.TestApp(app.load_app(conf=self.CONF))
|
||||
|
||||
def test_non_authenticated(self):
|
||||
response = self.get_json('/meters', expect_errors=True)
|
||||
|
@ -1,6 +1,7 @@
|
||||
#
|
||||
# Copyright 2012 New Dream Network, LLC (DreamHost)
|
||||
# Copyright 2013 eNovance
|
||||
# Copyright 2015 Red Hat, Inc.
|
||||
#
|
||||
# Licensed under the Apache License, Version 2.0 (the "License"); you may
|
||||
# not use this file except in compliance with the License. You may obtain
|
||||
@ -28,6 +29,7 @@ import sqlalchemy
|
||||
import testscenarios.testcase
|
||||
from testtools import testcase
|
||||
|
||||
from aodh import service
|
||||
from aodh import storage
|
||||
from aodh.tests import base as test_base
|
||||
try:
|
||||
@ -139,12 +141,8 @@ class TestBase(testscenarios.testcase.WithScenarios, test_base.BaseTestCase):
|
||||
raise testcase.TestSkipped(
|
||||
'Test is not applicable for %s' % engine)
|
||||
|
||||
# FIXME(jd) we need this to be sure ALL options are registered
|
||||
# This module could be otherwise imported later by something else and
|
||||
# fail because all options are not registered
|
||||
import aodh.service # noqa
|
||||
self.CONF = self.useFixture(fixture_config.Config()).conf
|
||||
self.CONF([], project='aodh', validate_default_values=True)
|
||||
conf = service.prepare_service([])
|
||||
self.CONF = self.useFixture(fixture_config.Config(conf)).conf
|
||||
self.CONF.set_override('connection', self.db_url, group="database")
|
||||
|
||||
try:
|
||||
|
@ -1,5 +1,6 @@
|
||||
#
|
||||
# Copyright 2013 eNovance <licensing@enovance.com>
|
||||
# Copyright 2015 Red Hat, Inc.
|
||||
#
|
||||
# Licensed under the Apache License, Version 2.0 (the "License"); you may
|
||||
# not use this file except in compliance with the License. You may obtain
|
||||
@ -16,11 +17,14 @@ import mock
|
||||
from oslo_config import fixture
|
||||
from oslotest import base
|
||||
|
||||
from aodh import service
|
||||
|
||||
|
||||
class TestEvaluatorBase(base.BaseTestCase):
|
||||
def setUp(self):
|
||||
super(TestEvaluatorBase, self).setUp()
|
||||
self.conf = self.useFixture(fixture.Config()).conf
|
||||
conf = service.prepare_service([])
|
||||
self.conf = self.useFixture(fixture.Config(conf)).conf
|
||||
self.api_client = mock.Mock()
|
||||
self.notifier = mock.MagicMock()
|
||||
self.evaluator = self.EVALUATOR(self.conf, self.notifier)
|
||||
|
@ -20,6 +20,7 @@ from unittest import case
|
||||
import uuid
|
||||
|
||||
from gabbi import fixture
|
||||
import mock
|
||||
from oslo_config import fixture as fixture_config
|
||||
from oslo_policy import opts
|
||||
|
||||
@ -51,8 +52,18 @@ class ConfigFixture(fixture.GabbiFixture):
|
||||
if db_url is None:
|
||||
raise case.SkipTest('No database connection configured')
|
||||
|
||||
service.prepare_service([])
|
||||
conf = fixture_config.Config().conf
|
||||
conf = service.prepare_service([])
|
||||
# NOTE(jd): prepare_service() is called twice: first by load_app() for
|
||||
# Pecan, then Pecan calls pastedeploy, which starts the app, which has
|
||||
# no way to pass the conf object so that Paste apps calls again
|
||||
# prepare_service. In real life, that's not a problem, but here we want
|
||||
# to be sure that the second time the same conf object is returned
|
||||
# since we tweaked it. To that, once we called prepare_service() we
|
||||
# mock it so it returns the same conf object.
|
||||
self.prepare_service = service.prepare_service
|
||||
service.prepare_service = mock.Mock()
|
||||
service.prepare_service.return_value = conf
|
||||
conf = fixture_config.Config(conf).conf
|
||||
self.conf = conf
|
||||
opts.set_defaults(self.conf)
|
||||
conf.set_override('policy_file',
|
||||
@ -69,3 +80,4 @@ class ConfigFixture(fixture.GabbiFixture):
|
||||
if self.conf:
|
||||
storage.get_connection_from_config(self.conf).clear()
|
||||
self.conf.reset()
|
||||
service.prepare_service = self.prepare_service
|
||||
|
@ -19,6 +19,7 @@ from oslo_config import fixture as fixture_config
|
||||
from oslotest import base
|
||||
import retrying
|
||||
|
||||
from aodh import service
|
||||
from aodh import storage
|
||||
from aodh.storage import impl_log
|
||||
|
||||
@ -28,7 +29,8 @@ import six
|
||||
class EngineTest(base.BaseTestCase):
|
||||
def setUp(self):
|
||||
super(EngineTest, self).setUp()
|
||||
self.CONF = self.useFixture(fixture_config.Config()).conf
|
||||
conf = service.prepare_service([])
|
||||
self.CONF = self.useFixture(fixture_config.Config(conf)).conf
|
||||
|
||||
def test_get_connection(self):
|
||||
self.CONF.set_override('connection', 'log://localhost',
|
||||
@ -49,7 +51,8 @@ class EngineTest(base.BaseTestCase):
|
||||
class ConnectionRetryTest(base.BaseTestCase):
|
||||
def setUp(self):
|
||||
super(ConnectionRetryTest, self).setUp()
|
||||
self.CONF = self.useFixture(fixture_config.Config()).conf
|
||||
conf = service.prepare_service([])
|
||||
self.CONF = self.useFixture(fixture_config.Config(conf)).conf
|
||||
|
||||
def test_retries(self):
|
||||
with mock.patch.object(retrying.time, 'sleep') as retry_sleep:
|
||||
@ -66,7 +69,8 @@ class ConnectionRetryTest(base.BaseTestCase):
|
||||
class ConnectionConfigTest(base.BaseTestCase):
|
||||
def setUp(self):
|
||||
super(ConnectionConfigTest, self).setUp()
|
||||
self.CONF = self.useFixture(fixture_config.Config()).conf
|
||||
conf = service.prepare_service([])
|
||||
self.CONF = self.useFixture(fixture_config.Config(conf)).conf
|
||||
|
||||
def test_only_default_url(self):
|
||||
self.CONF.set_override("connection", "log://", group="database")
|
||||
|
@ -20,6 +20,7 @@ from oslo_config import fixture as fixture_config
|
||||
import tooz.coordination
|
||||
|
||||
from aodh import coordination
|
||||
from aodh import service
|
||||
from aodh.tests import base
|
||||
from aodh import utils
|
||||
|
||||
@ -128,7 +129,8 @@ class TestPartitioning(base.BaseTestCase):
|
||||
|
||||
def setUp(self):
|
||||
super(TestPartitioning, self).setUp()
|
||||
self.CONF = self.useFixture(fixture_config.Config()).conf
|
||||
conf = service.prepare_service([])
|
||||
self.CONF = self.useFixture(fixture_config.Config(conf)).conf
|
||||
self.str_handler = MockLoggingHandler()
|
||||
coordination.LOG.logger.addHandler(self.str_handler)
|
||||
self.shared_storage = {}
|
||||
|
@ -19,13 +19,15 @@ from oslo_config import fixture as fixture_config
|
||||
from stevedore import extension
|
||||
|
||||
from aodh import evaluator
|
||||
from aodh import service
|
||||
from aodh.tests import base as tests_base
|
||||
|
||||
|
||||
class TestAlarmEvaluationService(tests_base.BaseTestCase):
|
||||
def setUp(self):
|
||||
super(TestAlarmEvaluationService, self).setUp()
|
||||
self.CONF = self.useFixture(fixture_config.Config()).conf
|
||||
conf = service.prepare_service([])
|
||||
self.CONF = self.useFixture(fixture_config.Config(conf)).conf
|
||||
self.setup_messaging(self.CONF)
|
||||
|
||||
self.threshold_eval = mock.Mock()
|
||||
|
@ -22,6 +22,7 @@ import requests
|
||||
import six.moves.urllib.parse as urlparse
|
||||
|
||||
from aodh import notifier
|
||||
from aodh import service
|
||||
from aodh.tests import base as tests_base
|
||||
|
||||
|
||||
@ -44,7 +45,8 @@ class TestAlarmNotifier(tests_base.BaseTestCase):
|
||||
|
||||
def setUp(self):
|
||||
super(TestAlarmNotifier, self).setUp()
|
||||
self.CONF = self.useFixture(fixture_config.Config()).conf
|
||||
conf = service.prepare_service([])
|
||||
self.CONF = self.useFixture(fixture_config.Config(conf)).conf
|
||||
self.setup_messaging(self.CONF)
|
||||
self.service = notifier.AlarmNotifierService(self.CONF)
|
||||
self.useFixture(mockpatch.Patch(
|
||||
|
@ -23,6 +23,7 @@ import six
|
||||
|
||||
from aodh import messaging
|
||||
from aodh import rpc
|
||||
from aodh import service
|
||||
from aodh.storage import models
|
||||
from aodh.tests import base as tests_base
|
||||
|
||||
@ -46,7 +47,8 @@ class FakeNotifier(object):
|
||||
class TestRPCAlarmNotifier(tests_base.BaseTestCase):
|
||||
def setUp(self):
|
||||
super(TestRPCAlarmNotifier, self).setUp()
|
||||
self.CONF = self.useFixture(fixture_config.Config()).conf
|
||||
conf = service.prepare_service([])
|
||||
self.CONF = self.useFixture(fixture_config.Config(conf)).conf
|
||||
self.setup_messaging(self.CONF)
|
||||
|
||||
self.notifier_server = FakeNotifier(self.CONF, self.transport)
|
||||
|
Loading…
x
Reference in New Issue
Block a user