From b3cc28d84b949907a89d76c54ece73ed1a69f353 Mon Sep 17 00:00:00 2001 From: Emma Foley Date: Wed, 29 Nov 2017 23:35:05 +0000 Subject: Move tests: unit/dispatcher * Fix pylint errors * Add TODOs Some errors are ignored locally, as they were a symptom of other problems. These issues have been flagged with a TODO, and should be fixed later. JIRA: YARDSTICK-837 Signed-off-by: Emma Foley Change-Id: I1f8a6041424c4c69f46ef30bd5c66d2d51d24347 --- tests/unit/dispatcher/__init__.py | 0 tests/unit/dispatcher/test_influxdb.py | 119 --------------------- .../unit/dispatcher/test_influxdb_line_protocol.py | 64 ----------- yardstick/tests/unit/dispatcher/__init__.py | 0 yardstick/tests/unit/dispatcher/test_influxdb.py | 114 ++++++++++++++++++++ .../unit/dispatcher/test_influxdb_line_protocol.py | 63 +++++++++++ 6 files changed, 177 insertions(+), 183 deletions(-) delete mode 100644 tests/unit/dispatcher/__init__.py delete mode 100644 tests/unit/dispatcher/test_influxdb.py delete mode 100644 tests/unit/dispatcher/test_influxdb_line_protocol.py create mode 100644 yardstick/tests/unit/dispatcher/__init__.py create mode 100644 yardstick/tests/unit/dispatcher/test_influxdb.py create mode 100644 yardstick/tests/unit/dispatcher/test_influxdb_line_protocol.py diff --git a/tests/unit/dispatcher/__init__.py b/tests/unit/dispatcher/__init__.py deleted file mode 100644 index e69de29bb..000000000 diff --git a/tests/unit/dispatcher/test_influxdb.py b/tests/unit/dispatcher/test_influxdb.py deleted file mode 100644 index 7ebe8c90b..000000000 --- a/tests/unit/dispatcher/test_influxdb.py +++ /dev/null @@ -1,119 +0,0 @@ -#!/usr/bin/env python - -############################################################################## -# Copyright (c) 2015 Huawei Technologies Co.,Ltd and others. -# -# All rights reserved. This program and the accompanying materials -# are made available under the terms of the Apache License, Version 2.0 -# which accompanies this distribution, and is available at -# http://www.apache.org/licenses/LICENSE-2.0 -############################################################################## - -# Unittest for yardstick.dispatcher.influxdb - -from __future__ import absolute_import -import unittest - - -try: - from unittest import mock -except ImportError: - import mock - -from yardstick import _init_logging -_init_logging() - -from yardstick.dispatcher.influxdb import InfluxdbDispatcher - - -class InfluxdbDispatcherTestCase(unittest.TestCase): - - def setUp(self): - self.data1 = { - "runner_id": 8921, - "context_cfg": { - "host": { - "ip": "10.229.43.154", - "key_filename": - "/root/yardstick/yardstick/resources/files" - "/yardstick_key", - "name": "kvm.LF", - "user": "root" - }, - "target": { - "ipaddr": "10.229.44.134" - } - }, - "scenario_cfg": { - "runner": { - "interval": 1, - "object": "yardstick.benchmark.scenarios.networking.ping" - ".Ping", - "output_filename": "/tmp/yardstick.out", - "runner_id": 8921, - "duration": 10, - "type": "Duration" - }, - "host": "kvm.LF", - "type": "Ping", - "target": "10.229.44.134", - "sla": { - "action": "monitor", - "max_rtt": 10 - }, - "tc": "ping", - "task_id": "ea958583-c91e-461a-af14-2a7f9d7f79e7" - } - } - self.data2 = { - "benchmark": { - "timestamp": "1451478117.883505", - "errors": "", - "data": { - "rtt": 0.613 - }, - "sequence": 1 - }, - "runner_id": 8921 - } - - self.yardstick_conf = {'dispatcher_influxdb': {}} - - @mock.patch('yardstick.dispatcher.influxdb.requests') - def test_record_result_data(self, mock_requests): - type(mock_requests.post.return_value).status_code = 204 - influxdb = InfluxdbDispatcher(self.yardstick_conf) - data = { - 'status': 1, - 'result': { - 'criteria': 'PASS', - 'info': { - }, - 'task_id': 'b9e2bbc2-dfd8-410d-8c24-07771e9f7979', - 'testcases': { - } - } - } - self.assertEqual(influxdb.flush_result_data(data), 0) - - def test__get_nano_timestamp(self): - influxdb = InfluxdbDispatcher(self.yardstick_conf) - results = {'timestamp': '1451461248.925574'} - self.assertEqual(influxdb._get_nano_timestamp(results), - '1451461248925574144') - - @mock.patch('yardstick.dispatcher.influxdb.time') - def test__get_nano_timestamp_except(self, mock_time): - results = {} - influxdb = InfluxdbDispatcher(self.yardstick_conf) - mock_time.time.return_value = 1451461248.925574 - self.assertEqual(influxdb._get_nano_timestamp(results), - '1451461248925574144') - - -def main(): - unittest.main() - - -if __name__ == '__main__': - main() diff --git a/tests/unit/dispatcher/test_influxdb_line_protocol.py b/tests/unit/dispatcher/test_influxdb_line_protocol.py deleted file mode 100644 index 51dc39e3c..000000000 --- a/tests/unit/dispatcher/test_influxdb_line_protocol.py +++ /dev/null @@ -1,64 +0,0 @@ -############################################################################## -# Copyright (c) 2017 Huawei Technologies Co.,Ltd and others. -# -# All rights reserved. This program and the accompanying materials -# are made available under the terms of the Apache License, Version 2.0 -# which accompanies this distribution, and is available at -# http://www.apache.org/licenses/LICENSE-2.0 -############################################################################## -# Unittest for yardstick.dispatcher.influxdb_line_protocol - -# yardstick comment: this file is a modified copy of -# influxdb-python/influxdb/tests/test_line_protocol.py - -from __future__ import absolute_import -import unittest -from third_party.influxdb.influxdb_line_protocol import make_lines - - -class TestLineProtocol(unittest.TestCase): - - def test_make_lines(self): - data = { - "tags": { - "empty_tag": "", - "none_tag": None, - "integer_tag": 2, - "string_tag": "hello" - }, - "points": [ - { - "measurement": "test", - "fields": { - "string_val": "hello!", - "int_val": 1, - "float_val": 1.1, - "none_field": None, - "bool_val": True, - } - } - ] - } - - self.assertEqual( - make_lines(data), - 'test,integer_tag=2,string_tag=hello ' - 'bool_val=True,float_val=1.1,int_val=1i,string_val="hello!"\n' - ) - - def test_string_val_newline(self): - data = { - "points": [ - { - "measurement": "m1", - "fields": { - "multi_line": "line1\nline1\nline3" - } - } - ] - } - - self.assertEqual( - make_lines(data), - 'm1 multi_line="line1\\nline1\\nline3"\n' - ) diff --git a/yardstick/tests/unit/dispatcher/__init__.py b/yardstick/tests/unit/dispatcher/__init__.py new file mode 100644 index 000000000..e69de29bb diff --git a/yardstick/tests/unit/dispatcher/test_influxdb.py b/yardstick/tests/unit/dispatcher/test_influxdb.py new file mode 100644 index 000000000..bca94e385 --- /dev/null +++ b/yardstick/tests/unit/dispatcher/test_influxdb.py @@ -0,0 +1,114 @@ +#!/usr/bin/env python + +############################################################################## +# Copyright (c) 2015 Huawei Technologies Co.,Ltd and others. +# +# All rights reserved. This program and the accompanying materials +# are made available under the terms of the Apache License, Version 2.0 +# which accompanies this distribution, and is available at +# http://www.apache.org/licenses/LICENSE-2.0 +############################################################################## + +# Unittest for yardstick.dispatcher.influxdb + +import mock +import unittest + +from yardstick.dispatcher.influxdb import InfluxdbDispatcher +from yardstick import _init_logging + + +_init_logging() + + +class InfluxdbDispatcherTestCase(unittest.TestCase): + + def setUp(self): + self.data1 = { + "runner_id": 8921, + "context_cfg": { + "host": { + "ip": "10.229.43.154", + "key_filename": + "/root/yardstick/yardstick/resources/files" + "/yardstick_key", + "name": "kvm.LF", + "user": "root" + }, + "target": { + "ipaddr": "10.229.44.134" + } + }, + "scenario_cfg": { + "runner": { + "interval": 1, + "object": "yardstick.benchmark.scenarios.networking.ping" + ".Ping", + "output_filename": "/tmp/yardstick.out", + "runner_id": 8921, + "duration": 10, + "type": "Duration" + }, + "host": "kvm.LF", + "type": "Ping", + "target": "10.229.44.134", + "sla": { + "action": "monitor", + "max_rtt": 10 + }, + "tc": "ping", + "task_id": "ea958583-c91e-461a-af14-2a7f9d7f79e7" + } + } + self.data2 = { + "benchmark": { + "timestamp": "1451478117.883505", + "errors": "", + "data": { + "rtt": 0.613 + }, + "sequence": 1 + }, + "runner_id": 8921 + } + + self.yardstick_conf = {'dispatcher_influxdb': {}} + + @mock.patch('yardstick.dispatcher.influxdb.requests') + def test_record_result_data(self, mock_requests): + type(mock_requests.post.return_value).status_code = 204 + influxdb = InfluxdbDispatcher(self.yardstick_conf) + data = { + 'status': 1, + 'result': { + 'criteria': 'PASS', + 'info': { + }, + 'task_id': 'b9e2bbc2-dfd8-410d-8c24-07771e9f7979', + 'testcases': { + } + } + } + self.assertEqual(influxdb.flush_result_data(data), 0) + + def test__get_nano_timestamp(self): + influxdb = InfluxdbDispatcher(self.yardstick_conf) + results = {'timestamp': '1451461248.925574'} + self.assertEqual(influxdb._get_nano_timestamp(results), + '1451461248925574144') + + @mock.patch('yardstick.dispatcher.influxdb.time') + def test__get_nano_timestamp_except(self, mock_time): + results = {} + influxdb = InfluxdbDispatcher(self.yardstick_conf) + mock_time.time.return_value = 1451461248.925574 + self.assertEqual(influxdb._get_nano_timestamp(results), + '1451461248925574144') + + +def main(): + unittest.main() + + +if __name__ == '__main__': + main() diff --git a/yardstick/tests/unit/dispatcher/test_influxdb_line_protocol.py b/yardstick/tests/unit/dispatcher/test_influxdb_line_protocol.py new file mode 100644 index 000000000..641e97fae --- /dev/null +++ b/yardstick/tests/unit/dispatcher/test_influxdb_line_protocol.py @@ -0,0 +1,63 @@ +############################################################################## +# Copyright (c) 2017 Huawei Technologies Co.,Ltd and others. +# +# All rights reserved. This program and the accompanying materials +# are made available under the terms of the Apache License, Version 2.0 +# which accompanies this distribution, and is available at +# http://www.apache.org/licenses/LICENSE-2.0 +############################################################################## +# Unittest for yardstick.dispatcher.influxdb_line_protocol + +# yardstick comment: this file is a modified copy of +# influxdb-python/influxdb/tests/test_line_protocol.py + +import unittest +from third_party.influxdb.influxdb_line_protocol import make_lines + + +class TestLineProtocol(unittest.TestCase): + + def test_make_lines(self): + data = { + "tags": { + "empty_tag": "", + "none_tag": None, + "integer_tag": 2, + "string_tag": "hello" + }, + "points": [ + { + "measurement": "test", + "fields": { + "string_val": "hello!", + "int_val": 1, + "float_val": 1.1, + "none_field": None, + "bool_val": True, + } + } + ] + } + + self.assertEqual( + make_lines(data), + 'test,integer_tag=2,string_tag=hello ' + 'bool_val=True,float_val=1.1,int_val=1i,string_val="hello!"\n' + ) + + def test_string_val_newline(self): + data = { + "points": [ + { + "measurement": "m1", + "fields": { + "multi_line": "line1\nline1\nline3" + } + } + ] + } + + self.assertEqual( + make_lines(data), + 'm1 multi_line="line1\\nline1\\nline3"\n' + ) -- cgit 1.2.3-korg