diff mbox

[5/6] KVM test: Getting rid of annoying deprecation message

Message ID 1264745252-14077-5-git-send-email-lmr@redhat.com (mailing list archive)
State New, archived
Headers show

Commit Message

Lucas Meneghel Rodrigues Jan. 29, 2010, 6:07 a.m. UTC
None
diff mbox

Patch

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: