From: Lucas Meneghel Rodrigues Subject: [PATCH 5/6] KVM test: Getting rid of annoying deprecation message Date: Fri, 29 Jan 2010 04:07:31 -0200 Message-ID: <1264745252-14077-5-git-send-email-lmr@redhat.com> References: <1264745252-14077-1-git-send-email-lmr@redhat.com> <1264745252-14077-2-git-send-email-lmr@redhat.com> <1264745252-14077-3-git-send-email-lmr@redhat.com> <1264745252-14077-4-git-send-email-lmr@redhat.com> Mime-Version: 1.0 Content-Type: text/plain; charset="us-ascii" Content-Transfer-Encoding: 7bit Cc: kvm@vger.kernel.org To: autotest@test.kernel.org Return-path: In-Reply-To: <1264745252-14077-4-git-send-email-lmr@redhat.com> List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Sender: autotest-bounces@test.kernel.org Errors-To: autotest-bounces@test.kernel.org List-Id: kvm.vger.kernel.org When using python > 2.5, use the recommended hashlib. When using python 2.4, fall back to the md5 and sha modules. Signed-off-by: Lucas Meneghel Rodrigues --- client/tests/kvm/kvm_utils.py | 18 ++++++++++++++---- client/tests/kvm/ppm_utils.py | 12 +++++++++--- client/tests/kvm/tests/steps.py | 2 +- 3 files changed, 24 insertions(+), 8 deletions(-) diff --git a/client/tests/kvm/kvm_utils.py b/client/tests/kvm/kvm_utils.py index 5452026..b1f184e 100644 --- a/client/tests/kvm/kvm_utils.py +++ b/client/tests/kvm/kvm_utils.py @@ -4,10 +4,14 @@ KVM test utility functions. @copyright: 2008-2009 Red Hat Inc. """ -import md5, sha, thread, subprocess, time, string, random, socket, os, signal +import thread, subprocess, time, string, random, socket, os, signal +try: + import hashlib +except ImportError: + import md5, sha import select, re, logging, commands, cPickle, pty from autotest_lib.client.bin import utils -from autotest_lib.client.common_lib import error +from autotest_lib.client.common_lib import error, logging_config import kvm_subprocess @@ -789,9 +793,15 @@ def hash_file(filename, size=None, method="md5"): f = open(filename, 'rb') if method == "md5": - hash = md5.new() + try: + hash = hashlib.new('md5') + except NameError: + hash = md5.new() elif method == "sha1": - hash = sha.new() + try: + hash = hashlib.new('sha1') + except NameError: + hash = sha.new() else: logging.error("Unknown hash type %s, returning None" % method) return None diff --git a/client/tests/kvm/ppm_utils.py b/client/tests/kvm/ppm_utils.py index 8ff31da..aaea298 100644 --- a/client/tests/kvm/ppm_utils.py +++ b/client/tests/kvm/ppm_utils.py @@ -4,8 +4,11 @@ Utility functions to deal with ppm (qemu screendump format) files. @copyright: Red Hat 2008-2009 """ -import md5, os, struct, time, re - +import os, struct, time, re +try: + import hashlib +except ImportError: + import md5 # Some directory/filename utils, for consistency @@ -120,7 +123,10 @@ def image_md5sum(width, height, data): @data: PPM file data """ header = "P6\n%d %d\n255\n" % (width, height) - md5obj = md5.new(header) + try: + md5obj = hashlib.md5(header) + except NameError: + md5obj = md5.new(header) md5obj.update(data) return md5obj.hexdigest() diff --git a/client/tests/kvm/tests/steps.py b/client/tests/kvm/tests/steps.py index 456fb44..8ebe7c1 100644 --- a/client/tests/kvm/tests/steps.py +++ b/client/tests/kvm/tests/steps.py @@ -4,7 +4,7 @@ Utilities to perform automatic guest installation using step files. @copyright: Red Hat 2008-2009 """ -import os, time, md5, re, shutil, logging +import os, time, re, shutil, logging from autotest_lib.client.common_lib import utils, error import kvm_utils, ppm_utils, kvm_subprocess try: -- 1.6.6