Check for correct neutron exceptions

Check for the correct exceptions from neutronclient
when replacing network id with network name in
'networks' attribute of server.

This also changes one of the tests to use a different
network name.

Change-Id: I9457ed93857805ee30e550f23b1da3d262dd83fd
Closes-Bug: #1694412
This commit is contained in:
rabi 2017-05-30 15:27:52 +05:30
parent 37625840df
commit 7b17c8b4ee
2 changed files with 11 additions and 6 deletions

View File

@ -1048,9 +1048,11 @@ class Server(server_base.BaseServer, sh.SchedulerHintsMixin,
try:
net_id = self.client_plugin(
'neutron').find_resourceid_by_name_or_id('network', key)
except (exception.EntityNotFound,
exception.PhysicalResourceNameAmbiguity):
net_id = None
except Exception as ex:
if (self.client_plugin('neutron').is_not_found(ex) or
self.client_plugin('neutron').is_no_unique(ex)):
net_id = None
raise
if net_id:
nets[net_id] = nets[key]
return nets

View File

@ -104,6 +104,7 @@ class CreateServerTest(functional_base.FunctionalTestsBase):
template=server_with_sub_fixed_ip_template,
stack_name='server_with_sub_ip',
parameters=parms)
networks = self.get_outputs(stack_identifier, 'networks')
self.assertEqual(['11.11.11.11'], networks['my_net'])
@ -117,13 +118,15 @@ class CreateServerTest(functional_base.FunctionalTestsBase):
parms = {'flavor': self.conf.minimal_instance_type,
'image': self.conf.minimal_image_ref}
template = server_with_sub_fixed_ip_template.replace(
'fixed_ip: 11.11.11.11', 'fixed_ip: 11.11.11.22')
'fixed_ip: 11.11.11.11',
'fixed_ip: 11.11.11.22').replace(
'name: my_net', 'name: your_net')
stack_identifier = self.stack_create(
template=template,
stack_name='create_server_with_sub_ip',
parameters=parms)
networks = self.get_outputs(stack_identifier, 'networks')
self.assertEqual(['11.11.11.22'], networks['my_net'])
self.assertEqual(['11.11.11.22'], networks['your_net'])
# update the server only with subnet, we won't pass
# both port_id and net_id to attach interface, then update success
@ -133,7 +136,7 @@ class CreateServerTest(functional_base.FunctionalTestsBase):
template_only_subnet,
parameters=parms)
new_networks = self.get_outputs(stack_identifier, 'networks')
self.assertNotEqual(['11.11.11.22'], new_networks['my_net'])
self.assertNotEqual(['11.11.11.22'], new_networks['your_net'])
def test_create_server_with_port(self):
parms = {'flavor': self.conf.minimal_instance_type,