KVM test: Add new utility functions to kvm_utils
PATCH 1/4 KVM test: Add new utility functions to kvm_utils
Some distributors ship CD and DVD files with SHA1 hash sums instead of MD5 hash sums, so let's extend the kvm_utils functions to evaluate and compare SHA1 hashes:
* hash_file(): Calculate a hash sum for a file, supports SHA1 check as well, replaces md5sum_file()
* unmap_url_cache(): Reimplementation of a function present on autotest utils that downloads a file and caches it. The reason I'm keeping it is that I want more testing before I move all needed function definitions to the autotest API
Also, extend VM.create() method to support SHA1 check.
2nd try, addressing Uri's comments.
Signed-off-by Lucas Meneghel Rodrigues <[email protected]>
--- client/tests/kvm/calc_md5sum_1m.py | 2 +- client/tests/kvm/kvm_utils.py | 105 ++++++++++++++++++++++++++++++++---- client/tests/kvm/kvm_vm.py | 20 +++++--- 3 files changed, 108 insertions(+), 19 deletions(-)
client/tests/kvm/calc_md5sum_1m.py +1 -1
@@ -18,4 +18,4 @@ else: 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.md5sum_file(fname, 1024*1024) + print kvm_utils.hash_file(fname, 1024*1024, method="md5")
client/tests/kvm/kvm_utils.py +94 -11
132 lines not on this page · raw message
client/tests/kvm/kvm_vm.py +13 -7
@@ -339,20 +339,26 @@ class VM: if params.get("md5sum_1m"): logging.debug("Comparing expected MD5 sum with MD5 sum of " "first MB of ISO file...") - actual_md5sum = kvm_utils.md5sum_file(iso, 1048576) - expected_md5sum = params.get("md5sum_1m") + actual_hash = kvm_utils.hash_file(iso, 1048576, method="md5") + expected_hash = params.get("md5sum_1m") compare = True elif params.get("md5sum"): logging.debug("Comparing expected MD5 sum with MD5 sum of ISO " "file...") - actual_md5sum = kvm_utils.md5sum_file(iso) - expected_md5sum = params.get("md5sum") + actual_hash = kvm_utils.md5sum_file(iso, method="md5") + expected_hash = params.get("md5sum") + compare = True + elif params.get("sha1sum"): + logging.debug("Comparing expected SHA1 sum with SHA1 sum of " + "ISO file...") + actual_hash = kvm_utils.md5sum_file(iso, method="sha1") + expected_hash = params.get("md5sum") compare = True if compare: - if actual_md5sum == expected_md5sum: - logging.debug("MD5 sums match") + if actual_hash == expected_hash: + logging.debug("Hashes match") else: - logging.error("Actual MD5 sum differs from expected one") + logging.error("Actual hash differs from expected one") return False # Make sure the following code is not executed by more than one thread
Signature · 1 line
1.6.2.5