Skip to content

Commit 914ee91

Browse files
Zuulopenstack-gerrit
authored andcommitted
Merge "Revert "Revert resize: wait for events according to hybrid plug""
2 parents ff0f33c + 83a5429 commit 914ee91

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

@@ -6483,8 +6448,8 @@ def pre_live_migration(self, context, instance, block_migration, disk,
64836448
return migrate_data
64846449

64856450
@staticmethod
6486-
def _neutron_failed_migration_callback(event_name, instance):
6487-
msg = ('Neutron reported failure during migration '
6451+
def _neutron_failed_live_migration_callback(event_name, instance):
6452+
msg = ('Neutron reported failure during live migration '
64886453
'with %(event)s for instance %(uuid)s')
64896454
msg_args = {'event': event_name, 'uuid': instance.uuid}
64906455
if CONF.vif_plugging_is_fatal:
@@ -6562,7 +6527,7 @@ class _BreakWaitForInstanceEvent(Exception):
65626527
disk = None
65636528

65646529
deadline = CONF.vif_plugging_timeout
6565-
error_cb = self._neutron_failed_migration_callback
6530+
error_cb = self._neutron_failed_live_migration_callback
65666531
# In order to avoid a race with the vif plugging that the virt
65676532
# driver does on the destination host, we register our events
65686533
# 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
@@ -5055,81 +5055,6 @@ def test_notify_volume_usage_detach_no_block_stats(self):
50555055
self.context, fake_instance, fake_bdm)
50565056
block_stats.assert_called_once_with(fake_instance, 'vda')
50575057

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

51345059
class ComputeManagerBuildInstanceTestCase(test.NoDBTestCase):
51355060
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)