From patchwork Tue Feb 26 15:53:25 2019 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Andrey Shinkevich X-Patchwork-Id: 10830511 Return-Path: Received: from mail.wl.linuxfoundation.org (pdx-wl-mail.web.codeaurora.org [172.30.200.125]) by pdx-korg-patchwork-2.web.codeaurora.org (Postfix) with ESMTP id 686261390 for ; Tue, 26 Feb 2019 15:54:22 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 55FE82CBD5 for ; Tue, 26 Feb 2019 15:54:22 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id 49C2E2CC0C; Tue, 26 Feb 2019 15:54:22 +0000 (UTC) X-Spam-Checker-Version: SpamAssassin 3.3.1 (2010-03-16) on pdx-wl-mail.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-2.9 required=2.0 tests=BAYES_00,MAILING_LIST_MULTI autolearn=ham version=3.3.1 Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) (using TLSv1 with cipher AES256-SHA (256/256 bits)) (No client certificate requested) by mail.wl.linuxfoundation.org (Postfix) with ESMTPS id EAF242CBD5 for ; Tue, 26 Feb 2019 15:54:21 +0000 (UTC) Received: from localhost ([127.0.0.1]:57590 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1gyf3l-0002Dp-4k for patchwork-qemu-devel@patchwork.kernel.org; Tue, 26 Feb 2019 10:54:21 -0500 Received: from eggs.gnu.org ([209.51.188.92]:49699) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1gyf34-0001rv-ND for qemu-devel@nongnu.org; Tue, 26 Feb 2019 10:53:39 -0500 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1gyf33-0003DN-Sk for qemu-devel@nongnu.org; Tue, 26 Feb 2019 10:53:38 -0500 Received: from relay.sw.ru ([185.231.240.75]:48998) by eggs.gnu.org with esmtps (TLS1.0:DHE_RSA_AES_256_CBC_SHA1:32) (Exim 4.71) (envelope-from ) id 1gyf2z-00039A-5S; Tue, 26 Feb 2019 10:53:36 -0500 Received: from [172.16.25.136] (helo=localhost.sw.ru) by relay.sw.ru with esmtp (Exim 4.91) (envelope-from ) id 1gyf2s-0000Fx-Mx; Tue, 26 Feb 2019 18:53:26 +0300 From: Andrey Shinkevich To: qemu-devel@nongnu.org, qemu-block@nongnu.org Date: Tue, 26 Feb 2019 18:53:25 +0300 Message-Id: <1551196405-23815-1-git-send-email-andrey.shinkevich@virtuozzo.com> X-Mailer: git-send-email 1.8.3.1 X-detected-operating-system: by eggs.gnu.org: GNU/Linux 3.x X-Received-From: 185.231.240.75 Subject: [Qemu-devel] [PATCH v3] iotests: handle TypeError for Python 3 in test 242 X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.21 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: kwolf@redhat.com, vsementsov@virtuozzo.com, ehabkost@redhat.com, mreitz@redhat.com, nsoffer@redhat.com, andrey.shinkevich@virtuozzo.com, den@openvz.org Errors-To: qemu-devel-bounces+patchwork-qemu-devel=patchwork.kernel.org@nongnu.org Sender: "Qemu-devel" X-Virus-Scanned: ClamAV using ClamSMTP The data type for bytes in Python 3 differs from the one in Python 2. The type cast that is compatible with both versions was applied. Signed-off-by: Andrey Shinkevich Reported-by: Kevin Wolf --- v2: The TypeError in Python3 was handled based on the version check. Discussed in the e-mail thread with the Message ID: <1550834773-873512-1-git-send-email-andrey.shinkevich@virtuozzo.com> v1: The TypeError in Python3 was handled as the exception. Discussed in the e-mail thread with the Message ID: <1550519997-253534-1-git-send-email-andrey.shinkevich@virtuozzo.com> tests/qemu-iotests/242 | 8 +++++--- 1 file changed, 5 insertions(+), 3 deletions(-) diff --git a/tests/qemu-iotests/242 b/tests/qemu-iotests/242 index 16c65ed..c176e92 100755 --- a/tests/qemu-iotests/242 +++ b/tests/qemu-iotests/242 @@ -20,6 +20,7 @@ import iotests import json +import struct from iotests import qemu_img_create, qemu_io, qemu_img_pipe, \ file_path, img_info_log, log, filter_qemu_io @@ -64,10 +65,11 @@ def write_to_disk(offset, size): def toggle_flag(offset): with open(disk, "r+b") as f: f.seek(offset, 0) - c = f.read(1) - toggled = chr(ord(c) ^ bitmap_flag_unknown) + # Read one byte in a way compatible with Python 2 + flags = struct.unpack("B", f.read(1)) + toggled = flags[0] ^ bitmap_flag_unknown f.seek(-1, 1) - f.write(toggled) + f.write(struct.pack("B", toggled)) qemu_img_create('-f', iotests.imgfmt, disk, '1M')