Merge "Fix libvirt Connection.get_disks method"
This commit is contained in:
commit
2c7e0d1e63
|
@ -693,6 +693,66 @@ class LibvirtConnTestCase(test.TestCase):
|
||||||
devices = conn.get_all_block_devices()
|
devices = conn.get_all_block_devices()
|
||||||
self.assertEqual(devices, ['/path/to/dev/1', '/path/to/dev/3'])
|
self.assertEqual(devices, ['/path/to/dev/1', '/path/to/dev/3'])
|
||||||
|
|
||||||
|
def test_get_disks(self):
|
||||||
|
xml = [
|
||||||
|
# NOTE(vish): id 0 is skipped
|
||||||
|
None,
|
||||||
|
"""
|
||||||
|
<domain type='kvm'>
|
||||||
|
<devices>
|
||||||
|
<disk type='file'>
|
||||||
|
<source file='filename'/>
|
||||||
|
<target dev='vda' bus='virtio'/>
|
||||||
|
</disk>
|
||||||
|
<disk type='block'>
|
||||||
|
<source dev='/path/to/dev/1'/>
|
||||||
|
<target dev='vdb' bus='virtio'/>
|
||||||
|
</disk>
|
||||||
|
</devices>
|
||||||
|
</domain>
|
||||||
|
""",
|
||||||
|
"""
|
||||||
|
<domain type='kvm'>
|
||||||
|
<devices>
|
||||||
|
<disk type='file'>
|
||||||
|
<source file='filename'/>
|
||||||
|
<target dev='vda' bus='virtio'/>
|
||||||
|
</disk>
|
||||||
|
</devices>
|
||||||
|
</domain>
|
||||||
|
""",
|
||||||
|
"""
|
||||||
|
<domain type='kvm'>
|
||||||
|
<devices>
|
||||||
|
<disk type='file'>
|
||||||
|
<source file='filename'/>
|
||||||
|
<target dev='vda' bus='virtio'/>
|
||||||
|
</disk>
|
||||||
|
<disk type='block'>
|
||||||
|
<source dev='/path/to/dev/3'/>
|
||||||
|
<target dev='vdb' bus='virtio'/>
|
||||||
|
</disk>
|
||||||
|
</devices>
|
||||||
|
</domain>
|
||||||
|
""",
|
||||||
|
]
|
||||||
|
|
||||||
|
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")
|
@test.skip_if(missing_libvirt(), "Test requires libvirt")
|
||||||
def test_snapshot_in_ami_format(self):
|
def test_snapshot_in_ami_format(self):
|
||||||
self.flags(image_service='nova.image.fake.FakeImageService')
|
self.flags(image_service='nova.image.fake.FakeImageService')
|
||||||
|
|
|
@ -1773,30 +1773,15 @@ class LibvirtConnection(driver.ComputeDriver):
|
||||||
"""
|
"""
|
||||||
domain = self._lookup_by_name(instance_name)
|
domain = self._lookup_by_name(instance_name)
|
||||||
xml = domain.XMLDesc(0)
|
xml = domain.XMLDesc(0)
|
||||||
doc = None
|
|
||||||
|
|
||||||
try:
|
try:
|
||||||
doc = etree.fromstring(xml)
|
doc = etree.fromstring(xml)
|
||||||
except Exception:
|
except Exception:
|
||||||
return []
|
return []
|
||||||
|
|
||||||
disks = []
|
return filter(bool,
|
||||||
|
[target.get("dev") \
|
||||||
ret = doc.findall('./devices/disk')
|
for target in doc.findall('devices/disk/target')])
|
||||||
|
|
||||||
for node in ret:
|
|
||||||
devdst = None
|
|
||||||
|
|
||||||
for child in node.children:
|
|
||||||
if child.name == 'target':
|
|
||||||
devdst = child.prop('dev')
|
|
||||||
|
|
||||||
if devdst is None:
|
|
||||||
continue
|
|
||||||
|
|
||||||
disks.append(devdst)
|
|
||||||
|
|
||||||
return disks
|
|
||||||
|
|
||||||
def get_interfaces(self, instance_name):
|
def get_interfaces(self, instance_name):
|
||||||
"""
|
"""
|
||||||
|
|
Loading…
Reference in New Issue