Enable decimal value input in imageutils.QemuImgInfo

Nova has test cases where it image sizes are in float value.
However imageutils has errors when given float values.
This patch enhances the regex to handle float values.
Test cases were added accordingly.

Change-Id: Ifcaf60f5c54d74e8fc317be6808363bce7429cc8
This commit is contained in:
Zhongyue Luo 2014-02-18 16:43:41 +08:00 committed by Gerrit Code Review
parent c71f8ab984
commit b455fac281
2 changed files with 8 additions and 1 deletions

View File

@ -29,7 +29,8 @@ class QemuImgInfo(object):
BACKING_FILE_RE = re.compile((r"^(.*?)\s*\(actual\s+path\s*:"
r"\s+(.*?)\)\s*$"), re.I)
TOP_LEVEL_RE = re.compile(r"^([\w\d\s\_\-]+):(.*)$")
SIZE_RE = re.compile(r"(\d+)(\w+)?(\s*\(\s*(\d+)\s+bytes\s*\))?", re.I)
SIZE_RE = re.compile(r"(\d*\.?\d+)(\w+)?(\s*\(\s*(\d+)\s+bytes\s*\))?",
re.I)
def __init__(self, cmd_output=None):
details = self._parse(cmd_output or '')

View File

@ -38,6 +38,10 @@ class ImageUtilsRawTestCase(test.BaseTestCase):
exp_virtual_size=67108844)),
('64M_byte', dict(virtual_size='67108844',
exp_virtual_size=67108844)),
('4.4M', dict(virtual_size='4.4M',
exp_virtual_size=4613735)),
('4.4M_with_byte_hint', dict(virtual_size='4.4M (4592640 bytes)',
exp_virtual_size=4592640)),
('2K', dict(virtual_size='2K',
exp_virtual_size=2048)),
('2K_with_byte_hint', dict(virtual_size='2K (2048 bytes)',
@ -49,6 +53,8 @@ class ImageUtilsRawTestCase(test.BaseTestCase):
exp_disk_size=98304)),
('96K_byte', dict(disk_size='963434',
exp_disk_size=963434)),
('3.1M', dict(disk_size='3.1G',
exp_disk_size=3328599655)),
]
_garbage_before_snapshot = [