aboutsummaryrefslogtreecommitdiffstats
path: root/yardstick/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 /yardstick/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 'yardstick/benchmark/contexts')
-rw-r--r--yardstick/benchmark/contexts/base.py1
-rw-r--r--yardstick/benchmark/contexts/dummy.py1
-rw-r--r--yardstick/benchmark/contexts/heat.py30
-rw-r--r--yardstick/benchmark/contexts/model.py4
-rw-r--r--yardstick/benchmark/contexts/node.py7
5 files changed, 29 insertions, 14 deletions
diff --git a/yardstick/benchmark/contexts/base.py b/yardstick/benchmark/contexts/base.py
index 76a828811..054ce4236 100644
--- a/yardstick/benchmark/contexts/base.py
+++ b/yardstick/benchmark/contexts/base.py
@@ -6,6 +6,7 @@
# which accompanies this distribution, and is available at
# http://www.apache.org/licenses/LICENSE-2.0
##############################################################################
+from __future__ import absolute_import
import abc
import six
diff --git a/yardstick/benchmark/contexts/dummy.py b/yardstick/benchmark/contexts/dummy.py
index 6901b2617..0e76b5a82 100644
--- a/yardstick/benchmark/contexts/dummy.py
+++ b/yardstick/benchmark/contexts/dummy.py
@@ -7,6 +7,7 @@
# http://www.apache.org/licenses/LICENSE-2.0
##############################################################################
+from __future__ import absolute_import
import logging
from yardstick.benchmark.contexts.base import Context
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
diff --git a/yardstick/benchmark/contexts/model.py b/yardstick/benchmark/contexts/model.py
index d31f4afc0..1d0a5a133 100644
--- a/yardstick/benchmark/contexts/model.py
+++ b/yardstick/benchmark/contexts/model.py
@@ -10,12 +10,15 @@
""" Logical model
"""
+from __future__ import absolute_import
+from six.moves import range
class Object(object):
'''Base class for classes in the logical model
Contains common attributes and methods
'''
+
def __init__(self, name, context):
# model identities and reference
self.name = name
@@ -61,6 +64,7 @@ class PlacementGroup(Object):
class Router(Object):
'''Class that represents a router in the logical model'''
+
def __init__(self, name, network_name, context, external_gateway_info):
super(self.__class__, self).__init__(name, context)
diff --git a/yardstick/benchmark/contexts/node.py b/yardstick/benchmark/contexts/node.py
index 78bce8259..6db51cccb 100644
--- a/yardstick/benchmark/contexts/node.py
+++ b/yardstick/benchmark/contexts/node.py
@@ -7,6 +7,7 @@
# http://www.apache.org/licenses/LICENSE-2.0
##############################################################################
+from __future__ import absolute_import
import sys
import os
import yaml
@@ -49,11 +50,11 @@ class NodeContext(Context):
self.nodes.extend(cfg["nodes"])
self.controllers.extend([node for node in cfg["nodes"]
- if node["role"] == "Controller"])
+ if node["role"] == "Controller"])
self.computes.extend([node for node in cfg["nodes"]
- if node["role"] == "Compute"])
+ if node["role"] == "Compute"])
self.baremetals.extend([node for node in cfg["nodes"]
- if node["role"] == "Baremetal"])
+ if node["role"] == "Baremetal"])
LOG.debug("Nodes: %r", self.nodes)
LOG.debug("Controllers: %r", self.controllers)
LOG.debug("Computes: %r", self.computes)