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:
Oleksii Chuprykov 2015-09-02 16:11:40 +03:00
parent 4e2cfb991a
commit 68a73b513c
19 changed files with 39 additions and 42 deletions

View File

@ -395,6 +395,16 @@ class UpdateReplace(Exception):
super(Exception, self).__init__(six.text_type(msg)) 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): class HTTPExceptionDisguise(Exception):
"""Disguises HTTP exceptions so they can be handled by the webob fault """Disguises HTTP exceptions so they can be handled by the webob fault
application in the wsgi pipeline. application in the wsgi pipeline.

View File

@ -22,7 +22,6 @@ from heat.common.i18n import _
from heat.common.i18n import _LI from heat.common.i18n import _LI
from heat.engine.clients import client_plugin from heat.engine.clients import client_plugin
from heat.engine import constraints from heat.engine import constraints
from heat.engine import resource
LOG = logging.getLogger(__name__) LOG = logging.getLogger(__name__)
@ -160,7 +159,7 @@ class CinderClientPlugin(client_plugin.ClientPlugin):
LOG.debug("Detachment failed - volume %(vol)s " LOG.debug("Detachment failed - volume %(vol)s "
"is in %(status)s status" % {"vol": vol.id, "is in %(status)s status" % {"vol": vol.id,
"status": vol.status}) "status": vol.status})
raise resource.ResourceUnknownStatus( raise exception.ResourceUnknownStatus(
resource_status=vol.status, resource_status=vol.status,
result=_('Volume detachment failed')) result=_('Volume detachment failed'))
else: else:
@ -178,7 +177,7 @@ class CinderClientPlugin(client_plugin.ClientPlugin):
LOG.debug("Attachment failed - volume %(vol)s is " LOG.debug("Attachment failed - volume %(vol)s is "
"in %(status)s status" % {"vol": vol_id, "in %(status)s status" % {"vol": vol_id,
"status": vol.status}) "status": vol.status})
raise resource.ResourceUnknownStatus( raise exception.ResourceUnknownStatus(
resource_status=vol.status, resource_status=vol.status,
result=_('Volume attachment failed')) result=_('Volume attachment failed'))

View File

@ -222,7 +222,7 @@ class NovaClientPlugin(client_plugin.ClientPlugin):
'code': fault.get('code', _('Unknown')) 'code': fault.get('code', _('Unknown'))
}) })
else: else:
raise resource.ResourceUnknownStatus( raise exception.ResourceUnknownStatus(
resource_status=server.status, resource_status=server.status,
result=_('%s is not active') % res_name) result=_('%s is not active') % res_name)
@ -451,8 +451,8 @@ echo -e '%s\tALL=(ALL)\tNOPASSWD: ALL' >> /etc/sudoers
return True return True
else: else:
msg = _("Could not confirm resize of server %s") % server_id msg = _("Could not confirm resize of server %s") % server_id
raise resource.ResourceUnknownStatus(result=msg, raise exception.ResourceUnknownStatus(
resource_status=status) result=msg, resource_status=status)
def check_verify_resize(self, server_id): def check_verify_resize(self, server_id):
server = self.fetch_server(server_id) server = self.fetch_server(server_id)
@ -465,8 +465,8 @@ echo -e '%s\tALL=(ALL)\tNOPASSWD: ALL' >> /etc/sudoers
return False return False
else: else:
msg = _("Confirm resize for server %s failed") % server_id msg = _("Confirm resize for server %s failed") % server_id
raise resource.ResourceUnknownStatus(result=msg, raise exception.ResourceUnknownStatus(
resource_status=status) result=msg, resource_status=status)
def rebuild(self, server_id, image_id, password=None, def rebuild(self, server_id, image_id, password=None,
preserve_ephemeral=False): preserve_ephemeral=False):

View File

@ -70,16 +70,6 @@ class ResourceInError(exception.HeatException):
**kwargs) **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): class UpdateInProgress(Exception):
def __init__(self, resource_name='Unknown'): def __init__(self, resource_name='Unknown'):
msg = _("The resource %s is already being updated.") % resource_name msg = _("The resource %s is already being updated.") % resource_name

View File

@ -869,7 +869,7 @@ class Instance(resource.Resource, sh.SchedulerHintsMixin):
if status in list(cp.deferred_server_statuses + ['ACTIVE']): if status in list(cp.deferred_server_statuses + ['ACTIVE']):
return status == 'SUSPENDED' return status == 'SUSPENDED'
else: else:
exc = resource.ResourceUnknownStatus( exc = exception.ResourceUnknownStatus(
result=_('Suspend of instance %s failed') % server.name, result=_('Suspend of instance %s failed') % server.name,
resource_status=status) resource_status=status)
raise exc raise exc

View File

@ -22,7 +22,6 @@ from heat.engine import attributes
from heat.engine.clients import progress from heat.engine.clients import progress
from heat.engine import constraints from heat.engine import constraints
from heat.engine import properties from heat.engine import properties
from heat.engine import resource
from heat.engine.resources import scheduler_hints as sh from heat.engine.resources import scheduler_hints as sh
from heat.engine.resources import volume_base as vb from heat.engine.resources import volume_base as vb
from heat.engine import support from heat.engine import support
@ -305,7 +304,7 @@ class CinderVolume(vb.BaseVolume, sh.SchedulerHintsMixin):
LOG.info(_LI("Resize failed: Volume %(vol)s " LOG.info(_LI("Resize failed: Volume %(vol)s "
"is in %(status)s state."), "is in %(status)s state."),
{'vol': vol.id, 'status': vol.status}) {'vol': vol.id, 'status': vol.status})
raise resource.ResourceUnknownStatus( raise exception.ResourceUnknownStatus(
resource_status=vol.status, resource_status=vol.status,
result=_('Volume resize failed')) result=_('Volume resize failed'))
@ -335,7 +334,7 @@ class CinderVolume(vb.BaseVolume, sh.SchedulerHintsMixin):
if vol.status != 'available': if vol.status != 'available':
LOG.info(_LI("Restore failed: Volume %(vol)s is in %(status)s " LOG.info(_LI("Restore failed: Volume %(vol)s is in %(status)s "
"state."), {'vol': vol.id, 'status': vol.status}) "state."), {'vol': vol.id, 'status': vol.status})
raise resource.ResourceUnknownStatus( raise exception.ResourceUnknownStatus(
resource_status=vol.status, resource_status=vol.status,
result=_('Volume backup restore failed')) result=_('Volume backup restore failed'))

View File

@ -257,7 +257,7 @@ class RemoteStack(resource.Resource):
else: else:
# Note: this should never happen, so it really means that # Note: this should never happen, so it really means that
# the resource/engine is in serious problem if it happens. # the resource/engine is in serious problem if it happens.
raise resource.ResourceUnknownStatus( raise exception.ResourceUnknownStatus(
resource_status=stack.stack_status, resource_status=stack.stack_status,
status_reason=stack.stack_status_reason) status_reason=stack.stack_status_reason)

View File

@ -14,6 +14,7 @@
from oslo_log import log as logging from oslo_log import log as logging
import six import six
from heat.common import exception
from heat.common.i18n import _ from heat.common.i18n import _
from heat.common.i18n import _LI from heat.common.i18n import _LI
from heat.engine import attributes from heat.engine import attributes
@ -257,8 +258,8 @@ class ManilaShare(resource.Resource):
else: else:
reason = _('Unknown share_status during creation of share "{0}"' reason = _('Unknown share_status during creation of share "{0}"'
).format(self.resource_id) ).format(self.resource_id)
raise resource.ResourceUnknownStatus(status_reason=reason, raise exception.ResourceUnknownStatus(
resource_status=share_status) status_reason=reason, resource_status=share_status)
def check_delete_complete(self, *args): def check_delete_complete(self, *args):
if not self.resource_id: if not self.resource_id:
@ -283,7 +284,7 @@ class ManilaShare(resource.Resource):
else: else:
reason = _('Unknown status during deleting share ' reason = _('Unknown status during deleting share '
'"{0}"').format(self.resource_id) '"{0}"').format(self.resource_id)
raise resource.ResourceUnknownStatus( raise exception.ResourceUnknownStatus(
status_reason=reason, resource_status=share.status) status_reason=reason, resource_status=share.status)
def handle_check(self): def handle_check(self):

View File

@ -476,7 +476,7 @@ class Pool(neutron.NeutronResource):
raise resource.ResourceInError( raise resource.ResourceInError(
resource_status=vip_status, resource_status=vip_status,
status_reason=_('error in vip')) status_reason=_('error in vip'))
raise resource.ResourceUnknownStatus( raise exception.ResourceUnknownStatus(
resource_status=vip_status, resource_status=vip_status,
result=_('Pool creation failed due to vip')) result=_('Pool creation failed due to vip'))
elif status == 'ERROR': elif status == 'ERROR':
@ -484,7 +484,7 @@ class Pool(neutron.NeutronResource):
resource_status=status, resource_status=status,
status_reason=_('error in pool')) status_reason=_('error in pool'))
else: else:
raise resource.ResourceUnknownStatus( raise exception.ResourceUnknownStatus(
resource_status=status, resource_status=status,
result=_('Pool creation failed')) result=_('Pool creation failed'))

View File

@ -114,7 +114,7 @@ class NeutronResource(resource.Resource):
raise resource.ResourceInError( raise resource.ResourceInError(
resource_status=status) resource_status=status)
else: else:
raise resource.ResourceUnknownStatus( raise exception.ResourceUnknownStatus(
resource_status=status, resource_status=status,
result=_('Resource is not built')) result=_('Resource is not built'))

View File

@ -28,7 +28,6 @@ from heat.engine.clients import progress
from heat.engine import constraints from heat.engine import constraints
from heat.engine import function from heat.engine import function
from heat.engine import properties from heat.engine import properties
from heat.engine import resource
from heat.engine.resources.openstack.neutron import subnet from heat.engine.resources.openstack.neutron import subnet
from heat.engine.resources.openstack.nova import server_network_mixin from heat.engine.resources.openstack.nova import server_network_mixin
from heat.engine.resources import scheduler_hints as sh 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']): if status in list(cp.deferred_server_statuses + ['ACTIVE']):
return status == 'SUSPENDED' return status == 'SUSPENDED'
else: else:
exc = resource.ResourceUnknownStatus( exc = exception.ResourceUnknownStatus(
result=_('Suspend of server %s failed') % server.name, result=_('Suspend of server %s failed') % server.name,
resource_status=status) resource_status=status)
raise exc raise exc

View File

@ -372,7 +372,7 @@ class StackResource(resource.Resource):
raise exception.ResourceFailure(nested.status_reason, self, raise exception.ResourceFailure(nested.status_reason, self,
action=action) action=action)
else: else:
raise resource.ResourceUnknownStatus( raise exception.ResourceUnknownStatus(
resource_status=nested.status, resource_status=nested.status,
status_reason=nested.status_reason, status_reason=nested.status_reason,
result=_('Stack unknown status')) result=_('Stack unknown status'))

View File

@ -54,7 +54,7 @@ class BaseVolume(resource.Resource):
raise resource.ResourceInError( raise resource.ResourceInError(
resource_status=vol.status) resource_status=vol.status)
else: else:
raise resource.ResourceUnknownStatus( raise exception.ResourceUnknownStatus(
resource_status=vol.status, resource_status=vol.status,
result=_('Volume create failed')) result=_('Volume create failed'))
@ -108,7 +108,7 @@ class BaseVolume(resource.Resource):
if backup.status == 'available': if backup.status == 'available':
return True return True
else: else:
raise resource.ResourceUnknownStatus( raise exception.ResourceUnknownStatus(
resource_status=backup.status, resource_status=backup.status,
result=_('Volume backup failed')) result=_('Volume backup failed'))

View File

@ -525,7 +525,7 @@ class InstancesTest(common.HeatTestCase):
return_server.status = 'BOGUS' return_server.status = 'BOGUS'
self.fc.servers.get(instance.resource_id).AndReturn(return_server) self.fc.servers.get(instance.resource_id).AndReturn(return_server)
self.m.ReplayAll() self.m.ReplayAll()
e = self.assertRaises(resource.ResourceUnknownStatus, e = self.assertRaises(exception.ResourceUnknownStatus,
instance.check_create_complete, instance.check_create_complete,
(creator, None)) (creator, None))
self.assertEqual('Instance is not active - Unknown status BOGUS ' self.assertEqual('Instance is not active - Unknown status BOGUS '

View File

@ -270,7 +270,7 @@ class NovaClientPluginCheckActiveTests(NovaClientPluginTestCase):
e_raise=resource.ResourceInError)), e_raise=resource.ResourceInError)),
('unknown', dict( ('unknown', dict(
status='VIKINGS!', status='VIKINGS!',
e_raise=resource.ResourceUnknownStatus)) e_raise=exception.ResourceUnknownStatus))
] ]
def setUp(self): def setUp(self):

View File

@ -135,7 +135,7 @@ class ManilaShareTest(common.HeatTestCase):
def test_share_create_unknown_status(self): def test_share_create_unknown_status(self):
share = self._init_share("stack_share_create_unknown") share = self._init_share("stack_share_create_unknown")
share.client().shares.get.return_value = self.deleting_share share.client().shares.get.return_value = self.deleting_share
exc = self.assertRaises(resource.ResourceUnknownStatus, exc = self.assertRaises(exception.ResourceUnknownStatus,
share.check_create_complete, share.check_create_complete,
self.deleting_share) self.deleting_share)
self.assertIn("Unknown status", six.text_type(exc)) self.assertIn("Unknown status", six.text_type(exc))

View File

@ -97,7 +97,7 @@ class NeutronTest(common.HeatTestCase):
'Went to status ERROR due to "Unknown"', 'Went to status ERROR due to "Unknown"',
six.text_type(e)) six.text_type(e))
e = self.assertRaises( e = self.assertRaises(
resource.ResourceUnknownStatus, exception.ResourceUnknownStatus,
nr.NeutronResource.is_built, {'status': 'FROBULATING'}) nr.NeutronResource.is_built, {'status': 'FROBULATING'})
self.assertEqual('Resource is not built - Unknown status ' self.assertEqual('Resource is not built - Unknown status '
'FROBULATING due to "Unknown"', 'FROBULATING due to "Unknown"',

View File

@ -513,7 +513,7 @@ class ServersTest(common.HeatTestCase):
self.fc.servers.get(server.resource_id).AndReturn(return_server) self.fc.servers.get(server.resource_id).AndReturn(return_server)
self.m.ReplayAll() self.m.ReplayAll()
e = self.assertRaises(resource.ResourceUnknownStatus, e = self.assertRaises(exception.ResourceUnknownStatus,
server.check_create_complete, server.check_create_complete,
server.resource_id) server.resource_id)
self.assertEqual('Server is not active - Unknown status BOGUS due to ' self.assertEqual('Server is not active - Unknown status BOGUS due to '
@ -2040,7 +2040,7 @@ class ServersTest(common.HeatTestCase):
ex = self.assertRaises(exception.ResourceFailure, ex = self.assertRaises(exception.ResourceFailure,
scheduler.TaskRunner(server.suspend)) scheduler.TaskRunner(server.suspend))
self.assertIsInstance(ex.exc, resource.ResourceUnknownStatus) self.assertIsInstance(ex.exc, exception.ResourceUnknownStatus)
self.assertEqual('Suspend of server %s failed - ' self.assertEqual('Suspend of server %s failed - '
'Unknown status TRANSMOGRIFIED ' 'Unknown status TRANSMOGRIFIED '
'due to "Unknown"' % return_server.name, 'due to "Unknown"' % return_server.name,

View File

@ -23,7 +23,6 @@ import testtools
from heat.common import exception from heat.common import exception
from heat.common import template_format from heat.common import template_format
from heat.engine import resource
from heat.engine.resources import stack_resource from heat.engine.resources import stack_resource
from heat.engine import stack as parser from heat.engine import stack as parser
from heat.engine import template as templatem from heat.engine import template as templatem
@ -758,7 +757,7 @@ class StackResourceCheckCompleteTest(StackResourceBaseTest):
self.nested.status_reason = 'broken on purpose' self.nested.status_reason = 'broken on purpose'
complete = getattr(self.parent_resource, complete = getattr(self.parent_resource,
'check_%s_complete' % self.action) '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( self.parent_resource.nested.assert_called_once_with(
show_deleted=self.show_deleted, force_reload=True) show_deleted=self.show_deleted, force_reload=True)