From 8197900238b69a3f707ba9cc5b8cb4315649252a Mon Sep 17 00:00:00 2001 From: Vijendar Komalla Date: Wed, 21 Aug 2013 08:55:43 -0500 Subject: [PATCH] Handling re-delete in rackspace db resource Current implementation of db resource throws exception if the resource was already deleted(All the other resources are not throwing). This fix is to make db resource behavior similar to other resources. Fixes Bug #1197077 Change-Id: I4537180115400e6f6183e72a74bdd3ada220a3fa --- .../resources/rackspace/clouddatabase.py | 18 +++++++++++++----- heat/tests/test_clouddatabase.py | 3 +-- 2 files changed, 14 insertions(+), 7 deletions(-) diff --git a/heat/engine/resources/rackspace/clouddatabase.py b/heat/engine/resources/rackspace/clouddatabase.py index ef344b92..f17cd701 100644 --- a/heat/engine/resources/rackspace/clouddatabase.py +++ b/heat/engine/resources/rackspace/clouddatabase.py @@ -13,6 +13,13 @@ # License for the specific language governing permissions and limitations # under the License. +try: + from pyrax.exceptions import NotFound +except ImportError: + # fake exception for testing without pyrax + class NotFound(Exception): + pass + from heat.common import exception from heat.engine.resources.rackspace import rackspace_resource from heat.openstack.common import log as logging @@ -174,12 +181,13 @@ class CloudDBInstance(rackspace_resource.RackspaceResource): Delete a Rackspace Cloud DB Instance. ''' logger.debug("CloudDBInstance handle_delete called.") - sqlinstancename = self.properties['InstanceName'] if self.resource_id is None: - logger.debug("resource_id is null and returning without delete.") - raise exception.ResourceNotFound(resource_name=sqlinstancename, - stack_name=self.stack.name) - instances = self.cloud_db().delete(self.resource_id) + return + + try: + instances = self.cloud_db().delete(self.resource_id) + except NotFound: + pass self.resource_id = None def validate(self): diff --git a/heat/tests/test_clouddatabase.py b/heat/tests/test_clouddatabase.py index 48218914..365be7ba 100644 --- a/heat/tests/test_clouddatabase.py +++ b/heat/tests/test_clouddatabase.py @@ -13,7 +13,6 @@ # under the License. -from heat.common import exception from heat.common import template_format from heat.engine import parser from heat.engine import environment @@ -142,7 +141,7 @@ class CloudDBInstanceTest(HeatTestCase): instance = self._setup_test_clouddbinstance('dbinstance_delete') instance.resource_id = None self.m.ReplayAll() - self.assertRaises(exception.ResourceNotFound, instance.handle_delete) + instance.handle_delete() self.m.VerifyAll() def test_attribute_not_found(self): -- 2.45.2