From 8926a202028e43ce9c600fdff5efd34fcdd235f0 Mon Sep 17 00:00:00 2001 From: Eoghan Glynn Date: Wed, 21 Jan 2015 17:10:59 +0000 Subject: [PATCH] Avoid unnecessary API dependency on tooz & ceilometerclient Previously, importing the alarm.service in the v2 API layer created an unnecessary transitive dependency on python-tooz and python-ceilometerclient. We avoid these dependencies simply by moving the relevant code. Change-Id: I1b936bf4dc2ad28afb7a45f61bfcd111adb20e1c Closes-Bug: #1413237 --- ceilometer/alarm/__init__.py | 26 +++++++++++++++++++++++++ ceilometer/alarm/service.py | 13 +++---------- ceilometer/api/controllers/v2.py | 4 ++-- ceilometer/tests/alarm/test_notifier.py | 3 ++- 4 files changed, 33 insertions(+), 13 deletions(-) diff --git a/ceilometer/alarm/__init__.py b/ceilometer/alarm/__init__.py index e69de29b..bbccacb2 100644 --- a/ceilometer/alarm/__init__.py +++ b/ceilometer/alarm/__init__.py @@ -0,0 +1,26 @@ +# +# Copyright 2015 Red Hat, Inc +# +# Authors: Eoghan Glynn +# +# 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 +# a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, WITHOUT +# WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the +# License for the specific language governing permissions and limitations +# under the License. + +from stevedore import extension + + +EVALUATOR_EXTENSIONS_NAMESPACE = "ceilometer.alarm.evaluator" +NOTIFIER_EXTENSIONS_NAMESPACE = "ceilometer.alarm.notifier" + +NOTIFIERS = extension.ExtensionManager(NOTIFIER_EXTENSIONS_NAMESPACE, + invoke_on_load=True) +NOTIFIER_SCHEMAS = NOTIFIERS.map(lambda x: x.name) diff --git a/ceilometer/alarm/service.py b/ceilometer/alarm/service.py index 6cbb2aea..087e49bf 100644 --- a/ceilometer/alarm/service.py +++ b/ceilometer/alarm/service.py @@ -25,6 +25,7 @@ from oslo_utils import netutils import six from stevedore import extension +from ceilometer import alarm as ceilometer_alarm from ceilometer.alarm.partition import coordination as alarm_coordination from ceilometer.alarm import rpc as rpc_alarm from ceilometer import coordination as coordination @@ -54,8 +55,6 @@ LOG = log.getLogger(__name__) @six.add_metaclass(abc.ABCMeta) class AlarmService(object): - EXTENSIONS_NAMESPACE = "ceilometer.alarm.evaluator" - def __init__(self): super(AlarmService, self).__init__() self._load_evaluators() @@ -63,7 +62,7 @@ class AlarmService(object): def _load_evaluators(self): self.evaluators = extension.ExtensionManager( - namespace=self.EXTENSIONS_NAMESPACE, + namespace=ceilometer_alarm.EVALUATOR_EXTENSIONS_NAMESPACE, invoke_on_load=True, invoke_args=(rpc_alarm.RPCAlarmNotifier(),) ) @@ -228,12 +227,6 @@ class PartitionedAlarmService(AlarmService, os_service.Service): class AlarmNotifierService(os_service.Service): - EXTENSIONS_NAMESPACE = "ceilometer.alarm.notifier" - - notifiers = extension.ExtensionManager(EXTENSIONS_NAMESPACE, - invoke_on_load=True) - notifiers_schemas = notifiers.map(lambda x: x.name) - def __init__(self): super(AlarmNotifierService, self).__init__() transport = messaging.get_transport() @@ -261,7 +254,7 @@ class AlarmNotifierService(os_service.Service): return try: - notifier = self.notifiers[action.scheme].obj + notifier = ceilometer_alarm.NOTIFIERS[action.scheme].obj except KeyError: scheme = action.scheme LOG.error( diff --git a/ceilometer/api/controllers/v2.py b/ceilometer/api/controllers/v2.py index e7b47c32..90cfd9e7 100644 --- a/ceilometer/api/controllers/v2.py +++ b/ceilometer/api/controllers/v2.py @@ -51,7 +51,7 @@ from wsme import types as wtypes import wsmeext.pecan as wsme_pecan import ceilometer -from ceilometer.alarm import service as alarm_service +from ceilometer import alarm as ceilometer_alarm from ceilometer.alarm.storage import models as alarm_models from ceilometer.api import rbac from ceilometer.event.storage import models as event_models @@ -1889,7 +1889,7 @@ class Alarm(_Base): @staticmethod def check_alarm_actions(alarm): - actions_schema = alarm_service.AlarmNotifierService.notifiers_schemas + actions_schema = ceilometer_alarm.NOTIFIER_SCHEMAS for state in state_kind: actions_name = state.replace(" ", "_") + '_actions' actions = getattr(alarm, actions_name) diff --git a/ceilometer/tests/alarm/test_notifier.py b/ceilometer/tests/alarm/test_notifier.py index ec568913..40390d46 100644 --- a/ceilometer/tests/alarm/test_notifier.py +++ b/ceilometer/tests/alarm/test_notifier.py @@ -23,6 +23,7 @@ from oslotest import mockpatch import requests import six.moves.urllib.parse as urlparse +from ceilometer import alarm as ceilometer_alarm from ceilometer.alarm import service from ceilometer.tests import base as tests_base @@ -71,7 +72,7 @@ class TestAlarmNotifier(tests_base.BaseTestCase): 'reason_data': {'fire': 'everywhere'} } self.service.notify_alarm(context.get_admin_context(), data) - notifications = self.service.notifiers['test'].obj.notifications + notifications = ceilometer_alarm.NOTIFIERS['test'].obj.notifications self.assertEqual(1, len(notifications)) self.assertEqual((urlparse.urlsplit(data['actions'][0]), data['alarm_id'],