Change in vdsm[master]: fix tests for qemuimg.convert() to allow additional capabili...
apahim at redhat.com
apahim at redhat.com
Tue Dec 23 18:11:47 UTC 2014
Amador Pahim has uploaded a new change for review.
Change subject: fix tests for qemuimg.convert() to allow additional capabilities checks
......................................................................
fix tests for qemuimg.convert() to allow additional capabilities checks
Tests for convert() are mocking execCmd() to fake _supports_qcow2_compat().
In order to allow other capabilities checks inside convert(), this patch
is testing the _supports_qcow2_compat() itself and removing the need of
mocking execCmd() inside convert, mocking _supports_qcow2_compat() instead.
Change-Id: I386772bf2a25a880b5ad387f284679eed81c5615
Signed-off-by: Amador Pahim <apahim at redhat.com>
---
M tests/qemuimgTests.py
1 file changed, 37 insertions(+), 16 deletions(-)
git pull ssh://gerrit.ovirt.org:29418/vdsm refs/changes/66/36366/1
diff --git a/tests/qemuimgTests.py b/tests/qemuimgTests.py
index 21288b7..e7423a7 100644
--- a/tests/qemuimgTests.py
+++ b/tests/qemuimgTests.py
@@ -171,17 +171,14 @@
qemuimg.convert('src', 'dst', True)
def test_qcow2_compat_unsupported(self):
- def qcow2_compat_unsupported(cmd, **kw):
- self.check_supports_qcow2_compat(cmd, **kw)
- return 0, 'Supported options:\nsize ...\n', ''
-
def convert(cmd, **kw):
expected = [QEMU_IMG, 'convert', '-t', 'none', 'src', '-O',
'qcow2', 'dst']
self.assertEqual(cmd, expected)
return 0, '', ''
- with FakeCmd(utils, 'execCmd', qcow2_compat_unsupported):
+ with FakeCmd(qemuimg, '_supports_qcow2_compat',
+ self.qcow2_compat_unsupported):
with FakeCmd(utils, 'watchCmd', convert):
qemuimg.convert('src', 'dst', True, dstFormat='qcow2')
@@ -192,7 +189,8 @@
self.assertEqual(cmd, expected)
return 0, '', ''
- with FakeCmd(utils, 'execCmd', self.qcow2_compat_supported):
+ with FakeCmd(qemuimg, '_supports_qcow2_compat',
+ self.qcow2_compat_supported):
with FakeCmd(utils, 'watchCmd', convert):
qemuimg.convert('src', 'dst', True, dstFormat='qcow2')
@@ -203,7 +201,8 @@
self.assertEqual(cmd, expected)
return 0, '', ''
- with FakeCmd(utils, 'execCmd', self.qcow2_compat_supported):
+ with FakeCmd(qemuimg, '_supports_qcow2_compat',
+ self.qcow2_compat_supported):
with FakeCmd(utils, 'watchCmd', convert):
qemuimg.convert('src', 'dst', None, dstFormat='qcow2')
@@ -215,7 +214,8 @@
self.assertEqual(cmd, expected)
return 0, '', ''
- with FakeCmd(utils, 'execCmd', self.qcow2_compat_supported):
+ with FakeCmd(qemuimg, '_supports_qcow2_compat',
+ self.qcow2_compat_supported):
with FakeCmd(utils, 'watchCmd', convert):
qemuimg.convert('src', 'dst', None, dstFormat='qcow2',
backing='bak')
@@ -227,7 +227,8 @@
self.assertEqual(cmd, expected)
return 0, '', ''
- with FakeCmd(utils, 'execCmd', self.qcow2_compat_supported):
+ with FakeCmd(qemuimg, '_supports_qcow2_compat',
+ self.qcow2_compat_supported):
with FakeCmd(utils, 'watchCmd', convert):
qemuimg.convert('src', 'dst', None, dstFormat='qcow2',
backingFormat='qcow2')
@@ -240,16 +241,36 @@
self.assertEqual(cmd, expected)
return 0, '', ''
- with FakeCmd(utils, 'execCmd', self.qcow2_compat_supported):
+ with FakeCmd(qemuimg, '_supports_qcow2_compat',
+ self.qcow2_compat_supported):
with FakeCmd(utils, 'watchCmd', convert):
qemuimg.convert('src', 'dst', None, dstFormat='qcow2',
backing='bak', backingFormat='qcow2')
- def check_supports_qcow2_compat(self, cmd, **kw):
- expected = [QEMU_IMG, 'convert', '-O', 'qcow2', '-o', '?', '/dev/null',
- '/dev/null']
- self.assertEqual(cmd, expected)
+ def test_qcow2_compat(self, **kw):
+ def call(cmd, **kw):
+ expected = [QEMU_IMG, 'convert', '-O', 'qcow2', '-o', '?',
+ '/dev/null', '/dev/null']
+ self.assertEqual(cmd, expected)
+ return 0, '', ''
+
+ def supported(cmd, **kw):
+ return 0, 'Supported options:\ncompat ...\n', ''
+
+ def unsupported(cmd, **kw):
+ return 0, 'Supported options:\nsize ...\n', ''
+
+ with FakeCmd(utils, 'execCmd', call):
+ qemuimg._supports_qcow2_compat('convert')
+
+ with FakeCmd(utils, 'execCmd', supported):
+ self.assertTrue(qemuimg._supports_qcow2_compat('convert'))
+
+ with FakeCmd(utils, 'execCmd', unsupported):
+ self.assertFalse(qemuimg._supports_qcow2_compat('convert'))
def qcow2_compat_supported(self, cmd, **kw):
- self.check_supports_qcow2_compat(cmd, **kw)
- return 0, 'Supported options:\ncompat ...\n', ''
+ return True
+
+ def qcow2_compat_unsupported(self, cmd, **kw):
+ return False
--
To view, visit http://gerrit.ovirt.org/36366
To unsubscribe, visit http://gerrit.ovirt.org/settings
Gerrit-MessageType: newchange
Gerrit-Change-Id: I386772bf2a25a880b5ad387f284679eed81c5615
Gerrit-PatchSet: 1
Gerrit-Project: vdsm
Gerrit-Branch: master
Gerrit-Owner: Amador Pahim <apahim at redhat.com>
More information about the vdsm-patches
mailing list