From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from eggs.gnu.org ([2001:4830:134:3::10]:58738) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1WODDe-00069h-Si for qemu-devel@nongnu.org; Thu, 13 Mar 2014 17:31:19 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1WODDa-0007VI-DF for qemu-devel@nongnu.org; Thu, 13 Mar 2014 17:31:14 -0400 Received: from mx1.redhat.com ([209.132.183.28]:41771) by eggs.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1WODDZ-0007VA-SA for qemu-devel@nongnu.org; Thu, 13 Mar 2014 17:31:10 -0400 Message-ID: <53222395.9080000@redhat.com> Date: Thu, 13 Mar 2014 22:31:01 +0100 From: Max Reitz MIME-Version: 1.0 References: <1394574786-32579-1-git-send-email-benoit.canet@irqsave.net> <1394574786-32579-4-git-send-email-benoit.canet@irqsave.net> In-Reply-To: <1394574786-32579-4-git-send-email-benoit.canet@irqsave.net> Content-Type: text/plain; charset=ISO-8859-1; format=flowed Content-Transfer-Encoding: quoted-printable Subject: Re: [Qemu-devel] [PATCH V2 3/3] qemu-iotests: Add 088 new test for drive-mirror-replace. List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , To: =?ISO-8859-1?Q?Beno=EEt_Canet?= , qemu-devel@nongnu.org Cc: kwolf@redhat.com, Benoit Canet , stefanha@redhat.com On 11.03.2014 22:53, Beno=EEt Canet wrote: > Tests for drive-mirror-replace whose purpose is to enable quorum file m= irroring > and replacement after failure. > > Signed-off-by: Benoit Canet > --- > tests/qemu-iotests/041 | 34 +------ > tests/qemu-iotests/088 | 221 +++++++++++++++++++++++++++++++++= +++++++++ > tests/qemu-iotests/088.out | 5 + > tests/qemu-iotests/group | 1 + > tests/qemu-iotests/iotests.py | 33 +++++++ > 5 files changed, 261 insertions(+), 33 deletions(-) > create mode 100755 tests/qemu-iotests/088 > create mode 100644 tests/qemu-iotests/088.out > > diff --git a/tests/qemu-iotests/041 b/tests/qemu-iotests/041 > index ec470b2..10535a6 100755 > --- a/tests/qemu-iotests/041 > +++ b/tests/qemu-iotests/041 > @@ -21,45 +21,13 @@ > import time > import os > import iotests > -from iotests import qemu_img, qemu_io > +from iotests import qemu_img, qemu_io, ImageMirroringTestCase > =20 > backing_img =3D os.path.join(iotests.test_dir, 'backing.img') > target_backing_img =3D os.path.join(iotests.test_dir, 'target-backing= .img') > test_img =3D os.path.join(iotests.test_dir, 'test.img') > target_img =3D os.path.join(iotests.test_dir, 'target.img') > =20 > -class ImageMirroringTestCase(iotests.QMPTestCase): > - '''Abstract base class for image mirroring test cases''' > - > - def wait_ready(self, drive=3D'drive0'): > - '''Wait until a block job BLOCK_JOB_READY event''' > - ready =3D False > - while not ready: > - for event in self.vm.get_qmp_events(wait=3DTrue): > - if event['event'] =3D=3D 'BLOCK_JOB_READY': > - self.assert_qmp(event, 'data/type', 'mirror') > - self.assert_qmp(event, 'data/device', drive) > - ready =3D True > - > - def wait_ready_and_cancel(self, drive=3D'drive0'): > - self.wait_ready(drive) > - event =3D self.cancel_and_wait() > - self.assertEquals(event['event'], 'BLOCK_JOB_COMPLETED') > - self.assert_qmp(event, 'data/type', 'mirror') > - self.assert_qmp(event, 'data/offset', self.image_len) > - self.assert_qmp(event, 'data/len', self.image_len) > - > - def complete_and_wait(self, drive=3D'drive0', wait_ready=3DTrue): > - '''Complete a block job and wait for it to finish''' > - if wait_ready: > - self.wait_ready() > - > - result =3D self.vm.qmp('block-job-complete', device=3Ddrive) > - self.assert_qmp(result, 'return', {}) > - > - event =3D self.wait_until_completed() > - self.assert_qmp(event, 'data/type', 'mirror') > - > class TestSingleDrive(ImageMirroringTestCase): > image_len =3D 1 * 1024 * 1024 # MB > =20 > diff --git a/tests/qemu-iotests/088 b/tests/qemu-iotests/088 > new file mode 100755 > index 0000000..326d307 > --- /dev/null > +++ b/tests/qemu-iotests/088 > @@ -0,0 +1,221 @@ > +#!/usr/bin/env python > +# > +# Tests for Quorum image replacement > +# > +# Copyright (C) 2014 Nodalink, EURL. > +# > +# based on 041 > +# > +# This program is free software; you can redistribute it and/or modify > +# it under the terms of the GNU General Public License as published by > +# the Free Software Foundation; either version 2 of the License, or > +# (at your option) any later version. > +# > +# This program is distributed in the hope that it will be useful, > +# but WITHOUT ANY WARRANTY; without even the implied warranty of > +# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the > +# GNU General Public License for more details. > +# > +# You should have received a copy of the GNU General Public License > +# along with this program. If not, see . > +# > + > +import subprocess > +import time > +import os > +import iotests > +from iotests import qemu_img, qemu_img_args > +from iotests import ImageMirroringTestCase > + > +quorum_img1 =3D os.path.join(iotests.test_dir, 'quorum1.img') > +quorum_img2 =3D os.path.join(iotests.test_dir, 'quorum2.img') > +quorum_img3 =3D os.path.join(iotests.test_dir, 'quorum3.img') > +quorum_backup_img =3D os.path.join(iotests.test_dir, 'quorum_backup.im= g') > +quorum_repair_img =3D os.path.join(iotests.test_dir, 'quorum_repair.im= g') > +quorum_snapshot_file =3D os.path.join(iotests.test_dir, 'quorum_snapsh= ot.img') > + > +class TestRepairQuorum(ImageMirroringTestCase): > + """ This class test quorum file repair using drive-mirror. > + It's mostly a fork of TestSingleDrive. """ > + image_len =3D 1 * 1024 * 1024 # MB > + IMAGES =3D [ quorum_img1, quorum_img2, quorum_img3 ] > + > + def setUp(self): > + self.vm =3D iotests.VM() > + > + # Add each individual quorum images > + for i in self.IMAGES: > + qemu_img('create', '-f', iotests.imgfmt, i, > + str(self.image_len)) > + # Assign a node name to each quorum image in order to mani= pulate > + # them > + opts =3D "node-name=3Dimg%i" % self.IMAGES.index(i) > + self.vm =3D self.vm.add_drive(i, opts) > + > + self.vm.launch() > + > + #assemble the quorum block device from the individual files > + args =3D { "options" : { "driver": "quorum", "id": "quorum0", > + "vote-threshold": 2, "children": [ "img0", "img1", "i= mg2" ] } } > + result =3D self.vm.qmp("blockdev-add", **args) > + self.assert_qmp(result, 'return', {}) > + > + > + def tearDown(self): > + self.vm.shutdown() > + for i in self.IMAGES + [ quorum_repair_img ]: > + # Do a try/except because the test may have deleted some i= mages > + try: > + os.remove(i) > + except OSError: > + pass > + > + def test_complete(self): > + self.assert_no_active_block_jobs() > + > + result =3D self.vm.qmp('drive-mirror', device=3D'quorum0', syn= c=3D'full', > + target=3Dquorum_repair_img, format=3Diote= sts.imgfmt) > + self.assert_qmp(result, 'return', {}) > + > + self.wait_ready(drive=3D'quorum0') > + > + result =3D self.vm.qmp('drive-mirror-replace', device=3D'quoru= m0', > + target_reference=3D'img1', new_node_name=3D= 'img11') > + self.assert_qmp(result, 'return', {}) > + > + event =3D self.wait_until_completed(drive=3D'quorum0') > + self.assert_qmp(event, 'data/type', 'mirror') > + > + result =3D self.vm.qmp('query-named-block-nodes') > + self.assert_qmp(result, 'return[0]/file', quorum_repair_img) > + # TODO: a better test requiring some QEMU infrastructure will = be added > + # to check that this file is really driven by quorum > + self.vm.shutdown() > + self.assertTrue(iotests.compare_images(quorum_img2, quorum_rep= air_img), > + 'target image does not match source after mirr= oring') Considering you didn't write anything to the images, this assertion=20 failing would be rather surprising. Perhaps you could write some test=20 data, so the drive-mirror blockjob actually does something? (or maybe=20 I'm mistaken and there is indeed some data) > + > + def test_device_not_active(self): > + result =3D self.vm.qmp('drive-mirror-replace', device=3D'quoru= m12', > + target_reference=3D'img1', new_node_name=3D= 'img11') > + self.assert_qmp(result, 'error/class', 'DeviceNotActive') Hm, this tests what happens if the block device given as the mirroring=20 source does not exist - I could imagine another test for what happens if=20 the block device does exist, but there is no (mirroring) blockjob=20 running. Without any blockjob running, the error path in the newly added=20 code is exactly the same, however (find_block_job() fails); and to test=20 what happens if a different blockjob type is running ("Can only be used=20 on a drive-mirror block job" should be returned) would probably be more=20 difficult. Thus, this test alone probably suffices. > + self.vm.shutdown() > + > + def test_sync_no_full(self): > + self.assert_no_active_block_jobs() > + > + result =3D self.vm.qmp('drive-mirror', device=3D'quorum0', syn= c=3D'none', > + target=3Dquorum_repair_img, format=3Diote= sts.imgfmt) > + self.assert_qmp(result, 'return', {}) > + > + self.wait_ready(drive=3D'quorum0') > + > + result =3D self.vm.qmp('drive-mirror-replace', device=3D'quoru= m0', > + target_reference=3D'img1', new_node_name=3D= 'img11') > + self.assert_qmp(result, 'error/class', 'GenericError') > + > + event =3D self.cancel_and_wait(drive=3D'quorum0', resume=3DTru= e) > + self.assert_qmp(event, 'data/type', 'mirror') > + > + self.vm.shutdown() > + > + def test_sync_empty_reference(self): > + self.assert_no_active_block_jobs() > + > + result =3D self.vm.qmp('drive-mirror', device=3D'quorum0', syn= c=3D'none', Since this test is not about the sync mode, this should most likely be=20 sync=3D'full' again, I guess. The same applies to all the following test=20 functions. > + target=3Dquorum_repair_img, format=3Diote= sts.imgfmt) > + self.assert_qmp(result, 'return', {}) > + > + self.wait_ready(drive=3D'quorum0') > + > + result =3D self.vm.qmp('drive-mirror-replace', device=3D'quoru= m0', > + target_reference=3D'', new_node_name=3D'i= mg11') > + self.assert_qmp(result, 'error/class', 'GenericError') > + > + event =3D self.cancel_and_wait(drive=3D'quorum0', resume=3DTru= e) > + self.assert_qmp(event, 'data/type', 'mirror') > + > + self.vm.shutdown() > + > + def test_sync_no_reference(self): > + self.assert_no_active_block_jobs() > + > + result =3D self.vm.qmp('drive-mirror', device=3D'quorum0', syn= c=3D'none', > + target=3Dquorum_repair_img, format=3Diote= sts.imgfmt) > + self.assert_qmp(result, 'return', {}) > + > + self.wait_ready(drive=3D'quorum0') > + > + result =3D self.vm.qmp('drive-mirror-replace', device=3D'quoru= m0', > + new_node_name=3D'img11') > + self.assert_qmp(result, 'error/class', 'GenericError') > + > + event =3D self.cancel_and_wait(drive=3D'quorum0', resume=3DTru= e) > + self.assert_qmp(event, 'data/type', 'mirror') > + > + self.vm.shutdown() > + > + def test_sync_no_node_name(self): > + self.assert_no_active_block_jobs() > + > + result =3D self.vm.qmp('drive-mirror', device=3D'quorum0', syn= c=3D'none', > + target=3Dquorum_repair_img, format=3Diote= sts.imgfmt) > + self.assert_qmp(result, 'return', {}) > + > + self.wait_ready(drive=3D'quorum0') > + > + result =3D self.vm.qmp('drive-mirror-replace', device=3D'quoru= m0', > + target_reference=3D'img1') > + self.assert_qmp(result, 'error/class', 'GenericError') > + > + event =3D self.cancel_and_wait(drive=3D'quorum0', resume=3DTru= e) > + self.assert_qmp(event, 'data/type', 'mirror') > + > + self.vm.shutdown() > + > + def test_sync_empty_node_name(self): > + self.assert_no_active_block_jobs() > + > + result =3D self.vm.qmp('drive-mirror', device=3D'quorum0', syn= c=3D'none', > + target=3Dquorum_repair_img, format=3Diote= sts.imgfmt) > + self.assert_qmp(result, 'return', {}) > + > + self.wait_ready(drive=3D'quorum0') > + > + result =3D self.vm.qmp('drive-mirror-replace', device=3D'quoru= m0', > + target_reference=3D'img1', new_node_name=3D= '') > + self.assert_qmp(result, 'error/class', 'GenericError') > + > + event =3D self.cancel_and_wait(drive=3D'quorum0', resume=3DTru= e) > + self.assert_qmp(event, 'data/type', 'mirror') > + > + self.vm.shutdown() > + > + def test_source_and_dest_equal(self): > + self.assert_no_active_block_jobs() > + > + result =3D self.vm.qmp('drive-mirror', device=3D'quorum0', syn= c=3D'none', > + target=3Dquorum_repair_img, format=3Diote= sts.imgfmt) > + self.assert_qmp(result, 'return', {}) > + > + self.wait_ready(drive=3D'quorum0') > + > + result =3D self.vm.qmp('drive-mirror-replace', device=3D'quoru= m0', > + target_reference=3D'quorum0', new_node_na= me=3D'img11') > + self.assert_qmp(result, 'error/class', 'GenericError') > + > + event =3D self.cancel_and_wait(drive=3D'quorum0', resume=3DTru= e) > + self.assert_qmp(event, 'data/type', 'mirror') > + > + self.vm.shutdown() In these above test functions, you maybe could even compare the error=20 message in order to make sure it's always appropriate. But the most=20 important thing is that these are reported as errors, hence I'm fine=20 with the GenericError assertions. > + > +if __name__ =3D=3D '__main__': > + p1 =3D subprocess.Popen(qemu_img_args, stdout=3Dsubprocess.PIPE) > + p2 =3D subprocess.Popen(["grep", "quorum"], stdin=3Dp1.stdout, std= out=3Dsubprocess.PIPE) > + p1.stdout.close() # Allow p1 to receive a SIGsubprocess.PIPE if p= 2 exits. > + has_quorum =3D len(p2.communicate()[0]) !=3D 0 > + if has_quorum: > + iotests.main(supported_fmts=3D['qcow2', 'qed']) > + else: > + f =3D open("088.out", "r") > + print(f.read().strip()) > + f.close() I think I'd prefer calling iotests.notrun() here, if possible, rather=20 than giving the impression this test succeeded when it was in fact not=20 run at all. I can live with leaving the other issues unchanged, but for this I do=20 request a change or at least an explanation before giving a reviewed-by. = ;-) Max > diff --git a/tests/qemu-iotests/088.out b/tests/qemu-iotests/088.out > new file mode 100644 > index 0000000..594c16f > --- /dev/null > +++ b/tests/qemu-iotests/088.out > @@ -0,0 +1,5 @@ > +........ > +---------------------------------------------------------------------- > +Ran 8 tests > + > +OK > diff --git a/tests/qemu-iotests/group b/tests/qemu-iotests/group > index b96c6bc..e590d09 100644 > --- a/tests/qemu-iotests/group > +++ b/tests/qemu-iotests/group > @@ -89,3 +89,4 @@ > 085 rw auto quick > 086 rw auto quick > 087 rw auto quick > +088 rw auto > diff --git a/tests/qemu-iotests/iotests.py b/tests/qemu-iotests/iotests= .py > index e4fa9af..a803943 100644 > --- a/tests/qemu-iotests/iotests.py > +++ b/tests/qemu-iotests/iotests.py > @@ -272,6 +272,39 @@ class QMPTestCase(unittest.TestCase): > self.assert_no_active_block_jobs() > return event > =20 > +# made common here for 041 and 088 > +class ImageMirroringTestCase(QMPTestCase): > + '''Abstract base class for image mirroring test cases''' > + > + def wait_ready(self, drive=3D'drive0'): > + '''Wait until a block job BLOCK_JOB_READY event''' > + ready =3D False > + while not ready: > + for event in self.vm.get_qmp_events(wait=3DTrue): > + if event['event'] =3D=3D 'BLOCK_JOB_READY': > + self.assert_qmp(event, 'data/type', 'mirror') > + self.assert_qmp(event, 'data/device', drive) > + ready =3D True > + > + def wait_ready_and_cancel(self, drive=3D'drive0'): > + self.wait_ready(drive=3Ddrive) > + event =3D self.cancel_and_wait(drive=3Ddrive) > + self.assertEquals(event['event'], 'BLOCK_JOB_COMPLETED') > + self.assert_qmp(event, 'data/type', 'mirror') > + self.assert_qmp(event, 'data/offset', self.image_len) > + self.assert_qmp(event, 'data/len', self.image_len) > + > + def complete_and_wait(self, drive=3D'drive0', wait_ready=3DTrue): > + '''Complete a block job and wait for it to finish''' > + if wait_ready: > + self.wait_ready(drive=3Ddrive) > + > + result =3D self.vm.qmp('block-job-complete', device=3Ddrive) > + self.assert_qmp(result, 'return', {}) > + > + event =3D self.wait_until_completed(drive=3Ddrive) > + self.assert_qmp(event, 'data/type', 'mirror') > + > def notrun(reason): > '''Skip this test suite''' > # Each test in qemu-iotests has a number ("seq")