aboutsummaryrefslogtreecommitdiffstats
path: root/yardstick/benchmark/scenarios/compute/cpuload.py
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 /yardstick/benchmark/scenarios/compute/cpuload.py
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 'yardstick/benchmark/scenarios/compute/cpuload.py')
-rw-r--r--yardstick/benchmark/scenarios/compute/cpuload.py23
1 files changed, 13 insertions, 10 deletions
diff --git a/yardstick/benchmark/scenarios/compute/cpuload.py b/yardstick/benchmark/scenarios/compute/cpuload.py
index 9d71038ef..121d5a75d 100644
--- a/yardstick/benchmark/scenarios/compute/cpuload.py
+++ b/yardstick/benchmark/scenarios/compute/cpuload.py
@@ -9,13 +9,16 @@
"""Processor statistics and system load."""
+from __future__ import absolute_import
+
import logging
-import time
import re
-import yardstick.ssh as ssh
+import time
-from yardstick.benchmark.scenarios import base
+from six.moves import map, zip
+import yardstick.ssh as ssh
+from yardstick.benchmark.scenarios import base
LOG = logging.getLogger(__name__)
@@ -145,7 +148,7 @@ class CPULoad(base.Scenario):
cpu = 'cpu' if line[0] == 'all' else 'cpu' + line[0]
values = line[1:]
if values and len(values) == len(fields):
- temp_dict = dict(zip(fields, values))
+ temp_dict = dict(list(zip(fields, values)))
if cpu not in maximum:
maximum[cpu] = temp_dict
else:
@@ -177,7 +180,7 @@ class CPULoad(base.Scenario):
cpu = 'cpu' if line[0] == 'all' else 'cpu' + line[0]
values = line[1:]
if values and len(values) == len(fields):
- average[cpu] = dict(zip(fields, values))
+ average[cpu] = dict(list(zip(fields, values)))
else:
raise RuntimeError("mpstat average: parse error",
fields, line)
@@ -210,9 +213,9 @@ class CPULoad(base.Scenario):
cpu = cur_list[0]
- cur_stats = map(int, cur_list[1:])
+ cur_stats = list(map(int, cur_list[1:]))
if self.interval > 0:
- prev_stats = map(int, prev_list[1:])
+ prev_stats = list(map(int, prev_list[1:]))
else:
prev_stats = [0] * len(cur_stats)
@@ -236,9 +239,9 @@ class CPULoad(base.Scenario):
else:
return "%.2f" % (100.0 * (x - y) / samples)
- load = map(_percent, cur_stats, prev_stats)
+ load = list(map(_percent, cur_stats, prev_stats))
- mpstat[cpu] = dict(zip(fields, load))
+ mpstat[cpu] = dict(list(zip(fields, load)))
return {'mpstat': mpstat}
@@ -278,7 +281,7 @@ class CPULoad(base.Scenario):
# p = CPULoad(args, ctx)
# p.run(result)
# import json
-# print json.dumps(result)
+# print(oslo_serialization.jsonutils.dump_as_bytes(result))
# if __name__ == '__main__':
# _test()