diff mbox

[2/6] KVM test: Introducing unattended install subtest

Message ID 1254790989-14204-2-git-send-email-lmr@redhat.com (mailing list archive)
State New, archived
Headers show

Commit Message

Lucas Meneghel Rodrigues Oct. 6, 2009, 1:03 a.m. UTC
None
diff mbox

Patch

diff --git a/client/tests/kvm/tests/unattended_install.py b/client/tests/kvm/tests/unattended_install.py
new file mode 100644
index 0000000..60e2a35
--- /dev/null
+++ b/client/tests/kvm/tests/unattended_install.py
@@ -0,0 +1,45 @@ 
+import logging, time, socket
+from autotest_lib.client.common_lib import error
+import kvm_utils, kvm_test_utils
+
+
+def run_unattended_install(test, params, env):
+    """
+    Unattended install test:
+    1) Starts a VM with an appropriated setup to start an unattended OS install.
+    2) Wait until the install reports to the install watcher its end.
+
+    @param test: KVM test object.
+    @param params: Dictionary with the test parameters.
+    @param env: Dictionary with test environment.
+    """
+    vm = kvm_utils.env_get_vm(env, params.get("main_vm"))
+    if not vm:
+        raise error.TestError("VM object not found in environment")
+    if not vm.is_alive():
+        raise error.TestError("VM seems to be dead; Test requires a living VM")
+
+    logging.info("Starting unattended install watch process")
+    server = socket.socket(socket.AF_INET, socket.SOCK_STREAM)
+    server.bind(('', 12323))
+    server.listen(1)
+
+    end_time = time.time() + float(params.get("timeout", 3000))
+
+    while True:
+        server.settimeout(end_time - time.time())
+        try:
+            (client, addr) = server.accept()
+        except socket.timeout:
+            server.close()
+            raise error.TestFail('Timeout elapsed while waiting for install to '
+                                 'finish.')
+        msg = client.recv(1024)
+        logging.debug("Received '%s' from %s", msg, addr)
+        if msg == 'done':
+            logging.info('Guest reported successful installation')
+            server.close()
+            break
+        else:
+            logging.error('Got invalid string from client: %s.' % msg)
+