Skip to content

Commit 83a5429

Browse files
slawqomriedem
authored andcommitted
Revert "Revert resize: wait for events according to hybrid plug"
This reverts commit 19f9b37. Commit 19f9b37 introduced a regression and caused errors on Neutron CI jobs which run on a single node with iptables_hybrid firewall driver. This is because the nova change made the resize revert flow wait for neutron-vif-plugged events in the ComputeManager when the port's host binding changes for iptables_hybrid ports but for those types of ports, Neutron does not send the event if the host does not change - which is the case for a same-host resize being reverted. Change-Id: I77b3639435c671bacca9cdfc1aa203e44a2fb042 Closes-Bug: #1833902
1 parent 19f9b37 commit 83a5429

File tree

7 files changed

+34
-240
lines changed

7 files changed

+34
-240
lines changed

nova/compute/manager.py

Lines changed: 14 additions & 49 deletions
Original file line numberDiff line numberDiff line change
@@ -4164,50 +4164,6 @@ def revert_resize(self, context, instance, migration):
41644164
self.compute_rpcapi.finish_revert_resize(context, instance,
41654165
migration, migration.source_compute)
41664166

4167-
def _finish_revert_resize_network_migrate_finish(self, context, instance,
4168-
migration):
4169-
"""Causes port binding to be updated. In some Neutron or port
4170-
configurations - see NetworkModel.get_bind_time_events() - we
4171-
expect the vif-plugged event from Neutron immediately and wait for it.
4172-
The rest of the time, the event is expected further along in the
4173-
virt driver, so we don't wait here.
4174-
4175-
:param context: The request context.
4176-
:param instance: The instance undergoing the revert resize.
4177-
:param migration: The Migration object of the resize being reverted.
4178-
:raises: eventlet.timeout.Timeout or
4179-
exception.VirtualInterfacePlugException.
4180-
"""
4181-
network_info = instance.get_network_info()
4182-
events = []
4183-
deadline = CONF.vif_plugging_timeout
4184-
if deadline and utils.is_neutron() and network_info:
4185-
events = network_info.get_bind_time_events()
4186-
if events:
4187-
LOG.debug('Will wait for bind-time events: %s', events,
4188-
instance=instance)
4189-
error_cb = self._neutron_failed_migration_callback
4190-
try:
4191-
with self.virtapi.wait_for_instance_event(instance, events,
4192-
deadline=deadline,
4193-
error_callback=error_cb):
4194-
# NOTE(hanrong): we need to change migration.dest_compute to
4195-
# source host temporarily.
4196-
# "network_api.migrate_instance_finish" will setup the network
4197-
# for the instance on the destination host. For revert resize,
4198-
# the instance will back to the source host, the setup of the
4199-
# network for instance should be on the source host. So set the
4200-
# migration.dest_compute to source host at here.
4201-
with utils.temporary_mutation(
4202-
migration, dest_compute=migration.source_compute):
4203-
self.network_api.migrate_instance_finish(context,
4204-
instance,
4205-
migration)
4206-
except eventlet.timeout.Timeout:
4207-
with excutils.save_and_reraise_exception():
4208-
LOG.error('Timeout waiting for Neutron events: %s', events,
4209-
instance=instance)
4210-
42114167
@wrap_exception()
42124168
@reverts_task_state
42134169
@wrap_instance_event(prefix='compute')
@@ -4255,8 +4211,17 @@ def finish_revert_resize(self, context, instance, migration):
42554211

42564212
self.network_api.setup_networks_on_host(context, instance,
42574213
migration.source_compute)
4258-
self._finish_revert_resize_network_migrate_finish(
4259-
context, instance, migration)
4214+
# NOTE(hanrong): we need to change migration.dest_compute to
4215+
# source host temporarily. "network_api.migrate_instance_finish"
4216+
# will setup the network for the instance on the destination host.
4217+
# For revert resize, the instance will back to the source host, the
4218+
# setup of the network for instance should be on the source host.
4219+
# So set the migration.dest_compute to source host at here.
4220+
with utils.temporary_mutation(
4221+
migration, dest_compute=migration.source_compute):
4222+
self.network_api.migrate_instance_finish(context,
4223+
instance,
4224+
migration)
42604225
network_info = self.network_api.get_instance_nw_info(context,
42614226
instance)
42624227

@@ -6474,8 +6439,8 @@ def pre_live_migration(self, context, instance, block_migration, disk,
64746439
return migrate_data
64756440

64766441
@staticmethod
6477-
def _neutron_failed_migration_callback(event_name, instance):
6478-
msg = ('Neutron reported failure during migration '
6442+
def _neutron_failed_live_migration_callback(event_name, instance):
6443+
msg = ('Neutron reported failure during live migration '
64796444
'with %(event)s for instance %(uuid)s')
64806445
msg_args = {'event': event_name, 'uuid': instance.uuid}
64816446
if CONF.vif_plugging_is_fatal:
@@ -6553,7 +6518,7 @@ class _BreakWaitForInstanceEvent(Exception):
65536518
disk = None
65546519

65556520
deadline = CONF.vif_plugging_timeout
6556-
error_cb = self._neutron_failed_migration_callback
6521+
error_cb = self._neutron_failed_live_migration_callback
65576522
# In order to avoid a race with the vif plugging that the virt
65586523
# driver does on the destination host, we register our events
65596524
# to wait for before calling pre_live_migration. Then if the

nova/network/model.py

Lines changed: 0 additions & 28 deletions
Original file line numberDiff line numberDiff line change
@@ -458,16 +458,6 @@ def labeled_ips(self):
458458
'ips': ips}
459459
return []
460460

461-
def has_bind_time_event(self):
462-
"""When updating the port binding to a host that already has the
463-
instance in a shutoff state (in practice, this currently means
464-
reverting a resize or cold migration), the following Neutron/port
465-
configurations cause network-vif-plugged events to be sent as soon as
466-
the binding is updated:
467-
- OVS with hybrid plug
468-
"""
469-
return self.is_hybrid_plug_enabled()
470-
471461
def is_hybrid_plug_enabled(self):
472462
return self['details'].get(VIF_DETAILS_OVS_HYBRID_PLUG, False)
473463

@@ -525,24 +515,6 @@ def wait(self, do_raise=True):
525515
def json(self):
526516
return jsonutils.dumps(self)
527517

528-
def get_bind_time_events(self):
529-
"""When updating the port binding to a host that already has the
530-
instance in a shutoff state (in practice, this currently means
531-
reverting a resize or cold migration), return external events that are
532-
sent as soon as the binding is updated.
533-
"""
534-
return [('network-vif-plugged', vif['id'])
535-
for vif in self if vif.has_bind_time_event()]
536-
537-
def get_plug_time_events(self):
538-
"""When updating the port binding to a host that already has the
539-
instance in a shutoff state (in practice, this currently means
540-
reverting a resize or cold migration), return external events that are
541-
sent when the VIF is plugged.
542-
"""
543-
return [('network-vif-plugged', vif['id'])
544-
for vif in self if not vif.has_bind_time_event()]
545-
546518

547519
class NetworkInfoAsyncWrapper(NetworkInfo):
548520
"""Wrapper around NetworkInfo that allows retrieving NetworkInfo

nova/tests/unit/compute/test_compute.py

Lines changed: 2 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -5891,9 +5891,7 @@ def fake_finish_revert_migration_driver(*args, **kwargs):
58915891
old_vm_state = vm_states.ACTIVE
58925892
else:
58935893
old_vm_state = vm_states.STOPPED
5894-
params = {'vm_state': old_vm_state,
5895-
'info_cache': objects.InstanceInfoCache(
5896-
network_info=network_model.NetworkInfo([]))}
5894+
params = {'vm_state': old_vm_state}
58975895
instance = self._create_fake_instance_obj(params)
58985896

58995897
self.stub_out('nova.virt.fake.FakeDriver.finish_migration', fake)
@@ -6043,9 +6041,7 @@ def test_finish_revert_resize_validate_source_compute(self):
60436041
def fake(*args, **kwargs):
60446042
pass
60456043

6046-
params = {'info_cache': objects.InstanceInfoCache(
6047-
network_info=network_model.NetworkInfo([]))}
6048-
instance = self._create_fake_instance_obj(params)
6044+
instance = self._create_fake_instance_obj()
60496045

60506046
self.stub_out('nova.virt.fake.FakeDriver.finish_migration', fake)
60516047
self.stub_out('nova.virt.fake.FakeDriver.finish_revert_migration',

nova/tests/unit/compute/test_compute_mgr.py

Lines changed: 0 additions & 75 deletions
Original file line numberDiff line numberDiff line change
@@ -5054,81 +5054,6 @@ def test_notify_volume_usage_detach_no_block_stats(self):
50545054
self.context, fake_instance, fake_bdm)
50555055
block_stats.assert_called_once_with(fake_instance, 'vda')
50565056

5057-
def _test_finish_revert_resize_network_migrate_finish(self, vifs, events):
5058-
instance = fake_instance.fake_instance_obj(self.context)
5059-
instance.info_cache = objects.InstanceInfoCache(
5060-
network_info=network_model.NetworkInfo(vifs))
5061-
migration = objects.Migration(
5062-
source_compute='fake-source',
5063-
dest_compute='fake-dest')
5064-
5065-
def fake_migrate_instance_finish(context, instance, migration):
5066-
self.assertEqual(migration.source_compute, 'fake-source')
5067-
# NOTE(artom) This looks weird, but it's checking that the
5068-
# temporaty_mutation() context manager did its job.
5069-
self.assertEqual(migration.dest_compute, 'fake-source')
5070-
5071-
with test.nested(
5072-
mock.patch.object(self.compute.virtapi,
5073-
'wait_for_instance_event'),
5074-
mock.patch.object(self.compute.network_api,
5075-
'migrate_instance_finish',
5076-
side_effect=fake_migrate_instance_finish)
5077-
) as (mock_wait, mock_migrate_instance_finish):
5078-
self.compute._finish_revert_resize_network_migrate_finish(
5079-
self.context, instance, migration)
5080-
mock_wait.assert_called_once_with(
5081-
instance, events, deadline=CONF.vif_plugging_timeout,
5082-
error_callback=self.compute._neutron_failed_migration_callback)
5083-
mock_migrate_instance_finish.assert_called_once_with(
5084-
self.context, instance, migration)
5085-
5086-
def test_finish_revert_resize_network_migrate_finish_wait(self):
5087-
"""Test that we wait for bind-time events if we have a hybrid-plugged
5088-
VIF.
5089-
"""
5090-
self._test_finish_revert_resize_network_migrate_finish(
5091-
[network_model.VIF(id=uuids.hybrid_vif,
5092-
details={'ovs_hybrid_plug': True}),
5093-
network_model.VIF(id=uuids.normal_vif,
5094-
details={'ovs_hybrid_plug': False})],
5095-
[('network-vif-plugged', uuids.hybrid_vif)])
5096-
5097-
def test_finish_revert_resize_network_migrate_finish_dont_wait(self):
5098-
"""Test that we're not waiting for any events if we don't have any
5099-
hybrid-plugged VIFs.
5100-
"""
5101-
self._test_finish_revert_resize_network_migrate_finish(
5102-
[network_model.VIF(id=uuids.hybrid_vif,
5103-
details={'ovs_hybrid_plug': False}),
5104-
network_model.VIF(id=uuids.normal_vif,
5105-
details={'ovs_hybrid_plug': False})],
5106-
[])
5107-
5108-
def test_finish_revert_resize_network_migrate_finish_no_vif_timeout(self):
5109-
"""Test that we're not waiting for any events if vif_plugging_timeout
5110-
is 0.
5111-
"""
5112-
self.flags(vif_plugging_timeout=0)
5113-
self._test_finish_revert_resize_network_migrate_finish(
5114-
[network_model.VIF(id=uuids.hybrid_vif,
5115-
details={'ovs_hybrid_plug': True}),
5116-
network_model.VIF(id=uuids.normal_vif,
5117-
details={'ovs_hybrid_plug': True})],
5118-
[])
5119-
5120-
@mock.patch.object(utils, 'is_neutron', return_value=False)
5121-
def test_finish_revert_resize_network_migrate_finish_not_neutron(self, _):
5122-
"""Test that we're not waiting for any events if we're not using
5123-
Neutron.
5124-
"""
5125-
self._test_finish_revert_resize_network_migrate_finish(
5126-
[network_model.VIF(id=uuids.hybrid_vif,
5127-
details={'ovs_hybrid_plug': True}),
5128-
network_model.VIF(id=uuids.normal_vif,
5129-
details={'ovs_hybrid_plug': True})],
5130-
[])
5131-
51325057

51335058
class ComputeManagerBuildInstanceTestCase(test.NoDBTestCase):
51345059
def setUp(self):

nova/tests/unit/network/test_network_info.py

Lines changed: 0 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,6 @@
1515
# under the License.
1616

1717
from oslo_config import cfg
18-
from oslo_utils.fixture import uuidsentinel as uuids
1918

2019
from nova import exception
2120
from nova.network import model
@@ -858,21 +857,6 @@ def test_injection_ipv6_with_lxc_no_gateway(self):
858857
libvirt_virt_type='lxc')
859858
self.assertEqual(expected, template)
860859

861-
def test_get_events(self):
862-
network_info = model.NetworkInfo([
863-
model.VIF(
864-
id=uuids.hybrid_vif,
865-
details={'ovs_hybrid_plug': True}),
866-
model.VIF(
867-
id=uuids.normal_vif,
868-
details={'ovs_hybrid_plug': False})])
869-
self.assertEqual(
870-
[('network-vif-plugged', uuids.hybrid_vif)],
871-
network_info.get_bind_time_events())
872-
self.assertEqual(
873-
[('network-vif-plugged', uuids.normal_vif)],
874-
network_info.get_plug_time_events())
875-
876860

877861
class TestNetworkMetadata(test.NoDBTestCase):
878862
def setUp(self):

0 commit comments

Comments
 (0)