Browse Source

Merge "Fix libvirt Connection.get_disks method"

changes/74/7374/1
Jenkins 10 years ago committed by Gerrit Code Review
parent
commit
2c7e0d1e63
  1. 60
      nova/tests/test_libvirt.py
  2. 21
      nova/virt/libvirt/connection.py

60
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,
"""
<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")
def test_snapshot_in_ami_format(self):
self.flags(image_service='nova.image.fake.FakeImageService')

21
nova/virt/libvirt/connection.py

@ -1773,30 +1773,15 @@ class LibvirtConnection(driver.ComputeDriver):
"""
domain = self._lookup_by_name(instance_name)
xml = domain.XMLDesc(0)
doc = None
try:
doc = etree.fromstring(xml)
except Exception:
return []
disks = []
ret = doc.findall('./devices/disk')
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
return filter(bool,
[target.get("dev") \
for target in doc.findall('devices/disk/target')])
def get_interfaces(self, instance_name):
"""

Loading…
Cancel
Save