Skip to content

Commit

Permalink
Another case of dictionary access
Browse files Browse the repository at this point in the history
Fixes bug 1076114 which was using the old dictionary
access for getting the qemu image info 'file format'
attribute which now should be through direct attribute
access to 'file_format' instead.

Change-Id: Id4c12b43b389b2fd2300d02743db17cf48b38e8f
  • Loading branch information
Joshua Harlow authored and russellb committed Nov 9, 2012
1 parent e83a155 commit 528add2
Show file tree
Hide file tree
Showing 2 changed files with 84 additions and 1 deletion.
83 changes: 83 additions & 0 deletions nova/tests/test_image_utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -18,9 +18,92 @@
from nova import utils

from nova.virt import images
from nova.virt.libvirt import utils as libvirt_utils


class ImageUtilsTestCase(test.TestCase):
def test_disk_type(self):
# Seems like lvm detection
# if its in /dev ??
for p in ['/dev/b', '/dev/blah/blah']:
d_type = libvirt_utils.get_disk_type(p)
self.assertEquals('lvm', d_type)
# Try the other types
template_output = """image: %(path)s
file format: %(format)s
virtual size: 64M (67108864 bytes)
cluster_size: 65536
disk size: 96K
"""
path = '/myhome/disk.config'
for f in ['raw', 'qcow2']:
output = template_output % ({
'format': f,
'path': path,
})
self.mox.StubOutWithMock(utils, 'execute')
utils.execute('env', 'LC_ALL=C', 'LANG=C',
'qemu-img', 'info', path).AndReturn((output, ''))
self.mox.ReplayAll()
d_type = libvirt_utils.get_disk_type(path)
self.assertEquals(f, d_type)
self.mox.UnsetStubs()

def test_disk_backing(self):
path = '/myhome/disk.config'
template_output = """image: %(path)s
file format: raw
virtual size: 2K (2048 bytes)
cluster_size: 65536
disk size: 96K
"""
output = template_output % ({
'path': path,
})
self.mox.StubOutWithMock(utils, 'execute')
utils.execute('env', 'LC_ALL=C', 'LANG=C',
'qemu-img', 'info', path).AndReturn((output, ''))
self.mox.ReplayAll()
d_backing = libvirt_utils.get_disk_backing_file(path)
self.assertEquals(None, d_backing)

def test_disk_size(self):
path = '/myhome/disk.config'
template_output = """image: %(path)s
file format: raw
virtual size: %(v_size)s (%(vsize_b)s bytes)
cluster_size: 65536
disk size: 96K
"""
for i in range(0, 128):
bytes = i * 65336
kbytes = bytes / 1024
mbytes = kbytes / 1024
output = template_output % ({
'v_size': "%sM" % (mbytes),
'vsize_b': i,
'path': path,
})
self.mox.StubOutWithMock(utils, 'execute')
utils.execute('env', 'LC_ALL=C', 'LANG=C',
'qemu-img', 'info', path).AndReturn((output, ''))
self.mox.ReplayAll()
d_size = libvirt_utils.get_disk_size(path)
self.assertEquals(i, d_size)
self.mox.UnsetStubs()
output = template_output % ({
'v_size': "%sK" % (kbytes),
'vsize_b': i,
'path': path,
})
self.mox.StubOutWithMock(utils, 'execute')
utils.execute('env', 'LC_ALL=C', 'LANG=C',
'qemu-img', 'info', path).AndReturn((output, ''))
self.mox.ReplayAll()
d_size = libvirt_utils.get_disk_size(path)
self.assertEquals(i, d_size)
self.mox.UnsetStubs()

def test_qemu_info_canon(self):
path = "disk.config"
example_output = """image: disk.config
Expand Down
2 changes: 1 addition & 1 deletion nova/virt/libvirt/utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -416,7 +416,7 @@ def get_disk_type(path):
if path.startswith('/dev'):
return 'lvm'

return images.qemu_img_info(path)['file format']
return images.qemu_img_info(path).file_format


def get_fs_info(path):
Expand Down

0 comments on commit 528add2

Please sign in to comment.