Fix race condition in XenAPI when using <object>.get_all

Fixes bug 887708

There are a handful of places where <object>.get_all is followed by a
<object>.get_record calls that are potentially racey. This patch fixes
all of these cases to use common code that is tolerant of HANDLE_INVALID
errors that would be indicative of a race between get_all and delete

Change-Id: Ib94adb6d21b6b55e7b26fc1da52ed46d9dba8275
This commit is contained in:
Johannes Erdfelt 2011-12-07 18:20:03 +00:00
parent 8b18df220f
commit 929a51f3f5

View File

@ -1110,13 +1110,15 @@ class HostStateTestCase(test.TestCase):
"""Tests HostState, which holds metrics from XenServer that get
reported back to the Schedulers."""
def _fake_safe_find_sr(self, session):
@classmethod
def _fake_safe_find_sr(cls, session):
"""None SR ref since we're ignoring it in FakeSR."""
return None
def test_host_state(self):
self.stubs = stubout.StubOutForTesting()
self.stubs.Set(vm_utils, 'safe_find_sr', self._fake_safe_find_sr)
self.stubs.Set(vm_utils.VMHelper, 'safe_find_sr',
self._fake_safe_find_sr)
host_state = xenapi_conn.HostState(FakeSession())
stats = host_state._stats
self.assertEquals(stats['disk_total'], 10000)