Move Resource exceptions to common module (2)
It is convenient to have all exceptions in exception module. Also it is reduces namespace cluttering of resource module and decreases the number of dependencies in other modules (we do not need to import resource in some cases for now). ResourceUnknownStatus exception is moved in this patch. Change-Id: Iad44c16252f5171984859f0ddd05b821f5dfc7e7
This commit is contained in:
parent
4e2cfb991a
commit
68a73b513c
@ -395,6 +395,16 @@ class UpdateReplace(Exception):
|
||||
super(Exception, self).__init__(six.text_type(msg))
|
||||
|
||||
|
||||
class ResourceUnknownStatus(HeatException):
|
||||
msg_fmt = _('%(result)s - Unknown status %(resource_status)s due to '
|
||||
'"%(status_reason)s"')
|
||||
|
||||
def __init__(self, result=_('Resource failed'),
|
||||
status_reason=_('Unknown'), **kwargs):
|
||||
super(ResourceUnknownStatus, self).__init__(
|
||||
result=result, status_reason=status_reason, **kwargs)
|
||||
|
||||
|
||||
class HTTPExceptionDisguise(Exception):
|
||||
"""Disguises HTTP exceptions so they can be handled by the webob fault
|
||||
application in the wsgi pipeline.
|
||||
|
@ -22,7 +22,6 @@ from heat.common.i18n import _
|
||||
from heat.common.i18n import _LI
|
||||
from heat.engine.clients import client_plugin
|
||||
from heat.engine import constraints
|
||||
from heat.engine import resource
|
||||
|
||||
|
||||
LOG = logging.getLogger(__name__)
|
||||
@ -160,7 +159,7 @@ class CinderClientPlugin(client_plugin.ClientPlugin):
|
||||
LOG.debug("Detachment failed - volume %(vol)s "
|
||||
"is in %(status)s status" % {"vol": vol.id,
|
||||
"status": vol.status})
|
||||
raise resource.ResourceUnknownStatus(
|
||||
raise exception.ResourceUnknownStatus(
|
||||
resource_status=vol.status,
|
||||
result=_('Volume detachment failed'))
|
||||
else:
|
||||
@ -178,7 +177,7 @@ class CinderClientPlugin(client_plugin.ClientPlugin):
|
||||
LOG.debug("Attachment failed - volume %(vol)s is "
|
||||
"in %(status)s status" % {"vol": vol_id,
|
||||
"status": vol.status})
|
||||
raise resource.ResourceUnknownStatus(
|
||||
raise exception.ResourceUnknownStatus(
|
||||
resource_status=vol.status,
|
||||
result=_('Volume attachment failed'))
|
||||
|
||||
|
@ -222,7 +222,7 @@ class NovaClientPlugin(client_plugin.ClientPlugin):
|
||||
'code': fault.get('code', _('Unknown'))
|
||||
})
|
||||
else:
|
||||
raise resource.ResourceUnknownStatus(
|
||||
raise exception.ResourceUnknownStatus(
|
||||
resource_status=server.status,
|
||||
result=_('%s is not active') % res_name)
|
||||
|
||||
@ -451,8 +451,8 @@ echo -e '%s\tALL=(ALL)\tNOPASSWD: ALL' >> /etc/sudoers
|
||||
return True
|
||||
else:
|
||||
msg = _("Could not confirm resize of server %s") % server_id
|
||||
raise resource.ResourceUnknownStatus(result=msg,
|
||||
resource_status=status)
|
||||
raise exception.ResourceUnknownStatus(
|
||||
result=msg, resource_status=status)
|
||||
|
||||
def check_verify_resize(self, server_id):
|
||||
server = self.fetch_server(server_id)
|
||||
@ -465,8 +465,8 @@ echo -e '%s\tALL=(ALL)\tNOPASSWD: ALL' >> /etc/sudoers
|
||||
return False
|
||||
else:
|
||||
msg = _("Confirm resize for server %s failed") % server_id
|
||||
raise resource.ResourceUnknownStatus(result=msg,
|
||||
resource_status=status)
|
||||
raise exception.ResourceUnknownStatus(
|
||||
result=msg, resource_status=status)
|
||||
|
||||
def rebuild(self, server_id, image_id, password=None,
|
||||
preserve_ephemeral=False):
|
||||
|
@ -70,16 +70,6 @@ class ResourceInError(exception.HeatException):
|
||||
**kwargs)
|
||||
|
||||
|
||||
class ResourceUnknownStatus(exception.HeatException):
|
||||
msg_fmt = _('%(result)s - Unknown status %(resource_status)s due to '
|
||||
'"%(status_reason)s"')
|
||||
|
||||
def __init__(self, result=_('Resource failed'),
|
||||
status_reason=_('Unknown'), **kwargs):
|
||||
super(ResourceUnknownStatus, self).__init__(
|
||||
result=result, status_reason=status_reason, **kwargs)
|
||||
|
||||
|
||||
class UpdateInProgress(Exception):
|
||||
def __init__(self, resource_name='Unknown'):
|
||||
msg = _("The resource %s is already being updated.") % resource_name
|
||||
|
@ -869,7 +869,7 @@ class Instance(resource.Resource, sh.SchedulerHintsMixin):
|
||||
if status in list(cp.deferred_server_statuses + ['ACTIVE']):
|
||||
return status == 'SUSPENDED'
|
||||
else:
|
||||
exc = resource.ResourceUnknownStatus(
|
||||
exc = exception.ResourceUnknownStatus(
|
||||
result=_('Suspend of instance %s failed') % server.name,
|
||||
resource_status=status)
|
||||
raise exc
|
||||
|
@ -22,7 +22,6 @@ from heat.engine import attributes
|
||||
from heat.engine.clients import progress
|
||||
from heat.engine import constraints
|
||||
from heat.engine import properties
|
||||
from heat.engine import resource
|
||||
from heat.engine.resources import scheduler_hints as sh
|
||||
from heat.engine.resources import volume_base as vb
|
||||
from heat.engine import support
|
||||
@ -305,7 +304,7 @@ class CinderVolume(vb.BaseVolume, sh.SchedulerHintsMixin):
|
||||
LOG.info(_LI("Resize failed: Volume %(vol)s "
|
||||
"is in %(status)s state."),
|
||||
{'vol': vol.id, 'status': vol.status})
|
||||
raise resource.ResourceUnknownStatus(
|
||||
raise exception.ResourceUnknownStatus(
|
||||
resource_status=vol.status,
|
||||
result=_('Volume resize failed'))
|
||||
|
||||
@ -335,7 +334,7 @@ class CinderVolume(vb.BaseVolume, sh.SchedulerHintsMixin):
|
||||
if vol.status != 'available':
|
||||
LOG.info(_LI("Restore failed: Volume %(vol)s is in %(status)s "
|
||||
"state."), {'vol': vol.id, 'status': vol.status})
|
||||
raise resource.ResourceUnknownStatus(
|
||||
raise exception.ResourceUnknownStatus(
|
||||
resource_status=vol.status,
|
||||
result=_('Volume backup restore failed'))
|
||||
|
||||
|
@ -257,7 +257,7 @@ class RemoteStack(resource.Resource):
|
||||
else:
|
||||
# Note: this should never happen, so it really means that
|
||||
# the resource/engine is in serious problem if it happens.
|
||||
raise resource.ResourceUnknownStatus(
|
||||
raise exception.ResourceUnknownStatus(
|
||||
resource_status=stack.stack_status,
|
||||
status_reason=stack.stack_status_reason)
|
||||
|
||||
|
@ -14,6 +14,7 @@
|
||||
from oslo_log import log as logging
|
||||
import six
|
||||
|
||||
from heat.common import exception
|
||||
from heat.common.i18n import _
|
||||
from heat.common.i18n import _LI
|
||||
from heat.engine import attributes
|
||||
@ -257,8 +258,8 @@ class ManilaShare(resource.Resource):
|
||||
else:
|
||||
reason = _('Unknown share_status during creation of share "{0}"'
|
||||
).format(self.resource_id)
|
||||
raise resource.ResourceUnknownStatus(status_reason=reason,
|
||||
resource_status=share_status)
|
||||
raise exception.ResourceUnknownStatus(
|
||||
status_reason=reason, resource_status=share_status)
|
||||
|
||||
def check_delete_complete(self, *args):
|
||||
if not self.resource_id:
|
||||
@ -283,7 +284,7 @@ class ManilaShare(resource.Resource):
|
||||
else:
|
||||
reason = _('Unknown status during deleting share '
|
||||
'"{0}"').format(self.resource_id)
|
||||
raise resource.ResourceUnknownStatus(
|
||||
raise exception.ResourceUnknownStatus(
|
||||
status_reason=reason, resource_status=share.status)
|
||||
|
||||
def handle_check(self):
|
||||
|
@ -476,7 +476,7 @@ class Pool(neutron.NeutronResource):
|
||||
raise resource.ResourceInError(
|
||||
resource_status=vip_status,
|
||||
status_reason=_('error in vip'))
|
||||
raise resource.ResourceUnknownStatus(
|
||||
raise exception.ResourceUnknownStatus(
|
||||
resource_status=vip_status,
|
||||
result=_('Pool creation failed due to vip'))
|
||||
elif status == 'ERROR':
|
||||
@ -484,7 +484,7 @@ class Pool(neutron.NeutronResource):
|
||||
resource_status=status,
|
||||
status_reason=_('error in pool'))
|
||||
else:
|
||||
raise resource.ResourceUnknownStatus(
|
||||
raise exception.ResourceUnknownStatus(
|
||||
resource_status=status,
|
||||
result=_('Pool creation failed'))
|
||||
|
||||
|
@ -114,7 +114,7 @@ class NeutronResource(resource.Resource):
|
||||
raise resource.ResourceInError(
|
||||
resource_status=status)
|
||||
else:
|
||||
raise resource.ResourceUnknownStatus(
|
||||
raise exception.ResourceUnknownStatus(
|
||||
resource_status=status,
|
||||
result=_('Resource is not built'))
|
||||
|
||||
|
@ -28,7 +28,6 @@ from heat.engine.clients import progress
|
||||
from heat.engine import constraints
|
||||
from heat.engine import function
|
||||
from heat.engine import properties
|
||||
from heat.engine import resource
|
||||
from heat.engine.resources.openstack.neutron import subnet
|
||||
from heat.engine.resources.openstack.nova import server_network_mixin
|
||||
from heat.engine.resources import scheduler_hints as sh
|
||||
@ -1338,7 +1337,7 @@ class Server(stack_user.StackUser, sh.SchedulerHintsMixin,
|
||||
if status in list(cp.deferred_server_statuses + ['ACTIVE']):
|
||||
return status == 'SUSPENDED'
|
||||
else:
|
||||
exc = resource.ResourceUnknownStatus(
|
||||
exc = exception.ResourceUnknownStatus(
|
||||
result=_('Suspend of server %s failed') % server.name,
|
||||
resource_status=status)
|
||||
raise exc
|
||||
|
@ -372,7 +372,7 @@ class StackResource(resource.Resource):
|
||||
raise exception.ResourceFailure(nested.status_reason, self,
|
||||
action=action)
|
||||
else:
|
||||
raise resource.ResourceUnknownStatus(
|
||||
raise exception.ResourceUnknownStatus(
|
||||
resource_status=nested.status,
|
||||
status_reason=nested.status_reason,
|
||||
result=_('Stack unknown status'))
|
||||
|
@ -54,7 +54,7 @@ class BaseVolume(resource.Resource):
|
||||
raise resource.ResourceInError(
|
||||
resource_status=vol.status)
|
||||
else:
|
||||
raise resource.ResourceUnknownStatus(
|
||||
raise exception.ResourceUnknownStatus(
|
||||
resource_status=vol.status,
|
||||
result=_('Volume create failed'))
|
||||
|
||||
@ -108,7 +108,7 @@ class BaseVolume(resource.Resource):
|
||||
if backup.status == 'available':
|
||||
return True
|
||||
else:
|
||||
raise resource.ResourceUnknownStatus(
|
||||
raise exception.ResourceUnknownStatus(
|
||||
resource_status=backup.status,
|
||||
result=_('Volume backup failed'))
|
||||
|
||||
|
@ -525,7 +525,7 @@ class InstancesTest(common.HeatTestCase):
|
||||
return_server.status = 'BOGUS'
|
||||
self.fc.servers.get(instance.resource_id).AndReturn(return_server)
|
||||
self.m.ReplayAll()
|
||||
e = self.assertRaises(resource.ResourceUnknownStatus,
|
||||
e = self.assertRaises(exception.ResourceUnknownStatus,
|
||||
instance.check_create_complete,
|
||||
(creator, None))
|
||||
self.assertEqual('Instance is not active - Unknown status BOGUS '
|
||||
|
@ -270,7 +270,7 @@ class NovaClientPluginCheckActiveTests(NovaClientPluginTestCase):
|
||||
e_raise=resource.ResourceInError)),
|
||||
('unknown', dict(
|
||||
status='VIKINGS!',
|
||||
e_raise=resource.ResourceUnknownStatus))
|
||||
e_raise=exception.ResourceUnknownStatus))
|
||||
]
|
||||
|
||||
def setUp(self):
|
||||
|
@ -135,7 +135,7 @@ class ManilaShareTest(common.HeatTestCase):
|
||||
def test_share_create_unknown_status(self):
|
||||
share = self._init_share("stack_share_create_unknown")
|
||||
share.client().shares.get.return_value = self.deleting_share
|
||||
exc = self.assertRaises(resource.ResourceUnknownStatus,
|
||||
exc = self.assertRaises(exception.ResourceUnknownStatus,
|
||||
share.check_create_complete,
|
||||
self.deleting_share)
|
||||
self.assertIn("Unknown status", six.text_type(exc))
|
||||
|
@ -97,7 +97,7 @@ class NeutronTest(common.HeatTestCase):
|
||||
'Went to status ERROR due to "Unknown"',
|
||||
six.text_type(e))
|
||||
e = self.assertRaises(
|
||||
resource.ResourceUnknownStatus,
|
||||
exception.ResourceUnknownStatus,
|
||||
nr.NeutronResource.is_built, {'status': 'FROBULATING'})
|
||||
self.assertEqual('Resource is not built - Unknown status '
|
||||
'FROBULATING due to "Unknown"',
|
||||
|
@ -513,7 +513,7 @@ class ServersTest(common.HeatTestCase):
|
||||
self.fc.servers.get(server.resource_id).AndReturn(return_server)
|
||||
self.m.ReplayAll()
|
||||
|
||||
e = self.assertRaises(resource.ResourceUnknownStatus,
|
||||
e = self.assertRaises(exception.ResourceUnknownStatus,
|
||||
server.check_create_complete,
|
||||
server.resource_id)
|
||||
self.assertEqual('Server is not active - Unknown status BOGUS due to '
|
||||
@ -2040,7 +2040,7 @@ class ServersTest(common.HeatTestCase):
|
||||
|
||||
ex = self.assertRaises(exception.ResourceFailure,
|
||||
scheduler.TaskRunner(server.suspend))
|
||||
self.assertIsInstance(ex.exc, resource.ResourceUnknownStatus)
|
||||
self.assertIsInstance(ex.exc, exception.ResourceUnknownStatus)
|
||||
self.assertEqual('Suspend of server %s failed - '
|
||||
'Unknown status TRANSMOGRIFIED '
|
||||
'due to "Unknown"' % return_server.name,
|
||||
|
@ -23,7 +23,6 @@ import testtools
|
||||
|
||||
from heat.common import exception
|
||||
from heat.common import template_format
|
||||
from heat.engine import resource
|
||||
from heat.engine.resources import stack_resource
|
||||
from heat.engine import stack as parser
|
||||
from heat.engine import template as templatem
|
||||
@ -758,7 +757,7 @@ class StackResourceCheckCompleteTest(StackResourceBaseTest):
|
||||
self.nested.status_reason = 'broken on purpose'
|
||||
complete = getattr(self.parent_resource,
|
||||
'check_%s_complete' % self.action)
|
||||
self.assertRaises(resource.ResourceUnknownStatus, complete, None)
|
||||
self.assertRaises(exception.ResourceUnknownStatus, complete, None)
|
||||
self.parent_resource.nested.assert_called_once_with(
|
||||
show_deleted=self.show_deleted, force_reload=True)
|
||||
|
||||
|
Loading…
x
Reference in New Issue
Block a user