From f036e9898a69f5041f9cde02e3652c29e2de1643 Mon Sep 17 00:00:00 2001 From: Ross Brattain Date: Mon, 5 Dec 2016 16:11:54 -0500 Subject: 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 --- .../scenarios/storage/test_storagecapacity.py | 44 +++++++++++++--------- 1 file changed, 27 insertions(+), 17 deletions(-) (limited to 'tests/unit/benchmark/scenarios/storage/test_storagecapacity.py') diff --git a/tests/unit/benchmark/scenarios/storage/test_storagecapacity.py b/tests/unit/benchmark/scenarios/storage/test_storagecapacity.py index ace0ca374..6fb5f5686 100644 --- a/tests/unit/benchmark/scenarios/storage/test_storagecapacity.py +++ b/tests/unit/benchmark/scenarios/storage/test_storagecapacity.py @@ -9,35 +9,41 @@ # http://www.apache.org/licenses/LICENSE-2.0 ############################################################################## -# Unittest for yardstick.benchmark.scenarios.storage.storagecapacity.StorageCapacity +# Unittest for +# yardstick.benchmark.scenarios.storage.storagecapacity.StorageCapacity + +from __future__ import absolute_import -import mock import unittest -import os -import json + +import mock +from oslo_serialization import jsonutils from yardstick.benchmark.scenarios.storage import storagecapacity -DISK_SIZE_SAMPLE_OUTPUT = '{"Numberf of devides": "2", "Total disk size in bytes": "1024000000"}' +DISK_SIZE_SAMPLE_OUTPUT = \ + '{"Numberf of devides": "2", "Total disk size in bytes": "1024000000"}' BLOCK_SIZE_SAMPLE_OUTPUT = '{"/dev/sda": 1024, "/dev/sdb": 4096}' DISK_UTIL_RAW_OUTPUT = "vda 10.00\nvda 0.00" -DISK_UTIL_SAMPLE_OUTPUT = '{"vda": {"avg_util": 5.0, "max_util": 10.0, "min_util": 0.0}}' +DISK_UTIL_SAMPLE_OUTPUT = \ + '{"vda": {"avg_util": 5.0, "max_util": 10.0, "min_util": 0.0}}' + @mock.patch('yardstick.benchmark.scenarios.storage.storagecapacity.ssh') class StorageCapacityTestCase(unittest.TestCase): def setUp(self): self.scn = { - "options": { - 'test_type': 'disk_size' - } + "options": { + 'test_type': 'disk_size' + } } self.ctx = { - "host": { - 'ip': '172.16.0.137', - 'user': 'cirros', - 'password': "root" - } + "host": { + 'ip': '172.16.0.137', + 'user': 'cirros', + 'password': "root" + } } self.result = {} @@ -54,7 +60,8 @@ class StorageCapacityTestCase(unittest.TestCase): mock_ssh.SSH().execute.return_value = (0, DISK_SIZE_SAMPLE_OUTPUT, '') c.run(self.result) - expected_result = json.loads(DISK_SIZE_SAMPLE_OUTPUT) + expected_result = jsonutils.loads( + DISK_SIZE_SAMPLE_OUTPUT) self.assertEqual(self.result, expected_result) def test_capacity_block_size_successful(self, mock_ssh): @@ -67,7 +74,8 @@ class StorageCapacityTestCase(unittest.TestCase): mock_ssh.SSH().execute.return_value = (0, BLOCK_SIZE_SAMPLE_OUTPUT, '') c.run(self.result) - expected_result = json.loads(BLOCK_SIZE_SAMPLE_OUTPUT) + expected_result = jsonutils.loads( + BLOCK_SIZE_SAMPLE_OUTPUT) self.assertEqual(self.result, expected_result) def test_capacity_disk_utilization_successful(self, mock_ssh): @@ -82,7 +90,8 @@ class StorageCapacityTestCase(unittest.TestCase): mock_ssh.SSH().execute.return_value = (0, DISK_UTIL_RAW_OUTPUT, '') c.run(self.result) - expected_result = json.loads(DISK_UTIL_SAMPLE_OUTPUT) + expected_result = jsonutils.loads( + DISK_UTIL_SAMPLE_OUTPUT) self.assertEqual(self.result, expected_result) def test_capacity_unsuccessful_script_error(self, mock_ssh): @@ -91,6 +100,7 @@ class StorageCapacityTestCase(unittest.TestCase): mock_ssh.SSH().execute.return_value = (1, '', 'FOOBAR') self.assertRaises(RuntimeError, c.run, self.result) + def main(): unittest.main() -- cgit 1.2.3-korg