summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorZuul <zuul@review.opendev.org>2020-02-26 16:06:35 +0000
committerGerrit Code Review <review@openstack.org>2020-02-26 16:06:35 +0000
commit8c15cafb8e688b62ab3b3e7ffac46712f50221ee (patch)
tree5ae42ff858e031f94b72a54fa056a2ed9af66f5b
parent7b7970f858a12f838958810b33bbcaa0a0090217 (diff)
parentebf8368501500767fd4e6e13602bb88950a4484b (diff)
downloadoslo-utils-8c15cafb8e688b62ab3b3e7ffac46712f50221ee.tar.gz
Merge "Fix regex to correctly recognize scientific notation with QemuImgInfo"4.1.0
-rw-r--r--oslo_utils/imageutils.py5
-rw-r--r--oslo_utils/tests/test_imageutils.py2
-rw-r--r--releasenotes/notes/image-utils-handle-scientific-notation-6f65d46e9c8c8f8c.yaml5
3 files changed, 11 insertions, 1 deletions
diff --git a/oslo_utils/imageutils.py b/oslo_utils/imageutils.py
index 1194df3..82ea29d 100644
--- a/oslo_utils/imageutils.py
+++ b/oslo_utils/imageutils.py
@@ -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:
diff --git a/oslo_utils/tests/test_imageutils.py b/oslo_utils/tests/test_imageutils.py
index bb6340c..bfb0817 100644
--- a/oslo_utils/tests/test_imageutils.py
+++ b/oslo_utils/tests/test_imageutils.py
@@ -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 = [
diff --git a/releasenotes/notes/image-utils-handle-scientific-notation-6f65d46e9c8c8f8c.yaml b/releasenotes/notes/image-utils-handle-scientific-notation-6f65d46e9c8c8f8c.yaml
new file mode 100644
index 0000000..9577fd8
--- /dev/null
+++ b/releasenotes/notes/image-utils-handle-scientific-notation-6f65d46e9c8c8f8c.yaml
@@ -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.