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 --- yardstick/benchmark/contexts/heat.py | 30 +++++++++++++++++++----------- 1 file changed, 19 insertions(+), 11 deletions(-) (limited to 'yardstick/benchmark/contexts/heat.py') diff --git a/yardstick/benchmark/contexts/heat.py b/yardstick/benchmark/contexts/heat.py index 29c47b39a..0b2fbdcd6 100644 --- a/yardstick/benchmark/contexts/heat.py +++ b/yardstick/benchmark/contexts/heat.py @@ -7,20 +7,28 @@ # http://www.apache.org/licenses/LICENSE-2.0 ############################################################################## +from __future__ import absolute_import +from __future__ import print_function + +import collections +import logging import os import sys import uuid -import pkg_resources + import paramiko +import pkg_resources from yardstick.benchmark.contexts.base import Context -from yardstick.benchmark.contexts.model import Server -from yardstick.benchmark.contexts.model import PlacementGroup from yardstick.benchmark.contexts.model import Network +from yardstick.benchmark.contexts.model import PlacementGroup +from yardstick.benchmark.contexts.model import Server from yardstick.benchmark.contexts.model import update_scheduler_hints from yardstick.orchestrator.heat import HeatTemplate, get_short_key_uuid from yardstick.definitions import YARDSTICK_ROOT_PATH +LOG = logging.getLogger(__name__) + class HeatContext(Context): '''Class that represents a context in the logical model''' @@ -193,7 +201,7 @@ class HeatContext(Context): def deploy(self): '''deploys template into a stack using cloud''' - print "Deploying context '%s'" % self.name + print("Deploying context '%s'" % self.name) heat_template = HeatTemplate(self.name, self.template_file, self.heat_parameters) @@ -214,29 +222,29 @@ class HeatContext(Context): for server in self.servers: if len(server.ports) > 0: # TODO(hafe) can only handle one internal network for now - port = server.ports.values()[0] + port = list(server.ports.values())[0] server.private_ip = self.stack.outputs[port["stack_name"]] if server.floating_ip: server.public_ip = \ self.stack.outputs[server.floating_ip["stack_name"]] - print "Context '%s' deployed" % self.name + print("Context '%s' deployed" % self.name) def undeploy(self): '''undeploys stack from cloud''' if self.stack: - print "Undeploying context '%s'" % self.name + print("Undeploying context '%s'" % self.name) self.stack.delete() self.stack = None - print "Context '%s' undeployed" % self.name + print("Context '%s' undeployed" % self.name) if os.path.exists(self.key_filename): try: os.remove(self.key_filename) os.remove(self.key_filename + ".pub") - except OSError, e: - print ("Error: %s - %s." % (e.key_filename, e.strerror)) + except OSError: + LOG.exception("Key filename %s", self.key_filename) def _get_server(self, attr_name): '''lookup server info by name from context @@ -247,7 +255,7 @@ class HeatContext(Context): 'yardstick.resources', 'files/yardstick_key-' + get_short_key_uuid(self.key_uuid)) - if type(attr_name) is dict: + if isinstance(attr_name, collections.Mapping): cname = attr_name["name"].split(".")[1] if cname != self.name: return None -- cgit 1.2.3-korg