From 1bb701217a370511e50023b2243cfb270acc6500 Mon Sep 17 00:00:00 2001 From: rabi Date: Wed, 31 May 2017 10:12:34 +0530 Subject: [PATCH] Check for correct Neutron exceptions harder The change to stop using the Nova passthrough API for networking in e8e0a2483a8cd0edbd0ec77d92d638974c72f290 changed the type of exceptions expected in a couple of places, without changing the exception handling code accordingly. 7b17c8b4eea1091ff91a8a3d9e41a75256ee9302 changed the exception handling in one case, but continued to raise the exception instead of suppressing it. This patch suppresses the exception, and makes the same change to another case of the problem. Use a different network name for test_create_server_with_port instead of 'my_net' which is also used by one of the other tests in the same file, to avoid the conflict at its source. Change-Id: I2f1210e546a5ad7eef3ffd6537335049120b2d2c Co-Authored-By: Zane Bitter Closes-Bug: #1694412 --- .../engine/resources/openstack/nova/server.py | 27 +++++++++++-------- .../functional/test_nova_server_networks.py | 2 +- 2 files changed, 17 insertions(+), 12 deletions(-) diff --git a/heat/engine/resources/openstack/nova/server.py b/heat/engine/resources/openstack/nova/server.py index 30d0b67a1d..5fef6ecb4f 100644 --- a/heat/engine/resources/openstack/nova/server.py +++ b/heat/engine/resources/openstack/nova/server.py @@ -876,14 +876,17 @@ class Server(server_base.BaseServer, sh.SchedulerHintsMixin, reality_nets = self._add_port_for_address(server, extend_networks=False) reality_net_ids = {} + client_plugin = self.client_plugin('neutron') for net_key in reality_nets: try: - net_id = self.client_plugin( - 'neutron').find_resourceid_by_name_or_id('network', - net_key) - except (exception.EntityNotFound, - exception.PhysicalResourceNameAmbiguity): - net_id = None + net_id = client_plugin.find_resourceid_by_name_or_id('network', + net_key) + except Exception as ex: + if (client_plugin.is_not_found(ex) or + client_plugin.is_no_unique(ex)): + net_id = None + else: + raise if net_id: reality_net_ids[net_id] = reality_nets.get(net_key) @@ -1044,15 +1047,17 @@ class Server(server_base.BaseServer, sh.SchedulerHintsMixin, This method is used only for resolving attributes. """ nets = copy.deepcopy(networks) + client_plugin = self.client_plugin('neutron') for key in list(nets.keys()): try: - net_id = self.client_plugin( - 'neutron').find_resourceid_by_name_or_id('network', key) + net_id = client_plugin.find_resourceid_by_name_or_id('network', + key) except Exception as ex: - if (self.client_plugin('neutron').is_not_found(ex) or - self.client_plugin('neutron').is_no_unique(ex)): + if (client_plugin.is_not_found(ex) or + client_plugin.is_no_unique(ex)): net_id = None - raise + else: + raise if net_id: nets[net_id] = nets[key] return nets diff --git a/heat_integrationtests/functional/test_nova_server_networks.py b/heat_integrationtests/functional/test_nova_server_networks.py index 7259b6cfab..9b6b5e6d8a 100644 --- a/heat_integrationtests/functional/test_nova_server_networks.py +++ b/heat_integrationtests/functional/test_nova_server_networks.py @@ -68,7 +68,7 @@ resources: net: type: OS::Neutron::Net properties: - name: my_net + name: server_with_port_net subnet: type: OS::Neutron::Subnet properties: