diff options
| author | Joshua Harlow <harlowja@yahoo-inc.com> | 2012-11-08 10:47:41 -0800 |
|---|---|---|
| committer | Russell Bryant <rbryant@redhat.com> | 2012-11-09 09:52:01 -0500 |
| commit | 528add2df39c2381cc7992a5026d283eea8816fa (patch) | |
| tree | 44e55088cf2408b6dbaac3dfe174dec99a77719d | |
| parent | e83a155f4cc92cbf9fae8b1587d14e8a8158f245 (diff) | |
| download | nova-528add2df39c2381cc7992a5026d283eea8816fa.tar.gz nova-528add2df39c2381cc7992a5026d283eea8816fa.tar.xz nova-528add2df39c2381cc7992a5026d283eea8816fa.zip | |
Another case of dictionary access
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
| -rw-r--r-- | nova/tests/test_image_utils.py | 83 | ||||
| -rw-r--r-- | nova/virt/libvirt/utils.py | 2 |
2 files changed, 84 insertions, 1 deletions
diff --git a/nova/tests/test_image_utils.py b/nova/tests/test_image_utils.py index fac0422bf..9c040f2e1 100644 --- a/nova/tests/test_image_utils.py +++ b/nova/tests/test_image_utils.py @@ -18,9 +18,92 @@ from nova import test 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 diff --git a/nova/virt/libvirt/utils.py b/nova/virt/libvirt/utils.py index 53b7a7571..6f163e8d0 100644 --- a/nova/virt/libvirt/utils.py +++ b/nova/virt/libvirt/utils.py @@ -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): |
