summaryrefslogtreecommitdiffstats
path: root/tests/unit/dispatcher
diff options
context:
space:
mode:
authorRoss Brattain <ross.b.brattain@intel.com>2016-12-05 16:11:54 -0500
committerRoss Brattain <ross.b.brattain@intel.com>2017-01-12 18:25:04 -0800
commitf036e9898a69f5041f9cde02e3652c29e2de1643 (patch)
tree36e5eea75811bb640bb30f442f5a3c617e945909 /tests/unit/dispatcher
parent5f0b3d417244397b2d5e61c7a6ddd145f1d25046 (diff)
Add support for Python 3
Porting to Python3 using Openstack guidelines: https://wiki.openstack.org/wiki/Python3 This passes unittests on Python 3.5 and passes opnfv_smoke suite Updates: use six for urlparse and urlopen fix exception.message attribute removal run unittests on python3 use unitest.mock on python 3 fix open mock for vsperf fix float division by using delta/eplison comparison use unicode in StringIO use plugin/sample_config.yaml relative path from test case fixed apexlake unittests upgraded to mock 2.0.0 to match python3 unittest.mock features fixed flake8 issues implement safe JSON decode with oslo_serialization.jsonutils.dump_as_bytes() implement safe unicode encode/decode with oslo_utils.encodeutils heat: convert pub key file from bytes to unicode pkg_resources returns raw bytes, in python3 we have to decode this to utf-8 unicode so JSON can encode it for heat template JIRA: YARDSTICK-452 Change-Id: Ib80dd1d0c0eb0592acd832b82f6a7f8f7c20bfda Signed-off-by: Ross Brattain <ross.b.brattain@intel.com>
Diffstat (limited to 'tests/unit/dispatcher')
-rw-r--r--tests/unit/dispatcher/test_influxdb.py36
-rw-r--r--tests/unit/dispatcher/test_influxdb_line_protocol.py1
2 files changed, 28 insertions, 9 deletions
diff --git a/tests/unit/dispatcher/test_influxdb.py b/tests/unit/dispatcher/test_influxdb.py
index 5553c86a9..b84389e7e 100644
--- a/tests/unit/dispatcher/test_influxdb.py
+++ b/tests/unit/dispatcher/test_influxdb.py
@@ -11,11 +11,17 @@
# Unittest for yardstick.dispatcher.influxdb
-import mock
+from __future__ import absolute_import
import unittest
+try:
+ from unittest import mock
+except ImportError:
+ import mock
+
from yardstick.dispatcher.influxdb import InfluxdbDispatcher
+
class InfluxdbDispatcherTestCase(unittest.TestCase):
def setUp(self):
@@ -24,7 +30,9 @@ class InfluxdbDispatcherTestCase(unittest.TestCase):
"context_cfg": {
"host": {
"ip": "10.229.43.154",
- "key_filename": "/root/yardstick/yardstick/resources/files/yardstick_key",
+ "key_filename":
+ "/root/yardstick/yardstick/resources/files"
+ "/yardstick_key",
"name": "kvm.LF",
"user": "root"
},
@@ -35,7 +43,8 @@ class InfluxdbDispatcherTestCase(unittest.TestCase):
"scenario_cfg": {
"runner": {
"interval": 1,
- "object": "yardstick.benchmark.scenarios.networking.ping.Ping",
+ "object": "yardstick.benchmark.scenarios.networking.ping"
+ ".Ping",
"output_filename": "/tmp/yardstick.out",
"runner_id": 8921,
"duration": 10,
@@ -63,7 +72,7 @@ class InfluxdbDispatcherTestCase(unittest.TestCase):
},
"runner_id": 8921
}
- self.data3 ={
+ self.data3 = {
"benchmark": {
"data": {
"mpstat": {
@@ -99,26 +108,35 @@ class InfluxdbDispatcherTestCase(unittest.TestCase):
self.assertEqual(influxdb.flush_result_data(), 0)
def test__dict_key_flatten(self):
- line = 'mpstat.loadavg1=0.29,rtt=1.03,mpstat.loadavg0=1.09,mpstat.cpu0.%idle=99.00,mpstat.cpu0.%sys=0.00'
+ line = 'mpstat.loadavg1=0.29,rtt=1.03,mpstat.loadavg0=1.09,' \
+ 'mpstat.cpu0.%idle=99.00,mpstat.cpu0.%sys=0.00'
+ # need to sort for assert to work
+ line = ",".join(sorted(line.split(',')))
influxdb = InfluxdbDispatcher(None)
- flattened_data = influxdb._dict_key_flatten(self.data3['benchmark']['data'])
- result = ",".join([k+"="+v for k, v in flattened_data.items()])
+ flattened_data = influxdb._dict_key_flatten(
+ self.data3['benchmark']['data'])
+ result = ",".join(
+ [k + "=" + v for k, v in sorted(flattened_data.items())])
self.assertEqual(result, line)
def test__get_nano_timestamp(self):
influxdb = InfluxdbDispatcher(None)
results = {'benchmark': {'timestamp': '1451461248.925574'}}
- self.assertEqual(influxdb._get_nano_timestamp(results), '1451461248925574144')
+ 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(None)
mock_time.time.return_value = 1451461248.925574
- self.assertEqual(influxdb._get_nano_timestamp(results), '1451461248925574144')
+ 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
index 42553c498..debb1994a 100644
--- a/tests/unit/dispatcher/test_influxdb_line_protocol.py
+++ b/tests/unit/dispatcher/test_influxdb_line_protocol.py
@@ -3,6 +3,7 @@
# 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