summaryrefslogtreecommitdiff
path: root/ceilometer/tests/alarm
diff options
context:
space:
mode:
Diffstat (limited to 'ceilometer/tests/alarm')
-rw-r--r--ceilometer/tests/alarm/partition/test_coordination.py4
-rw-r--r--ceilometer/tests/alarm/test_notifier.py8
-rw-r--r--ceilometer/tests/alarm/test_partitioned_alarm_svc.py12
-rw-r--r--ceilometer/tests/alarm/test_rpc.py86
-rw-r--r--ceilometer/tests/alarm/test_singleton_alarm_svc.py4
5 files changed, 68 insertions, 46 deletions
diff --git a/ceilometer/tests/alarm/partition/test_coordination.py b/ceilometer/tests/alarm/partition/test_coordination.py
index bdd8e72a..707122ea 100644
--- a/ceilometer/tests/alarm/partition/test_coordination.py
+++ b/ceilometer/tests/alarm/partition/test_coordination.py
@@ -26,6 +26,7 @@ import mock
from six import moves
from ceilometer.alarm.partition import coordination
+from ceilometer import messaging
from ceilometer.openstack.common.fixture import config
from ceilometer.openstack.common import test
from ceilometer.openstack.common import timeutils
@@ -36,6 +37,9 @@ class TestCoordinate(test.BaseTestCase):
def setUp(self):
super(TestCoordinate, self).setUp()
self.CONF = self.useFixture(config.Config()).conf
+ messaging.setup('fake://')
+ self.addCleanup(messaging.cleanup)
+
self.test_interval = 120
self.CONF.set_override('evaluation_interval',
self.test_interval,
diff --git a/ceilometer/tests/alarm/test_notifier.py b/ceilometer/tests/alarm/test_notifier.py
index 583ac6fa..8f282833 100644
--- a/ceilometer/tests/alarm/test_notifier.py
+++ b/ceilometer/tests/alarm/test_notifier.py
@@ -21,6 +21,7 @@ import mock
import requests
from ceilometer.alarm import service
+from ceilometer import messaging
from ceilometer.openstack.common import context
from ceilometer.openstack.common.fixture import config
from ceilometer.openstack.common import test
@@ -41,15 +42,18 @@ class TestAlarmNotifier(test.BaseTestCase):
def setUp(self):
super(TestAlarmNotifier, self).setUp()
+ messaging.setup('fake://')
+ self.addCleanup(messaging.cleanup)
+
self.CONF = self.useFixture(config.Config()).conf
- self.service = service.AlarmNotifierService('somehost', 'sometopic')
+ self.service = service.AlarmNotifierService()
@mock.patch('ceilometer.pipeline.setup_pipeline', mock.MagicMock())
def test_init_host(self):
# If we try to create a real RPC connection, init_host() never
# returns. Mock it out so we can establish the service
# configuration.
- with mock.patch('ceilometer.openstack.common.rpc.create_connection'):
+ with mock.patch.object(self.service.rpc_server, 'start'):
self.service.start()
def test_notify_alarm(self):
diff --git a/ceilometer/tests/alarm/test_partitioned_alarm_svc.py b/ceilometer/tests/alarm/test_partitioned_alarm_svc.py
index 18fed237..7b22d700 100644
--- a/ceilometer/tests/alarm/test_partitioned_alarm_svc.py
+++ b/ceilometer/tests/alarm/test_partitioned_alarm_svc.py
@@ -18,11 +18,11 @@
"""Tests for ceilometer.alarm.service.PartitionedAlarmService.
"""
import contextlib
-
import mock
from stevedore import extension
from ceilometer.alarm import service
+from ceilometer import messaging
from ceilometer.openstack.common.fixture import config
from ceilometer.openstack.common import test
@@ -30,6 +30,9 @@ from ceilometer.openstack.common import test
class TestPartitionedAlarmService(test.BaseTestCase):
def setUp(self):
super(TestPartitionedAlarmService, self).setUp()
+ messaging.setup('fake://')
+ self.addCleanup(messaging.cleanup)
+
self.threshold_eval = mock.Mock()
self.api_client = mock.MagicMock()
self.CONF = self.useFixture(config.Config()).conf
@@ -60,10 +63,9 @@ class TestPartitionedAlarmService(test.BaseTestCase):
test_interval,
group='alarm')
get_client = 'ceilometerclient.client.get_client'
- create_conn = 'ceilometer.openstack.common.rpc.create_connection'
- with contextlib.nested(mock.patch(get_client,
- return_value=self.api_client),
- mock.patch(create_conn)):
+ with contextlib.nested(
+ mock.patch(get_client, return_value=self.api_client),
+ mock.patch.object(self.partitioned.rpc_server, 'start')):
self.partitioned.start()
pc = self.partitioned.partition_coordinator
expected = [
diff --git a/ceilometer/tests/alarm/test_rpc.py b/ceilometer/tests/alarm/test_rpc.py
index 792b6b24..d798c4e2 100644
--- a/ceilometer/tests/alarm/test_rpc.py
+++ b/ceilometer/tests/alarm/test_rpc.py
@@ -22,26 +22,27 @@ from ceilometerclient.v2 import alarms
import mock
from ceilometer.alarm import rpc as rpc_alarm
-from ceilometer.openstack.common.fixture import config
+from ceilometer import messaging
from ceilometer.openstack.common.fixture import mockpatch
-from ceilometer.openstack.common import rpc
from ceilometer.openstack.common import test
from ceilometer.openstack.common import timeutils
from ceilometer.storage import models
class TestRPCAlarmNotifier(test.BaseTestCase):
- def fake_cast(self, context, topic, msg):
- self.notified.append((topic, msg))
- self.CONF = self.useFixture(config.Config()).conf
+ def fake_cast(self, context, method, **args):
+ self.notified.append((method, args))
def setUp(self):
super(TestRPCAlarmNotifier, self).setUp()
+ messaging.setup('fake://')
+ self.addCleanup(messaging.cleanup)
+
self.notified = []
+ self.notifier = rpc_alarm.RPCAlarmNotifier()
self.useFixture(mockpatch.PatchObject(
- rpc, 'cast',
+ self.notifier.client, 'cast',
side_effect=self.fake_cast))
- self.notifier = rpc_alarm.RPCAlarmNotifier()
self.alarms = [
alarms.Alarm(None, info={
'name': 'instance_running_hot',
@@ -77,6 +78,10 @@ class TestRPCAlarmNotifier(test.BaseTestCase):
}),
]
+ def test_rpc_target(self):
+ topic = self.notifier.client.target.topic
+ self.assertEqual('alarm_notifier', topic)
+
def test_notify_alarm(self):
previous = ['alarm', 'ok']
for i, a in enumerate(self.alarms):
@@ -85,25 +90,22 @@ class TestRPCAlarmNotifier(test.BaseTestCase):
self.assertEqual(2, len(self.notified))
for i, a in enumerate(self.alarms):
actions = getattr(a, models.Alarm.ALARM_ACTIONS_MAP[a.state])
- self.assertEqual(self.CONF.alarm.notifier_rpc_topic,
- self.notified[i][0])
+ self.assertEqual('notify_alarm', self.notified[i][0])
self.assertEqual(self.alarms[i].alarm_id,
- self.notified[i][1]["args"]["data"]["alarm_id"])
- self.assertEqual(actions,
- self.notified[i][1]["args"]["data"]["actions"])
+ self.notified[i][1]["data"]["alarm_id"])
+ self.assertEqual(actions, self.notified[i][1]["data"]["actions"])
self.assertEqual(previous[i],
- self.notified[i][1]["args"]["data"]["previous"])
+ self.notified[i][1]["data"]["previous"])
self.assertEqual(self.alarms[i].state,
- self.notified[i][1]["args"]["data"]["current"])
+ self.notified[i][1]["data"]["current"])
self.assertEqual("what? %d" % i,
- self.notified[i][1]["args"]["data"]["reason"])
- self.assertEqual(
- {'fire': '%d' % i},
- self.notified[i][1]["args"]["data"]["reason_data"])
+ self.notified[i][1]["data"]["reason"])
+ self.assertEqual({'fire': '%d' % i},
+ self.notified[i][1]["data"]["reason_data"])
def test_notify_non_string_reason(self):
self.notifier.notify(self.alarms[0], 'ok', 42, {})
- reason = self.notified[0][1]['args']['data']['reason']
+ reason = self.notified[0][1]['data']['reason']
self.assertIsInstance(reason, basestring)
def test_notify_no_actions(self):
@@ -128,42 +130,48 @@ class TestRPCAlarmNotifier(test.BaseTestCase):
class TestRPCAlarmPartitionCoordination(test.BaseTestCase):
- def fake_fanout_cast(self, context, topic, msg):
- self.notified.append((topic, msg))
+ def fake_fanout_cast(self, context, method, **args):
+ self.notified.append((method, args))
+
+ def fake_prepare(self, fanout):
+ self.assertTrue(fanout)
+ cctxt = mock.Mock()
+ cctxt.cast.side_effect = self.fake_fanout_cast
+ return cctxt
def setUp(self):
super(TestRPCAlarmPartitionCoordination, self).setUp()
+ messaging.setup('fake://')
+ self.addCleanup(messaging.cleanup)
+
self.notified = []
- self.useFixture(mockpatch.PatchObject(
- rpc, 'fanout_cast',
- side_effect=self.fake_fanout_cast))
self.ordination = rpc_alarm.RPCAlarmPartitionCoordination()
+ self.useFixture(mockpatch.PatchObject(
+ self.ordination.client, 'prepare',
+ side_effect=self.fake_prepare))
self.alarms = [mock.MagicMock(), mock.MagicMock()]
def test_ordination_presence(self):
id = uuid.uuid4()
priority = float(timeutils.utcnow().strftime('%s.%f'))
self.ordination.presence(id, priority)
- topic, msg = self.notified[0]
- self.assertEqual('alarm_partition_coordination', topic)
- self.assertEqual(id, msg['args']['data']['uuid'])
- self.assertEqual(priority, msg['args']['data']['priority'])
- self.assertEqual('presence', msg['method'])
+ method, args = self.notified[0]
+ self.assertEqual(id, args['data']['uuid'])
+ self.assertEqual(priority, args['data']['priority'])
+ self.assertEqual('presence', method)
def test_ordination_assign(self):
id = uuid.uuid4()
self.ordination.assign(id, self.alarms)
- topic, msg = self.notified[0]
- self.assertEqual('alarm_partition_coordination', topic)
- self.assertEqual(id, msg['args']['data']['uuid'])
- self.assertEqual(2, len(msg['args']['data']['alarms']))
- self.assertEqual('assign', msg['method'])
+ method, args = self.notified[0]
+ self.assertEqual(id, args['data']['uuid'])
+ self.assertEqual(2, len(args['data']['alarms']))
+ self.assertEqual('assign', method)
def test_ordination_allocate(self):
id = uuid.uuid4()
self.ordination.allocate(id, self.alarms)
- topic, msg = self.notified[0]
- self.assertEqual('alarm_partition_coordination', topic)
- self.assertEqual(id, msg['args']['data']['uuid'])
- self.assertEqual(2, len(msg['args']['data']['alarms']))
- self.assertEqual('allocate', msg['method'])
+ method, args = self.notified[0]
+ self.assertEqual(id, args['data']['uuid'])
+ self.assertEqual(2, len(args['data']['alarms']))
+ self.assertEqual('allocate', method)
diff --git a/ceilometer/tests/alarm/test_singleton_alarm_svc.py b/ceilometer/tests/alarm/test_singleton_alarm_svc.py
index 2055439c..7e3c1aed 100644
--- a/ceilometer/tests/alarm/test_singleton_alarm_svc.py
+++ b/ceilometer/tests/alarm/test_singleton_alarm_svc.py
@@ -24,12 +24,16 @@ from oslo.config import cfg
from stevedore import extension
from ceilometer.alarm import service
+from ceilometer import messaging
from ceilometer.openstack.common import test
class TestSingletonAlarmService(test.BaseTestCase):
def setUp(self):
super(TestSingletonAlarmService, self).setUp()
+ messaging.setup('fake://')
+ self.addCleanup(messaging.cleanup)
+
self.threshold_eval = mock.Mock()
self.evaluators = extension.ExtensionManager.make_test_instance(
[