Merge "dispatcher: remove deprecated CADF code in HTTP"

This commit is contained in:
Jenkins 2015-12-04 07:03:03 +00:00 committed by Gerrit Code Review
commit 22bb881a72
2 changed files with 2 additions and 74 deletions

View File

@ -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 '
@ -66,7 +59,6 @@ class HttpDispatcher(dispatcher.MeterDispatcherBase,
[dispatcher_http]
target = www.example.com
event_target = www.example.com
cadf_only = true
timeout = 2
"""
@ -77,7 +69,6 @@ class HttpDispatcher(dispatcher.MeterDispatcherBase,
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 == '':
@ -102,19 +93,9 @@ class HttpDispatcher(dispatcher.MeterDispatcherBase,
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 '

View File

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