diff --git a/zun/common/utils.py b/zun/common/utils.py index d67703263..05a24a0f7 100644 --- a/zun/common/utils.py +++ b/zun/common/utils.py @@ -755,3 +755,15 @@ def is_port_active(neutron_port): neutron client's 'show_port' """ return (neutron_port['status'] == n_const.PORT_STATUS_ACTIVE) + + +def reraise(tp, value, tb=None): + try: + if value is None: + value = tp() + if value.__traceback__ is not tb: + raise value.with_traceback(tb) + raise value + finally: + value = None + tb = None diff --git a/zun/container/docker/utils.py b/zun/container/docker/utils.py index f1832c92c..cac401fe7 100644 --- a/zun/container/docker/utils.py +++ b/zun/container/docker/utils.py @@ -11,7 +11,6 @@ # under the License. import contextlib -import six import sys import tarfile @@ -23,6 +22,7 @@ from oslo_utils import encodeutils from zun.common import consts from zun.common import exception from zun.common.i18n import _ +from zun.common import utils import zun.conf @@ -46,7 +46,7 @@ def docker_client(): ) except errors.APIError as e: desired_exc = exception.DockerError(error_msg=str(e)) - six.reraise(type(desired_exc), desired_exc, sys.exc_info()[2]) + utils.reraise(type(desired_exc), desired_exc, sys.exc_info()[2]) class DockerHTTPClient(docker.APIClient): diff --git a/zun/network/kuryr_network.py b/zun/network/kuryr_network.py index 85792b823..4f375d759 100644 --- a/zun/network/kuryr_network.py +++ b/zun/network/kuryr_network.py @@ -11,7 +11,6 @@ # under the License. import math -import six import sys import time @@ -22,6 +21,7 @@ from oslo_utils import excutils from zun.common import consts from zun.common import exception from zun.common.i18n import _ +from zun.common import utils import zun.conf from zun.network import network from zun.network import neutron @@ -317,7 +317,7 @@ class KuryrNetwork(network.Network): raise exception.SecurityGroupCannotBeApplied( str(e)) else: - six.reraise(*exc_info) + utils.reraise(*exc_info) except Exception: with excutils.save_and_reraise_exception(): LOG.exception("Neutron Error:") @@ -350,7 +350,7 @@ class KuryrNetwork(network.Network): raise exception.SecurityGroupCannotBeRemoved( str(e)) else: - six.reraise(*exc_info) + utils.reraise(*exc_info) except Exception: with excutils.save_and_reraise_exception(): LOG.exception("Neutron Error:")