From 232fe4ae02fbad2ad57e925a76cb5323f6a452d1 Mon Sep 17 00:00:00 2001 From: huangtianhua Date: Wed, 3 Jun 2015 10:20:19 +0800 Subject: [PATCH] Use EntityNotFound instead of ServerNotFound This patch will use EntityNotFound instead of ServerNotFound. And will remove ServerNotFound exception class definition. Change-Id: I5a5aba82d57056893d5d7e644448cbd3de632ea5 Closes-Bug: #1461343 --- heat/common/exception.py | 4 ---- heat/engine/clients/os/nova.py | 4 ++-- heat/tests/autoscaling/test_launch_config.py | 5 +++-- heat/tests/autoscaling/test_scaling_group.py | 6 +++--- heat/tests/test_nova_client.py | 6 +++--- 5 files changed, 11 insertions(+), 14 deletions(-) diff --git a/heat/common/exception.py b/heat/common/exception.py index 1708484f02..6c5e2c2402 100644 --- a/heat/common/exception.py +++ b/heat/common/exception.py @@ -231,10 +231,6 @@ class EntityNotFound(HeatException): msg_fmt = _("The %(entity)s (%(name)s) could not be found.") -class ServerNotFound(HeatException): - msg_fmt = _("The server (%(server)s) could not be found.") - - class VolumeNotFound(HeatException): msg_fmt = _("The Volume (%(volume)s) could not be found.") diff --git a/heat/engine/clients/os/nova.py b/heat/engine/clients/os/nova.py index 532ed2e315..96033383c7 100644 --- a/heat/engine/clients/os/nova.py +++ b/heat/engine/clients/os/nova.py @@ -425,7 +425,7 @@ echo -e '%s\tALL=(ALL)\tNOPASSWD: ALL' >> /etc/sudoers except exceptions.NotFound as ex: LOG.warn(_LW('Server (%(server)s) not found: %(ex)s'), {'server': server, 'ex': ex}) - raise exception.ServerNotFound(server=server) + raise exception.EntityNotFound(entity='Server', name=server) def absolute_limits(self): """Return the absolute limits as a dictionary.""" @@ -545,7 +545,7 @@ echo -e '%s\tALL=(ALL)\tNOPASSWD: ALL' >> /etc/sudoers class ServerConstraint(constraints.BaseCustomConstraint): - expected_exceptions = (exception.ServerNotFound,) + expected_exceptions = (exception.EntityNotFound,) def validate_with_client(self, client, server): client.client_plugin('nova').get_server(server) diff --git a/heat/tests/autoscaling/test_launch_config.py b/heat/tests/autoscaling/test_launch_config.py index be298eb09f..58f7d59018 100644 --- a/heat/tests/autoscaling/test_launch_config.py +++ b/heat/tests/autoscaling/test_launch_config.py @@ -132,10 +132,11 @@ class LaunchConfigurationTest(common.HeatTestCase): rsrc = stack['LaunchConfig'] self.patchobject(nova.NovaClientPlugin, 'get_server', - side_effect=exception.ServerNotFound(server='5678')) + side_effect=exception.EntityNotFound( + entity='Server', name='5678')) msg = ("Property error : " "Resources.LaunchConfig.Properties.InstanceId: " - "Error validating value '5678': The server (5678) " + "Error validating value '5678': The Server (5678) " "could not be found.") exc = self.assertRaises(exception.StackValidationFailed, rsrc.validate) diff --git a/heat/tests/autoscaling/test_scaling_group.py b/heat/tests/autoscaling/test_scaling_group.py index 37d8784a1d..3351e72c03 100644 --- a/heat/tests/autoscaling/test_scaling_group.py +++ b/heat/tests/autoscaling/test_scaling_group.py @@ -183,8 +183,8 @@ class TestAutoScalingGroupValidation(common.HeatTestCase): mock_server.security_groups = [{u'name': u'hth_test'}] if not_found: self.patchobject(nova.NovaClientPlugin, 'get_server', - side_effect=exception.ServerNotFound( - server='5678')) + side_effect=exception.EntityNotFound( + entity='Server', name='5678')) else: self.patchobject(nova.NovaClientPlugin, 'get_server', return_value=mock_server) @@ -222,7 +222,7 @@ class TestAutoScalingGroupValidation(common.HeatTestCase): self.m.ReplayAll() msg = ("Property error : " "Resources.WebServerGroup.Properties.InstanceId: " - "Error validating value '5678': The server (5678) could " + "Error validating value '5678': The Server (5678) could " "not be found.") exc = self.assertRaises(exception.StackValidationFailed, rsrc.validate) diff --git a/heat/tests/test_nova_client.py b/heat/tests/test_nova_client.py index 682fe8aa39..359277eb58 100644 --- a/heat/tests/test_nova_client.py +++ b/heat/tests/test_nova_client.py @@ -103,7 +103,7 @@ class NovaClientPluginTests(NovaClientPluginTestCase): self.nova_client.servers.get.side_effect = [ my_server, nova_exceptions.NotFound(404)] self.assertEqual(my_server, self.nova_plugin.get_server('my_server')) - self.assertRaises(exception.ServerNotFound, + self.assertRaises(exception.EntityNotFound, self.nova_plugin.get_server, 'idontexist') calls = [mock.call('my_server'), mock.call('idontexist')] @@ -319,8 +319,8 @@ class ServerConstraintTest(common.HeatTestCase): self.assertTrue(self.constraint.validate("foo", self.ctx)) def test_validation_error(self): - self.mock_get_server.side_effect = exception.ServerNotFound( - server='bar') + self.mock_get_server.side_effect = exception.EntityNotFound( + entity='Server', name='bar') self.assertFalse(self.constraint.validate("bar", self.ctx))