From nobody Mon Feb 9 12:27:07 2026 Delivered-To: importer@patchew.org Received-SPF: pass (zohomail.com: domain of redhat.com designates 205.139.110.120 as permitted sender) client-ip=205.139.110.120; envelope-from=libvir-list-bounces@redhat.com; helo=us-smtp-1.mimecast.com; Authentication-Results: mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of redhat.com designates 205.139.110.120 as permitted sender) smtp.mailfrom=libvir-list-bounces@redhat.com; dmarc=pass(p=none dis=none) header.from=redhat.com ARC-Seal: i=1; a=rsa-sha256; t=1587562135; cv=none; d=zohomail.com; s=zohoarc; b=cAv7+QP/cnD9RCGCkU8VMx9Mp4iypXyGw8h1Od8GzXHlDHl4+uVy/Kf1au2cZpSoY96UrkNGWNmNMFpz+KNH4CGpjsCoMBYxKh0RUpQ4t+9AWUYwRtte4RNcjalyli949L984iEGjRirLxDLytrLPg6R/8eioO3mZX5N4W8bTJs= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1587562135; h=Content-Type:Content-Transfer-Encoding:Cc:Date:From:In-Reply-To:List-Subscribe:List-Post:List-Id:List-Archive:List-Help:List-Unsubscribe:MIME-Version:Message-ID:References:Sender:Subject:To; bh=NKMcUrtxV/6IJ1xYDTX3bBnDWmlnjHqRGU8oWkPEFR4=; b=c4HUkCkth3mNGqdNRerrG2kPO5fKoKjbIF4nE0thld6tPrFxtFV2HCj5Qq/xoTRO/qP0g4rWZ+aUzAjaNJXcToNI32CpYPCRel2y4TkqlZoIhCnFIIZjMNVyPI4YlrgNkMf1L6cEUKaqhZ7GLxVvbgtGWLP90CAmU+Gb/zucYmM= ARC-Authentication-Results: i=1; mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of redhat.com designates 205.139.110.120 as permitted sender) smtp.mailfrom=libvir-list-bounces@redhat.com; dmarc=pass header.from= (p=none dis=none) header.from= Return-Path: Received: from us-smtp-1.mimecast.com (us-smtp-delivery-1.mimecast.com [205.139.110.120]) by mx.zohomail.com with SMTPS id 1587562135289473.3631716849733; Wed, 22 Apr 2020 06:28:55 -0700 (PDT) Received: from mimecast-mx01.redhat.com (mimecast-mx01.redhat.com [209.132.183.4]) (Using TLS) by relay.mimecast.com with ESMTP id us-mta-364-8vg-1uacM0m5g8ntkYgl8A-1; Wed, 22 Apr 2020 09:28:49 -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 mimecast-mx01.redhat.com (Postfix) with ESMTPS id 4DE631922961; Wed, 22 Apr 2020 13:28:43 +0000 (UTC) Received: from colo-mx.corp.redhat.com (colo-mx01.intmail.prod.int.phx2.redhat.com [10.5.11.20]) by smtp.corp.redhat.com (Postfix) with ESMTPS id 13D265C557; Wed, 22 Apr 2020 13:28:43 +0000 (UTC) Received: from lists01.pubmisc.prod.ext.phx2.redhat.com (lists01.pubmisc.prod.ext.phx2.redhat.com [10.5.19.33]) by colo-mx.corp.redhat.com (Postfix) with ESMTP id 8D5C31809543; Wed, 22 Apr 2020 13:28:42 +0000 (UTC) Received: from smtp.corp.redhat.com (int-mx03.intmail.prod.int.phx2.redhat.com [10.5.11.13]) by lists01.pubmisc.prod.ext.phx2.redhat.com (8.13.8/8.13.8) with ESMTP id 03MDSd52005804 for ; Wed, 22 Apr 2020 09:28:39 -0400 Received: by smtp.corp.redhat.com (Postfix) id B738A6084B; Wed, 22 Apr 2020 13:28:39 +0000 (UTC) Received: from sturgeon.redhat.com (unknown [10.40.192.155]) by smtp.corp.redhat.com (Postfix) with ESMTP id 0BB066084A; Wed, 22 Apr 2020 13:28:38 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1587562133; h=from:from:sender:sender:reply-to:subject:subject:date:date: message-id:message-id:to:to:cc:cc:mime-version:mime-version: content-type:content-type: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references:list-id:list-help: list-unsubscribe:list-subscribe:list-post; bh=NKMcUrtxV/6IJ1xYDTX3bBnDWmlnjHqRGU8oWkPEFR4=; b=dar0aXgWAXNyS2IvCibwDh5aJFAIrW68wf1stQRsQVtnKDJxQ9xFKcRCeTj9beuLr2tFum qoaH7yBJxG7e/JaxCzQAmHwAUXYZmq70Q08dWXy1/NAvflMozXoCdQDyemEEtCO7OYhE4M RoCwDr1Y5OS5kITD+qmASbih9WT8jTA= X-MC-Unique: 8vg-1uacM0m5g8ntkYgl8A-1 From: Erik Skultety To: libvir-list@redhat.com Subject: [libvirt-ci PATCH 03/13] lcitool: Prefer tempfile's native wrappers over low level primitives Date: Wed, 22 Apr 2020 15:28:21 +0200 Message-Id: In-Reply-To: References: MIME-Version: 1.0 X-Scanned-By: MIMEDefang 2.79 on 10.5.11.13 X-loop: libvir-list@redhat.com Cc: Erik Skultety X-BeenThere: libvir-list@redhat.com X-Mailman-Version: 2.1.12 Precedence: junk List-Id: Development discussions about the libvirt library & tools List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Sender: libvir-list-bounces@redhat.com Errors-To: libvir-list-bounces@redhat.com X-Scanned-By: MIMEDefang 2.79 on 10.5.11.16 X-Mimecast-Spam-Score: 0 X-Mimecast-Originator: redhat.com Content-Transfer-Encoding: quoted-printable X-ZohoMail-DKIM: pass (identity @redhat.com) Content-Type: text/plain; charset="utf-8" Rather than requiring shutil module to get rid of the temporary directory we're creating for virt-install, let's use the TemporaryDirectory method instead which returns a file-like object which can be used to clean up the standard Python way. Although the internal exit handlers will take care of closing the temporary directories (and thus removing their contents) automatically, let's be explicit anyway and use the 'finally' clause to clean these up on both success and failure. Signed-off-by: Erik Skultety Reviewed-by: Andrea Bolognani --- guests/lcitool | 9 ++++----- 1 file changed, 4 insertions(+), 5 deletions(-) diff --git a/guests/lcitool b/guests/lcitool index 9a9326d..51ee211 100755 --- a/guests/lcitool +++ b/guests/lcitool @@ -23,7 +23,6 @@ import json import os import platform import random -import shutil import string import subprocess import sys @@ -608,8 +607,8 @@ class Application: facts[option] ) =20 - tempdir =3D tempfile.mkdtemp() - initrd_inject =3D os.path.join(tempdir, install_config) + tempdir =3D tempfile.TemporaryDirectory() + initrd_inject =3D os.path.join(tempdir.name, install_config) =20 with open(initrd_inject, "w") as inject: inject.write(content) @@ -663,8 +662,8 @@ class Application: subprocess.check_call(cmd) except Exception as ex: raise Exception("Failed to install '{}': {}".format(host, = ex)) - - shutil.rmtree(tempdir, ignore_errors=3DTrue) + finally: + tempdir.cleanup() =20 def _action_update(self, args): self._execute_playbook("update", args.hosts, args.projects, --=20 2.25.3