Check for correct Neutron exceptions harder

The change to stop using the Nova passthrough API for networking in
e8e0a2483a changed the type of exceptions
expected in a couple of places, without changing the exception handling
code accordingly.

7b17c8b4ee 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 <zbitter@redhat.com>
Closes-Bug: #1694412
This commit is contained in:
rabi 2017-05-31 10:12:34 +05:30 committed by Zane Bitter
parent 7b17c8b4ee
commit 1bb701217a
2 changed files with 17 additions and 12 deletions

View File

@ -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

View File

@ -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: