notifier: stop using global conf object

Change-Id: I99b1eb1b7fedbe86320f6d843213418b3c38c530
This commit is contained in:
Julien Danjou 2015-07-24 12:43:06 +02:00
parent ad2a9a2bba
commit 61717e7a8d
4 changed files with 21 additions and 14 deletions

View File

@ -31,6 +31,10 @@ LOG = logging.getLogger(__name__)
class AlarmNotifier(object):
"""Base class for alarm notifier plugins."""
@staticmethod
def __init__(conf):
pass
@abc.abstractmethod
def notify(self, action, alarm_id, alarm_name, severity, previous,
current, reason, reason_data):
@ -58,7 +62,8 @@ class AlarmNotifierService(os_service.Service):
self.notifiers = extension.ExtensionManager(
self.NOTIFIER_EXTENSIONS_NAMESPACE,
invoke_on_load=True)
invoke_on_load=True,
invoke_args=(conf,))
def start(self):
super(AlarmNotifierService, self).start()

View File

@ -58,8 +58,11 @@ cfg.CONF.register_opts(OPTS)
class RestAlarmNotifier(notifier.AlarmNotifier):
"""Rest alarm notifier."""
@staticmethod
def notify(action, alarm_id, alarm_name, severity, previous,
def __init__(self, conf):
super(RestAlarmNotifier, self).__init__(conf)
self.conf = conf
def notify(self, action, alarm_id, alarm_name, severity, previous,
current, reason, reason_data, headers=None):
headers = headers or {}
if not headers.get('x-openstack-request-id'):
@ -82,14 +85,14 @@ class RestAlarmNotifier(notifier.AlarmNotifier):
'headers': headers}
if action.scheme == 'https':
default_verify = int(cfg.CONF.rest_notifier_ssl_verify)
default_verify = int(self.conf.rest_notifier_ssl_verify)
options = urlparse.parse_qs(action.query)
verify = bool(int(options.get('aodh-alarm-ssl-verify',
[default_verify])[-1]))
kwargs['verify'] = verify
cert = cfg.CONF.rest_notifier_certificate_file
key = cfg.CONF.rest_notifier_certificate_key
cert = self.conf.rest_notifier_certificate_file
key = self.conf.rest_notifier_certificate_key
if cert:
kwargs['cert'] = (cert, key) if key else cert
@ -97,7 +100,7 @@ class RestAlarmNotifier(notifier.AlarmNotifier):
# library. However, there's no interval between retries in urllib3
# implementation. It will be better to put some interval between
# retries (future work).
max_retries = cfg.CONF.rest_notifier_max_retries
max_retries = self.conf.rest_notifier_max_retries
session = requests.Session()
session.mount(action.geturl(),
requests.adapters.HTTPAdapter(max_retries=max_retries))

View File

@ -1,5 +1,5 @@
#
# Copyright 2013 eNovance
# Copyright 2013-2015 eNovance
#
# 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
@ -20,7 +20,8 @@ from aodh import notifier
class TestAlarmNotifier(notifier.AlarmNotifier):
"Test alarm notifier."""
def __init__(self):
def __init__(self, conf):
super(TestAlarmNotifier, self).__init__(conf)
self.notifications = []
def notify(self, action, alarm_id, alarm_name, severity,

View File

@ -14,7 +14,6 @@
# under the License.
"""Rest alarm notifier with trusted authentication."""
from oslo_config import cfg
from six.moves.urllib import parse
from aodh import keystone_client
@ -31,12 +30,11 @@ class TrustRestAlarmNotifier(rest.RestAlarmNotifier):
The URL must be in the form trust+http://trust-id@host/action.
"""
@staticmethod
def notify(action, alarm_id, alarm_name, severity, previous, current,
def notify(self, action, alarm_id, alarm_name, severity, previous, current,
reason, reason_data):
trust_id = action.username
client = keystone_client.get_v3_client(cfg.CONF, trust_id)
client = keystone_client.get_v3_client(self.conf, trust_id)
# Remove the fake user
netloc = action.netloc.split("@")[1]
@ -47,6 +45,6 @@ class TrustRestAlarmNotifier(rest.RestAlarmNotifier):
action.fragment)
headers = {'X-Auth-Token': client.auth_token}
rest.RestAlarmNotifier.notify(
super(TrustRestAlarmNotifier, self).notify(
action, alarm_id, alarm_name, severity, previous, current, reason,
reason_data, headers)