diff --git a/contrib/heat_docker/heat_docker/resources/docker_container.py b/contrib/heat_docker/heat_docker/resources/docker_container.py index 9a9038dd48..ad830ebac8 100644 --- a/contrib/heat_docker/heat_docker/resources/docker_container.py +++ b/contrib/heat_docker/heat_docker/resources/docker_container.py @@ -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): diff --git a/contrib/heat_docker/heat_docker/tests/test_docker_container.py b/contrib/heat_docker/heat_docker/tests/test_docker_container.py index 2dd5218776..37748ae536 100644 --- a/contrib/heat_docker/heat_docker/tests/test_docker_container.py +++ b/contrib/heat_docker/heat_docker/tests/test_docker_container.py @@ -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)) diff --git a/heat/common/exception.py b/heat/common/exception.py index 9cd163dbe9..5b0f7bac7b 100644 --- a/heat/common/exception.py +++ b/heat/common/exception.py @@ -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. diff --git a/heat/engine/clients/os/nova.py b/heat/engine/clients/os/nova.py index c08161f80d..baf9bd0e6b 100644 --- a/heat/engine/clients/os/nova.py +++ b/heat/engine/clients/os/nova.py @@ -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): diff --git a/heat/engine/resource.py b/heat/engine/resource.py index 19fbeb4b60..6343cbfd98 100644 --- a/heat/engine/resource.py +++ b/heat/engine/resource.py @@ -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 diff --git a/heat/engine/resources/openstack/heat/remote_stack.py b/heat/engine/resources/openstack/heat/remote_stack.py index 9e378621d6..0fbdfe2d5b 100644 --- a/heat/engine/resources/openstack/heat/remote_stack.py +++ b/heat/engine/resources/openstack/heat/remote_stack.py @@ -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: diff --git a/heat/engine/resources/openstack/manila/share.py b/heat/engine/resources/openstack/manila/share.py index 8fb4b75ea8..b35fb05ba4 100644 --- a/heat/engine/resources/openstack/manila/share.py +++ b/heat/engine/resources/openstack/manila/share.py @@ -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), diff --git a/heat/engine/resources/openstack/neutron/loadbalancer.py b/heat/engine/resources/openstack/neutron/loadbalancer.py index dffad21de6..6bf9a60257 100644 --- a/heat/engine/resources/openstack/neutron/loadbalancer.py +++ b/heat/engine/resources/openstack/neutron/loadbalancer.py @@ -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: diff --git a/heat/engine/resources/openstack/neutron/neutron.py b/heat/engine/resources/openstack/neutron/neutron.py index 79aaca7bda..2394a4b749 100644 --- a/heat/engine/resources/openstack/neutron/neutron.py +++ b/heat/engine/resources/openstack/neutron/neutron.py @@ -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( diff --git a/heat/engine/resources/openstack/sahara/sahara_cluster.py b/heat/engine/resources/openstack/sahara/sahara_cluster.py index 20b6c77b25..766bac924a 100644 --- a/heat/engine/resources/openstack/sahara/sahara_cluster.py +++ b/heat/engine/resources/openstack/sahara/sahara_cluster.py @@ -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 diff --git a/heat/engine/resources/openstack/trove/os_database.py b/heat/engine/resources/openstack/trove/os_database.py index 156dfa35b0..1ae5dc293d 100644 --- a/heat/engine/resources/openstack/trove/os_database.py +++ b/heat/engine/resources/openstack/trove/os_database.py @@ -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"))) diff --git a/heat/engine/resources/openstack/trove/trove_cluster.py b/heat/engine/resources/openstack/trove/trove_cluster.py index 2cb3b974f3..bf80cfb22c 100644 --- a/heat/engine/resources/openstack/trove/trove_cluster.py +++ b/heat/engine/resources/openstack/trove/trove_cluster.py @@ -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"))) diff --git a/heat/engine/resources/volume_base.py b/heat/engine/resources/volume_base.py index cf21dc4089..a835a24f06 100644 --- a/heat/engine/resources/volume_base.py +++ b/heat/engine/resources/volume_base.py @@ -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( diff --git a/heat/tests/aws/test_instance.py b/heat/tests/aws/test_instance.py index d07b14510c..66876524c9 100644 --- a/heat/tests/aws/test_instance.py +++ b/heat/tests/aws/test_instance.py @@ -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"', diff --git a/heat/tests/clients/test_nova_client.py b/heat/tests/clients/test_nova_client.py index c0f95be9f0..e83fc50b31 100644 --- a/heat/tests/clients/test_nova_client.py +++ b/heat/tests/clients/test_nova_client.py @@ -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)) diff --git a/heat/tests/manila/test_manila_share.py b/heat/tests/manila/test_manila_share.py index 4554b64ec0..a5527076d7 100644 --- a/heat/tests/manila/test_manila_share.py +++ b/heat/tests/manila/test_manila_share.py @@ -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)) diff --git a/heat/tests/neutron/test_neutron.py b/heat/tests/neutron/test_neutron.py index 9623f643b6..77694e6d60 100644 --- a/heat/tests/neutron/test_neutron.py +++ b/heat/tests/neutron/test_neutron.py @@ -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"', diff --git a/heat/tests/nova/test_server.py b/heat/tests/nova/test_server.py index 78dfddd188..ce06fbb07a 100644 --- a/heat/tests/nova/test_server.py +++ b/heat/tests/nova/test_server.py @@ -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( diff --git a/heat/tests/test_os_database.py b/heat/tests/test_os_database.py index a6ea7cd235..64462f94a3 100644 --- a/heat/tests/test_os_database.py +++ b/heat/tests/test_os_database.py @@ -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)) diff --git a/heat/tests/test_resource.py b/heat/tests/test_resource.py index 93eafc788b..f668e70966 100644 --- a/heat/tests/test_resource.py +++ b/heat/tests/test_resource.py @@ -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)