Change in vdsm[ovirt-3.5]: qemu-img: Handle image end offset on different lines of output
alitke at redhat.com
alitke at redhat.com
Thu Mar 5 20:46:56 UTC 2015
Adam Litke has uploaded a new change for review.
Change subject: qemu-img: Handle image end offset on different lines of output
......................................................................
qemu-img: Handle image end offset on different lines of output
Current code assumes that qemu-img check output will place the image end
offset in the second line of output but it can appear later:
$ sudo qemu-img check
/rhev/data-center/.../41b2b944-77f0-40d5-a681-c63e0dbb7482
No errors were found on the image.
70088/98304 = 71.30% allocated, 0.17% fragmented, 0.00% compressed clusters
Image end offset: 4594466816
Update the scanner so it can find it on any line from the second until
the end of output.
Change-Id: Id6610baf1702c9075d8512bdb1da0e05527a0060
Bug-Url: https://bugzilla.redhat.com/show_bug.cgi?id=1196072
Signed-off-by: Adam Litke <alitke at redhat.com>
---
M lib/vdsm/qemuimg.py
M tests/qemuimgTests.py
2 files changed, 51 insertions(+), 11 deletions(-)
git pull ssh://gerrit.ovirt.org:29418/vdsm refs/changes/38/38438/1
diff --git a/lib/vdsm/qemuimg.py b/lib/vdsm/qemuimg.py
index 2aa130a..61d67bc 100644
--- a/lib/vdsm/qemuimg.py
+++ b/lib/vdsm/qemuimg.py
@@ -50,7 +50,11 @@
'offset': re.compile("^Image end offset: (?P<value>\d+)$"),
}
-INFO_OPTFIELDS_STARTIDX = 4 # qemu-img info optional fields start in this line
+# The first row of qemu-img info output where optional fields may appear
+_INFO_OPTFIELDS_STARTIDX = 4
+
+# The first row of qemu-img check output where the 'offset' may appear
+_CHECK_OPTFIELDS_STARTIDX = 1
class _RegexSearchError(Exception):
@@ -97,7 +101,7 @@
raise QImgError(rc, out, err, "unable to parse qemu-img info output")
# Scan for optional fields in the output
- row = INFO_OPTFIELDS_STARTIDX
+ row = _INFO_OPTFIELDS_STARTIDX
for field, filterFn in (('clustersize', int), ('backingfile', str)):
try:
info[field] = filterFn(__iregexSearch(field, out[row]))
@@ -179,15 +183,18 @@
# FIXME: handle different error codes and raise errors accordingly
if rc != 0:
raise QImgError(rc, out, err)
- try:
- check = {
- 'offset': int(__iregexSearch("offset", out[1]))
- }
- # TODO: Add requires for qemu supporting offset and print exc_info
- except:
- raise QImgError(rc, out, err, "unable to parse qemu-img check output")
-
- return check
+ # Scan for 'offset' in the output
+ for row in range(_CHECK_OPTFIELDS_STARTIDX, len(out)):
+ try:
+ check = {
+ 'offset': int(__iregexSearch("offset", out[row]))
+ }
+ return check
+ except _RegexSearchError:
+ pass
+ except:
+ break
+ raise QImgError(rc, out, err, "unable to parse qemu-img check output")
def convert(srcImage, dstImage, stop, srcFormat=None, dstFormat=None):
diff --git a/tests/qemuimgTests.py b/tests/qemuimgTests.py
index ce7cb76..0ffbab5 100644
--- a/tests/qemuimgTests.py
+++ b/tests/qemuimgTests.py
@@ -174,3 +174,36 @@
with FakeExecCmd(qcow2_compat_supported, create_qcow2_compat):
qemuimg.create('image', format='qcow2')
+
+
+class CheckTests(TestCaseBase):
+
+ def test_offset_with_stats(self):
+ def call(cmd, **kw):
+ out = ["No errors were found on the image.",
+ "65157/98304 = 66.28% allocated, 0.00% fragmented, 0.00% "
+ "compressed clusters",
+ "Image end offset: 4271243264"]
+ return 0, out, []
+
+ with FakeExecCmd(call):
+ check = qemuimg.check('unused')
+ self.assertEquals(4271243264, check['offset'])
+
+ def test_offset_without_stats(self):
+ def call(cmd, **kw):
+ out = ["No errors were found on the image.",
+ "Image end offset: 4271243264"]
+ return 0, out, []
+
+ with FakeExecCmd(call):
+ check = qemuimg.check('unused')
+ self.assertEquals(4271243264, check['offset'])
+
+ def test_offset_no_match(self):
+ def call(cmd, **kw):
+ out = ["All your base are belong to us."]
+ return 0, out, []
+
+ with FakeExecCmd(call):
+ self.assertRaises(qemuimg.QImgError, qemuimg.check, 'unused')
--
To view, visit https://gerrit.ovirt.org/38438
To unsubscribe, visit https://gerrit.ovirt.org/settings
Gerrit-MessageType: newchange
Gerrit-Change-Id: Id6610baf1702c9075d8512bdb1da0e05527a0060
Gerrit-PatchSet: 1
Gerrit-Project: vdsm
Gerrit-Branch: ovirt-3.5
Gerrit-Owner: Adam Litke <alitke at redhat.com>
More information about the vdsm-patches
mailing list