Fix exception re-raise during task execution for py34
This is the code fragment from six (executed when the interpreter is python 3): def reraise(tp, value, tb=None): if value is None: value = tp() if value.__traceback__ is not tb: raise value.with_traceback(tb) raise value We want `raise value` or `raise value.with_traceback(tb)` to be executed as we are invoking six.reraise with a class instance. Change-Id: Ic0c7e14cecb1cbdcb8cae87047e20514c4d38301
This commit is contained in:
parent
77a5f1f756
commit
4d80851fae
|
@ -66,7 +66,8 @@ class Task(object):
|
|||
def wait(self):
|
||||
self._finished.wait()
|
||||
if self._exception:
|
||||
six.reraise(self._exception, None, self._traceback)
|
||||
six.reraise(type(self._exception), self._exception,
|
||||
self._traceback)
|
||||
return self._result
|
||||
|
||||
def run(self, client):
|
||||
|
|
|
@ -0,0 +1,42 @@
|
|||
# Copyright (c) 2015 Hewlett-Packard Development Company, L.P.
|
||||
#
|
||||
# Licensed under the Apache License, Version 2.0 (the "License");
|
||||
# you may not use this file except in compliance with the License.
|
||||
# You may obtain a copy of the License at
|
||||
#
|
||||
# http://www.apache.org/licenses/LICENSE-2.0
|
||||
#
|
||||
# Unless required by applicable law or agreed to in writing, software
|
||||
# distributed under the License is distributed on an "AS IS" BASIS,
|
||||
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
# See the License for the specific language governing permissions and
|
||||
# limitations under the License.
|
||||
|
||||
|
||||
from shade import task_manager
|
||||
from shade.tests.unit import base
|
||||
|
||||
|
||||
class TestException(Exception):
|
||||
pass
|
||||
|
||||
|
||||
class TestTask(task_manager.Task):
|
||||
def main(self, client):
|
||||
raise TestException("This is a test exception")
|
||||
|
||||
|
||||
class TestTaskManager(base.TestCase):
|
||||
|
||||
def setUp(self):
|
||||
super(TestTaskManager, self).setUp()
|
||||
self.manager = task_manager.TaskManager(name='test', client=self)
|
||||
|
||||
def test_wait_re_raise(self):
|
||||
"""Test that Exceptions thrown in a Task is reraised correctly
|
||||
|
||||
This test is aimed to six.reraise(), called in Task::wait().
|
||||
Specifically, we test if we get the same behaviour with all the
|
||||
configured interpreters (e.g. py27, p34, pypy, ...)
|
||||
"""
|
||||
self.assertRaises(TestException, self.manager.submitTask, TestTask())
|
Loading…
Reference in New Issue