Received: from eggs.gnu.org ([208.118.235.92]:44260) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1Uhe9D-0008RH-Ud for qemu-devel@nongnu.org; Wed, 29 May 2013 07:02:34 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1Uhe97-0007l2-Pr for qemu-devel@nongnu.org; Wed, 29 May 2013 07:02:27 -0400 Received: from mx1.redhat.com ([209.132.183.28]:58655) by eggs.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1Uhe97-0007jz-I5 for qemu-devel@nongnu.org; Wed, 29 May 2013 07:02:21 -0400 Received: from int-mx11.intmail.prod.int.phx2.redhat.com (int-mx11.intmail.prod.int.phx2.redhat.com [10.5.11.24]) by mx1.redhat.com (8.14.4/8.14.4) with ESMTP id r4TB2JwM026279 (version=TLSv1/SSLv3 cipher=DHE-RSA-AES256-SHA bits=256 verify=OK) for ; Wed, 29 May 2013 07:02:20 -0400 Date: Wed, 29 May 2013 13:02:17 +0200 From: Stefan Hajnoczi Message-ID: <20130529110217.GA6932@stefanha-thinkpad.redhat.com> References: <1369753897-15140-1-git-send-email-stefanha@redhat.com> <1369753897-15140-3-git-send-email-stefanha@redhat.com> <20130529095456.GD3521@dhcp-200-207.str.redhat.com> MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: <20130529095456.GD3521@dhcp-200-207.str.redhat.com> Subject: Re: [Qemu-devel] [PATCH 2/4] qemu-iotests: make cancel_and_wait() common List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , To: Kevin Wolf Cc: qemu-devel@nongnu.org On Wed, May 29, 2013 at 11:54:56AM +0200, Kevin Wolf wrote: > Am 28.05.2013 um 17:11 hat Stefan Hajnoczi geschrieben: > > - def cancel_and_wait(self, drive='drive0', wait_ready=True): > > - '''Cancel a block job and wait for it to finish''' > > - if wait_ready: > > - ready = False > > - while not ready: > > - for event in self.vm.get_qmp_events(wait=True): > > - if event['event'] == 'BLOCK_JOB_READY': > > - self.assert_qmp(event, 'data/type', 'mirror') > > - self.assert_qmp(event, 'data/device', drive) > > - ready = True > > - > > - result = self.vm.qmp('block-job-cancel', device=drive, > > - force=not wait_ready) > > - self.assert_qmp(result, 'return', {}) > > - > > - cancelled = False > > - while not cancelled: > > + def wait_ready(self, drive='drive0'): > > + '''Wait until a block job BLOCK_JOB_READY event''' > > + ready = False > > + while not ready: > > for event in self.vm.get_qmp_events(wait=True): > > - if event['event'] == 'BLOCK_JOB_COMPLETED' or \ > > - event['event'] == 'BLOCK_JOB_CANCELLED': > > + if event['event'] == 'BLOCK_JOB_READY': > > self.assert_qmp(event, 'data/type', 'mirror') > > self.assert_qmp(event, 'data/device', drive) > > - if wait_ready: > > - self.assertEquals(event['event'], 'BLOCK_JOB_COMPLETED') > > - self.assert_qmp(event, 'data/offset', self.image_len) > > - self.assert_qmp(event, 'data/len', self.image_len) > > - cancelled = True > > + ready = True > > Why don't you just move the whole function including the wait_ready > parameter? It doesn't do any harm to other callers that don't need the > feature, and will likely be useful for other test cases later. The BLOCK_JOB_READY and block-job-complete concepts are used by mirroring only. Plus the mirroring test cases perform additional checks on the event object which aren't common. I figured the cleanest solution is the patch I posted. Stefan