From patchwork Sun Jul 17 20:56:31 2011 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Lucas Meneghel Rodrigues X-Patchwork-Id: 984482 Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by demeter2.kernel.org (8.14.4/8.14.4) with ESMTP id p6HKudwr027050 for ; Sun, 17 Jul 2011 20:56:39 GMT Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1756350Ab1GQU4f (ORCPT ); Sun, 17 Jul 2011 16:56:35 -0400 Received: from mx1.redhat.com ([209.132.183.28]:44995 "EHLO mx1.redhat.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1755124Ab1GQU4f (ORCPT ); Sun, 17 Jul 2011 16:56:35 -0400 Received: from int-mx10.intmail.prod.int.phx2.redhat.com (int-mx10.intmail.prod.int.phx2.redhat.com [10.5.11.23]) by mx1.redhat.com (8.14.4/8.14.4) with ESMTP id p6HKuYQv022146 (version=TLSv1/SSLv3 cipher=DHE-RSA-AES256-SHA bits=256 verify=OK); Sun, 17 Jul 2011 16:56:34 -0400 Received: from freedom.redhat.com (vpn-9-95.rdu.redhat.com [10.11.9.95]) by int-mx10.intmail.prod.int.phx2.redhat.com (8.14.4/8.14.4) with ESMTP id p6HKuW07019243; Sun, 17 Jul 2011 16:56:33 -0400 From: Lucas Meneghel Rodrigues To: autotest@test.kernel.org Cc: kvm@vger.kernel.org, Lucas Meneghel Rodrigues Subject: [PATCH] client.virt.virt_utils: Only try to load the env file if it exists Date: Sun, 17 Jul 2011 17:56:31 -0300 Message-Id: <1310936191-862-1-git-send-email-lmr@redhat.com> X-Scanned-By: MIMEDefang 2.68 on 10.5.11.23 Sender: kvm-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: kvm@vger.kernel.org X-Greylist: IP, sender and recipient auto-whitelisted, not delayed by milter-greylist-4.2.6 (demeter2.kernel.org [140.211.167.43]); Sun, 17 Jul 2011 20:56:39 +0000 (UTC) We are trying to load a previous env file even when there's no such file available, leading to the unnecessary warning message 15:44:52 WARNI| [Errno 2] No such file or directory: '/home/lmr/Code/autotest-git/client/tests/kvm/env' So let's try to load the env file only if the file exists, otherwise just skip the cPickle.load(file) step. Signed-off-by: Lucas Meneghel Rodrigues --- client/virt/virt_utils.py | 16 ++++++++++------ 1 files changed, 10 insertions(+), 6 deletions(-) diff --git a/client/virt/virt_utils.py b/client/virt/virt_utils.py index d443a84..7026492 100644 --- a/client/virt/virt_utils.py +++ b/client/virt/virt_utils.py @@ -150,13 +150,17 @@ class Env(UserDict.IterableUserDict): if filename: self._filename = filename try: - f = open(filename, "r") - env = cPickle.load(f) - f.close() - if env.get("version", 0) >= version: - self.data = env + if os.path.isfile(filename): + f = open(filename, "r") + env = cPickle.load(f) + f.close() + if env.get("version", 0) >= version: + self.data = env + else: + logging.warn("Incompatible env file found. Not using it.") + self.data = empty else: - logging.warn("Incompatible env file found. Not using it.") + # No previous env file found, proceed... self.data = empty # Almost any exception can be raised during unpickling, so let's # catch them all