Fix regex to correctly recognize scientific notation with QemuImgInfo
qemu 4.1.0 output shifts to scientific notation at 1000mb, breaking oslo.utils. Problem here is that the qemu-img output shifts to scientific notation: 999 => 999 MiB 1000 => 1e+03 MiB The regex in python-oslo-utils does not cover this. This issue is likely regexp parsing "disk size: 1e+03 MiB" value. These changes fix that. Change-Id: I4c016865890135023ceb497de18d75ccebd5961a Closes-Bug: 1864529
This commit is contained in:
parent
2180db82b6
commit
ebf8368501
@ -44,7 +44,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*\.?\d+)\s*(\w+)?(\s*\(\s*(\d+)\s+bytes\s*\))?",
|
||||
SIZE_RE = re.compile(r"([0-9]+[eE][-+][0-9]+|\d*\.?\d+)"
|
||||
"\s*(\w+)?(\s*\(\s*(\d+)\s+bytes\s*\))?",
|
||||
re.I)
|
||||
|
||||
def __init__(self, cmd_output=None, format='human'):
|
||||
@ -104,6 +105,8 @@ class QemuImgInfo(object):
|
||||
if not real_size:
|
||||
raise ValueError(_('Invalid input value "%s".') % details)
|
||||
magnitude = real_size.group(1)
|
||||
if "e" in magnitude.lower():
|
||||
magnitude = format(float(real_size.group(1)), '.0f')
|
||||
unit_of_measure = real_size.group(2)
|
||||
bytes_info = real_size.group(3)
|
||||
if bytes_info:
|
||||
|
@ -69,6 +69,8 @@ class ImageUtilsRawTestCase(test_base.BaseTestCase):
|
||||
exp_disk_size=3328599655)),
|
||||
('unavailable', dict(disk_size='unavailable',
|
||||
exp_disk_size=0)),
|
||||
('1e+03 MiB', dict(disk_size='1e+03 MiB',
|
||||
exp_disk_size=1048576000)),
|
||||
]
|
||||
|
||||
_garbage_before_snapshot = [
|
||||
|
@ -0,0 +1,5 @@
|
||||
---
|
||||
fixes:
|
||||
- |
|
||||
qemu 4.1.0 output shifts to scientific notation at 1000mb,
|
||||
breaking oslo.utils. ``QemuImgInfo`` is now fixed to support this notation.
|
Loading…
x
Reference in New Issue
Block a user