]> review.fuel-infra Code Review - openstack-build/heat-build.git/commitdiff
Catch 404s when deleting quantum resources.
authorSteve Baker <sbaker@redhat.com>
Mon, 11 Feb 2013 01:34:32 +0000 (14:34 +1300)
committerSteve Baker <sbaker@redhat.com>
Mon, 11 Feb 2013 03:36:43 +0000 (16:36 +1300)
Quantum resources are often automatically deleted when their
dependencies are deleted, so resource deletion needs to tolerate
the resource no longer being there.

Change-Id: Id2679a7b72b83f05c1ebac07305ae9a5e5923df9

heat/engine/resources/quantum/floatingip.py
heat/engine/resources/quantum/net.py
heat/engine/resources/quantum/port.py
heat/engine/resources/quantum/router.py
heat/engine/resources/quantum/subnet.py
heat/engine/resources/vpc.py

index c18af1eca608cb1cbbef0dae4853814f56037f0d..d9edff16e666472a647d9fa2a3422a3956097920 100644 (file)
@@ -13,6 +13,8 @@
 #    License for the specific language governing permissions and limitations
 #    under the License.
 
+from quantumclient.common.exceptions import QuantumClientException
+
 from heat.engine import clients
 from heat.openstack.common import log as logging
 from heat.engine.resources.quantum import quantum
@@ -36,7 +38,11 @@ class FloatingIP(quantum.QuantumResource):
 
     def handle_delete(self):
         client = self.quantum()
-        client.delete_floatingip(self.resource_id)
+        try:
+            client.delete_floatingip(self.resource_id)
+        except QuantumClientException as ex:
+            if ex.status_code != 404:
+                raise ex
 
     def FnGetAtt(self, key):
         attributes = self.quantum().show_floatingip(
@@ -66,8 +72,13 @@ class FloatingIPAssociation(quantum.QuantumResource):
     def handle_delete(self):
         client = self.quantum()
         (floatingip_id, port_id) = self.resource_id.split(':')
-        client.update_floatingip(floatingip_id,
-                                 {'floatingip': {'port_id': None}})
+        try:
+            client.update_floatingip(
+                floatingip_id,
+                {'floatingip': {'port_id': None}})
+        except QuantumClientException as ex:
+            if ex.status_code != 404:
+                raise ex
 
 
 def resource_mapping():
index 768b6da7192cc7856917bb86b19045a1773fcfed..007aff2a8a4028b0bd2e22ba59cf068287ac201e 100644 (file)
@@ -13,6 +13,8 @@
 #    License for the specific language governing permissions and limitations
 #    under the License.
 
+from quantumclient.common.exceptions import QuantumClientException
+
 from heat.engine import clients
 from heat.openstack.common import log as logging
 from heat.engine.resources.quantum import quantum
@@ -37,7 +39,11 @@ class Net(quantum.QuantumResource):
 
     def handle_delete(self):
         client = self.quantum()
-        client.delete_network(self.resource_id)
+        try:
+            client.delete_network(self.resource_id)
+        except QuantumClientException as ex:
+            if ex.status_code != 404:
+                raise ex
 
     def FnGetAtt(self, key):
         attributes = self.quantum().show_network(
index eba805eea07b49439c48cfb13a1be0a988aa2241..222d379c106d411087c342a67f63400157123cbc 100644 (file)
@@ -13,6 +13,8 @@
 #    License for the specific language governing permissions and limitations
 #    under the License.
 
+from quantumclient.common.exceptions import QuantumClientException
+
 from heat.engine import clients
 from heat.openstack.common import log as logging
 from heat.engine.resources.quantum import quantum
@@ -50,7 +52,11 @@ class Port(quantum.QuantumResource):
 
     def handle_delete(self):
         client = self.quantum()
-        client.delete_port(self.resource_id)
+        try:
+            client.delete_port(self.resource_id)
+        except QuantumClientException as ex:
+            if ex.status_code != 404:
+                raise ex
 
     def FnGetAtt(self, key):
         attributes = self.quantum().show_port(
index 9f74d23f69e8855fdb517a2dc3cdb57fbae9f077..291def422575d068a6113b5ae7b170903d1054b2 100644 (file)
@@ -13,6 +13,8 @@
 #    License for the specific language governing permissions and limitations
 #    under the License.
 
+from quantumclient.common.exceptions import QuantumClientException
+
 from heat.engine import clients
 from heat.engine.resources.quantum import quantum
 
@@ -38,7 +40,11 @@ class Router(quantum.QuantumResource):
 
     def handle_delete(self):
         client = self.quantum()
-        client.delete_router(self.resource_id)
+        try:
+            client.delete_router(self.resource_id)
+        except QuantumClientException as ex:
+            if ex.status_code != 404:
+                raise ex
 
     def FnGetAtt(self, key):
         attributes = self.quantum().show_router(
@@ -58,15 +64,21 @@ class RouterInterface(quantum.QuantumResource):
     def handle_create(self):
         router_id = self.properties.get('router_id')
         subnet_id = self.properties.get('subnet_id')
-        self.quantum().add_interface_router(router_id,
-                                            {'subnet_id': subnet_id})
+        self.quantum().add_interface_router(
+            router_id,
+            {'subnet_id': subnet_id})
         self.resource_id_set('%s:%s' % (router_id, subnet_id))
 
     def handle_delete(self):
         client = self.quantum()
         (router_id, subnet_id) = self.resource_id.split(':')
-        client.remove_interface_router(router_id,
-                                       {'subnet_id': subnet_id})
+        try:
+            client.remove_interface_router(
+                router_id,
+                {'subnet_id': subnet_id})
+        except QuantumClientException as ex:
+            if ex.status_code != 404:
+                raise ex
 
 
 class RouterGateway(quantum.QuantumResource):
@@ -81,14 +93,19 @@ class RouterGateway(quantum.QuantumResource):
     def handle_create(self):
         router_id = self.properties.get('router_id')
         network_id = self.properties.get('network_id')
-        self.quantum().add_gateway_router(router_id,
-                                          {'network_id': network_id})
+        self.quantum().add_gateway_router(
+            router_id,
+            {'network_id': network_id})
         self.resource_id_set('%s:%s' % (router_id, network_id))
 
     def handle_delete(self):
         client = self.quantum()
         (router_id, network_id) = self.resource_id.split(':')
-        client.remove_gateway_router(router_id)
+        try:
+            client.remove_gateway_router(router_id)
+        except QuantumClientException as ex:
+            if ex.status_code != 404:
+                raise ex
 
 
 def resource_mapping():
index d6db25b85e72dcc3b7df38bc7bd2c6327aaad96d..90251d7acf1666f687284217d5b8be25ee3713ef 100644 (file)
@@ -13,6 +13,8 @@
 #    License for the specific language governing permissions and limitations
 #    under the License.
 
+from quantumclient.common.exceptions import QuantumClientException
+
 from heat.engine import clients
 from heat.openstack.common import log as logging
 from heat.engine.resources.quantum import quantum
@@ -56,7 +58,11 @@ class Subnet(quantum.QuantumResource):
 
     def handle_delete(self):
         client = self.quantum()
-        client.delete_subnet(self.resource_id)
+        try:
+            client.delete_subnet(self.resource_id)
+        except QuantumClientException as ex:
+            if ex.status_code != 404:
+                raise ex
 
     def FnGetAtt(self, key):
         attributes = self.quantum().show_subnet(
index 6ddb7d9650f3d5932942320220ece7ad31b30dfc..b0d05ffa73455b576b904257c59a95c5412dc938 100644 (file)
@@ -13,6 +13,8 @@
 #    License for the specific language governing permissions and limitations
 #    under the License.
 
+from quantumclient.common.exceptions import QuantumClientException
+
 from heat.openstack.common import log as logging
 from heat.engine import resource
 
@@ -42,8 +44,17 @@ class VPC(resource.Resource):
     def handle_delete(self):
         client = self.quantum()
         (network_id, router_id) = self.resource_id.split(':')
-        client.delete_router(router_id)
-        client.delete_network(network_id)
+        try:
+            client.delete_router(router_id)
+        except QuantumClientException as ex:
+            if ex.status_code != 404:
+                raise ex
+
+        try:
+            client.delete_network(network_id)
+        except QuantumClientException as ex:
+            if ex.status_code != 404:
+                raise ex
 
     def handle_update(self, json_snippet):
         return self.UPDATE_REPLACE