summaryrefslogtreecommitdiffstats
path: root/tests/unit/benchmark/contexts
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/benchmark/contexts
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/benchmark/contexts')
-rw-r--r--tests/unit/benchmark/contexts/test_dummy.py1
-rw-r--r--tests/unit/benchmark/contexts/test_heat.py25
-rw-r--r--tests/unit/benchmark/contexts/test_model.py5
-rw-r--r--tests/unit/benchmark/contexts/test_node.py2
4 files changed, 24 insertions, 9 deletions
diff --git a/tests/unit/benchmark/contexts/test_dummy.py b/tests/unit/benchmark/contexts/test_dummy.py
index 5214e6630..1a54035df 100644
--- a/tests/unit/benchmark/contexts/test_dummy.py
+++ b/tests/unit/benchmark/contexts/test_dummy.py
@@ -11,6 +11,7 @@
# Unittest for yardstick.benchmark.contexts.dummy
+from __future__ import absolute_import
import unittest
from yardstick.benchmark.contexts import dummy
diff --git a/tests/unit/benchmark/contexts/test_heat.py b/tests/unit/benchmark/contexts/test_heat.py
index dd830a485..f8f349205 100644
--- a/tests/unit/benchmark/contexts/test_heat.py
+++ b/tests/unit/benchmark/contexts/test_heat.py
@@ -11,14 +11,21 @@
# Unittest for yardstick.benchmark.contexts.heat
+from __future__ import absolute_import
+
+import logging
import os
-import mock
import unittest
+import uuid
+
+import mock
-from yardstick.benchmark.contexts import model
from yardstick.benchmark.contexts import heat
+LOG = logging.getLogger(__name__)
+
+
class HeatContextTestCase(unittest.TestCase):
def setUp(self):
@@ -70,7 +77,8 @@ class HeatContextTestCase(unittest.TestCase):
'bar', self.test_context, networks['bar'])
self.assertTrue(len(self.test_context.networks) == 1)
- mock_server.assert_called_with('baz', self.test_context, servers['baz'])
+ mock_server.assert_called_with('baz', self.test_context,
+ servers['baz'])
self.assertTrue(len(self.test_context.servers) == 1)
if os.path.exists(self.test_context.key_filename):
@@ -78,7 +86,8 @@ class HeatContextTestCase(unittest.TestCase):
os.remove(self.test_context.key_filename)
os.remove(self.test_context.key_filename + ".pub")
except OSError:
- LOG.exception("key_filename: %s", e.key_filename)
+ LOG.exception("key_filename: %s",
+ self.test_context.key_filename)
@mock.patch('yardstick.benchmark.contexts.heat.HeatTemplate')
def test__add_resources_to_template_no_servers(self, mock_template):
@@ -88,8 +97,9 @@ class HeatContextTestCase(unittest.TestCase):
self.test_context.key_uuid = "2f2e4997-0a8e-4eb7-9fa4-f3f8fbbc393b"
self.test_context._add_resources_to_template(mock_template)
- mock_template.add_keypair.assert_called_with("foo-key",
- "2f2e4997-0a8e-4eb7-9fa4-f3f8fbbc393b")
+ mock_template.add_keypair.assert_called_with(
+ "foo-key",
+ "2f2e4997-0a8e-4eb7-9fa4-f3f8fbbc393b")
mock_template.add_security_group.assert_called_with("foo-secgroup")
@mock.patch('yardstick.benchmark.contexts.heat.HeatTemplate')
@@ -113,12 +123,13 @@ class HeatContextTestCase(unittest.TestCase):
self.assertTrue(mock_template.delete.called)
-
def test__get_server(self):
self.mock_context.name = 'bar'
self.mock_context.stack.outputs = {'public_ip': '127.0.0.1',
'private_ip': '10.0.0.1'}
+ self.mock_context.key_uuid = uuid.uuid4()
+
attr_name = {'name': 'foo.bar',
'public_ip_attr': 'public_ip',
'private_ip_attr': 'private_ip'}
diff --git a/tests/unit/benchmark/contexts/test_model.py b/tests/unit/benchmark/contexts/test_model.py
index a1978e320..537a8c008 100644
--- a/tests/unit/benchmark/contexts/test_model.py
+++ b/tests/unit/benchmark/contexts/test_model.py
@@ -11,6 +11,7 @@
# Unittest for yardstick.benchmark.contexts.model
+from __future__ import absolute_import
import mock
import unittest
@@ -119,7 +120,8 @@ class NetworkTestCase(unittest.TestCase):
attrs = {'external_network': 'ext_net'}
test_network = model.Network('foo', self.mock_context, attrs)
- exp_router = model.Router('router', 'foo', self.mock_context, 'ext_net')
+ exp_router = model.Router('router', 'foo', self.mock_context,
+ 'ext_net')
self.assertEqual(test_network.router.stack_name, exp_router.stack_name)
self.assertEqual(test_network.router.stack_if_name,
@@ -219,4 +221,3 @@ class ServerTestCase(unittest.TestCase):
user=self.mock_context.user,
key_name=self.mock_context.keypair_name,
scheduler_hints='hints')
-
diff --git a/tests/unit/benchmark/contexts/test_node.py b/tests/unit/benchmark/contexts/test_node.py
index 6939b8551..de5ba7066 100644
--- a/tests/unit/benchmark/contexts/test_node.py
+++ b/tests/unit/benchmark/contexts/test_node.py
@@ -11,6 +11,7 @@
# Unittest for yardstick.benchmark.contexts.node
+from __future__ import absolute_import
import os
import unittest
@@ -21,6 +22,7 @@ class NodeContextTestCase(unittest.TestCase):
NODES_SAMPLE = "nodes_sample.yaml"
NODES_DUPLICATE_SAMPLE = "nodes_duplicate_sample.yaml"
+
def setUp(self):
self.test_context = node.NodeContext()