From patchwork Wed Jun 27 02:14:18 2018 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Eduardo Habkost X-Patchwork-Id: 935224 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@bilbo.ozlabs.org Authentication-Results: ozlabs.org; spf=pass (mailfrom) smtp.mailfrom=nongnu.org (client-ip=2001:4830:134:3::11; helo=lists.gnu.org; envelope-from=qemu-devel-bounces+incoming=patchwork.ozlabs.org@nongnu.org; receiver=) Authentication-Results: ozlabs.org; dmarc=fail (p=none dis=none) header.from=redhat.com Received: from lists.gnu.org (lists.gnu.org [IPv6:2001:4830:134:3::11]) (using TLSv1 with cipher AES256-SHA (256/256 bits)) (No client certificate requested) by ozlabs.org (Postfix) with ESMTPS id 41Fmhs5d9Zz9s29 for ; Wed, 27 Jun 2018 12:15:25 +1000 (AEST) Received: from localhost ([::1]:56126 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1fXzzP-0006hS-9z for incoming@patchwork.ozlabs.org; Tue, 26 Jun 2018 22:15:23 -0400 Received: from eggs.gnu.org ([2001:4830:134:3::10]:38554) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1fXzyk-0006fu-KY for qemu-devel@nongnu.org; Tue, 26 Jun 2018 22:14:43 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1fXzyj-00020l-PO for qemu-devel@nongnu.org; Tue, 26 Jun 2018 22:14:42 -0400 Received: from mx1.redhat.com ([209.132.183.28]:52000) by eggs.gnu.org with esmtps (TLS1.0:DHE_RSA_AES_256_CBC_SHA1:32) (Exim 4.71) (envelope-from ) id 1fXzyj-0001zu-Ia for qemu-devel@nongnu.org; Tue, 26 Jun 2018 22:14:41 -0400 Received: from smtp.corp.redhat.com (int-mx06.intmail.prod.int.phx2.redhat.com [10.5.11.16]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mx1.redhat.com (Postfix) with ESMTPS id D240F30820C2; Wed, 27 Jun 2018 02:14:40 +0000 (UTC) Received: from localhost (ovpn-116-35.gru2.redhat.com [10.97.116.35]) by smtp.corp.redhat.com (Postfix) with ESMTP id 7CBE082F6D; Wed, 27 Jun 2018 02:14:32 +0000 (UTC) From: Eduardo Habkost To: qemu-devel@nongnu.org Date: Tue, 26 Jun 2018 23:14:18 -0300 Message-Id: <20180627021423.18404-2-ehabkost@redhat.com> In-Reply-To: <20180627021423.18404-1-ehabkost@redhat.com> References: <20180627021423.18404-1-ehabkost@redhat.com> X-Scanned-By: MIMEDefang 2.79 on 10.5.11.16 X-Greylist: Sender IP whitelisted, not delayed by milter-greylist-4.5.16 (mx1.redhat.com [10.5.110.47]); Wed, 27 Jun 2018 02:14:40 +0000 (UTC) X-detected-operating-system: by eggs.gnu.org: GNU/Linux 2.2.x-3.x [generic] [fuzzy] X-Received-From: 209.132.183.28 Subject: [Qemu-devel] [PATCH 1/6] docker: Use BytesIO instead of StringIO 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: Fam Zheng , =?utf-8?q?Philippe_Mathieu-Daud=C3=A9?= , Stefan Hajnoczi , Cleber Rosa , =?utf-8?q?Alex_Benn=C3=A9e?= Errors-To: qemu-devel-bounces+incoming=patchwork.ozlabs.org@nongnu.org Sender: "Qemu-devel" The file passed as argument to TarFile.addfile() must be a binary file, so BytesIO is more appropriate than StringIO. This is necessary to make the code work on Python 3. Signed-off-by: Eduardo Habkost --- tests/docker/docker.py | 15 ++++++--------- 1 file changed, 6 insertions(+), 9 deletions(-) diff --git a/tests/docker/docker.py b/tests/docker/docker.py index 8e13f18e6c..0de7662146 100755 --- a/tests/docker/docker.py +++ b/tests/docker/docker.py @@ -24,10 +24,7 @@ import tempfile import re import signal from tarfile import TarFile, TarInfo -try: - from StringIO import StringIO -except ImportError: - from io import StringIO +from io import BytesIO from shutil import copy, rmtree from pwd import getpwuid from datetime import datetime,timedelta @@ -372,13 +369,13 @@ class UpdateCommand(SubCommand): tmp_tar.add(os.path.realpath(l), arcname=l) # Create a Docker buildfile - df = StringIO() - df.write("FROM %s\n" % args.tag) - df.write("ADD . /\n") - df.seek(0) + df = BytesIO() + df.write(b"FROM %s\n" % args.tag.encode()) + df.write(b"ADD . /\n") df_tar = TarInfo(name="Dockerfile") - df_tar.size = len(df.buf) + df_tar.size = df.tell() + df.seek(0) tmp_tar.addfile(df_tar, fileobj=df) tmp_tar.close()