evaluator: stop using global conf in Evaluator
Change-Id: I1380fbc375a9fb8424dbc6e596997ab4caf9b546
This commit is contained in:
parent
69fb02f17e
commit
dd569eb3d7
@ -61,18 +61,19 @@ cfg.CONF.register_opts(OPTS)
|
||||
class Evaluator(object):
|
||||
"""Base class for alarm rule evaluator plugins."""
|
||||
|
||||
def __init__(self, notifier):
|
||||
def __init__(self, conf, notifier):
|
||||
self.conf = conf
|
||||
self.notifier = notifier
|
||||
self.storage_conn = None
|
||||
|
||||
@property
|
||||
def _storage_conn(self):
|
||||
if not self.storage_conn:
|
||||
self.storage_conn = storage.get_connection_from_config(cfg.CONF)
|
||||
self.storage_conn = storage.get_connection_from_config(self.conf)
|
||||
return self.storage_conn
|
||||
|
||||
def _record_change(self, alarm):
|
||||
if not cfg.CONF.record_history:
|
||||
if not self.conf.record_history:
|
||||
return
|
||||
type = models.AlarmChange.STATE_TRANSITION
|
||||
detail = json.dumps({'state': alarm.state})
|
||||
@ -96,7 +97,7 @@ class Evaluator(object):
|
||||
except aodh.NotImplementedError:
|
||||
pass
|
||||
notification = "alarm.state_transition"
|
||||
transport = messaging.get_transport(cfg.CONF)
|
||||
transport = messaging.get_transport(self.conf)
|
||||
notifier = messaging.get_notifier(transport,
|
||||
publisher_id="aodh.evaluator")
|
||||
notifier.info(context.RequestContext(), notification, payload)
|
||||
@ -188,7 +189,7 @@ class AlarmService(object):
|
||||
self.evaluators = extension.ExtensionManager(
|
||||
namespace=self.EVALUATOR_EXTENSIONS_NAMESPACE,
|
||||
invoke_on_load=True,
|
||||
invoke_args=(rpc.RPCAlarmNotifier(),)
|
||||
invoke_args=(cfg.CONF, rpc.RPCAlarmNotifier(),)
|
||||
)
|
||||
|
||||
def _evaluate_assigned_alarms(self):
|
||||
|
@ -36,8 +36,8 @@ cfg.CONF.import_opt('http_timeout', 'aodh.service')
|
||||
|
||||
class GnocchiThresholdEvaluator(threshold.ThresholdEvaluator):
|
||||
|
||||
def __init__(self, notifier):
|
||||
super(threshold.ThresholdEvaluator, self).__init__(notifier)
|
||||
def __init__(self, conf, notifier):
|
||||
super(threshold.ThresholdEvaluator, self).__init__(conf, notifier)
|
||||
self.gnocchi_url = cfg.CONF.gnocchi_url
|
||||
self._ks_client = None
|
||||
|
||||
|
@ -47,8 +47,8 @@ class ThresholdEvaluator(evaluator.Evaluator):
|
||||
# for reporting/ingestion lag
|
||||
look_back = 1
|
||||
|
||||
def __init__(self, notifier):
|
||||
super(ThresholdEvaluator, self).__init__(notifier)
|
||||
def __init__(self, conf, notifier):
|
||||
super(ThresholdEvaluator, self).__init__(conf, notifier)
|
||||
self.api_client = None
|
||||
|
||||
@property
|
||||
|
@ -12,9 +12,8 @@
|
||||
# WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
|
||||
# License for the specific language governing permissions and limitations
|
||||
# under the License.
|
||||
"""Base class for tests in aodh/evaluator/
|
||||
"""
|
||||
import mock
|
||||
from oslo_config import cfg
|
||||
from oslotest import base
|
||||
|
||||
|
||||
@ -23,7 +22,7 @@ class TestEvaluatorBase(base.BaseTestCase):
|
||||
super(TestEvaluatorBase, self).setUp()
|
||||
self.api_client = mock.Mock()
|
||||
self.notifier = mock.MagicMock()
|
||||
self.evaluator = self.EVALUATOR(self.notifier)
|
||||
self.evaluator = self.EVALUATOR(cfg.CONF, self.notifier)
|
||||
self.storage_conn = mock.MagicMock()
|
||||
self.evaluator.storage_conn = self.storage_conn
|
||||
self.prepare_alarms()
|
||||
|
@ -17,6 +17,7 @@
|
||||
import datetime
|
||||
|
||||
import mock
|
||||
from oslo_config import cfg
|
||||
from oslo_utils import timeutils
|
||||
from oslotest import base
|
||||
|
||||
@ -40,7 +41,7 @@ class TestEvaluatorBaseClass(base.BaseTestCase):
|
||||
def evaluate(self, alarm):
|
||||
pass
|
||||
|
||||
ev = EvaluatorSub(notifier)
|
||||
ev = EvaluatorSub(cfg.CONF, notifier)
|
||||
ev.storage_conn = mock.MagicMock()
|
||||
ev._record_change = mock.MagicMock()
|
||||
ev._refresh(mock.MagicMock(), mock.MagicMock(),
|
||||
|
Loading…
x
Reference in New Issue
Block a user