From patchwork Fri Sep 11 14:14:58 2009 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Michael Goldish X-Patchwork-Id: 46863 Received: from vger.kernel.org (vger.kernel.org [209.132.176.167]) by demeter.kernel.org (8.14.2/8.14.2) with ESMTP id n8BEIFxs024959 for ; Fri, 11 Sep 2009 14:18:15 GMT Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1753268AbZIKOSI (ORCPT ); Fri, 11 Sep 2009 10:18:08 -0400 Received: (majordomo@vger.kernel.org) by vger.kernel.org id S1753193AbZIKOSI (ORCPT ); Fri, 11 Sep 2009 10:18:08 -0400 Received: from mx1.redhat.com ([209.132.183.28]:26206 "EHLO mx1.redhat.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1752463AbZIKOSH (ORCPT ); Fri, 11 Sep 2009 10:18:07 -0400 Received: from int-mx05.intmail.prod.int.phx2.redhat.com (int-mx05.intmail.prod.int.phx2.redhat.com [10.5.11.18]) by mx1.redhat.com (8.13.8/8.13.8) with ESMTP id n8BEI9Zb005562; Fri, 11 Sep 2009 10:18:10 -0400 Received: from ns3.rdu.redhat.com (ns3.rdu.redhat.com [10.11.255.199]) by int-mx05.intmail.prod.int.phx2.redhat.com (8.13.8/8.13.8) with ESMTP id n8BEI9PN017840; Fri, 11 Sep 2009 10:18:09 -0400 Received: from localhost.localdomain (dhcp-1-188.tlv.redhat.com [10.35.1.188]) by ns3.rdu.redhat.com (8.13.8/8.13.8) with ESMTP id n8BEI74p023208; Fri, 11 Sep 2009 10:18:07 -0400 From: Michael Goldish To: autotest@test.kernel.org, kvm@vger.kernel.org Cc: Michael Goldish Subject: [KVM-AUTOTEST PATCH v2 1/3] KVM test: use a better source for random numbers Date: Fri, 11 Sep 2009 17:14:58 +0300 Message-Id: <1252678500-29244-1-git-send-email-mgoldish@redhat.com> X-Scanned-By: MIMEDefang 2.67 on 10.5.11.18 Sender: kvm-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: kvm@vger.kernel.org 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 --- client/tests/kvm/kvm.py | 5 +---- client/tests/kvm/kvm_utils.py | 3 ++- 2 files changed, 3 insertions(+), 5 deletions(-) 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