Don't copy exception classes
see: http://stackoverflow.com/questions/9541025/how-to-copy-a-python-class https://review.openstack.org/194487 This simplifies the method so it just re-raises local exceptions and if it is Remote, raises ResourceFailure. Closes-Bug: #1474153 Change-Id: I9c4dcadcbcf6abe6ff71dbcdccaae4706b684a83
This commit is contained in:
parent
e8c661f736
commit
716471f37c
@ -11,7 +11,6 @@
|
|||||||
# License for the specific language governing permissions and limitations
|
# License for the specific language governing permissions and limitations
|
||||||
# under the License.
|
# under the License.
|
||||||
|
|
||||||
import copy
|
|
||||||
import hashlib
|
import hashlib
|
||||||
import json
|
import json
|
||||||
|
|
||||||
@ -298,20 +297,6 @@ class StackResource(resource.Resource):
|
|||||||
self.resource_id_set(result['stack_id'])
|
self.resource_id_set(result['stack_id'])
|
||||||
|
|
||||||
def raise_local_exception(self, ex):
|
def raise_local_exception(self, ex):
|
||||||
ex_type = ex.__class__.__name__
|
|
||||||
|
|
||||||
is_remote = ex_type.endswith('_Remote')
|
|
||||||
if is_remote:
|
|
||||||
ex_type = ex_type[:-len('_Remote')]
|
|
||||||
|
|
||||||
full_message = six.text_type(ex)
|
|
||||||
if full_message.find('\n') > -1 and is_remote:
|
|
||||||
message, msg_trace = full_message.split('\n', 1)
|
|
||||||
elif isinstance(ex, exception.HeatException):
|
|
||||||
message = ex.message
|
|
||||||
else:
|
|
||||||
message = full_message
|
|
||||||
|
|
||||||
if (isinstance(ex, exception.ActionInProgress) and
|
if (isinstance(ex, exception.ActionInProgress) and
|
||||||
self.stack.action == self.stack.ROLLBACK):
|
self.stack.action == self.stack.ROLLBACK):
|
||||||
# The update was interrupted and the rollback is already in
|
# The update was interrupted and the rollback is already in
|
||||||
@ -319,12 +304,16 @@ class StackResource(resource.Resource):
|
|||||||
# finish
|
# finish
|
||||||
return
|
return
|
||||||
|
|
||||||
if hasattr(exception, ex_type):
|
if not ex.__class__.__name__.endswith('_Remote'):
|
||||||
local_ex = copy.copy(getattr(exception, ex_type))
|
raise ex
|
||||||
local_ex.msg_fmt = "%(message)s"
|
|
||||||
raise local_ex(message=message)
|
full_message = six.text_type(ex)
|
||||||
|
if full_message.find('\n') > -1:
|
||||||
|
message, msg_trace = full_message.split('\n', 1)
|
||||||
else:
|
else:
|
||||||
raise exception.ResourceFailure(ex, self, 'remote')
|
message = full_message
|
||||||
|
|
||||||
|
raise exception.ResourceFailure(message, self, action=self.action)
|
||||||
|
|
||||||
def check_create_complete(self, cookie=None):
|
def check_create_complete(self, cookie=None):
|
||||||
return self._check_status_complete(resource.Resource.CREATE)
|
return self._check_status_complete(resource.Resource.CREATE)
|
||||||
|
@ -868,11 +868,13 @@ class RaiseLocalException(StackResourceBaseTest):
|
|||||||
|
|
||||||
def test_messaging_timeout(self):
|
def test_messaging_timeout(self):
|
||||||
local = msg_exceptions.MessagingTimeout('took too long')
|
local = msg_exceptions.MessagingTimeout('took too long')
|
||||||
self.assertRaises(exception.ResourceFailure,
|
self.assertRaises(msg_exceptions.MessagingTimeout,
|
||||||
self.parent_resource.raise_local_exception, local)
|
self.parent_resource.raise_local_exception, local)
|
||||||
|
|
||||||
def test_remote_heat_ex(self):
|
def test_remote_heat_ex(self):
|
||||||
InvalidResourceType_Remote = exception.InvalidResourceType
|
class InvalidResourceType_Remote(exception.InvalidResourceType):
|
||||||
|
pass
|
||||||
|
|
||||||
local = InvalidResourceType_Remote(message='test')
|
local = InvalidResourceType_Remote(message='test')
|
||||||
self.assertRaises(exception.InvalidResourceType,
|
self.assertRaises(exception.ResourceFailure,
|
||||||
self.parent_resource.raise_local_exception, local)
|
self.parent_resource.raise_local_exception, local)
|
||||||
|
Loading…
Reference in New Issue
Block a user