From: Steve Baker Date: Mon, 11 Feb 2013 01:34:32 +0000 (+1300) Subject: Catch 404s when deleting quantum resources. X-Git-Tag: 2014.1~910^2 X-Git-Url: https://review.fuel-infra.org/gitweb?a=commitdiff_plain;h=0104c7ba5c89c5991ed9437e394e050c14ed1291;p=openstack-build%2Fheat-build.git Catch 404s when deleting quantum resources. 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 --- diff --git a/heat/engine/resources/quantum/floatingip.py b/heat/engine/resources/quantum/floatingip.py index c18af1ec..d9edff16 100644 --- a/heat/engine/resources/quantum/floatingip.py +++ b/heat/engine/resources/quantum/floatingip.py @@ -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(): diff --git a/heat/engine/resources/quantum/net.py b/heat/engine/resources/quantum/net.py index 768b6da7..007aff2a 100644 --- a/heat/engine/resources/quantum/net.py +++ b/heat/engine/resources/quantum/net.py @@ -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( diff --git a/heat/engine/resources/quantum/port.py b/heat/engine/resources/quantum/port.py index eba805ee..222d379c 100644 --- a/heat/engine/resources/quantum/port.py +++ b/heat/engine/resources/quantum/port.py @@ -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( diff --git a/heat/engine/resources/quantum/router.py b/heat/engine/resources/quantum/router.py index 9f74d23f..291def42 100644 --- a/heat/engine/resources/quantum/router.py +++ b/heat/engine/resources/quantum/router.py @@ -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(): diff --git a/heat/engine/resources/quantum/subnet.py b/heat/engine/resources/quantum/subnet.py index d6db25b8..90251d7a 100644 --- a/heat/engine/resources/quantum/subnet.py +++ b/heat/engine/resources/quantum/subnet.py @@ -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( diff --git a/heat/engine/resources/vpc.py b/heat/engine/resources/vpc.py index 6ddb7d96..b0d05ffa 100644 --- a/heat/engine/resources/vpc.py +++ b/heat/engine/resources/vpc.py @@ -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