From patchwork Mon Oct 26 23:20:45 2009 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Lucas Meneghel Rodrigues X-Patchwork-Id: 55999 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 n9QNKsU4015963 for ; Mon, 26 Oct 2009 23:20:54 GMT Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1754727AbZJZXUr (ORCPT ); Mon, 26 Oct 2009 19:20:47 -0400 Received: (majordomo@vger.kernel.org) by vger.kernel.org id S1754733AbZJZXUr (ORCPT ); Mon, 26 Oct 2009 19:20:47 -0400 Received: from mx1.redhat.com ([209.132.183.28]:29296 "EHLO mx1.redhat.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1754726AbZJZXUq (ORCPT ); Mon, 26 Oct 2009 19:20:46 -0400 Received: from int-mx01.intmail.prod.int.phx2.redhat.com (int-mx01.intmail.prod.int.phx2.redhat.com [10.5.11.11]) by mx1.redhat.com (8.13.8/8.13.8) with ESMTP id n9QNKmR5026347; Mon, 26 Oct 2009 19:20:48 -0400 Received: from localhost.localdomain (vpn-12-156.rdu.redhat.com [10.11.12.156]) by int-mx01.intmail.prod.int.phx2.redhat.com (8.13.8/8.13.8) with ESMTP id n9QNKkQg019441; Mon, 26 Oct 2009 19:20:46 -0400 From: Lucas Meneghel Rodrigues To: autotest@test.kernel.org Cc: kvm@vger.kernel.org, Lucas Meneghel Rodrigues Subject: [PATCH] KVM test: Add new program cd_hash.py Date: Mon, 26 Oct 2009 21:20:45 -0200 Message-Id: <1256599245-5807-1-git-send-email-lmr@redhat.com> X-Scanned-By: MIMEDefang 2.67 on 10.5.11.11 Sender: kvm-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: kvm@vger.kernel.org diff --git a/client/tests/kvm/calc_md5sum_1m.py b/client/tests/kvm/calc_md5sum_1m.py deleted file mode 100755 index 153a1e0..0000000 --- a/client/tests/kvm/calc_md5sum_1m.py +++ /dev/null @@ -1,21 +0,0 @@ -#!/usr/bin/python -""" -Program that calculates the md5sum for the first megabyte of a file. -It's faster than calculating the md5sum for the whole ISO image. - -@copyright: Red Hat 2008-2009 -@author: Uri Lublin (uril@redhat.com) -""" - -import os, sys -import kvm_utils - - -if len(sys.argv) < 2: - print 'usage: %s ' % sys.argv[0] -else: - fname = sys.argv[1] - if not os.access(fname, os.F_OK) or not os.access(fname, os.R_OK): - print 'bad file name or permissions' - else: - print kvm_utils.hash_file(fname, 1024*1024, method="md5") diff --git a/client/tests/kvm/cd_hash.py b/client/tests/kvm/cd_hash.py new file mode 100755 index 0000000..483d71c --- /dev/null +++ b/client/tests/kvm/cd_hash.py @@ -0,0 +1,54 @@ +#!/usr/bin/python +""" +Program that calculates several hashes for a given CD image. + +@copyright: Red Hat 2008-2009 +""" + +import os, sys, optparse, logging +import common, kvm_utils +from autotest_lib.client.common_lib import logging_config, logging_manager + + +class KvmLoggingConfig(logging_config.LoggingConfig): + def configure_logging(self, results_dir=None, verbose=False): + super(KvmLoggingConfig, self).configure_logging(use_console=True, + verbose=verbose) + +if __name__ == "__main__": + parser = optparse.OptionParser() + parser.add_option('-i', '--iso', type="string", dest="filename", + action='store', + help='path to a ISO file whose hash string will be ' + 'evaluated.') + + options, args = parser.parse_args() + filename = options.filename + + logging_manager.configure_logging(KvmLoggingConfig()) + + if not filename: + parser.print_help() + sys.exit(1) + + filename = os.path.abspath(filename) + + file_exists = os.path.isfile(filename) + can_read_file = os.access(filename, os.R_OK) + if not file_exists: + logging.critical("File %s does not exist. Aborting...", filename) + sys.exit(1) + if not can_read_file: + logging.critical("File %s does not have read permissions. " + "Aborting...", filename) + sys.exit(1) + + logging.info("Hash values for file %s", os.path.basename(filename)) + logging.info("md5 (1m): %s", kvm_utils.hash_file(filename, 1024*1024, + method="md5")) + logging.info("sha1 (1m): %s", kvm_utils.hash_file(filename, 1024*1024, + method="sha1")) + logging.info("md5 (full): %s", kvm_utils.hash_file(filename, + method="md5")) + logging.info("sha1 (full): %s", kvm_utils.hash_file(filename, + method="sha1"))