Skip to content

Commit 93888df

Browse files
Zuulopenstack-gerrit
authored andcommitted
Merge "Update nova network info when doing rebuild for evacuate operation"
2 parents 0e2c37e + 8e052c7 commit 93888df

File tree

2 files changed

+98
-7
lines changed

2 files changed

+98
-7
lines changed

nova/compute/manager.py

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3175,11 +3175,17 @@ def _do_rebuild_instance(self, context, instance, orig_image_ref,
31753175
# are so similar, we should really try to unify them.
31763176
self.network_api.setup_instance_network_on_host(
31773177
context, instance, self.host, migration)
3178+
# TODO(mriedem): Consider decorating setup_instance_network_on_host
3179+
# with @base_api.refresh_cache and then we wouldn't need this
3180+
# explicit call to get_instance_nw_info.
3181+
network_info = self.network_api.get_instance_nw_info(context,
3182+
instance)
3183+
else:
3184+
network_info = instance.get_network_info()
31783185

31793186
allocations = self.reportclient.get_allocations_for_consumer(
31803187
context, instance.uuid)
31813188

3182-
network_info = instance.get_network_info()
31833189
if bdms is None:
31843190
bdms = objects.BlockDeviceMappingList.get_by_instance_uuid(
31853191
context, instance.uuid)

nova/tests/unit/compute/test_compute_mgr.py

Lines changed: 91 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -4194,12 +4194,13 @@ def test_evacuate_late_server_group_policy_check(
41944194
request_spec = objects.RequestSpec()
41954195
request_spec.scheduler_hints = {'group': [uuids.group]}
41964196

4197-
self.compute.rebuild_instance(
4198-
self.context, instance, None, None, None, None, None,
4199-
None, recreate=True, on_shared_storage=None,
4200-
preserve_ephemeral=False, migration=None,
4201-
scheduled_node='fake-node',
4202-
limits={}, request_spec=request_spec)
4197+
with mock.patch.object(self.compute, 'network_api'):
4198+
self.compute.rebuild_instance(
4199+
self.context, instance, None, None, None, None, None,
4200+
None, recreate=True, on_shared_storage=None,
4201+
preserve_ephemeral=False, migration=None,
4202+
scheduled_node='fake-node',
4203+
limits={}, request_spec=request_spec)
42034204

42044205
mock_validate_policy.assert_called_once_with(
42054206
elevated_context, instance, {'group': [uuids.group]})
@@ -4284,6 +4285,90 @@ def test_rebuild_node_updated_if_recreate(self):
42844285
mock_set.assert_called_once_with(None, 'done')
42854286
mock_rt.assert_called_once_with()
42864287

4288+
@mock.patch.object(compute_utils, 'notify_about_instance_rebuild')
4289+
@mock.patch.object(compute_utils, 'notify_usage_exists')
4290+
@mock.patch.object(compute_utils, 'notify_about_instance_action')
4291+
@mock.patch.object(objects.ImageMeta, 'from_instance')
4292+
@mock.patch.object(objects.Instance, 'save', return_value=None)
4293+
def test_rebuild_nw_updated_if_recreate(self,
4294+
mock_save,
4295+
mock_image_ref,
4296+
mock_notify,
4297+
mock_notify_exists,
4298+
mock_notify_rebuild):
4299+
with test.nested(
4300+
mock.patch.object(self.compute,
4301+
'_notify_about_instance_usage'),
4302+
mock.patch.object(self.compute.network_api,
4303+
'setup_networks_on_host'),
4304+
mock.patch.object(self.compute.network_api,
4305+
'setup_instance_network_on_host'),
4306+
mock.patch.object(self.compute.network_api,
4307+
'get_instance_nw_info'),
4308+
mock.patch.object(self.compute,
4309+
'_get_instance_block_device_info',
4310+
return_value='fake-bdminfo'),
4311+
mock.patch.object(self.compute, '_check_trusted_certs'),
4312+
) as(
4313+
mock_notify_usage,
4314+
mock_setup,
4315+
mock_setup_inst,
4316+
mock_get_nw_info,
4317+
mock_get_blk,
4318+
mock_check_trusted_certs
4319+
):
4320+
self.flags(group="glance", api_servers="http://127.0.0.1:9292")
4321+
instance = fake_instance.fake_instance_obj(self.context)
4322+
orig_vif = fake_network_cache_model.new_vif(
4323+
{'profile': {"pci_slot": "0000:01:00.1"}})
4324+
orig_nw_info = network_model.NetworkInfo([orig_vif])
4325+
new_vif = fake_network_cache_model.new_vif(
4326+
{'profile': {"pci_slot": "0000:02:00.1"}})
4327+
new_nw_info = network_model.NetworkInfo([new_vif])
4328+
4329+
info_cache = objects.InstanceInfoCache(network_info=orig_nw_info,
4330+
instance_uuid=instance.uuid)
4331+
4332+
instance.info_cache = info_cache
4333+
instance.task_state = task_states.REBUILDING
4334+
instance.migration_context = None
4335+
instance.numa_topology = None
4336+
instance.pci_requests = None
4337+
instance.pci_devices = None
4338+
orig_image_ref = None
4339+
image_ref = None
4340+
injected_files = []
4341+
new_pass = None
4342+
orig_sys_metadata = None
4343+
bdms = []
4344+
recreate = True
4345+
on_shared_storage = None
4346+
preserve_ephemeral = None
4347+
4348+
mock_get_nw_info.return_value = new_nw_info
4349+
4350+
self.compute._do_rebuild_instance(self.context, instance,
4351+
orig_image_ref, image_ref,
4352+
injected_files, new_pass,
4353+
orig_sys_metadata, bdms,
4354+
recreate, on_shared_storage,
4355+
preserve_ephemeral, {}, {})
4356+
4357+
mock_notify_usage.assert_has_calls(
4358+
[mock.call(self.context, instance, "rebuild.start",
4359+
extra_usage_info=mock.ANY),
4360+
mock.call(self.context, instance, "rebuild.end",
4361+
network_info=new_nw_info,
4362+
extra_usage_info=mock.ANY)])
4363+
self.assertTrue(mock_image_ref.called)
4364+
self.assertTrue(mock_save.called)
4365+
self.assertTrue(mock_notify_exists.called)
4366+
mock_setup.assert_called_once_with(self.context, instance,
4367+
mock.ANY)
4368+
mock_setup_inst.assert_called_once_with(self.context, instance,
4369+
mock.ANY, mock.ANY)
4370+
mock_get_nw_info.assert_called_once_with(self.context, instance)
4371+
42874372
def test_rebuild_default_impl(self):
42884373
def _detach(context, bdms):
42894374
# NOTE(rpodolyaka): check that instance has been powered off by

0 commit comments

Comments
 (0)