aboutsummaryrefslogtreecommitdiffstats
path: root/yardstick/orchestrator
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/orchestrator
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/orchestrator')
-rw-r--r--yardstick/orchestrator/heat.py42
1 files changed, 24 insertions, 18 deletions
diff --git a/yardstick/orchestrator/heat.py b/yardstick/orchestrator/heat.py
index e32d360e4..7e0f360c4 100644
--- a/yardstick/orchestrator/heat.py
+++ b/yardstick/orchestrator/heat.py
@@ -9,20 +9,23 @@
"""Heat template and stack management"""
-import time
+from __future__ import absolute_import
+from __future__ import print_function
+
+import collections
import datetime
import getpass
-import socket
import logging
-import json
+import socket
+import time
-from oslo_utils import encodeutils
import heatclient
import pkg_resources
+from oslo_serialization import jsonutils
+from oslo_utils import encodeutils
-from yardstick.common import template_format
import yardstick.common.openstack_utils as op_utils
-
+from yardstick.common import template_format
log = logging.getLogger(__name__)
@@ -36,6 +39,7 @@ def get_short_key_uuid(uuid):
class HeatObject(object):
''' base class for template and stack'''
+
def __init__(self):
self._heat_client = None
self.uuid = None
@@ -119,7 +123,7 @@ class HeatStack(HeatObject):
self._delete()
break
except RuntimeError as err:
- log.warn(err.args)
+ log.warning(err.args)
time.sleep(2)
i += 1
@@ -173,7 +177,7 @@ class HeatTemplate(HeatObject):
if template_file:
with open(template_file) as stream:
- print "Parsing external template:", template_file
+ print("Parsing external template:", template_file)
template_str = stream.read()
self._template = template_format.parse(template_str)
self._parameters = heat_parameters
@@ -312,6 +316,7 @@ class HeatTemplate(HeatObject):
'type': 'OS::Nova::KeyPair',
'properties': {
'name': name,
+ # resource_string returns bytes, so we must decode to unicode
'public_key': encodeutils.safe_decode(
pkg_resources.resource_string(
'yardstick.resources',
@@ -402,7 +407,7 @@ class HeatTemplate(HeatObject):
)
if networks:
- for i in range(len(networks)):
+ for i, _ in enumerate(networks):
server_properties['networks'].append({'network': networks[i]})
if scheduler_hints:
@@ -412,11 +417,11 @@ class HeatTemplate(HeatObject):
server_properties['user_data'] = user_data
if metadata:
- assert type(metadata) is dict
+ assert isinstance(metadata, collections.Mapping)
server_properties['metadata'] = metadata
if additional_properties:
- assert type(additional_properties) is dict
+ assert isinstance(additional_properties, collections.Mapping)
for prop in additional_properties:
server_properties[prop] = additional_properties[prop]
@@ -438,13 +443,15 @@ class HeatTemplate(HeatObject):
stack = HeatStack(self.name)
heat = self._get_heat_client()
- json_template = json.dumps(self._template)
+ json_template = jsonutils.dump_as_bytes(
+ self._template)
start_time = time.time()
stack.uuid = self.uuid = heat.stacks.create(
stack_name=self.name, template=json_template,
parameters=self.heat_parameters)['stack']['id']
status = self.status()
+ outputs = []
if block:
while status != u'CREATE_COMPLETE':
@@ -458,13 +465,12 @@ class HeatTemplate(HeatObject):
end_time = time.time()
outputs = getattr(heat.stacks.get(self.uuid), 'outputs')
+ log.info("Created stack '%s' in %d secs",
+ self.name, end_time - start_time)
- for output in outputs:
- self.outputs[output["output_key"].encode("ascii")] = \
- output["output_value"].encode("ascii")
-
- log.info("Created stack '%s' in %d secs",
- self.name, end_time - start_time)
+ # keep outputs as unicode
+ self.outputs = {output["output_key"]: output["output_value"] for output
+ in outputs}
stack.outputs = self.outputs
return stack