diff mbox

[KVM-AUTOTEST,v2,1/3] KVM test: use a better source for random numbers

Message ID 1252678500-29244-1-git-send-email-mgoldish@redhat.com (mailing list archive)
State New, archived
Headers show

Commit Message

Michael Goldish Sept. 11, 2009, 2:14 p.m. UTC
Use random.SystemRandom() (which uses /dev/urandom) in
kvm_utils.generate_random_string().
Currently, when running multiple jobs in parallel, the generated strings
occasionally collide, and this is very bad.

Also, don't seed the random number generator in kvm.py.  This is not necessary
and is probably done by default anyway.

Signed-off-by: Michael Goldish <mgoldish@redhat.com>
---
 client/tests/kvm/kvm.py       |    5 +----
 client/tests/kvm/kvm_utils.py |    3 ++-
 2 files changed, 3 insertions(+), 5 deletions(-)
diff mbox

Patch

diff --git a/client/tests/kvm/kvm.py b/client/tests/kvm/kvm.py
index 4930e80..97c1b00 100644
--- a/client/tests/kvm/kvm.py
+++ b/client/tests/kvm/kvm.py
@@ -1,4 +1,4 @@ 
-import sys, os, time, shelve, random, resource, logging, cPickle
+import sys, os, time, shelve, resource, logging, cPickle
 from autotest_lib.client.bin import test
 from autotest_lib.client.common_lib import error
 
@@ -68,9 +68,6 @@  class kvm(test.test):
         import kvm_utils
         import kvm_preprocessing
 
-        # Seed the random number generator
-        random.seed()
-
         # Enable core dumps
         resource.setrlimit(resource.RLIMIT_CORE, (-1, -1))
 
diff --git a/client/tests/kvm/kvm_utils.py b/client/tests/kvm/kvm_utils.py
index ac9ede7..e4c3580 100644
--- a/client/tests/kvm/kvm_utils.py
+++ b/client/tests/kvm/kvm_utils.py
@@ -676,10 +676,11 @@  def generate_random_string(length):
 
     @length: length of the string that will be generated.
     """
+    r = random.SystemRandom()
     str = ""
     chars = string.letters + string.digits
     while length > 0:
-        str += random.choice(chars)
+        str += r.choice(chars)
         length -= 1
     return str