diff options
author | Hervé Beraud <hberaud@redhat.com> | 2020-02-24 20:15:48 +0100 |
---|---|---|
committer | Hervé Beraud <hberaud@redhat.com> | 2020-02-26 12:39:35 +0100 |
commit | 85cd57d1c5b7f1e046f831b9b1caa341b688cfb4 (patch) | |
tree | 7d99956d3eea15a2d3eb8db239a1417a4d6ed75e /oslo_utils/imageutils.py | |
parent | 39870f6807e07811bd5d98d82bb8799feeca73d6 (diff) | |
download | oslo-utils-85cd57d1c5b7f1e046f831b9b1caa341b688cfb4.tar.gz |
Fix regex to correctly recognize scientific notation with QemuImgInfo3.41.5
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
(cherry picked from commit ebf8368501500767fd4e6e13602bb88950a4484b)
Diffstat (limited to 'oslo_utils/imageutils.py')
-rw-r--r-- | oslo_utils/imageutils.py | 5 |
1 files changed, 4 insertions, 1 deletions
diff --git a/oslo_utils/imageutils.py b/oslo_utils/imageutils.py index 14d7b5c..e4d62a1 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'): @@ -100,6 +101,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: |