diff options
| author | Chris Behrens <cbehrens@codestud.com> | 2013-03-07 21:03:19 +0000 |
|---|---|---|
| committer | Chris Behrens <cbehrens@codestud.com> | 2013-03-07 21:48:22 +0000 |
| commit | 6a080df6bd8817019d204e3142a236b7974f7656 (patch) | |
| tree | d7bd4f7c15e6584c5f04b98fea6ce03ae6fda711 /nova/tests | |
| parent | e23769827dbd5c9eb9d392e6452ca33253f88329 (diff) | |
Fix access_ip_* race
The code currently sets access_ip_* in a 2nd DB call after an instance
goes ACTIVE, which means there's a slight race when someone is querying
the API for their instance. It's possible to see the instance ACTIVE but
access_ip_* will be blank.
To fix this, we should set access_ip_* at the same time the instance goes
ACTIVE. This also removes an unnecessary extra DB call.
Fixes bug 1152328
Change-Id: I0fe542d49fbc95f27a24f57f674264f8789bc527
Diffstat (limited to 'nova/tests')
| -rw-r--r-- | nova/tests/compute/test_compute.py | 16 |
1 files changed, 14 insertions, 2 deletions
diff --git a/nova/tests/compute/test_compute.py b/nova/tests/compute/test_compute.py index c86992f3d..e247b41c9 100644 --- a/nova/tests/compute/test_compute.py +++ b/nova/tests/compute/test_compute.py @@ -605,6 +605,18 @@ class ComputeTestCase(BaseTestCase): fake_network.unset_stub_network_methods(self.stubs) instance = jsonutils.to_primitive(self._create_fake_instance()) + orig_update = self.compute._instance_update + + # Make sure the access_ip_* updates happen in the same DB + # update as the set to ACTIVE. + def _instance_update(ctxt, instance_uuid, **kwargs): + if kwargs.get('vm_state', None) == vm_states.ACTIVE: + self.assertEqual(kwargs['access_ip_v4'], '192.168.1.100') + self.assertEqual(kwargs['access_ip_v6'], '2001:db8:0:1::1') + return orig_update(ctxt, instance_uuid, **kwargs) + + self.stubs.Set(self.compute, '_instance_update', _instance_update) + try: self.compute.run_instance(self.context, instance=instance, is_first_time=True) @@ -7355,7 +7367,7 @@ class ComputeRescheduleOrReraiseTestCase(BaseTestCase): actual=task_states.DELETING) self.compute._spawn(mox.IgnoreArg(), self.instance, mox.IgnoreArg(), mox.IgnoreArg(), mox.IgnoreArg(), mox.IgnoreArg(), - mox.IgnoreArg()).AndRaise(exc) + mox.IgnoreArg(), set_access_ip=False).AndRaise(exc) self.mox.ReplayAll() # test succeeds if mocked method '_reschedule_or_reraise' is not @@ -7373,7 +7385,7 @@ class ComputeRescheduleOrReraiseTestCase(BaseTestCase): actual=task_states.SCHEDULING) self.compute._spawn(mox.IgnoreArg(), self.instance, mox.IgnoreArg(), mox.IgnoreArg(), mox.IgnoreArg(), mox.IgnoreArg(), - mox.IgnoreArg()).AndRaise(exc) + mox.IgnoreArg(), set_access_ip=False).AndRaise(exc) self.mox.ReplayAll() self.assertRaises(exception.UnexpectedTaskStateError, |
