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
This commit is contained in:
Eoghan Glynn 2015-01-21 17:10:59 +00:00
parent d407213722
commit 8926a20202
4 changed files with 33 additions and 13 deletions

View File

@ -0,0 +1,26 @@
#
# Copyright 2015 Red Hat, Inc
#
# Authors: Eoghan Glynn <eglynn@redhat.com>
#
# 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)

View File

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

View File

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

View File

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