From d71eea81d5e630c739b1d8e499775ee6ffd9bf89 Mon Sep 17 00:00:00 2001 From: Julien Danjou Date: Fri, 25 Sep 2015 17:33:50 +0200 Subject: [PATCH] dispatcher: remove deprecated CADF code in HTTP Change-Id: I2980431ebbca5dc5a9913e7dff5f5c2c309059c6 --- ceilometer/dispatcher/http.py | 23 +------- ceilometer/tests/unit/dispatcher/test_http.py | 53 ------------------- 2 files changed, 2 insertions(+), 74 deletions(-) diff --git a/ceilometer/dispatcher/http.py b/ceilometer/dispatcher/http.py index f26c358a..c2888b0c 100644 --- a/ceilometer/dispatcher/http.py +++ b/ceilometer/dispatcher/http.py @@ -34,13 +34,6 @@ http_dispatcher_opts = [ help='The target for event data where the http request ' 'will be sent to. If this is not set, it will default ' 'to same as Sample target.'), - cfg.BoolOpt('cadf_only', - default=False, - deprecated_for_removal=True, - help='The flag that indicates if only cadf message should ' - 'be posted. If false, all meters will be posted. This is ' - 'deprecated in favor of keystonemiddleware\'s audit ' - 'middleware functionality'), cfg.IntOpt('timeout', default=5, help='The max time in seconds to wait for a request to ' @@ -64,7 +57,6 @@ class HttpDispatcher(dispatcher.Base): [dispatcher_http] target = www.example.com event_target = www.example.com - cadf_only = true timeout = 2 """ def __init__(self, conf): @@ -74,7 +66,6 @@ class HttpDispatcher(dispatcher.Base): self.target = self.conf.dispatcher_http.target self.event_target = (self.conf.dispatcher_http.event_target or self.target) - self.cadf_only = self.conf.dispatcher_http.cadf_only def record_metering_data(self, data): if self.target == '': @@ -99,19 +90,9 @@ class HttpDispatcher(dispatcher.Base): if publisher_utils.verify_signature( meter, self.conf.publisher.telemetry_secret): try: - if self.cadf_only: - # Only cadf messages are being wanted. - req_data = meter.get('resource_metadata', - {}).get('request') - if req_data and 'CADF_EVENT' in req_data: - data = req_data['CADF_EVENT'] - else: - continue - else: - # Every meter should be posted to the target - data = meter + # Every meter should be posted to the target res = requests.post(self.target, - data=json.dumps(data), + data=json.dumps(meter), headers=self.headers, timeout=self.timeout) LOG.debug('Message posting finished with status code ' diff --git a/ceilometer/tests/unit/dispatcher/test_http.py b/ceilometer/tests/unit/dispatcher/test_http.py index e9bb72a5..00122d64 100644 --- a/ceilometer/tests/unit/dispatcher/test_http.py +++ b/ceilometer/tests/unit/dispatcher/test_http.py @@ -42,12 +42,10 @@ class TestDispatcherHttp(base.BaseTestCase): def test_http_dispatcher_config_options(self): self.CONF.dispatcher_http.target = 'fake' self.CONF.dispatcher_http.timeout = 2 - self.CONF.dispatcher_http.cadf_only = True dispatcher = http.HttpDispatcher(self.CONF) self.assertEqual('fake', dispatcher.target) self.assertEqual(2, dispatcher.timeout) - self.assertEqual(True, dispatcher.cadf_only) def test_http_dispatcher_with_no_target(self): self.CONF.dispatcher_http.target = '' @@ -65,59 +63,8 @@ class TestDispatcherHttp(base.BaseTestCase): def test_http_dispatcher_with_no_metadata(self): self.CONF.dispatcher_http.target = 'fake' - self.CONF.dispatcher_http.cadf_only = True dispatcher = http.HttpDispatcher(self.CONF) - with mock.patch.object(requests, 'post') as post: - dispatcher.record_metering_data(self.msg) - - self.assertEqual(0, post.call_count) - - def test_http_dispatcher_without_cadf_event(self): - self.CONF.dispatcher_http.target = 'fake' - self.CONF.dispatcher_http.cadf_only = True - dispatcher = http.HttpDispatcher(self.CONF) - - self.msg['resource_metadata'] = {'request': {'NONE_CADF_EVENT': { - 'q1': 'v1', 'q2': 'v2'}, }, } - self.msg['message_signature'] = utils.compute_signature( - self.msg, self.CONF.publisher.telemetry_secret, - ) - - with mock.patch.object(requests, 'post') as post: - dispatcher.record_metering_data(self.msg) - - # Since the meter does not have metadata or CADF_EVENT, the method - # call count should be zero - self.assertEqual(0, post.call_count) - - def test_http_dispatcher_with_cadf_event(self): - self.CONF.dispatcher_http.target = 'fake' - self.CONF.dispatcher_http.cadf_only = True - dispatcher = http.HttpDispatcher(self.CONF) - - self.msg['resource_metadata'] = {'request': {'CADF_EVENT': { - 'q1': 'v1', 'q2': 'v2'}, }, } - self.msg['message_signature'] = utils.compute_signature( - self.msg, self.CONF.publisher.telemetry_secret, - ) - - with mock.patch.object(requests, 'post') as post: - dispatcher.record_metering_data(self.msg) - - self.assertEqual(1, post.call_count) - - def test_http_dispatcher_with_none_cadf_event(self): - self.CONF.dispatcher_http.target = 'fake' - self.CONF.dispatcher_http.cadf_only = False - dispatcher = http.HttpDispatcher(self.CONF) - - self.msg['resource_metadata'] = {'any': {'thing1': 'v1', - 'thing2': 'v2', }, } - self.msg['message_signature'] = utils.compute_signature( - self.msg, self.CONF.publisher.telemetry_secret, - ) - with mock.patch.object(requests, 'post') as post: dispatcher.record_metering_data(self.msg)