Hello Nir Soffer, Francesco Romani,
I'd like you to do a code review. Please visit
https://gerrit.ovirt.org/60987
to review the following change.
Change subject: qemuimg: Unbreak qmemuimg.check
......................................................................
qemuimg: Unbreak qmemuimg.check
Since commit 3e7a11954582 (qemuimg: Use --output json for 'check' and
'info') qemuimg.check is broken, but the tests are passing. This is
caused by unneeded mocking.
qemuimg.check fails now with this error:
File "/usr/lib/python2.7/site-packages/vdsm/qemuimg.py", line 309, in
_parse_qemuimg_json
obj = json.loads(output)
File "/usr/lib64/python2.7/json/__init__.py", line 338, in loads
return _default_decoder.decode(s)
File "/usr/lib64/python2.7/json/decoder.py", line 365, in decode
obj, end = self.raw_decode(s, idx=_w(s, 0).end())
TypeError: expected string or buffer
Replace the harmful mocking with running qemuimg.check with a real
image, and add the missing raw=True to get a string from the command.
Change-Id: I732b8bb7285352ed92d69b295b8cf6c2598b8f41
Signed-off-by: Nir Soffer <[email protected]>
Reviewed-on: https://gerrit.ovirt.org/60168
Continuous-Integration: Jenkins CI
Reviewed-by: Francesco Romani <[email protected]>
Reviewed-by: Adam Litke <[email protected]>
---
M lib/vdsm/qemuimg.py
M tests/qemuimgTests.py
2 files changed, 8 insertions(+), 14 deletions(-)
git pull ssh://gerrit.ovirt.org:29418/vdsm refs/changes/87/60987/1
diff --git a/lib/vdsm/qemuimg.py b/lib/vdsm/qemuimg.py
index c9d73fe..59a580a 100644
--- a/lib/vdsm/qemuimg.py
+++ b/lib/vdsm/qemuimg.py
@@ -137,7 +137,7 @@
cmd.extend(("-f", format))
cmd.append(image)
- rc, out, err = commands.execCmd(cmd, deathSignal=signal.SIGKILL)
+ rc, out, err = commands.execCmd(cmd, deathSignal=signal.SIGKILL, raw=True)
# FIXME: handle different error codes and raise errors accordingly
if rc != 0:
diff --git a/tests/qemuimgTests.py b/tests/qemuimgTests.py
index ac7c0b1..574bb25 100644
--- a/tests/qemuimgTests.py
+++ b/tests/qemuimgTests.py
@@ -385,20 +385,14 @@
class CheckTests(TestCaseBase):
- def _fake_info(self):
- return {
- "image-end-offset": 262144,
- "total-clusters": 16,
- "check-errors": 0,
- "filename": "/var/tmp/leaf.img",
- "format": "qcow2"
- }
-
+ @MonkeyPatch(qemuimg, 'config', CONFIG)
def test_check(self):
- with MonkeyPatchScope([(commands, "execCmd",
- partial(fake_json_call, self._fake_info()))]):
- check = qemuimg.check('unused')
- self.assertEqual(262144, check['offset'])
+ with namedTemporaryDir() as tmpdir:
+ path = os.path.join(tmpdir, 'test.qcow2')
+ qemuimg.create(path, size=1048576, format=qemuimg.FORMAT.QCOW2)
+ info = qemuimg.check(path)
+ # The exact value depends on qcow2 internals
+ self.assertEqual(int, type(info['offset']))
def test_offset_no_match(self):
with MonkeyPatchScope([(commands, "execCmd",
--
To view, visit https://gerrit.ovirt.org/60987
To unsubscribe, visit https://gerrit.ovirt.org/settings
Gerrit-MessageType: newchange
Gerrit-Change-Id: I732b8bb7285352ed92d69b295b8cf6c2598b8f41
Gerrit-PatchSet: 1
Gerrit-Project: vdsm
Gerrit-Branch: ovirt-4.0
Gerrit-Owner: Adam Litke <[email protected]>
Gerrit-Reviewer: Francesco Romani <[email protected]>
Gerrit-Reviewer: Nir Soffer <[email protected]>
_______________________________________________
vdsm-patches mailing list
[email protected]
https://lists.fedorahosted.org/admin/lists/[email protected]