Change compute pollster API to work on one instance at a time

We will eventually need the compute agent to accept instructions to
poll the status of an instance before nova deletes it (for details
see bug 1005944). This change prepares for that fix by making
the compute agent pollsters take an instance as an argument
provided by the caller, instead of accessing the database directly
to look up the instances known to be running on the current
host.

Change-Id: I6a16405fd65bfb3c190d02f3d70b2bde7fc0fc83
Signed-off-by: Doug Hellmann <doug.hellmann@dreamhost.com>
This commit is contained in:
Doug Hellmann
2012-07-30 14:42:00 -04:00
parent 0e8f2359d9
commit dbccbb5cb9
5 changed files with 87 additions and 66 deletions

View File

@@ -42,22 +42,29 @@ class TestDiskIOPollster(test.TestCase):
self.manager = manager.AgentManager()
self.pollster = libvirt.DiskIOPollster()
super(TestDiskIOPollster, self).setUp()
self.instance = db.instance_create(self.context, {})
flags.FLAGS.compute_driver = 'libvirt.LibvirtDriver'
@test.skip_if(libvirt_missing, 'Test requires libvirt')
def test_fetch_diskio(self):
list(self.pollster.get_counters(self.manager, self.context))
counters = list(self.pollster.get_counters(self.manager,
self.instance))
#assert counters
# FIXME(dhellmann): The CI environment doesn't produce
# a response when the fake driver asks for the disks, so
# we do not get any counters in response.
@test.skip_if(libvirt_missing, 'Test requires libvirt')
def test_fetch_diskio_not_libvirt(self):
flags.FLAGS.compute_driver = 'fake.FakeDriver'
counters = list(self.pollster.get_counters(self.manager,
self.instance))
assert not counters
@test.skip_if(libvirt_missing, 'Test requires libvirt')
def test_fetch_diskio_with_libvirt_non_existent_instance(self):
flags.FLAGS.compute_driver = 'libvirt.LibvirtDriver'
instance = db.instance_create(self.context, {})
self.mox.StubOutWithMock(self.manager.db, 'instance_get_all_by_host')
self.manager.db.instance_get_all_by_host(self.context,
self.manager.host,
).AndReturn([instance])
self.mox.ReplayAll()
list(self.pollster.get_counters(self.manager, self.context))
print 'ID:', self.instance.id
inst = db.instance_get(self.context, self.instance.id)
inst.id = 999 # change the id so the driver cannot find the instance
counters = list(self.pollster.get_counters(self.manager, inst))
assert not counters