|
19 | 19 |
|
20 | 20 | import mock
|
21 | 21 | from oslo_config import fixture as fixture_config
|
22 |
| -from oslo_context import context |
23 | 22 | from oslo_utils import netutils
|
24 | 23 | import testscenarios.testcase
|
25 | 24 |
|
26 | 25 | from ceilometer.event.storage import models as event
|
27 |
| -from ceilometer import messaging |
28 | 26 | from ceilometer.publisher import messaging as msg_publisher
|
29 | 27 | from ceilometer import sample
|
30 | 28 | from ceilometer.tests import base as tests_base
|
@@ -103,76 +101,6 @@ def setUp(self):
|
103 | 101 | self.setup_messaging(self.CONF)
|
104 | 102 |
|
105 | 103 |
|
106 |
| -class RpcOnlyPublisherTest(BasePublisherTestCase): |
107 |
| - def test_published_no_mock(self): |
108 |
| - publisher = msg_publisher.RPCPublisher( |
109 |
| - netutils.urlsplit('rpc://')) |
110 |
| - |
111 |
| - endpoint = mock.MagicMock(['record_metering_data']) |
112 |
| - collector = messaging.get_rpc_server( |
113 |
| - self.transport, self.CONF.publisher_rpc.metering_topic, endpoint) |
114 |
| - endpoint.record_metering_data.side_effect = (lambda *args, **kwds: |
115 |
| - collector.stop()) |
116 |
| - |
117 |
| - collector.start() |
118 |
| - publisher.publish_samples(context.RequestContext(), |
119 |
| - self.test_sample_data) |
120 |
| - collector.wait() |
121 |
| - |
122 |
| - class Matcher(object): |
123 |
| - @staticmethod |
124 |
| - def __eq__(data): |
125 |
| - for i, sample_item in enumerate(data): |
126 |
| - if (sample_item['counter_name'] != |
127 |
| - self.test_sample_data[i].name): |
128 |
| - return False |
129 |
| - return True |
130 |
| - |
131 |
| - endpoint.record_metering_data.assert_called_once_with( |
132 |
| - mock.ANY, data=Matcher()) |
133 |
| - |
134 |
| - def test_publish_target(self): |
135 |
| - publisher = msg_publisher.RPCPublisher( |
136 |
| - netutils.urlsplit('rpc://?target=custom_procedure_call')) |
137 |
| - cast_context = mock.MagicMock() |
138 |
| - with mock.patch.object(publisher.rpc_client, 'prepare') as prepare: |
139 |
| - prepare.return_value = cast_context |
140 |
| - publisher.publish_samples(mock.MagicMock(), |
141 |
| - self.test_sample_data) |
142 |
| - |
143 |
| - prepare.assert_called_once_with( |
144 |
| - topic=self.CONF.publisher_rpc.metering_topic) |
145 |
| - cast_context.cast.assert_called_once_with( |
146 |
| - mock.ANY, 'custom_procedure_call', data=mock.ANY) |
147 |
| - |
148 |
| - def test_published_with_per_meter_topic(self): |
149 |
| - publisher = msg_publisher.RPCPublisher( |
150 |
| - netutils.urlsplit('rpc://?per_meter_topic=1')) |
151 |
| - with mock.patch.object(publisher.rpc_client, 'prepare') as prepare: |
152 |
| - publisher.publish_samples(mock.MagicMock(), |
153 |
| - self.test_sample_data) |
154 |
| - |
155 |
| - class MeterGroupMatcher(object): |
156 |
| - def __eq__(self, meters): |
157 |
| - return len(set(meter['counter_name'] |
158 |
| - for meter in meters)) == 1 |
159 |
| - |
160 |
| - topic = self.CONF.publisher_rpc.metering_topic |
161 |
| - expected = [mock.call(topic=topic), |
162 |
| - mock.call().cast(mock.ANY, 'record_metering_data', |
163 |
| - data=mock.ANY), |
164 |
| - mock.call(topic=topic + '.test'), |
165 |
| - mock.call().cast(mock.ANY, 'record_metering_data', |
166 |
| - data=MeterGroupMatcher()), |
167 |
| - mock.call(topic=topic + '.test2'), |
168 |
| - mock.call().cast(mock.ANY, 'record_metering_data', |
169 |
| - data=MeterGroupMatcher()), |
170 |
| - mock.call(topic=topic + '.test3'), |
171 |
| - mock.call().cast(mock.ANY, 'record_metering_data', |
172 |
| - data=MeterGroupMatcher())] |
173 |
| - self.assertEqual(expected, prepare.mock_calls) |
174 |
| - |
175 |
| - |
176 | 104 | class NotifierOnlyPublisherTest(BasePublisherTestCase):
|
177 | 105 |
|
178 | 106 | @mock.patch('oslo_messaging.Notifier')
|
@@ -203,17 +131,13 @@ class TestPublisher(testscenarios.testcase.WithScenarios,
|
203 | 131 | publisher_cls=msg_publisher.EventNotifierPublisher,
|
204 | 132 | test_data=BasePublisherTestCase.test_event_data,
|
205 | 133 | pub_func='publish_events', attr='event_type')),
|
206 |
| - ('rpc', dict(protocol="rpc", |
207 |
| - publisher_cls=msg_publisher.RPCPublisher, |
208 |
| - test_data=BasePublisherTestCase.test_sample_data, |
209 |
| - pub_func='publish_samples', attr='source')), |
210 | 134 | ]
|
211 | 135 |
|
212 | 136 | def setUp(self):
|
213 | 137 | super(TestPublisher, self).setUp()
|
214 | 138 | self.topic = (self.CONF.publisher_notifier.event_topic
|
215 | 139 | if self.pub_func == 'publish_events' else
|
216 |
| - self.CONF.publisher_rpc.metering_topic) |
| 140 | + self.CONF.publisher_notifier.metering_topic) |
217 | 141 |
|
218 | 142 |
|
219 | 143 | class TestPublisherPolicy(TestPublisher):
|
|
0 commit comments