Move Resource exceptions to common module (3)
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). ResourceInError exception is moved in this patch. Change-Id: I122c032468efeb97d165af4ae372bc35b60a11a2
This commit is contained in:
parent
68a73b513c
commit
6d41bcc1d3
@ -476,8 +476,8 @@ class DockerContainer(resource.Resource):
|
||||
exit_status = status.get('ExitCode')
|
||||
if exit_status is not None and exit_status != 0:
|
||||
logs = self.get_client().logs(self.resource_id)
|
||||
raise resource.ResourceInError(resource_status=self.FAILED,
|
||||
status_reason=logs)
|
||||
raise exception.ResourceInError(resource_status=self.FAILED,
|
||||
status_reason=logs)
|
||||
return status['Running']
|
||||
|
||||
def handle_delete(self):
|
||||
|
@ -127,7 +127,7 @@ class DockerContainerTest(common.HeatTestCase):
|
||||
res_def = mock.Mock(spec=rsrc_defn.ResourceDefinition)
|
||||
docker_res = docker_container.DockerContainer("test", res_def,
|
||||
mock_stack)
|
||||
exc = self.assertRaises(resource.ResourceInError,
|
||||
exc = self.assertRaises(exception.ResourceInError,
|
||||
docker_res.check_create_complete,
|
||||
'foo')
|
||||
self.assertIn("Container startup failed", six.text_type(exc))
|
||||
|
@ -405,6 +405,15 @@ class ResourceUnknownStatus(HeatException):
|
||||
result=result, status_reason=status_reason, **kwargs)
|
||||
|
||||
|
||||
class ResourceInError(HeatException):
|
||||
msg_fmt = _('Went to status %(resource_status)s '
|
||||
'due to "%(status_reason)s"')
|
||||
|
||||
def __init__(self, status_reason=_('Unknown'), **kwargs):
|
||||
super(ResourceInError, self).__init__(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.
|
||||
|
@ -34,7 +34,6 @@ from heat.common.i18n import _LI
|
||||
from heat.common.i18n import _LW
|
||||
from heat.engine.clients import client_plugin
|
||||
from heat.engine import constraints
|
||||
from heat.engine import resource
|
||||
|
||||
LOG = logging.getLogger(__name__)
|
||||
|
||||
@ -215,7 +214,7 @@ class NovaClientPlugin(client_plugin.ClientPlugin):
|
||||
return True
|
||||
elif status == 'ERROR':
|
||||
fault = getattr(server, 'fault', {})
|
||||
raise resource.ResourceInError(
|
||||
raise exception.ResourceInError(
|
||||
resource_status=status,
|
||||
status_reason=_("Message: %(message)s, Code: %(code)s") % {
|
||||
'message': fault.get('message', _('Unknown')),
|
||||
@ -406,8 +405,8 @@ echo -e '%s\tALL=(ALL)\tNOPASSWD: ALL' >> /etc/sudoers
|
||||
"%(message)s") % dict(name=server.name,
|
||||
code=code,
|
||||
message=message)
|
||||
raise resource.ResourceInError(resource_status=status,
|
||||
status_reason=errmsg)
|
||||
raise exception.ResourceInError(resource_status=status,
|
||||
status_reason=errmsg)
|
||||
return False
|
||||
|
||||
def rename(self, server, name):
|
||||
|
@ -61,15 +61,6 @@ class NoActionRequired(Exception):
|
||||
pass
|
||||
|
||||
|
||||
class ResourceInError(exception.HeatException):
|
||||
msg_fmt = _('Went to status %(resource_status)s '
|
||||
'due to "%(status_reason)s"')
|
||||
|
||||
def __init__(self, status_reason=_('Unknown'), **kwargs):
|
||||
super(ResourceInError, self).__init__(status_reason=status_reason,
|
||||
**kwargs)
|
||||
|
||||
|
||||
class UpdateInProgress(Exception):
|
||||
def __init__(self, resource_name='Unknown'):
|
||||
msg = _("The resource %s is already being updated.") % resource_name
|
||||
@ -775,7 +766,7 @@ class Resource(object):
|
||||
else:
|
||||
action = self.CREATE
|
||||
except exception.ResourceFailure as failure:
|
||||
if not isinstance(failure.exc, ResourceInError):
|
||||
if not isinstance(failure.exc, exception.ResourceInError):
|
||||
raise failure
|
||||
|
||||
count[action] += 1
|
||||
|
@ -251,7 +251,7 @@ class RemoteStack(resource.Resource):
|
||||
elif stack.status == self.COMPLETE:
|
||||
return True
|
||||
elif stack.status == self.FAILED:
|
||||
raise resource.ResourceInError(
|
||||
raise exception.ResourceInError(
|
||||
resource_status=stack.stack_status,
|
||||
status_reason=stack.stack_status_reason)
|
||||
else:
|
||||
|
@ -249,12 +249,12 @@ class ManilaShare(resource.Resource):
|
||||
'Error during applying access rules to share "{0}". '
|
||||
'The root cause of the problem is the following: {1}.'
|
||||
).format(self.resource_id, ex.message)
|
||||
raise resource.ResourceInError(status_reason=reason)
|
||||
raise exception.ResourceInError(status_reason=reason)
|
||||
elif share_status == self.STATUS_ERROR:
|
||||
reason = _('Error during creation of share "{0}"').format(
|
||||
self.resource_id)
|
||||
raise resource.ResourceInError(status_reason=reason,
|
||||
resource_status=share_status)
|
||||
raise exception.ResourceInError(status_reason=reason,
|
||||
resource_status=share_status)
|
||||
else:
|
||||
reason = _('Unknown share_status during creation of share "{0}"'
|
||||
).format(self.resource_id)
|
||||
@ -276,7 +276,7 @@ class ManilaShare(resource.Resource):
|
||||
return False
|
||||
elif share.status in (self.STATUS_ERROR,
|
||||
self.STATUS_ERROR_DELETING):
|
||||
raise resource.ResourceInError(
|
||||
raise exception.ResourceInError(
|
||||
status_reason=_(
|
||||
'Error during deleting share "{0}".'
|
||||
).format(self.resource_id),
|
||||
|
@ -473,14 +473,14 @@ class Pool(neutron.NeutronResource):
|
||||
if vip_status == 'ACTIVE':
|
||||
return True
|
||||
if vip_status == 'ERROR':
|
||||
raise resource.ResourceInError(
|
||||
raise exception.ResourceInError(
|
||||
resource_status=vip_status,
|
||||
status_reason=_('error in vip'))
|
||||
raise exception.ResourceUnknownStatus(
|
||||
resource_status=vip_status,
|
||||
result=_('Pool creation failed due to vip'))
|
||||
elif status == 'ERROR':
|
||||
raise resource.ResourceInError(
|
||||
raise exception.ResourceInError(
|
||||
resource_status=status,
|
||||
status_reason=_('error in pool'))
|
||||
else:
|
||||
|
@ -111,7 +111,7 @@ class NeutronResource(resource.Resource):
|
||||
if status in ('ACTIVE', 'DOWN'):
|
||||
return True
|
||||
elif status == 'ERROR':
|
||||
raise resource.ResourceInError(
|
||||
raise exception.ResourceInError(
|
||||
resource_status=status)
|
||||
else:
|
||||
raise exception.ResourceUnknownStatus(
|
||||
|
@ -175,7 +175,7 @@ class SaharaCluster(resource.Resource):
|
||||
def check_create_complete(self, cluster_id):
|
||||
cluster = self.client().clusters.get(cluster_id)
|
||||
if cluster.status == self.CLUSTER_ERROR:
|
||||
raise resource.ResourceInError(resource_status=cluster.status)
|
||||
raise exception.ResourceInError(resource_status=cluster.status)
|
||||
|
||||
if cluster.status != self.CLUSTER_ACTIVE:
|
||||
return False
|
||||
@ -196,7 +196,7 @@ class SaharaCluster(resource.Resource):
|
||||
return True
|
||||
else:
|
||||
if cluster.status == self.CLUSTER_ERROR:
|
||||
raise resource.ResourceInError(resource_status=cluster.status)
|
||||
raise exception.ResourceInError(resource_status=cluster.status)
|
||||
|
||||
return False
|
||||
|
||||
|
@ -388,7 +388,7 @@ class OSDBInstance(resource.Resource):
|
||||
if instance is None:
|
||||
return False
|
||||
if instance.status in self.BAD_STATUSES:
|
||||
raise resource.ResourceInError(
|
||||
raise exception.ResourceInError(
|
||||
resource_status=instance.status,
|
||||
status_reason=self.TROVE_STATUS_REASON.get(instance.status,
|
||||
_("Unknown")))
|
||||
|
@ -13,6 +13,7 @@
|
||||
|
||||
from oslo_log import log as logging
|
||||
|
||||
from heat.common import exception
|
||||
from heat.common.i18n import _
|
||||
from heat.common.i18n import _LI
|
||||
from heat.common.i18n import _LW
|
||||
@ -183,7 +184,7 @@ class TroveCluster(resource.Resource):
|
||||
|
||||
for instance in cluster.instances:
|
||||
if instance['status'] in self.BAD_STATUSES:
|
||||
raise resource.ResourceInError(
|
||||
raise exception.ResourceInError(
|
||||
resource_status=instance['status'],
|
||||
status_reason=self.TROVE_STATUS_REASON.get(
|
||||
instance['status'], _("Unknown")))
|
||||
|
@ -51,7 +51,7 @@ class BaseVolume(resource.Resource):
|
||||
if vol.status in self._volume_creating_status:
|
||||
return False
|
||||
if vol.status == 'error':
|
||||
raise resource.ResourceInError(
|
||||
raise exception.ResourceInError(
|
||||
resource_status=vol.status)
|
||||
else:
|
||||
raise exception.ResourceUnknownStatus(
|
||||
|
@ -28,7 +28,6 @@ from heat.engine.clients.os import neutron
|
||||
from heat.engine.clients.os import nova
|
||||
from heat.engine.clients import progress
|
||||
from heat.engine import environment
|
||||
from heat.engine import resource
|
||||
from heat.engine.resources.aws.ec2 import instance as instances
|
||||
from heat.engine.resources import scheduler_hints as sh
|
||||
from heat.engine import scheduler
|
||||
@ -549,7 +548,7 @@ class InstancesTest(common.HeatTestCase):
|
||||
self.fc.servers.get(instance.resource_id).AndReturn(return_server)
|
||||
self.m.ReplayAll()
|
||||
|
||||
e = self.assertRaises(resource.ResourceInError,
|
||||
e = self.assertRaises(exception.ResourceInError,
|
||||
instance.check_create_complete,
|
||||
(creator, None))
|
||||
self.assertEqual(
|
||||
@ -572,7 +571,7 @@ class InstancesTest(common.HeatTestCase):
|
||||
self.m.ReplayAll()
|
||||
|
||||
e = self.assertRaises(
|
||||
resource.ResourceInError, instance.check_create_complete,
|
||||
exception.ResourceInError, instance.check_create_complete,
|
||||
(creator, None))
|
||||
self.assertEqual(
|
||||
'Went to status ERROR due to "Message: Unknown, Code: Unknown"',
|
||||
|
@ -24,7 +24,6 @@ import six
|
||||
|
||||
from heat.common import exception
|
||||
from heat.engine.clients.os import nova
|
||||
from heat.engine import resource
|
||||
from heat.tests import common
|
||||
from heat.tests.nova import fakes as fakes_nova
|
||||
from heat.tests import utils
|
||||
@ -267,7 +266,7 @@ class NovaClientPluginCheckActiveTests(NovaClientPluginTestCase):
|
||||
e_raise=False)),
|
||||
('error', dict(
|
||||
status='ERROR',
|
||||
e_raise=resource.ResourceInError)),
|
||||
e_raise=exception.ResourceInError)),
|
||||
('unknown', dict(
|
||||
status='VIKINGS!',
|
||||
e_raise=exception.ResourceUnknownStatus))
|
||||
|
@ -18,7 +18,6 @@ import six
|
||||
|
||||
from heat.common import exception
|
||||
from heat.common import template_format
|
||||
from heat.engine import resource
|
||||
from heat.engine.resources.openstack.manila import share as mshare
|
||||
from heat.engine import rsrc_defn
|
||||
from heat.engine import scheduler
|
||||
@ -127,7 +126,7 @@ class ManilaShareTest(common.HeatTestCase):
|
||||
def test_share_create_fail(self):
|
||||
share = self._init_share("stack_share_create_fail")
|
||||
share.client().shares.get.return_value = self.failed_share
|
||||
exc = self.assertRaises(resource.ResourceInError,
|
||||
exc = self.assertRaises(exception.ResourceInError,
|
||||
share.check_create_complete,
|
||||
self.failed_share)
|
||||
self.assertIn("Error during creation", six.text_type(exc))
|
||||
|
@ -20,7 +20,6 @@ from heat.common import exception
|
||||
from heat.engine.clients.os import neutron
|
||||
from heat.engine.hot import functions
|
||||
from heat.engine import properties
|
||||
from heat.engine import resource
|
||||
from heat.engine.resources.openstack.neutron import net
|
||||
from heat.engine.resources.openstack.neutron import neutron as nr
|
||||
from heat.engine.resources.openstack.neutron import subnet
|
||||
@ -91,7 +90,7 @@ class NeutronTest(common.HeatTestCase):
|
||||
self.assertTrue(nr.NeutronResource.is_built({'status': 'DOWN'}))
|
||||
self.assertFalse(nr.NeutronResource.is_built({'status': 'BUILD'}))
|
||||
e = self.assertRaises(
|
||||
resource.ResourceInError,
|
||||
exception.ResourceInError,
|
||||
nr.NeutronResource.is_built, {'status': 'ERROR'})
|
||||
self.assertEqual(
|
||||
'Went to status ERROR due to "Unknown"',
|
||||
|
@ -30,7 +30,6 @@ from heat.engine.clients.os import nova
|
||||
from heat.engine.clients.os import swift
|
||||
from heat.engine.clients.os import zaqar
|
||||
from heat.engine import environment
|
||||
from heat.engine import resource
|
||||
from heat.engine.resources.openstack.nova import server as servers
|
||||
from heat.engine.resources import scheduler_hints as sh
|
||||
from heat.engine import scheduler
|
||||
@ -536,7 +535,7 @@ class ServersTest(common.HeatTestCase):
|
||||
self.fc.servers.get(server.resource_id).AndReturn(return_server)
|
||||
self.m.ReplayAll()
|
||||
|
||||
e = self.assertRaises(resource.ResourceInError,
|
||||
e = self.assertRaises(exception.ResourceInError,
|
||||
server.check_create_complete,
|
||||
server.resource_id)
|
||||
self.assertEqual(
|
||||
|
@ -22,7 +22,6 @@ from heat.common import template_format
|
||||
from heat.engine.clients.os import neutron
|
||||
from heat.engine.clients.os import nova
|
||||
from heat.engine.clients.os import trove
|
||||
from heat.engine import resource
|
||||
from heat.engine.resources.openstack.trove import os_database
|
||||
from heat.engine import rsrc_defn
|
||||
from heat.engine import scheduler
|
||||
@ -195,7 +194,7 @@ class OSDBInstanceTest(common.HeatTestCase):
|
||||
trove_mock.instances.get.return_value = mock_input
|
||||
error_string = ('Went to status ERROR due to "The last operation for '
|
||||
'the database instance failed due to an error."')
|
||||
exc = self.assertRaises(resource.ResourceInError,
|
||||
exc = self.assertRaises(exception.ResourceInError,
|
||||
osdb_res.check_create_complete,
|
||||
mock_input)
|
||||
self.assertIn(error_string, six.text_type(exc))
|
||||
@ -208,7 +207,7 @@ class OSDBInstanceTest(common.HeatTestCase):
|
||||
'datastore. If a database instance is in the FAILED '
|
||||
'state, it should be deleted and a new one should '
|
||||
'be created."')
|
||||
exc = self.assertRaises(resource.ResourceInError,
|
||||
exc = self.assertRaises(exception.ResourceInError,
|
||||
osdb_res.check_create_complete,
|
||||
mock_input)
|
||||
self.assertIn(error_string, six.text_type(exc))
|
||||
@ -220,7 +219,7 @@ class OSDBInstanceTest(common.HeatTestCase):
|
||||
mock_input.status = 'ERROR'
|
||||
error_string = ('Went to status ERROR due to "Unknown"')
|
||||
trove_mock.instances.get.return_value = mock_input
|
||||
exc = self.assertRaises(resource.ResourceInError,
|
||||
exc = self.assertRaises(exception.ResourceInError,
|
||||
osdb_res.check_create_complete,
|
||||
mock_input)
|
||||
self.assertIn(error_string, six.text_type(exc))
|
||||
|
@ -682,11 +682,11 @@ class ResourceTest(common.HeatTestCase):
|
||||
|
||||
# first attempt to create fails
|
||||
generic_rsrc.ResourceWithProps.handle_create().AndRaise(
|
||||
resource.ResourceInError(resource_name='test_resource',
|
||||
resource_status='ERROR',
|
||||
resource_type='GenericResourceType',
|
||||
resource_action='CREATE',
|
||||
status_reason='just because'))
|
||||
exception.ResourceInError(resource_name='test_resource',
|
||||
resource_status='ERROR',
|
||||
resource_type='GenericResourceType',
|
||||
resource_action='CREATE',
|
||||
status_reason='just because'))
|
||||
# delete error resource from first attempt
|
||||
generic_rsrc.ResourceWithProps.handle_delete().AndReturn(None)
|
||||
|
||||
@ -711,11 +711,11 @@ class ResourceTest(common.HeatTestCase):
|
||||
|
||||
# attempt to create fails
|
||||
generic_rsrc.ResourceWithProps.handle_create().AndRaise(
|
||||
resource.ResourceInError(resource_name='test_resource',
|
||||
resource_status='ERROR',
|
||||
resource_type='GenericResourceType',
|
||||
resource_action='CREATE',
|
||||
status_reason='just because'))
|
||||
exception.ResourceInError(resource_name='test_resource',
|
||||
resource_status='ERROR',
|
||||
resource_type='GenericResourceType',
|
||||
resource_action='CREATE',
|
||||
status_reason='just because'))
|
||||
self.m.ReplayAll()
|
||||
|
||||
estr = ('ResourceInError: resources.test_resource: '
|
||||
@ -738,26 +738,26 @@ class ResourceTest(common.HeatTestCase):
|
||||
|
||||
# first attempt to create fails
|
||||
generic_rsrc.ResourceWithProps.handle_create().AndRaise(
|
||||
resource.ResourceInError(resource_name='test_resource',
|
||||
resource_status='ERROR',
|
||||
resource_type='GenericResourceType',
|
||||
resource_action='CREATE',
|
||||
status_reason='just because'))
|
||||
exception.ResourceInError(resource_name='test_resource',
|
||||
resource_status='ERROR',
|
||||
resource_type='GenericResourceType',
|
||||
resource_action='CREATE',
|
||||
status_reason='just because'))
|
||||
# first attempt to delete fails
|
||||
generic_rsrc.ResourceWithProps.handle_delete().AndRaise(
|
||||
resource.ResourceInError(resource_name='test_resource',
|
||||
resource_status='ERROR',
|
||||
resource_type='GenericResourceType',
|
||||
resource_action='DELETE',
|
||||
status_reason='delete failed'))
|
||||
exception.ResourceInError(resource_name='test_resource',
|
||||
resource_status='ERROR',
|
||||
resource_type='GenericResourceType',
|
||||
resource_action='DELETE',
|
||||
status_reason='delete failed'))
|
||||
# second attempt to delete fails
|
||||
timeutils.retry_backoff_delay(1, jitter_max=2.0).AndReturn(0.01)
|
||||
generic_rsrc.ResourceWithProps.handle_delete().AndRaise(
|
||||
resource.ResourceInError(resource_name='test_resource',
|
||||
resource_status='ERROR',
|
||||
resource_type='GenericResourceType',
|
||||
resource_action='DELETE',
|
||||
status_reason='delete failed again'))
|
||||
exception.ResourceInError(resource_name='test_resource',
|
||||
resource_status='ERROR',
|
||||
resource_type='GenericResourceType',
|
||||
resource_action='DELETE',
|
||||
status_reason='delete failed again'))
|
||||
|
||||
# third attempt to delete succeeds
|
||||
timeutils.retry_backoff_delay(2, jitter_max=2.0).AndReturn(0.01)
|
||||
@ -783,22 +783,22 @@ class ResourceTest(common.HeatTestCase):
|
||||
|
||||
# first attempt to create fails
|
||||
generic_rsrc.ResourceWithProps.handle_create().AndRaise(
|
||||
resource.ResourceInError(resource_name='test_resource',
|
||||
resource_status='ERROR',
|
||||
resource_type='GenericResourceType',
|
||||
resource_action='CREATE',
|
||||
status_reason='just because'))
|
||||
exception.ResourceInError(resource_name='test_resource',
|
||||
resource_status='ERROR',
|
||||
resource_type='GenericResourceType',
|
||||
resource_action='CREATE',
|
||||
status_reason='just because'))
|
||||
# delete error resource from first attempt
|
||||
generic_rsrc.ResourceWithProps.handle_delete().AndReturn(None)
|
||||
|
||||
# second attempt to create fails
|
||||
timeutils.retry_backoff_delay(1, jitter_max=2.0).AndReturn(0.01)
|
||||
generic_rsrc.ResourceWithProps.handle_create().AndRaise(
|
||||
resource.ResourceInError(resource_name='test_resource',
|
||||
resource_status='ERROR',
|
||||
resource_type='GenericResourceType',
|
||||
resource_action='CREATE',
|
||||
status_reason='just because'))
|
||||
exception.ResourceInError(resource_name='test_resource',
|
||||
resource_status='ERROR',
|
||||
resource_type='GenericResourceType',
|
||||
resource_action='CREATE',
|
||||
status_reason='just because'))
|
||||
# delete error resource from second attempt
|
||||
generic_rsrc.ResourceWithProps.handle_delete().AndReturn(None)
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user