From nobody Wed May 8 23:23:09 2024 Delivered-To: importer@patchew.org Received-SPF: pass (zoho.com: domain of gnu.org designates 209.51.188.17 as permitted sender) client-ip=209.51.188.17; envelope-from=qemu-devel-bounces+importer=patchew.org@nongnu.org; helo=lists.gnu.org; Authentication-Results: mx.zohomail.com; dkim=fail; spf=pass (zoho.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; dmarc=fail(p=none dis=none) header.from=linaro.org ARC-Seal: i=1; a=rsa-sha256; t=1567089757; cv=none; d=zoho.com; s=zohoarc; b=aDRx21nl9F+Pv3UwxPd2m2fjcazRk8A5FvPZRulrDlGP3aWP4FiZedW/HcwPiZ71CZ2lKfVTceq9H1Hz0Ti1tB2erRS4kQzuP31Dm83reeva1twLZkiFSWyE9cY/muN4EK1z/4ehCzU8CfYSmD/KKn8/D7xzbJX3U8CBbkXMOew= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zoho.com; s=zohoarc; t=1567089757; h=Content-Type:Content-Transfer-Encoding:Cc:Date:From:List-Subscribe:List-Post:List-Id:List-Archive:List-Help:List-Unsubscribe:MIME-Version:Message-ID:Sender:Subject:To:ARC-Authentication-Results; bh=MkUUiHNi/V+ZSI721KImT4VbYLQNe8mvaERHRh/XulI=; b=AH4lwQJabnJKlSqkJO0kRB//tOGHQo6SQtnvnEAVw9TEhiyr2K90vMo02045e1GtSGd0mdoBlHJjwAX7Zgt7bofyQrb/g8DL0TXqYvtT3y6qe7QFflWsaUseWMzpmV5DxUH2DiGctSbEhbx7gT0EpfisNwvxqJwfb0gfvODiRq4= ARC-Authentication-Results: i=1; mx.zoho.com; dkim=fail; spf=pass (zoho.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; dmarc=fail header.from= (p=none dis=none) header.from= Return-Path: Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) by mx.zohomail.com with SMTPS id 1567089757843571.0721257538394; Thu, 29 Aug 2019 07:42:37 -0700 (PDT) Received: from localhost ([::1]:50562 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1i3LdB-0004xt-61 for importer@patchew.org; Thu, 29 Aug 2019 10:42:33 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]:42933) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1i3LcF-0004Yc-3a for qemu-devel@nongnu.org; Thu, 29 Aug 2019 10:41:36 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1i3LcD-0001QE-MJ for qemu-devel@nongnu.org; Thu, 29 Aug 2019 10:41:34 -0400 Received: from mail-wm1-x32b.google.com ([2a00:1450:4864:20::32b]:34218) by eggs.gnu.org with esmtps (TLS1.0:RSA_AES_128_CBC_SHA1:16) (Exim 4.71) (envelope-from ) id 1i3LcD-0001Of-FE for qemu-devel@nongnu.org; Thu, 29 Aug 2019 10:41:33 -0400 Received: by mail-wm1-x32b.google.com with SMTP id y135so2235210wmc.1 for ; Thu, 29 Aug 2019 07:41:32 -0700 (PDT) Received: from zen.linaroharston ([51.148.130.216]) by smtp.gmail.com with ESMTPSA id c201sm5779984wmd.33.2019.08.29.07.41.30 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 29 Aug 2019 07:41:30 -0700 (PDT) Received: from zen.lan (localhost [127.0.0.1]) by zen.linaroharston (Postfix) with ESMTP id 38E591FF87; Thu, 29 Aug 2019 15:41:30 +0100 (BST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linaro.org; s=google; h=from:to:cc:subject:date:message-id:mime-version :content-transfer-encoding; bh=MkUUiHNi/V+ZSI721KImT4VbYLQNe8mvaERHRh/XulI=; b=qek6ysllYi7gIGSaUg/7OtqdYrNk9PDyTEFRS2+fL/wrJnlTDHOm0v4YQdoL72VU+n 4H0h7oK+dKJ3pbYVAVdFNfXTZgj7z2XCQclLlD0URbarNiJ6VpEvydv4b3jMdNB2Nv6X Hz+5lrnNvl/4Syicqd0JaZp7Akeq4ubgwMSCfGmQenAsGdAvS5W4SMWxoKqBMhiWmIZj KQehqn3aTV9D3nex8A18wymg08oTMsaVNlbZNWOYitChCXE5Io0CE89z5t1W2dukt1/B eI8VCw/MoVh8dKJJ2BaRt4z+GLIxa1Y/7NKnBjo70dxbh++HqVLZGdjS7FWGEL82307C zDag== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:cc:subject:date:message-id:mime-version :content-transfer-encoding; bh=MkUUiHNi/V+ZSI721KImT4VbYLQNe8mvaERHRh/XulI=; b=ufjDVM0GHhNCI8Ff0wCQrqtNsHFcXxHdbgcuWHF/pkOveYXyPBarHWWAWr448T548h ucRMoej6TDKsOXE/7lMjSkhfptkBLw28SwbcWuexeivwWXwTondamTWy3krwyhb6YYih /8O302Fz7ecw9q/7dH6gan4bEi6/av5Q1o+C9FsZffVzE/XyO6jSahn8gnNuU8yRX2dA eTBhR22ZgsOR5k39PsPj+WnWEmmrmg0nvSpPOQSzqqR9GhYVYwXPtG0YZjoWrqTVC7JS 6w1DAdlZfk4h8HxOCAQG4cTW+Odo9Mt5gke285WmjrSdxQ0N6EfdoSKRteeqxY6CsVbt iv2g== X-Gm-Message-State: APjAAAVeZXB8SsH5mTuk5aXlc8gDuljlUYwaWaG6ULZ6mzSqMfPBveRq VfCxjA2E6A2yuhXrUjTKTIYlAQ== X-Google-Smtp-Source: APXvYqzje/X5GV8MtB1Vz19YZPwThycmKR6Ow1EKniOPzIa0OQDLtvRS8Q5l32zHHQzNXfkcEfy8aA== X-Received: by 2002:a1c:be11:: with SMTP id o17mr11936645wmf.115.1567089691476; Thu, 29 Aug 2019 07:41:31 -0700 (PDT) From: =?UTF-8?q?Alex=20Benn=C3=A9e?= To: qemu-devel@nongnu.org Date: Thu, 29 Aug 2019 15:41:20 +0100 Message-Id: <20190829144120.12701-1-alex.bennee@linaro.org> X-Mailer: git-send-email 2.20.1 MIME-Version: 1.0 Content-Type: text/plain; charset="utf-8" Content-Transfer-Encoding: quoted-printable X-detected-operating-system: by eggs.gnu.org: Genre and OS details not recognized. X-Received-From: 2a00:1450:4864:20::32b Subject: [Qemu-devel] [PATCH] tests/docker: upgrade docker.py to python3 X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.23 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: Fam Zheng , berrange@redhat.com, =?UTF-8?q?Philippe=20Mathieu-Daud=C3=A9?= , f4bug@amsat.org, =?UTF-8?q?Marc-Andr=C3=A9=20Lureau?= , =?UTF-8?q?Alex=20Benn=C3=A9e?= Errors-To: qemu-devel-bounces+importer=patchew.org@nongnu.org Sender: "Qemu-devel" X-ZohoMail-DKIM: fail (Header signature does not verify) The recent podman changes (9459f754134bb) imported enum which is part of the python3 standard library but only available as an external library for python2. This causes problems on the fairly restricted environment such as shippable. Lets bite the bullet and make the script a fully python3 one. To that end: - drop the from __future__ import (we are there now ;-) - avoid the StringIO import hack - be consistent with the mode we read/write dockerfiles - s/iteritems/items/ - ensure check_output returns strings for processing Signed-off-by: Alex Benn=C3=A9e Cc: Marc-Andr=C3=A9 Lureau Reviewed-by: Daniel P. Berrang=C3=A9 Reviewed-by: Philippe Mathieu-Daud=C3=A9 --- tests/docker/docker.py | 27 ++++++++++++++------------- 1 file changed, 14 insertions(+), 13 deletions(-) diff --git a/tests/docker/docker.py b/tests/docker/docker.py index ac5baab4cad..4bba29e104e 100755 --- a/tests/docker/docker.py +++ b/tests/docker/docker.py @@ -1,4 +1,4 @@ -#!/usr/bin/env python2 +#!/usr/bin/env python3 # # Docker controlling module # @@ -11,7 +11,6 @@ # or (at your option) any later version. See the COPYING file in # the top-level directory. =20 -from __future__ import print_function import os import sys import subprocess @@ -25,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 StringIO from shutil import copy, rmtree from pwd import getpwuid from datetime import datetime, timedelta @@ -62,11 +58,13 @@ USE_ENGINE =3D EngineEnum.AUTO =20 def _text_checksum(text): """Calculate a digest string unique to the text content""" - return hashlib.sha1(text).hexdigest() + return hashlib.sha1(text.encode('utf-8')).hexdigest() =20 +def _read_dockerfile(path): + return open(path, 'rt', encoding=3D'utf-8').read() =20 def _file_checksum(filename): - return _text_checksum(open(filename, 'rb').read()) + return _text_checksum(_read_dockerfile(filename)) =20 =20 def _guess_engine_command(): @@ -192,7 +190,7 @@ def _read_qemu_dockerfile(img_name): =20 df =3D os.path.join(os.path.dirname(__file__), "dockerfiles", img_name + ".docker") - return open(df, "r").read() + return _read_dockerfile(df) =20 =20 def _dockerfile_preprocess(df): @@ -262,6 +260,7 @@ class Docker(object): def _output(self, cmd, **kwargs): return subprocess.check_output(self._command + cmd, stderr=3Dsubprocess.STDOUT, + encoding=3D'utf-8', **kwargs) =20 def inspect_tag(self, tag): @@ -283,7 +282,9 @@ class Docker(object): if argv is None: argv =3D [] =20 - tmp_df =3D tempfile.NamedTemporaryFile(dir=3Ddocker_dir, suffix=3D= ".docker") + tmp_df =3D tempfile.NamedTemporaryFile(mode=3D"w+t", + encoding=3D'utf-8', + dir=3Ddocker_dir, suffix=3D".= docker") tmp_df.write(dockerfile) =20 if user: @@ -396,7 +397,7 @@ class BuildCommand(SubCommand): help=3D"Dockerfile name") =20 def run(self, args, argv): - dockerfile =3D open(args.dockerfile, "rb").read() + dockerfile =3D _read_dockerfile(args.dockerfile) tag =3D args.tag =20 dkr =3D Docker() @@ -442,7 +443,7 @@ class BuildCommand(SubCommand): cksum +=3D [(filename, _file_checksum(filename))] =20 argv +=3D ["--build-arg=3D" + k.lower() + "=3D" + v - for k, v in os.environ.iteritems() + for k, v in os.environ.items() if k.lower() in FILTERED_ENV_NAMES] dkr.build_image(tag, docker_dir, dockerfile, quiet=3Dargs.quiet, user=3Dargs.user, argv=3Da= rgv, @@ -611,7 +612,7 @@ class CheckCommand(SubCommand): print("Need a dockerfile for tag:%s" % (tag)) return 1 =20 - dockerfile =3D open(args.dockerfile, "rb").read() + dockerfile =3D _read_dockerfile(args.dockerfile) =20 if dkr.image_matches_dockerfile(tag, dockerfile): if not args.quiet: --=20 2.20.1