neutron: check for same host in _update_port_binding_for_instance
If we're doing a resize to the same host, like all resize tests in the gate, the host hasn't changed so there is no point in updating the port binding host in neutron so add a check for that case. Related-Bug: #1323658 Change-Id: Ieb5ade398da8c11b29a3fa83b01ecf14e5e1f5b7
This commit is contained in:
parent
fc858b5505
commit
cc8b8dc826
|
@ -1598,13 +1598,16 @@ class API(base_api.NetworkAPI):
|
|||
data = neutron.list_ports(**search_opts)
|
||||
ports = data['ports']
|
||||
for p in ports:
|
||||
try:
|
||||
neutron.update_port(p['id'],
|
||||
{'port': {'binding:host_id': host}})
|
||||
except Exception:
|
||||
with excutils.save_and_reraise_exception():
|
||||
LOG.exception(_LE("Unable to update host of port %s"),
|
||||
p['id'])
|
||||
# If the host hasn't changed, like in the case of resizing to the
|
||||
# same host, there is nothing to do.
|
||||
if p.get('binding:host_id') != host:
|
||||
try:
|
||||
neutron.update_port(p['id'],
|
||||
{'port': {'binding:host_id': host}})
|
||||
except Exception:
|
||||
with excutils.save_and_reraise_exception():
|
||||
LOG.exception(_LE("Unable to update host of port %s"),
|
||||
p['id'])
|
||||
|
||||
|
||||
def _ensure_requested_network_ordering(accessor, unordered, preferred):
|
||||
|
|
|
@ -3101,6 +3101,29 @@ class TestNeutronv2WithMock(test.TestCase):
|
|||
self.assertEqual(('fake-uuid2', 'fake-network2'),
|
||||
(net_objs[1].uuid, net_objs[1].name))
|
||||
|
||||
@mock.patch.object(neutronapi, 'get_client', return_value=mock.Mock())
|
||||
def test_update_port_bindings_for_instance_same_host(self,
|
||||
get_client_mock):
|
||||
instance = fake_instance.fake_instance_obj(self.context)
|
||||
self.api._has_port_binding_extension = mock.Mock(return_value=True)
|
||||
|
||||
# We test two ports, one with the same host as the host passed in and
|
||||
# one where binding:host_id isn't set, so we update that port.
|
||||
fake_ports = {'ports': [
|
||||
{'id': 'fake-port-1',
|
||||
'binding:host_id': instance.host},
|
||||
{'id': 'fake-port-2'}]}
|
||||
list_ports_mock = mock.Mock(return_value=fake_ports)
|
||||
get_client_mock.return_value.list_ports = list_ports_mock
|
||||
update_port_mock = mock.Mock()
|
||||
get_client_mock.return_value.update_port = update_port_mock
|
||||
|
||||
self.api._update_port_binding_for_instance(self.context, instance,
|
||||
instance.host)
|
||||
# Assert that update_port was only called on the port without a host.
|
||||
update_port_mock.assert_called_once_with(
|
||||
'fake-port-2', {'port': {'binding:host_id': instance.host}})
|
||||
|
||||
|
||||
class TestNeutronv2ModuleMethods(test.TestCase):
|
||||
|
||||
|
|
Loading…
Reference in New Issue