Make sure instance saves network_info when we go ACTIVE
This makes sure that when we do a save() on our instance during creation, that we don't save the empty network_info we created earlier over a potentially-full one built during the process. This may happen since we wrap the networkinfo in the async helper. This also moves the network_info.wait() out from under a conditional which could cover up other issues leading to a case where it is None (which shouldn't be possible). If we didn't call wait(), then saving it wouldn't be productive or correct. Change-Id: I9bd8dd0dce9e17cd128c7495acd52aa82119c57c Related-bug: 1249065
This commit is contained in:
parent
90d3041850
commit
a798282be7
|
@ -1737,9 +1737,8 @@ class ComputeManager(manager.Manager):
|
|||
if set_access_ip:
|
||||
_set_access_ip_values()
|
||||
|
||||
if network_info is not None:
|
||||
network_info.wait(do_raise=True)
|
||||
|
||||
network_info.wait(do_raise=True)
|
||||
instance.info_cache.network_info = network_info
|
||||
instance.save(expected_task_state=task_states.SPAWNING)
|
||||
return instance
|
||||
|
||||
|
|
|
@ -1469,6 +1469,17 @@ class ComputeManagerBuildInstanceTestCase(test.NoDBTestCase):
|
|||
instance_update.assert_has_calls(mock.call(self.context,
|
||||
self.instance['uuid'], mock.ANY, 'conductor'))
|
||||
|
||||
@mock.patch('nova.compute.manager.ComputeManager._get_power_state')
|
||||
def test_spawn_waits_for_network_and_saves_info_cache(self, gps):
|
||||
inst = mock.MagicMock()
|
||||
network_info = mock.MagicMock()
|
||||
with mock.patch.object(self.compute, 'driver'):
|
||||
self.compute._spawn(self.context, inst, {}, network_info, None,
|
||||
None, None)
|
||||
network_info.wait.assert_called_once_with(do_raise=True)
|
||||
self.assertEqual(network_info, inst.info_cache.network_info)
|
||||
inst.save.assert_called_with(expected_task_state=task_states.SPAWNING)
|
||||
|
||||
def test_reschedule_on_resources_unavailable(self):
|
||||
reason = 'resource unavailable'
|
||||
exc = exception.ComputeResourcesUnavailable(reason=reason)
|
||||
|
|
Loading…
Reference in New Issue