Commit a133af22 authored by Carlos Valiente's avatar Carlos Valiente Committed by Iustin Pop
Browse files

Avoid DeprecationWarning on Python >= 2.6



Python 2.6 complains about module 'sha' being deprecated. It makes
execution of Ganeti commands a bit annoying, and when you run
'ganeti-watcher' in cron jobs, you get a mail message after every
execution.

Tests pass under under Python 2.6 and Python 2.4.
Signed-off-by: default avatarIustin Pop <iustin@google.com>
Reviewed-by: default avatarIustin Pop <iustin@google.com>
parent 3994f455
...@@ -29,7 +29,6 @@ the command line scripts. ...@@ -29,7 +29,6 @@ the command line scripts.
import sys import sys
import os import os
import sha
import time import time
import subprocess import subprocess
import re import re
...@@ -47,6 +46,12 @@ import signal ...@@ -47,6 +46,12 @@ import signal
from cStringIO import StringIO from cStringIO import StringIO
try:
from hashlib import sha1
except ImportError:
import sha
sha1 = sha.new
from ganeti import errors from ganeti import errors
from ganeti import constants from ganeti import constants
...@@ -330,7 +335,7 @@ def _FingerprintFile(filename): ...@@ -330,7 +335,7 @@ def _FingerprintFile(filename):
f = open(filename) f = open(filename)
fp = sha.sha() fp = sha1()
while True: while True:
data = f.read(4096) data = f.read(4096)
if not data: if not data:
...@@ -1179,7 +1184,7 @@ def GenerateSecret(): ...@@ -1179,7 +1184,7 @@ def GenerateSecret():
@return: a sha1 hexdigest of a block of 64 random bytes @return: a sha1 hexdigest of a block of 64 random bytes
""" """
return sha.new(os.urandom(64)).hexdigest() return sha1(os.urandom(64)).hexdigest()
def EnsureDirs(dirs): def EnsureDirs(dirs):
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment