summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorzhangsong <zhangsong@cmss.chinamobile.com>2015-12-08 16:57:29 +0800
committerzhangsong <zhangsong@cmss.chinamobile.com>2015-12-09 03:42:31 +0000
commitfa73d96f144e9357db79da6d981f8d43aed5d1a1 (patch)
treee3b84daf425c1738da2e06671e348d1a4fd90d54
parent479587c6d9f2fd519f1ea4c7fab3cbf2da1a92f4 (diff)
downloadoslo-utils-fa73d96f144e9357db79da6d981f8d43aed5d1a1.tar.gz
Fix the bug of can't get the desired image info
When we use 'qemu-img info' command to get image info, some kinds of image may show an 'unavailable' disk size. For example: $qemu-img info sheepdog:volume-1af1afa0-7820-4063-9b90-4fa6161a74a9 image: sheepdog:volume-1af1afa0-7820-4063-9b90-4fa6161a74a9 file format: raw virtual size: 10G (10737418240 bytes) disk size: unavailable $qemu-img info -f rbd rbd:data/foo image: rbd:data/foo file format: rbd virtual size: 10G (10737418240 bytes) disk size: unavailable cluster_size: 4194304 The current code didn't consider 'unavailable' size, and it will raise a ValueError in this case. This patch fixed this bug by adding the judgment of 'unavailable' size. I also fixed some problems of the test case. (This patch is a sync from cinder: Change-Id Ic5f3b80e172baaafc07432319f8aa24bf117b392) Change-Id: Ie64822299af5ca20f9e1961cfab386c38729444d Closes-Bug: #1516083
-rw-r--r--oslo_utils/imageutils.py2
-rw-r--r--oslo_utils/tests/test_imageutils.py8
2 files changed, 6 insertions, 4 deletions
diff --git a/oslo_utils/imageutils.py b/oslo_utils/imageutils.py
index c63314a..b829abd 100644
--- a/oslo_utils/imageutils.py
+++ b/oslo_utils/imageutils.py
@@ -92,7 +92,7 @@ class QemuImgInfo(object):
real_details = backing_match.group(2).strip()
elif root_cmd in ['virtual_size', 'cluster_size', 'disk_size']:
# Replace it with the byte amount (if we can convert it)
- if root_details == 'None':
+ if root_details in ('None', 'unavailable'):
real_details = 0
else:
real_details = self._extract_bytes(root_details)
diff --git a/oslo_utils/tests/test_imageutils.py b/oslo_utils/tests/test_imageutils.py
index cb8b356..5c328fe 100644
--- a/oslo_utils/tests/test_imageutils.py
+++ b/oslo_utils/tests/test_imageutils.py
@@ -51,10 +51,12 @@ class ImageUtilsRawTestCase(test_base.BaseTestCase):
_disk_size = [
('96K', dict(disk_size='96K',
exp_disk_size=98304)),
- ('96K_byte', dict(disk_size='963434',
- exp_disk_size=963434)),
- ('3.1M', dict(disk_size='3.1G',
+ ('96K_byte', dict(disk_size='98304',
+ exp_disk_size=98304)),
+ ('3.1G', dict(disk_size='3.1G',
exp_disk_size=3328599655)),
+ ('unavailable', dict(disk_size='unavailable',
+ exp_disk_size=0)),
]
_garbage_before_snapshot = [