@@ -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
@@ -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()
@@ -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: