Neutron use ClientPlugin.ignore_not_found etc

Change-Id: Ie1e75ac1537a8c0d800e4e381eac9f866576bb9d
This commit is contained in:
Steve Baker 2014-06-17 17:25:26 +12:00 committed by Randall Burt
parent 98003258a8
commit 93c8dc9b54
25 changed files with 187 additions and 244 deletions

View File

@ -16,8 +16,6 @@ from heat.common import exception
from heat.engine import properties
from heat.engine.resources.neutron import neutron
from neutronclient.common.exceptions import NeutronClientException
class ExtraRoute(neutron.NeutronResource):
@ -90,8 +88,8 @@ class ExtraRoute(neutron.NeutronResource):
return
self.neutron().update_router(router_id, {'router':
{'routes': routes}})
except NeutronClientException as ex:
self._handle_not_found_exception(ex)
except Exception as ex:
self.client_plugin().ignore_not_found(ex)
def resource_mapping():

View File

@ -21,8 +21,6 @@ from heat.openstack.common import excutils
from heat.openstack.common.gettextutils import _
from heat.openstack.common import log as logging
from neutronclient.common.exceptions import NeutronClientException
LOG = logging.getLogger(__name__)
@ -71,9 +69,9 @@ class ElasticIp(resource.Resource):
if self.properties[self.DOMAIN]:
try:
ips = self.neutron().show_floatingip(self.resource_id)
except NeutronClientException as e:
if e.status_code == 404:
LOG.warn(_("Floating IPs not found: %s") % e)
except Exception as ex:
self.client_plugin('neutron').ignore_not_found(ex)
LOG.warn(_("Floating IPs not found"))
else:
self.ipaddress = ips['floatingip']['floating_ip_address']
else:
@ -134,9 +132,8 @@ class ElasticIp(resource.Resource):
if self.properties[self.DOMAIN]:
try:
self.neutron().delete_floatingip(self.resource_id)
except NeutronClientException as e:
if e.status_code != 404:
raise e
except Exception as ex:
self.client_plugin('neutron').ignore_not_found(ex)
else:
try:
self.nova().floating_ips.delete(self.resource_id)
@ -249,9 +246,8 @@ class ElasticIpAssociation(resource.Resource):
try:
self.neutron().update_floatingip(
float_id, {'floatingip': {'port_id': None}})
except NeutronClientException as e:
if e.status_code != 404:
raise e
except Exception as ex:
self.client_plugin('neutron').ignore_not_found(ex)
def resource_mapping():

View File

@ -97,6 +97,8 @@ class VPCGatewayAttachment(resource.Resource):
),
}
default_client_name = 'neutron'
def _vpc_route_tables(self):
for resource in self.stack.itervalues():
if (resource.has_interface('AWS::EC2::RouteTable') and
@ -121,15 +123,12 @@ class VPCGatewayAttachment(resource.Resource):
'network_id': external_network_id})
def handle_delete(self):
from neutronclient.common.exceptions import NeutronClientException
client = self.neutron()
for router in self._vpc_route_tables():
try:
client.remove_gateway_router(router.resource_id)
except NeutronClientException as ex:
if ex.status_code != 404:
raise ex
except Exception as ex:
self.client_plugin().ignore_not_found(ex)
def resource_mapping():

View File

@ -11,8 +11,6 @@
# License for the specific language governing permissions and limitations
# under the License.
from neutronclient.common.exceptions import NeutronClientException
from heat.engine import attributes
from heat.engine import properties
from heat.engine import resource
@ -90,6 +88,8 @@ class NetworkInterface(resource.Resource):
),
}
default_client_name = 'neutron'
@staticmethod
def network_id_from_subnet_id(neutronclient, subnet_id):
subnet_info = neutronclient.show_subnet(subnet_id)
@ -127,9 +127,8 @@ class NetworkInterface(resource.Resource):
client = self.neutron()
try:
client.delete_port(self.resource_id)
except NeutronClientException as ex:
if ex.status_code != 404:
raise ex
except Exception as ex:
self.client_plugin().ignore_not_found(ex)
def _get_fixed_ip_address(self, ):
if self.fixed_ip_address is None:
@ -138,9 +137,8 @@ class NetworkInterface(resource.Resource):
port = client.show_port(self.resource_id)['port']
if port['fixed_ips'] and len(port['fixed_ips']) > 0:
self.fixed_ip_address = port['fixed_ips'][0]['ip_address']
except NeutronClientException as ex:
if ex.status_code != 404:
raise ex
except Exception as ex:
self.client_plugin().ignore_not_found(ex)
return self.fixed_ip_address

View File

@ -16,8 +16,6 @@ from heat.engine import constraints
from heat.engine import properties
from heat.engine.resources.neutron import neutron
from neutronclient.common.exceptions import NeutronClientException
class Firewall(neutron.NeutronResource):
"""
@ -111,8 +109,8 @@ class Firewall(neutron.NeutronResource):
client = self.neutron()
try:
client.delete_firewall(self.resource_id)
except NeutronClientException as ex:
self._handle_not_found_exception(ex)
except Exception as ex:
self.client_plugin().ignore_not_found(ex)
else:
return self._delete_task()
@ -213,8 +211,8 @@ class FirewallPolicy(neutron.NeutronResource):
client = self.neutron()
try:
client.delete_firewall_policy(self.resource_id)
except NeutronClientException as ex:
self._handle_not_found_exception(ex)
except Exception as ex:
self.client_plugin().ignore_not_found(ex)
else:
return self._delete_task()
@ -384,8 +382,8 @@ class FirewallRule(neutron.NeutronResource):
client = self.neutron()
try:
client.delete_firewall_rule(self.resource_id)
except NeutronClientException as ex:
self._handle_not_found_exception(ex)
except Exception as ex:
self.client_plugin().ignore_not_found(ex)
else:
return self._delete_task()

View File

@ -18,8 +18,6 @@ from heat.engine.resources.neutron import neutron_utils
from heat.engine.resources.neutron import router
from heat.engine import support
from neutronclient.common.exceptions import NeutronClientException
class FloatingIP(neutron.NeutronResource):
PROPERTIES = (
@ -132,8 +130,8 @@ class FloatingIP(neutron.NeutronResource):
client = self.neutron()
try:
client.delete_floatingip(self.resource_id)
except NeutronClientException as ex:
self._handle_not_found_exception(ex)
except Exception as ex:
self.client_plugin().ignore_not_found(ex)
class FloatingIPAssociation(neutron.NeutronResource):
@ -182,8 +180,8 @@ class FloatingIPAssociation(neutron.NeutronResource):
client.update_floatingip(
floatingip_id,
{'floatingip': {'port_id': None}})
except NeutronClientException as ex:
self._handle_not_found_exception(ex)
except Exception as ex:
self.client_plugin().ignore_not_found(ex)
def handle_update(self, json_snippet, tmpl_diff, prop_diff):
if prop_diff:
@ -196,8 +194,8 @@ class FloatingIPAssociation(neutron.NeutronResource):
neutron_client.update_floatingip(
floatingip_id,
{'floatingip': {'port_id': None}})
except NeutronClientException as ex:
self._handle_not_found_exception(ex)
except Exception as ex:
self.client_plugin().ignore_not_found(ex)
# associate the floatingip with the new port
floatingip_id = (prop_diff.get(self.FLOATINGIP_ID) or

View File

@ -22,8 +22,6 @@ from heat.engine.resources import nova_utils
from heat.engine import scheduler
from heat.engine import support
from neutronclient.common.exceptions import NeutronClientException
class HealthMonitor(neutron.NeutronResource):
"""
@ -162,8 +160,8 @@ class HealthMonitor(neutron.NeutronResource):
def handle_delete(self):
try:
self.neutron().delete_health_monitor(self.resource_id)
except NeutronClientException as ex:
self._handle_not_found_exception(ex)
except Exception as ex:
self.client_plugin().ignore_not_found(ex)
else:
return self._delete_task()
@ -463,8 +461,8 @@ class Pool(neutron.NeutronResource):
try:
yield
client.show_vip(self.metadata_get()['vip'])
except NeutronClientException as ex:
self._handle_not_found_exception(ex)
except Exception as ex:
self.client_plugin().ignore_not_found(ex)
break
def handle_delete(self):
@ -472,14 +470,14 @@ class Pool(neutron.NeutronResource):
if self.metadata_get():
try:
self.neutron().delete_vip(self.metadata_get()['vip'])
except NeutronClientException as ex:
self._handle_not_found_exception(ex)
except Exception as ex:
self.client_plugin().ignore_not_found(ex)
else:
checkers.append(scheduler.TaskRunner(self._confirm_vip_delete))
try:
self.neutron().delete_pool(self.resource_id)
except NeutronClientException as ex:
self._handle_not_found_exception(ex)
except Exception as ex:
self.client_plugin().ignore_not_found(ex)
else:
checkers.append(scheduler.TaskRunner(self._confirm_delete))
return checkers
@ -607,8 +605,8 @@ class PoolMember(neutron.NeutronResource):
client = self.neutron()
try:
client.delete_member(self.resource_id)
except NeutronClientException as ex:
self._handle_not_found_exception(ex)
except Exception as ex:
self.client_plugin().ignore_not_found(ex)
else:
return self._delete_task()
@ -644,6 +642,8 @@ class LoadBalancer(resource.Resource):
),
}
default_client_name = 'neutron'
def handle_create(self):
pool = self.properties[self.POOL_ID]
client = self.neutron()
@ -669,9 +669,8 @@ class LoadBalancer(resource.Resource):
member_id = rd_members[member]
try:
client.delete_member(member_id)
except NeutronClientException as ex:
if ex.status_code != 404:
raise ex
except Exception as ex:
self.client_plugin().ignore_not_found(ex)
self.data_delete(member)
pool = self.properties[self.POOL_ID]
nova_client = self.nova()
@ -691,9 +690,8 @@ class LoadBalancer(resource.Resource):
member_id = self.data().get(member)
try:
client.delete_member(member_id)
except NeutronClientException as ex:
if ex.status_code != 404:
raise ex
except Exception as ex:
self.client_plugin().ignore_not_found(ex)
self.data_delete(member)

View File

@ -16,8 +16,6 @@ from heat.engine import constraints
from heat.engine import properties
from heat.engine.resources.neutron import neutron
from neutronclient.common.exceptions import NeutronClientException
class MeteringLabel(neutron.NeutronResource):
"""
@ -73,8 +71,8 @@ class MeteringLabel(neutron.NeutronResource):
def handle_delete(self):
try:
self.neutron().delete_metering_label(self.resource_id)
except NeutronClientException as ex:
self._handle_not_found_exception(ex)
except Exception as ex:
self.client_plugin().ignore_not_found(ex)
else:
return self._delete_task()
@ -159,8 +157,8 @@ class MeteringRule(neutron.NeutronResource):
def handle_delete(self):
try:
self.neutron().delete_metering_label_rule(self.resource_id)
except NeutronClientException as ex:
self._handle_not_found_exception(ex)
except Exception as ex:
self.client_plugin().ignore_not_found(ex)
else:
return self._delete_task()

View File

@ -15,8 +15,6 @@ from heat.engine import attributes
from heat.engine import properties
from heat.engine.resources.neutron import neutron
import neutronclient.common.exceptions as neutron_exp
class Net(neutron.NeutronResource):
PROPERTIES = (
@ -124,8 +122,8 @@ class Net(neutron.NeutronResource):
client = self.neutron()
try:
client.delete_network(self.resource_id)
except neutron_exp.NeutronClientException as ex:
self._handle_not_found_exception(ex)
except Exception as ex:
self.client_plugin().ignore_not_found(ex)
else:
return self._delete_task()
@ -147,12 +145,6 @@ class Net(neutron.NeutronResource):
attributes = self._show_resource()
return self.is_built(attributes)
def _handle_not_found_exception(self, ex):
# raise any exception which is not for a not found network
if not (ex.status_code == 404 or
isinstance(ex, neutron_exp.NetworkNotFoundClient)):
raise ex
def _replace_dhcp_agents(self, dhcp_agent_ids):
ret = self.neutron().list_dhcp_agent_hosting_networks(
self.resource_id)
@ -163,21 +155,22 @@ class Net(neutron.NeutronResource):
try:
self.neutron().add_network_to_dhcp_agent(
dhcp_agent_id, {'network_id': self.resource_id})
except neutron_exp.NeutronClientException as ex:
except Exception as ex:
# if 409 is happened, the agent is already associated.
if ex.status_code != 409:
raise ex
if not self.client_plugin().is_conflict(ex):
raise
for dhcp_agent_id in old - new:
try:
self.neutron().remove_network_from_dhcp_agent(
dhcp_agent_id, self.resource_id)
except neutron_exp.NeutronClientException as ex:
except Exception as ex:
# assume 2 patterns about status_code following:
# 404: the network or agent is already gone
# 409: the network isn't scheduled by the dhcp_agent
if ex.status_code not in (404, 409):
raise ex
if not (self.client_plugin().is_conflict(ex) or
self.client_plugin().is_not_found(ex)):
raise
def resource_mapping():

View File

@ -22,8 +22,6 @@ from heat.engine.resources.neutron import neutron
from heat.engine.resources.neutron import neutron_utils
from heat.engine import support
from neutronclient.common.exceptions import NeutronClientException
class NetworkGateway(neutron.NeutronResource):
'''
@ -199,13 +197,13 @@ class NetworkGateway(neutron.NeutronResource):
client.disconnect_network_gateway(
self.resource_id, connection
)
except NeutronClientException as ex:
self._handle_not_found_exception(ex)
except Exception as ex:
self.client_plugin().ignore_not_found(ex)
try:
client.delete_network_gateway(self.resource_id)
except NeutronClientException as ex:
self._handle_not_found_exception(ex)
except Exception as ex:
self.client_plugin().ignore_not_found(ex)
else:
return self._delete_task()
@ -235,8 +233,8 @@ class NetworkGateway(neutron.NeutronResource):
self.neutron().disconnect_network_gateway(
self.resource_id, connection
)
except NeutronClientException as ex:
self._handle_not_found_exception(ex)
except Exception as ex:
self.client_plugin().ignore_not_found(ex)
for connection in connections:
neutron_utils.resolve_network(
self.neutron(), connection, self.NETWORK, 'network_id')

View File

@ -11,8 +11,6 @@
# License for the specific language governing permissions and limitations
# under the License.
from neutronclient.common.exceptions import NeutronClientException
from heat.common import exception
from heat.engine import resource
from heat.engine import scheduler
@ -24,6 +22,8 @@ LOG = logging.getLogger(__name__)
class NeutronResource(resource.Resource):
default_client_name = 'neutron'
def validate(self):
'''
Validate any of the provided params
@ -117,7 +117,8 @@ class NeutronResource(resource.Resource):
def _resolve_attribute(self, name):
try:
attributes = self._show_resource()
except NeutronClientException as ex:
except Exception as ex:
self.client_plugin().ignore_not_found(ex)
LOG.warn(_("failed to fetch resource attributes: %s") % ex)
return None
if name == 'show':
@ -130,14 +131,10 @@ class NeutronResource(resource.Resource):
try:
yield
self._show_resource()
except NeutronClientException as ex:
self._handle_not_found_exception(ex)
except Exception as ex:
self.client_plugin().ignore_not_found(ex)
return
def _handle_not_found_exception(self, ex):
if ex.status_code != 404:
raise ex
def FnGetRefId(self):
return unicode(self.resource_id)

View File

@ -19,8 +19,6 @@ from heat.engine.resources.neutron import subnet
from heat.engine import support
from heat.openstack.common import log as logging
import neutronclient.common.exceptions as neutron_exp
LOG = logging.getLogger(__name__)
@ -269,17 +267,11 @@ class Port(neutron.NeutronResource):
client = self.neutron()
try:
client.delete_port(self.resource_id)
except neutron_exp.NeutronClientException as ex:
self._handle_not_found_exception(ex)
except Exception as ex:
self.client_plugin().ignore_not_found(ex)
else:
return self._delete_task()
def _handle_not_found_exception(self, ex):
# raise any exception which is not for a not found port
if not (ex.status_code == 404 or
isinstance(ex, neutron_exp.PortNotFoundClient)):
raise ex
def handle_update(self, json_snippet, tmpl_diff, prop_diff):
props = self.prepare_update_properties(json_snippet)

View File

@ -19,8 +19,6 @@ from heat.engine.resources.neutron import neutron_utils
from heat.engine.resources.neutron import subnet
from heat.engine import support
from neutronclient.common.exceptions import NeutronClientException
class Router(neutron.NeutronResource):
@ -163,8 +161,8 @@ class Router(neutron.NeutronResource):
client = self.neutron()
try:
client.delete_router(self.resource_id)
except NeutronClientException as ex:
self._handle_not_found_exception(ex)
except Exception as ex:
self.client_plugin().ignore_not_found(ex)
else:
return self._delete_task()
@ -275,8 +273,8 @@ class RouterInterface(neutron.NeutronResource):
client.remove_interface_router(
router_id,
{key: value})
except NeutronClientException as ex:
self._handle_not_found_exception(ex)
except Exception as ex:
self.client_plugin().ignore_not_found(ex)
class RouterGateway(neutron.NeutronResource):
@ -360,8 +358,8 @@ class RouterGateway(neutron.NeutronResource):
(router_id, network_id) = self.resource_id.split(':')
try:
client.remove_gateway_router(router_id)
except NeutronClientException as ex:
self._handle_not_found_exception(ex)
except Exception as ex:
self.client_plugin().ignore_not_found(ex)
def resource_mapping():

View File

@ -16,8 +16,6 @@ from heat.engine import constraints
from heat.engine import properties
from heat.engine.resources.neutron import neutron
import neutronclient.common.exceptions as neutron_exp
class SecurityGroup(neutron.NeutronResource):
@ -188,24 +186,23 @@ class SecurityGroup(neutron.NeutronResource):
try:
self.neutron().create_security_group_rule(
{'security_group_rule': rule})
except neutron_exp.NeutronClientException as ex:
# ignore error if rule already exists
if ex.status_code != 409:
except Exception as ex:
if not self.client_plugin().is_conflict(ex):
raise
def _delete_rules(self, to_delete=None):
try:
sec = self.neutron().show_security_group(
self.resource_id)['security_group']
except neutron_exp.NeutronClientException as ex:
self._handle_not_found_exception(ex)
except Exception as ex:
self.client_plugin().ignore_not_found(ex)
else:
for rule in sec['security_group_rules']:
if to_delete is None or to_delete(rule):
try:
self.neutron().delete_security_group_rule(rule['id'])
except neutron_exp.NeutronClientException as ex:
self._handle_not_found_exception(ex)
except Exception as ex:
self.client_plugin().ignore_not_found(ex)
def handle_delete(self):
@ -215,8 +212,8 @@ class SecurityGroup(neutron.NeutronResource):
self._delete_rules()
try:
self.neutron().delete_security_group(self.resource_id)
except neutron_exp.NeutronClientException as ex:
self._handle_not_found_exception(ex)
except Exception as ex:
self.client_plugin().ignore_not_found(ex)
self.resource_id_set(None)
def handle_update(self, json_snippet, tmpl_diff, prop_diff):

View File

@ -18,8 +18,6 @@ from heat.engine.resources.neutron import neutron
from heat.engine.resources.neutron import neutron_utils
from heat.engine import support
from neutronclient.common.exceptions import NeutronClientException
class Subnet(neutron.NeutronResource):
@ -217,8 +215,8 @@ class Subnet(neutron.NeutronResource):
client = self.neutron()
try:
client.delete_subnet(self.resource_id)
except NeutronClientException as ex:
self._handle_not_found_exception(ex)
except Exception as ex:
self.client_plugin().ignore_not_found(ex)
else:
return self._delete_task()

View File

@ -18,8 +18,6 @@ from heat.engine.resources.neutron import neutron
from heat.engine.resources.neutron import neutron_utils
from heat.engine import support
from neutronclient.common.exceptions import NeutronClientException
class VPNService(neutron.NeutronResource):
"""
@ -136,8 +134,8 @@ class VPNService(neutron.NeutronResource):
client = self.neutron()
try:
client.delete_vpnservice(self.resource_id)
except NeutronClientException as ex:
self._handle_not_found_exception(ex)
except Exception as ex:
self.client_plugin().ignore_not_found(ex)
else:
return self._delete_task()
@ -358,8 +356,8 @@ class IPsecSiteConnection(neutron.NeutronResource):
client = self.neutron()
try:
client.delete_ipsec_site_connection(self.resource_id)
except NeutronClientException as ex:
self._handle_not_found_exception(ex)
except Exception as ex:
self.client_plugin().ignore_not_found(ex)
else:
return self._delete_task()
@ -518,8 +516,8 @@ class IKEPolicy(neutron.NeutronResource):
client = self.neutron()
try:
client.delete_ikepolicy(self.resource_id)
except NeutronClientException as ex:
self._handle_not_found_exception(ex)
except Exception as ex:
self.client_plugin().ignore_not_found(ex)
else:
return self._delete_task()
@ -680,8 +678,8 @@ class IPsecPolicy(neutron.NeutronResource):
client = self.neutron()
try:
client.delete_ipsecpolicy(self.resource_id)
except NeutronClientException as ex:
self._handle_not_found_exception(ex)
except Exception as ex:
self.client_plugin().ignore_not_found(ex)
else:
return self._delete_task()

View File

@ -16,8 +16,6 @@ from heat.engine import resource
from heat.engine.resources.neutron import neutron
from heat.engine.resources.vpc import VPC
from neutronclient.common.exceptions import NeutronClientException
class RouteTable(resource.Resource):
@ -89,16 +87,14 @@ class RouteTable(resource.Resource):
router_id = self.resource_id
try:
client.delete_router(router_id)
except NeutronClientException as ex:
if ex.status_code != 404:
raise ex
except Exception as ex:
self.client_plugin('neutron').ignore_not_found(ex)
# just in case this router has been added to a gateway, remove it
try:
client.remove_gateway_router(router_id)
except NeutronClientException as ex:
if ex.status_code != 404:
raise ex
except Exception as ex:
self.client_plugin('neutron').ignore_not_found(ex)
class SubnetRouteTableAssociation(resource.Resource):
@ -135,9 +131,8 @@ class SubnetRouteTableAssociation(resource.Resource):
client.remove_interface_router(
previous_router['id'],
{'subnet_id': subnet_id})
except NeutronClientException as ex:
if ex.status_code != 404:
raise ex
except Exception as ex:
self.client_plugin('neutron').ignore_not_found(ex)
client.add_interface_router(
router_id, {'subnet_id': subnet_id})
@ -158,9 +153,8 @@ class SubnetRouteTableAssociation(resource.Resource):
try:
client.remove_interface_router(router_id, {
'subnet_id': subnet_id})
except NeutronClientException as ex:
if ex.status_code != 404:
raise ex
except Exception as ex:
self.client_plugin('neutron').ignore_not_found(ex)
# add back the default router
try:
@ -168,9 +162,8 @@ class SubnetRouteTableAssociation(resource.Resource):
if default_router:
client.add_interface_router(
default_router['id'], {'subnet_id': subnet_id})
except NeutronClientException as ex:
if ex.status_code != 404:
raise ex
except Exception as ex:
self.client_plugin('neutron').ignore_not_found(ex)
def resource_mapping():

View File

@ -111,7 +111,6 @@ class SecurityGroup(resource.Resource):
}
def _handle_create_neutron(self):
from neutronclient.common.exceptions import NeutronClientException
client = self.neutron()
sec = client.create_security_group({'security_group': {
@ -140,8 +139,8 @@ class SecurityGroup(resource.Resource):
'security_group_rule':
self._convert_to_neutron_rule('ingress', i)
})
except NeutronClientException as ex:
if ex.status_code == 409:
except Exception as ex:
if self.client_plugin('neutron').is_conflict(ex):
# no worries, the rule is already there
pass
else:
@ -160,8 +159,8 @@ class SecurityGroup(resource.Resource):
'security_group_rule':
self._convert_to_neutron_rule('egress', i)
})
except NeutronClientException as ex:
if ex.status_code == 409:
except Exception as ex:
if self.client_plugin('neutron').is_conflict(ex):
# no worries, the rule is already there
pass
else:
@ -237,29 +236,25 @@ class SecurityGroup(resource.Resource):
self.resource_id_set(None)
def _handle_delete_neutron(self):
from neutronclient.common.exceptions import NeutronClientException
client = self.neutron()
if self.resource_id is not None:
try:
sec = client.show_security_group(
self.resource_id)['security_group']
except NeutronClientException as ex:
if ex.status_code != 404:
raise
except Exception as ex:
self.client_plugin('neutron').ignore_not_found(ex)
else:
for rule in sec['security_group_rules']:
try:
client.delete_security_group_rule(rule['id'])
except NeutronClientException as ex:
if ex.status_code != 404:
raise
except Exception as ex:
self.client_plugin('neutron').ignore_not_found(ex)
try:
client.delete_security_group(self.resource_id)
except NeutronClientException as ex:
if ex.status_code != 404:
raise
except Exception as ex:
self.client_plugin('neutron').ignore_not_found(ex)
self.resource_id_set(None)
def FnGetRefId(self):

View File

@ -77,6 +77,8 @@ class Subnet(resource.Resource):
),
}
default_client_name = 'neutron'
def handle_create(self):
client = self.neutron()
# TODO(sbaker) Verify that this CidrBlock is within the vpc CidrBlock
@ -98,8 +100,6 @@ class Subnet(resource.Resource):
self.resource_id_set(subnet['id'])
def handle_delete(self):
from neutronclient.common.exceptions import NeutronClientException
client = self.neutron()
network_id = self.properties.get(self.VPC_ID)
subnet_id = self.resource_id
@ -110,15 +110,13 @@ class Subnet(resource.Resource):
client.remove_interface_router(
router['id'],
{'subnet_id': subnet_id})
except NeutronClientException as ex:
if ex.status_code != 404:
raise ex
except Exception as ex:
self.client_plugin().ignore_not_found(ex)
try:
client.delete_subnet(subnet_id)
except NeutronClientException as ex:
if ex.status_code != 404:
raise ex
except Exception as ex:
self.client_plugin().ignore_not_found(ex)
def _resolve_attribute(self, name):
if name == self.AVAILABILITY_ZONE:

View File

@ -69,6 +69,8 @@ class VPC(resource.Resource):
),
}
default_client_name = 'neutron'
def handle_create(self):
client = self.neutron()
# The VPC's net and router are associated by having identical names.
@ -107,20 +109,17 @@ class VPC(resource.Resource):
return neutron.NeutronResource.is_built(router)
def handle_delete(self):
from neutronclient.common.exceptions import NeutronClientException
client = self.neutron()
router = self.router_for_vpc(client, self.resource_id)
try:
client.delete_router(router['id'])
except NeutronClientException as ex:
if ex.status_code != 404:
raise ex
except Exception as ex:
self.client_plugin().ignore_not_found(ex)
try:
client.delete_network(self.resource_id)
except NeutronClientException as ex:
if ex.status_code != 404:
raise ex
except Exception as ex:
self.client_plugin().ignore_not_found(ex)
def resource_mapping():

View File

@ -14,6 +14,7 @@
import copy
import six
from neutronclient.common import exceptions
from neutronclient.v2_0 import client as neutronclient
from heat.common import exception
@ -118,7 +119,7 @@ class FirewallTest(HeatTestCase):
'firewall': {
'name': 'test-firewall', 'admin_state_up': True,
'firewall_policy_id': 'policy-id'}}
).AndRaise(firewall.NeutronClientException())
).AndRaise(exceptions.NeutronClientException())
self.m.ReplayAll()
snippet = template_format.parse(firewall_template)
@ -138,7 +139,7 @@ class FirewallTest(HeatTestCase):
def test_delete(self):
neutronclient.Client.delete_firewall('5678')
neutronclient.Client.show_firewall('5678').AndRaise(
firewall.NeutronClientException(status_code=404))
exceptions.NeutronClientException(status_code=404))
rsrc = self.create_firewall()
self.m.ReplayAll()
@ -149,7 +150,7 @@ class FirewallTest(HeatTestCase):
def test_delete_already_gone(self):
neutronclient.Client.delete_firewall('5678').AndRaise(
firewall.NeutronClientException(status_code=404))
exceptions.NeutronClientException(status_code=404))
rsrc = self.create_firewall()
self.m.ReplayAll()
@ -160,7 +161,7 @@ class FirewallTest(HeatTestCase):
def test_delete_failed(self):
neutronclient.Client.delete_firewall('5678').AndRaise(
firewall.NeutronClientException(status_code=400))
exceptions.NeutronClientException(status_code=400))
rsrc = self.create_firewall()
self.m.ReplayAll()
@ -245,7 +246,7 @@ class FirewallPolicyTest(HeatTestCase):
'firewall_policy': {
'name': 'test-firewall-policy', 'shared': True,
'audited': True, 'firewall_rules': ['rule-id-1', 'rule-id-2']}}
).AndRaise(firewall.NeutronClientException())
).AndRaise(exceptions.NeutronClientException())
self.m.ReplayAll()
snippet = template_format.parse(firewall_policy_template)
@ -265,7 +266,7 @@ class FirewallPolicyTest(HeatTestCase):
def test_delete(self):
neutronclient.Client.delete_firewall_policy('5678')
neutronclient.Client.show_firewall_policy('5678').AndRaise(
firewall.NeutronClientException(status_code=404))
exceptions.NeutronClientException(status_code=404))
rsrc = self.create_firewall_policy()
self.m.ReplayAll()
@ -276,7 +277,7 @@ class FirewallPolicyTest(HeatTestCase):
def test_delete_already_gone(self):
neutronclient.Client.delete_firewall_policy('5678').AndRaise(
firewall.NeutronClientException(status_code=404))
exceptions.NeutronClientException(status_code=404))
rsrc = self.create_firewall_policy()
self.m.ReplayAll()
@ -287,7 +288,7 @@ class FirewallPolicyTest(HeatTestCase):
def test_delete_failed(self):
neutronclient.Client.delete_firewall_policy('5678').AndRaise(
firewall.NeutronClientException(status_code=400))
exceptions.NeutronClientException(status_code=400))
rsrc = self.create_firewall_policy()
self.m.ReplayAll()
@ -373,7 +374,7 @@ class FirewallRuleTest(HeatTestCase):
'name': 'test-firewall-rule', 'shared': True,
'action': 'allow', 'protocol': 'tcp', 'enabled': True,
'ip_version': "4"}}
).AndRaise(firewall.NeutronClientException())
).AndRaise(exceptions.NeutronClientException())
self.m.ReplayAll()
snippet = template_format.parse(firewall_rule_template)
@ -393,7 +394,7 @@ class FirewallRuleTest(HeatTestCase):
def test_delete(self):
neutronclient.Client.delete_firewall_rule('5678')
neutronclient.Client.show_firewall_rule('5678').AndRaise(
firewall.NeutronClientException(status_code=404))
exceptions.NeutronClientException(status_code=404))
rsrc = self.create_firewall_rule()
self.m.ReplayAll()
@ -404,7 +405,7 @@ class FirewallRuleTest(HeatTestCase):
def test_delete_already_gone(self):
neutronclient.Client.delete_firewall_rule('5678').AndRaise(
firewall.NeutronClientException(status_code=404))
exceptions.NeutronClientException(status_code=404))
rsrc = self.create_firewall_rule()
self.m.ReplayAll()
@ -415,7 +416,7 @@ class FirewallRuleTest(HeatTestCase):
def test_delete_failed(self):
neutronclient.Client.delete_firewall_rule('5678').AndRaise(
firewall.NeutronClientException(status_code=400))
exceptions.NeutronClientException(status_code=400))
rsrc = self.create_firewall_rule()
self.m.ReplayAll()

View File

@ -16,6 +16,7 @@ import mox
from oslo.config import cfg
import six
from neutronclient.common import exceptions
from neutronclient.v2_0 import client as neutronclient
from heat.common import exception
@ -254,7 +255,7 @@ class HealthMonitorTest(HeatTestCase):
'health_monitor': {
'delay': 3, 'max_retries': 5, 'type': u'HTTP',
'timeout': 10, 'admin_state_up': True}}
).AndRaise(loadbalancer.NeutronClientException())
).AndRaise(exceptions.NeutronClientException())
self.m.ReplayAll()
snippet = template_format.parse(health_monitor_template)
@ -273,7 +274,7 @@ class HealthMonitorTest(HeatTestCase):
def test_delete(self):
neutronclient.Client.delete_health_monitor('5678')
neutronclient.Client.show_health_monitor('5678').AndRaise(
loadbalancer.NeutronClientException(status_code=404))
exceptions.NeutronClientException(status_code=404))
rsrc = self.create_health_monitor()
self.m.ReplayAll()
@ -284,7 +285,7 @@ class HealthMonitorTest(HeatTestCase):
def test_delete_already_gone(self):
neutronclient.Client.delete_health_monitor('5678').AndRaise(
loadbalancer.NeutronClientException(status_code=404))
exceptions.NeutronClientException(status_code=404))
rsrc = self.create_health_monitor()
self.m.ReplayAll()
@ -295,7 +296,7 @@ class HealthMonitorTest(HeatTestCase):
def test_delete_failed(self):
neutronclient.Client.delete_health_monitor('5678').AndRaise(
loadbalancer.NeutronClientException(status_code=400))
exceptions.NeutronClientException(status_code=400))
rsrc = self.create_health_monitor()
self.m.ReplayAll()
@ -563,7 +564,7 @@ class PoolTest(HeatTestCase):
'subnet_id': 'sub123', 'protocol': u'HTTP',
'name': utils.PhysName('test_stack', 'pool'),
'lb_method': 'ROUND_ROBIN', 'admin_state_up': True}}
).AndRaise(loadbalancer.NeutronClientException())
).AndRaise(exceptions.NeutronClientException())
self.m.ReplayAll()
snippet = template_format.parse(pool_template)
@ -694,10 +695,10 @@ class PoolTest(HeatTestCase):
rsrc = self.create_pool()
neutronclient.Client.delete_vip('xyz')
neutronclient.Client.show_vip('xyz').AndRaise(
loadbalancer.NeutronClientException(status_code=404))
exceptions.NeutronClientException(status_code=404))
neutronclient.Client.delete_pool('5678')
neutronclient.Client.show_pool('5678').AndRaise(
loadbalancer.NeutronClientException(status_code=404))
exceptions.NeutronClientException(status_code=404))
self.m.ReplayAll()
scheduler.TaskRunner(rsrc.create)()
scheduler.TaskRunner(rsrc.delete)()
@ -706,9 +707,9 @@ class PoolTest(HeatTestCase):
def test_delete_already_gone(self):
neutronclient.Client.delete_vip('xyz').AndRaise(
loadbalancer.NeutronClientException(status_code=404))
exceptions.NeutronClientException(status_code=404))
neutronclient.Client.delete_pool('5678').AndRaise(
loadbalancer.NeutronClientException(status_code=404))
exceptions.NeutronClientException(status_code=404))
rsrc = self.create_pool()
self.m.ReplayAll()
@ -719,7 +720,7 @@ class PoolTest(HeatTestCase):
def test_delete_vip_failed(self):
neutronclient.Client.delete_vip('xyz').AndRaise(
loadbalancer.NeutronClientException(status_code=400))
exceptions.NeutronClientException(status_code=400))
rsrc = self.create_pool()
self.m.ReplayAll()
@ -734,9 +735,9 @@ class PoolTest(HeatTestCase):
def test_delete_failed(self):
neutronclient.Client.delete_vip('xyz').AndRaise(
loadbalancer.NeutronClientException(status_code=404))
exceptions.NeutronClientException(status_code=404))
neutronclient.Client.delete_pool('5678').AndRaise(
loadbalancer.NeutronClientException(status_code=400))
exceptions.NeutronClientException(status_code=400))
rsrc = self.create_pool()
self.m.ReplayAll()
@ -923,7 +924,7 @@ class PoolMemberTest(HeatTestCase):
rsrc = self.create_member()
neutronclient.Client.delete_member(u'member5678')
neutronclient.Client.show_member(u'member5678').AndRaise(
loadbalancer.NeutronClientException(status_code=404))
exceptions.NeutronClientException(status_code=404))
self.m.ReplayAll()
scheduler.TaskRunner(rsrc.create)()
@ -934,7 +935,7 @@ class PoolMemberTest(HeatTestCase):
def test_delete_missing_member(self):
rsrc = self.create_member()
neutronclient.Client.delete_member(u'member5678').AndRaise(
loadbalancer.NeutronClientException(status_code=404))
exceptions.NeutronClientException(status_code=404))
self.m.ReplayAll()
scheduler.TaskRunner(rsrc.create)()
@ -995,7 +996,7 @@ class LoadBalancerTest(HeatTestCase):
def test_update_missing_member(self):
rsrc = self.create_load_balancer()
neutronclient.Client.delete_member(u'member5678').AndRaise(
loadbalancer.NeutronClientException(status_code=404))
exceptions.NeutronClientException(status_code=404))
self.m.ReplayAll()
scheduler.TaskRunner(rsrc.create)()
@ -1020,7 +1021,7 @@ class LoadBalancerTest(HeatTestCase):
def test_delete_missing_member(self):
rsrc = self.create_load_balancer()
neutronclient.Client.delete_member(u'member5678').AndRaise(
loadbalancer.NeutronClientException(status_code=404))
exceptions.NeutronClientException(status_code=404))
self.m.ReplayAll()
scheduler.TaskRunner(rsrc.create)()

View File

@ -11,6 +11,7 @@
# License for the specific language governing permissions and limitations
# under the License.
from neutronclient.common import exceptions
from neutronclient.v2_0 import client as neutronclient
import six
@ -89,7 +90,7 @@ class MeteringLabelTest(HeatTestCase):
'metering_label': {
'name': 'TestLabel',
'description': 'Description of TestLabel'}
}).AndRaise(metering.NeutronClientException())
}).AndRaise(exceptions.NeutronClientException())
self.m.ReplayAll()
snippet = template_format.parse(metering_template)
@ -108,7 +109,7 @@ class MeteringLabelTest(HeatTestCase):
def test_delete(self):
neutronclient.Client.delete_metering_label('1234')
neutronclient.Client.show_metering_label('1234').AndRaise(
metering.NeutronClientException(status_code=404))
exceptions.NeutronClientException(status_code=404))
rsrc = self.create_metering_label()
self.m.ReplayAll()
@ -119,7 +120,7 @@ class MeteringLabelTest(HeatTestCase):
def test_delete_already_gone(self):
neutronclient.Client.delete_metering_label('1234').AndRaise(
metering.NeutronClientException(status_code=404))
exceptions.NeutronClientException(status_code=404))
rsrc = self.create_metering_label()
self.m.ReplayAll()
@ -130,7 +131,7 @@ class MeteringLabelTest(HeatTestCase):
def test_delete_failed(self):
neutronclient.Client.delete_metering_label('1234').AndRaise(
metering.NeutronClientException(status_code=400))
exceptions.NeutronClientException(status_code=400))
rsrc = self.create_metering_label()
self.m.ReplayAll()
@ -202,7 +203,7 @@ class MeteringRuleTest(HeatTestCase):
'remote_ip_prefix': '10.0.3.0/24',
'direction': 'ingress',
'excluded': False}
}).AndRaise(metering.NeutronClientException())
}).AndRaise(exceptions.NeutronClientException())
self.m.ReplayAll()
snippet = template_format.parse(metering_template)
@ -221,7 +222,7 @@ class MeteringRuleTest(HeatTestCase):
def test_delete(self):
neutronclient.Client.delete_metering_label_rule('5678')
neutronclient.Client.show_metering_label_rule('5678').AndRaise(
metering.NeutronClientException(status_code=404))
exceptions.NeutronClientException(status_code=404))
rsrc = self.create_metering_label_rule()
self.m.ReplayAll()
@ -232,7 +233,7 @@ class MeteringRuleTest(HeatTestCase):
def test_delete_already_gone(self):
neutronclient.Client.delete_metering_label_rule('5678').AndRaise(
metering.NeutronClientException(status_code=404))
exceptions.NeutronClientException(status_code=404))
rsrc = self.create_metering_label_rule()
self.m.ReplayAll()
@ -243,7 +244,7 @@ class MeteringRuleTest(HeatTestCase):
def test_delete_failed(self):
neutronclient.Client.delete_metering_label_rule('5678').AndRaise(
metering.NeutronClientException(status_code=400))
exceptions.NeutronClientException(status_code=400))
rsrc = self.create_metering_label_rule()
self.m.ReplayAll()

View File

@ -444,7 +444,7 @@ class NeutronNetworkGatewayTest(HeatTestCase):
'interface_name': u'breth1'}]
}
}
).AndRaise(network_gateway.NeutronClientException)
).AndRaise(qe.NeutronClientException)
self.m.ReplayAll()

View File

@ -13,6 +13,7 @@
import copy
import mox
from neutronclient.common import exceptions
from neutronclient.v2_0 import client as neutronclient
import six
@ -212,7 +213,7 @@ class VPNServiceTest(HeatTestCase):
).AndReturn('sub123')
neutronclient.Client.create_vpnservice(self.VPN_SERVICE_CONF).AndRaise(
vpnservice.NeutronClientException())
exceptions.NeutronClientException())
self.m.ReplayAll()
snippet = template_format.parse(vpnservice_template)
self.stack = utils.parse_stack(snippet)
@ -231,7 +232,7 @@ class VPNServiceTest(HeatTestCase):
def test_delete(self):
neutronclient.Client.delete_vpnservice('vpn123')
neutronclient.Client.show_vpnservice('vpn123').AndRaise(
vpnservice.NeutronClientException(status_code=404))
exceptions.NeutronClientException(status_code=404))
rsrc = self.create_vpnservice()
self.m.ReplayAll()
scheduler.TaskRunner(rsrc.create)()
@ -241,7 +242,7 @@ class VPNServiceTest(HeatTestCase):
def test_delete_already_gone(self):
neutronclient.Client.delete_vpnservice('vpn123').AndRaise(
vpnservice.NeutronClientException(status_code=404))
exceptions.NeutronClientException(status_code=404))
rsrc = self.create_vpnservice()
self.m.ReplayAll()
scheduler.TaskRunner(rsrc.create)()
@ -251,7 +252,7 @@ class VPNServiceTest(HeatTestCase):
def test_delete_failed(self):
neutronclient.Client.delete_vpnservice('vpn123').AndRaise(
vpnservice.NeutronClientException(status_code=400))
exceptions.NeutronClientException(status_code=400))
rsrc = self.create_vpnservice()
self.m.ReplayAll()
scheduler.TaskRunner(rsrc.create)()
@ -358,7 +359,7 @@ class IPsecSiteConnectionTest(HeatTestCase):
def test_create_failed(self):
neutronclient.Client.create_ipsec_site_connection(
self.IPSEC_SITE_CONNECTION_CONF).AndRaise(
vpnservice.NeutronClientException())
exceptions.NeutronClientException())
self.m.ReplayAll()
snippet = template_format.parse(ipsec_site_connection_template)
self.stack = utils.parse_stack(snippet)
@ -378,7 +379,7 @@ class IPsecSiteConnectionTest(HeatTestCase):
def test_delete(self):
neutronclient.Client.delete_ipsec_site_connection('con123')
neutronclient.Client.show_ipsec_site_connection('con123').AndRaise(
vpnservice.NeutronClientException(status_code=404))
exceptions.NeutronClientException(status_code=404))
rsrc = self.create_ipsec_site_connection()
self.m.ReplayAll()
scheduler.TaskRunner(rsrc.create)()
@ -388,7 +389,7 @@ class IPsecSiteConnectionTest(HeatTestCase):
def test_delete_already_gone(self):
neutronclient.Client.delete_ipsec_site_connection('con123').AndRaise(
vpnservice.NeutronClientException(status_code=404))
exceptions.NeutronClientException(status_code=404))
rsrc = self.create_ipsec_site_connection()
self.m.ReplayAll()
scheduler.TaskRunner(rsrc.create)()
@ -398,7 +399,7 @@ class IPsecSiteConnectionTest(HeatTestCase):
def test_delete_failed(self):
neutronclient.Client.delete_ipsec_site_connection('con123').AndRaise(
vpnservice.NeutronClientException(status_code=400))
exceptions.NeutronClientException(status_code=400))
rsrc = self.create_ipsec_site_connection()
self.m.ReplayAll()
scheduler.TaskRunner(rsrc.create)()
@ -504,7 +505,7 @@ class IKEPolicyTest(HeatTestCase):
def test_create_failed(self):
neutronclient.Client.create_ikepolicy(
self.IKE_POLICY_CONF).AndRaise(
vpnservice.NeutronClientException())
exceptions.NeutronClientException())
self.m.ReplayAll()
snippet = template_format.parse(ikepolicy_template)
self.stack = utils.parse_stack(snippet)
@ -524,7 +525,7 @@ class IKEPolicyTest(HeatTestCase):
def test_delete(self):
neutronclient.Client.delete_ikepolicy('ike123')
neutronclient.Client.show_ikepolicy('ike123').AndRaise(
vpnservice.NeutronClientException(status_code=404))
exceptions.NeutronClientException(status_code=404))
rsrc = self.create_ikepolicy()
self.m.ReplayAll()
scheduler.TaskRunner(rsrc.create)()
@ -534,7 +535,7 @@ class IKEPolicyTest(HeatTestCase):
def test_delete_already_gone(self):
neutronclient.Client.delete_ikepolicy('ike123').AndRaise(
vpnservice.NeutronClientException(status_code=404))
exceptions.NeutronClientException(status_code=404))
rsrc = self.create_ikepolicy()
self.m.ReplayAll()
scheduler.TaskRunner(rsrc.create)()
@ -544,7 +545,7 @@ class IKEPolicyTest(HeatTestCase):
def test_delete_failed(self):
neutronclient.Client.delete_ikepolicy('ike123').AndRaise(
vpnservice.NeutronClientException(status_code=400))
exceptions.NeutronClientException(status_code=400))
rsrc = self.create_ikepolicy()
self.m.ReplayAll()
scheduler.TaskRunner(rsrc.create)()
@ -645,7 +646,7 @@ class IPsecPolicyTest(HeatTestCase):
def test_create_failed(self):
neutronclient.Client.create_ipsecpolicy(
self.IPSEC_POLICY_CONF).AndRaise(
vpnservice.NeutronClientException())
exceptions.NeutronClientException())
self.m.ReplayAll()
snippet = template_format.parse(ipsecpolicy_template)
self.stack = utils.parse_stack(snippet)
@ -665,7 +666,7 @@ class IPsecPolicyTest(HeatTestCase):
def test_delete(self):
neutronclient.Client.delete_ipsecpolicy('ips123')
neutronclient.Client.show_ipsecpolicy('ips123').AndRaise(
vpnservice.NeutronClientException(status_code=404))
exceptions.NeutronClientException(status_code=404))
rsrc = self.create_ipsecpolicy()
self.m.ReplayAll()
scheduler.TaskRunner(rsrc.create)()
@ -675,7 +676,7 @@ class IPsecPolicyTest(HeatTestCase):
def test_delete_already_gone(self):
neutronclient.Client.delete_ipsecpolicy('ips123').AndRaise(
vpnservice.NeutronClientException(status_code=404))
exceptions.NeutronClientException(status_code=404))
rsrc = self.create_ipsecpolicy()
self.m.ReplayAll()
scheduler.TaskRunner(rsrc.create)()
@ -685,7 +686,7 @@ class IPsecPolicyTest(HeatTestCase):
def test_delete_failed(self):
neutronclient.Client.delete_ipsecpolicy('ips123').AndRaise(
vpnservice.NeutronClientException(status_code=400))
exceptions.NeutronClientException(status_code=400))
rsrc = self.create_ipsecpolicy()
self.m.ReplayAll()
scheduler.TaskRunner(rsrc.create)()