From 3da14256ac20dfee3b8fe10052036e2ec36fe4e5 Mon Sep 17 00:00:00 2001 From: Ravi Shekhar Jethani Date: Wed, 20 Jan 2016 23:23:49 -0800 Subject: [PATCH] Python3: Add support for raise and urlparse Replaced raise exc_type, exc_value, exc_tb with six.reraise(exc_type, exc_value, exc_tb) Replaced urlparse to use from six.moves.urllib2.urlparse.urlparse Blueprint murano-python-3-support Change-Id: I293337889f15afbcb1f95ea37c80d5c8e88d037e --- murano/dsl/helpers.py | 2 +- murano/dsl/typespec.py | 6 ++++-- murano/engine/package_loader.py | 7 ++++--- murano/engine/system/agent.py | 4 ++-- 4 files changed, 11 insertions(+), 8 deletions(-) diff --git a/murano/dsl/helpers.py b/murano/dsl/helpers.py index 0adaebb7..07c5901a 100644 --- a/murano/dsl/helpers.py +++ b/murano/dsl/helpers.py @@ -125,7 +125,7 @@ def parallel_select(collection, func, limit=1000): except StopIteration: return map(lambda t: t[0], result) else: - raise exception[0], None, exception[2] + six.reraise(exception[0], None, exception[2]) def enum(**enums): diff --git a/murano/dsl/typespec.py b/murano/dsl/typespec.py index a193dda4..034bfd7b 100644 --- a/murano/dsl/typespec.py +++ b/murano/dsl/typespec.py @@ -76,7 +76,8 @@ class PropertySpec(Spec): except exceptions.ContractViolationException as e: msg = u'[{0}.{1}{2}] {3}'.format( self.class_name, self.property_name, e.path, six.text_type(e)) - raise exceptions.ContractViolationException, msg, sys.exc_info()[2] + six.reraise(exceptions.ContractViolationException, + msg, sys.exc_info()[2]) class ArgumentSpec(Spec): @@ -93,4 +94,5 @@ class ArgumentSpec(Spec): msg = u'[{0}::{1}({2}{3})] {4}'.format( self.class_name, self.method_name, self.arg_name, e.path, six.text_type(e)) - raise exceptions.ContractViolationException, msg, sys.exc_info()[2] + six.reraise(exceptions.ContractViolationException, + msg, sys.exc_info()[2]) diff --git a/murano/engine/package_loader.py b/murano/engine/package_loader.py index 0da2effa..763eb562 100644 --- a/murano/engine/package_loader.py +++ b/murano/engine/package_loader.py @@ -82,7 +82,8 @@ class ApiPackageLoader(package_loader.MuranoPackageLoader): package_definition = self._get_definition(filter_opts) except LookupError: exc_info = sys.exc_info() - raise exceptions.NoPackageFound(package_name), None, exc_info[2] + six.reraise(exceptions.NoPackageFound(package_name), + None, exc_info[2]) return self._to_dsl_package( self._get_package_by_definition(package_definition)) @@ -156,7 +157,7 @@ class ApiPackageLoader(package_loader.MuranoPackageLoader): package_id, str(e) ) exc_info = sys.exc_info() - raise pkg_exc.PackageLoadError(msg), None, exc_info[2] + six.reraise(pkg_exc.PackageLoadError(msg), None, exc_info[2]) package_file = None try: with tempfile.NamedTemporaryFile(delete=False) as package_file: @@ -170,7 +171,7 @@ class ApiPackageLoader(package_loader.MuranoPackageLoader): except IOError: msg = 'Unable to extract package data for %s' % package_id exc_info = sys.exc_info() - raise pkg_exc.PackageLoadError(msg), None, exc_info[2] + six.reraise(pkg_exc.PackageLoadError(msg), None, exc_info[2]) finally: try: if package_file: diff --git a/murano/engine/system/agent.py b/murano/engine/system/agent.py index b7354f80..860966c0 100644 --- a/murano/engine/system/agent.py +++ b/murano/engine/system/agent.py @@ -16,12 +16,12 @@ import copy import datetime import os -import urlparse import uuid import eventlet.event from oslo_config import cfg from oslo_log import log as logging +from six.moves import urllib from yaql import specs import murano.common.exceptions as exceptions @@ -258,7 +258,7 @@ class Agent(object): def _is_url(self, file): file = self._get_url(file) - parts = urlparse.urlsplit(file) + parts = urllib.parse.urlsplit(file) if not parts.scheme or not parts.netloc: return False else: