From af0e503c1d1b8acd5d0e4b776f2019864bfe8855 Mon Sep 17 00:00:00 2001 From: Julien Danjou Date: Fri, 11 May 2012 17:31:38 +0200 Subject: [PATCH] Fix libvirt Connection.get_disks method The get_disks() method is not used anywhere yet, and is not tested properly, but it does not work as reported in bug #998089. This patch add unit test for it and fixes it so it's now possible to retrieve the list of device name associated with a libvirt domain. Change-Id: If09fb683364174fe02cbcbec4c6bbcda991287d6 Signed-off-by: Julien Danjou --- nova/tests/test_libvirt.py | 60 ++++++++++++++++++++++++++++++++++++++ 1 file changed, 60 insertions(+) diff --git a/nova/tests/test_libvirt.py b/nova/tests/test_libvirt.py index 9e53df27..e340c36c 100644 --- a/nova/tests/test_libvirt.py +++ b/nova/tests/test_libvirt.py @@ -693,6 +693,66 @@ class LibvirtConnTestCase(test.TestCase): devices = conn.get_all_block_devices() self.assertEqual(devices, ['/path/to/dev/1', '/path/to/dev/3']) + def test_get_disks(self): + xml = [ + # NOTE(vish): id 0 is skipped + None, + """ + + + + + + + + + + + + + """, + """ + + + + + + + + + """, + """ + + + + + + + + + + + + + """, + ] + + def fake_lookup(id): + return FakeVirtDomain(xml[id]) + + def fake_lookup_name(name): + return FakeVirtDomain(xml[1]) + + self.mox.StubOutWithMock(connection.LibvirtConnection, '_conn') + connection.LibvirtConnection._conn.listDomainsID = lambda: range(4) + connection.LibvirtConnection._conn.lookupByID = fake_lookup + connection.LibvirtConnection._conn.lookupByName = fake_lookup_name + + self.mox.ReplayAll() + conn = connection.LibvirtConnection(False) + devices = conn.get_disks(conn.list_instances()[0]) + self.assertEqual(devices, ['vda', 'vdb']) + @test.skip_if(missing_libvirt(), "Test requires libvirt") def test_snapshot_in_ami_format(self): self.flags(image_service='nova.image.fake.FakeImageService')