From patchwork Wed Jul 7 10:32:18 2010 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Michael Goldish X-Patchwork-Id: 110609 Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by demeter.kernel.org (8.14.4/8.14.3) with ESMTP id o67AWZgB003396 for ; Wed, 7 Jul 2010 10:32:35 GMT Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1754573Ab0GGKcc (ORCPT ); Wed, 7 Jul 2010 06:32:32 -0400 Received: from mx1.redhat.com ([209.132.183.28]:42824 "EHLO mx1.redhat.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1753867Ab0GGKcb (ORCPT ); Wed, 7 Jul 2010 06:32:31 -0400 Received: from int-mx05.intmail.prod.int.phx2.redhat.com (int-mx05.intmail.prod.int.phx2.redhat.com [10.5.11.18]) by mx1.redhat.com (8.13.8/8.13.8) with ESMTP id o67AWUep028530 (version=TLSv1/SSLv3 cipher=DHE-RSA-AES256-SHA bits=256 verify=OK); Wed, 7 Jul 2010 06:32:30 -0400 Received: from ns3.rdu.redhat.com (ns3.rdu.redhat.com [10.11.255.199]) by int-mx05.intmail.prod.int.phx2.redhat.com (8.13.8/8.13.8) with ESMTP id o67AWTn0018454; Wed, 7 Jul 2010 06:32:29 -0400 Received: from localhost.localdomain (dhcp-1-188.tlv.redhat.com [10.35.1.188]) by ns3.rdu.redhat.com (8.13.8/8.13.8) with ESMTP id o67AWOQH026807; Wed, 7 Jul 2010 06:32:28 -0400 From: Michael Goldish To: autotest@test.kernel.org, kvm@vger.kernel.org Cc: Michael Goldish Subject: [KVM-AUTOTEST PATCH] KVM test: deal with incompatible env files gracefully (using version numbers) Date: Wed, 7 Jul 2010 13:32:18 +0300 Message-Id: <1278498738-2622-3-git-send-email-mgoldish@redhat.com> In-Reply-To: <1278498738-2622-2-git-send-email-mgoldish@redhat.com> References: <1278498738-2622-1-git-send-email-mgoldish@redhat.com> <1278498738-2622-2-git-send-email-mgoldish@redhat.com> X-Scanned-By: MIMEDefang 2.67 on 10.5.11.18 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.3 (demeter.kernel.org [140.211.167.41]); Wed, 07 Jul 2010 10:32:35 +0000 (UTC) diff --git a/client/tests/kvm/kvm.py b/client/tests/kvm/kvm.py index 9da4c33..f656238 100644 --- a/client/tests/kvm/kvm.py +++ b/client/tests/kvm/kvm.py @@ -21,6 +21,7 @@ class kvm(test.test): (Online doc - Getting started with KVM testing) """ version = 1 + env_version = 0 def run_once(self, params): # Report the parameters we've received and write them as keyvals @@ -39,7 +40,7 @@ class kvm(test.test): logging.info("Unpickling env. You may see some harmless error " "messages.") env_filename = os.path.join(self.bindir, params.get("env", "env")) - env = kvm_utils.load_env(env_filename, {}) + env = kvm_utils.load_env(env_filename, self.env_version) logging.debug("Contents of environment: %s", env) test_passed = False diff --git a/client/tests/kvm/kvm_utils.py b/client/tests/kvm/kvm_utils.py index 4183f1c..fb2d1c2 100644 --- a/client/tests/kvm/kvm_utils.py +++ b/client/tests/kvm/kvm_utils.py @@ -21,17 +21,23 @@ def dump_env(obj, filename): file.close() -def load_env(filename, default={}): +def load_env(filename, version): """ - Load KVM test environment from an environment file. + Load KVM test environment from an env file. + If the version recorded in the file is lower than version, return an empty + env. If some other error occurs during unpickling, return an empty env. - @param filename: Path to a file where the environment was dumped to. + @param filename: Path to an env file. """ + default = {"version": version} try: file = open(filename, "r") - obj = cPickle.load(file) + env = cPickle.load(file) file.close() - return obj + if env.get("version", 0) < version: + logging.warn("Incompatible env file found. Not using it.") + return default + return env # Almost any exception can be raised during unpickling, so let's catch # them all except Exception, e: