Get rid of questions and lengthy downloads setting up
a basic virt testing. With this patch, it is possible to
get started with a single 18 MB download, made on demand.

Obviously the idea is to mature from this initial patch,
but with this it's already possible to have an idea of
using a basic subset of the virt tests in a more comfortable
and easier way.

Signed-off-by: Lucas Meneghel Rodrigues <[email protected]>
---
 client/virt/virt_utils.py |   88 ++++++++++++++++++++------------------------
 1 files changed, 40 insertions(+), 48 deletions(-)

diff --git a/client/virt/virt_utils.py b/client/virt/virt_utils.py
index 20ed4ba..2d2b1fe 100644
--- a/client/virt/virt_utils.py
+++ b/client/virt/virt_utils.py
@@ -3471,51 +3471,57 @@ def if_set_macaddress(ifname, mac):
     ctrl_sock.close()
 
 
-def check_iso(url, destination, iso_sha1):
+def download_file(url, destination, sha1, ask=False):
     """
-    Verifies if ISO that can be find on url is on destination with right hash.
+    Verifies if file that can be find on url is on destination with right hash.
 
-    This function will verify the SHA1 hash of the ISO image. If the file
-    turns out to be missing or corrupted, let the user know we can download it.
+    This function will verify the SHA1 hash of the file. If the file
+    appears to be missing or corrupted, let the user know.
 
-    @param url: URL where the ISO file can be found.
-    @param destination: Directory in local disk where we'd like the iso to be.
-    @param iso_sha1: SHA1 hash for the ISO image.
+    @param url: URL where the file can be found.
+    @param destination: Directory in local disk where we'd like the file to be.
+    @param iso_sha1: SHA1 hash for the file.
     """
     file_ok = False
     if not os.path.isdir(destination):
         os.makedirs(destination)
-    iso_path = os.path.join(destination, os.path.basename(url))
-    if not os.path.isfile(iso_path):
-        logging.warning("File %s not found", iso_path)
-        logging.warning("Expected SHA1 sum: %s", iso_sha1)
-        answer = utils.ask("Would you like to download it from %s?" % url)
+    path = os.path.join(destination, os.path.basename(url))
+    if not os.path.isfile(path):
+        logging.warning("File %s not found", path)
+        logging.warning("Expected SHA1 sum: %s", sha1)
+        if ask:
+            answer = utils.ask("Would you like to download it from %s?" % url)
+        else:
+            answer = 'y'
         if answer == 'y':
-            logging.info("Downloading to %s", iso_path)
-            os.system("wget %s -O %s" % (url, iso_path))
+            logging.info("Downloading to %s", path)
+            os.system("wget %s -O %s" % (url, path))
         else:
-            logging.warning("Missing file %s", iso_path)
+            logging.warning("Missing file %s", path)
             logging.warning("Please download it or put an exsiting copy on the 
"
                             "appropriate location")
             return
     else:
-        logging.info("Found %s", iso_path)
-        logging.info("Expected SHA1 sum: %s", iso_sha1)
-        answer = utils.ask("Would you like to check %s? It might take a while" 
%
-                           iso_path)
+        logging.info("Found %s", path)
+        logging.info("Expected SHA1 sum: %s", sha1)
+        if ask:
+            answer = utils.ask("Would you like to check %s? It might take a"
+                               "while" % path)
+        else:
+            answer = 'y'
         if answer == 'y':
-            actual_iso_sha1 = utils.hash_file(iso_path, method='sha1')
-            if actual_iso_sha1 != iso_sha1:
-                logging.error("Actual SHA1 sum: %s", actual_iso_sha1)
+            actual_sha1 = utils.hash_file(path, method='sha1')
+            if actual_sha1 != sha1:
+                logging.error("Actual SHA1 sum: %s", actual_sha1)
             else:
                 logging.info("SHA1 sum check OK")
         else:
             logging.info("File %s present, but chose to not verify it",
-                         iso_path)
+                         path)
             return
 
     if file_ok:
-        logging.info("%s present, with proper checksum", iso_path)
+        logging.info("%s present, with proper checksum", path)
 
 
 def virt_test_assistant(test_name, test_dir, base_dir, default_userspace_paths,
@@ -3568,30 +3574,16 @@ def virt_test_assistant(test_name, test_dir, base_dir, 
default_userspace_paths,
 
     logging.info("")
     step += 1
-    logging.info("%s - Verifying iso (make sure we have the OS ISO needed for "
-                 "the default test set)", step)
-
-    iso_name = "Fedora-16-x86_64-DVD.iso"
-    fedora_dir = "pub/fedora/linux/releases/16/Fedora/x86_64/iso"
-    url = os.path.join("http://download.fedoraproject.org/";, fedora_dir,
-                       iso_name)
-    iso_sha1 = "76dd59c37e9a0ec2af56263fa892ff571c92c89a"
-    destination = os.path.join(base_dir, 'isos', 'linux')
-    check_iso(url, destination, iso_sha1)
-
-    logging.info("")
-    step += 1
-    logging.info("%d - Verifying winutils.iso (make sure we have the utility "
-                 "ISO needed for Windows testing)", step)
-
-    logging.info("In order to run the KVM autotests in Windows guests, we "
-                 "provide you an ISO that this script can download")
-
-    url = "http://people.redhat.com/mrodrigu/kvm/winutils.iso";
-    iso_sha1 = "02930224756510e383c44c49bffb760e35d6f892"
-    destination = os.path.join(base_dir, 'isos', 'windows')
-    path = os.path.join(destination, iso_name)
-    check_iso(url, destination, iso_sha1)
+    logging.info("%s - Verifying (and possibly downloading) guest image", step)
+
+    guest_tarball = "jeos_x86_64.tar.bz2"
+    url = os.path.join("http://lmr.fedorapeople.org/jeos_images";, 
guest_tarball)
+    tarball_sha1 = "0b549b6a868913cdbace065b2a602c4dd329f83c"
+    destination = os.path.join(base_dir, 'images')
+    download_file(url, destination, tarball_sha1)
+    tarball_path = os.path.join(destination, guest_tarball)
+    if os.path.isfile(tarball_path):
+        utils.run("bzcat %s | tar -C %s -xvf -" % (tarball_path, destination))
 
     logging.info("")
     step += 1
-- 
1.7.7.6

_______________________________________________
Autotest mailing list
[email protected]
http://test.kernel.org/cgi-bin/mailman/listinfo/autotest

Reply via email to