Index: client/tests/kvm/tests/unattended_install.py |
diff --git a/client/tests/kvm/tests/unattended_install.py b/client/tests/kvm/tests/unattended_install.py |
index 471ab56f6ecaab8194abd83dda994937f23c8116..7c6d8451f8db32fe45c8430739672b155acadad5 100644 |
--- a/client/tests/kvm/tests/unattended_install.py |
+++ b/client/tests/kvm/tests/unattended_install.py |
@@ -1,8 +1,9 @@ |
-import logging, time, socket |
+import logging, time, socket, re |
from autotest_lib.client.common_lib import error |
-import kvm_utils, kvm_test_utils |
+import kvm_vm |
+@error.context_aware |
def run_unattended_install(test, params, env): |
""" |
Unattended install test: |
@@ -13,46 +14,56 @@ def run_unattended_install(test, params, env): |
@param params: Dictionary with the test parameters. |
@param env: Dictionary with test environment. |
""" |
- buf = 1024 |
- vm = kvm_test_utils.get_living_vm(env, params.get("main_vm")) |
+ vm = env.get_vm(params["main_vm"]) |
+ vm.verify_alive() |
+ install_timeout = int(params.get("timeout", 3000)) |
+ post_install_delay = int(params.get("post_install_delay", 0)) |
port = vm.get_port(int(params.get("guest_port_unattended_install"))) |
- if params.get("post_install_delay"): |
- post_install_delay = int(params.get("post_install_delay")) |
- else: |
- post_install_delay = 0 |
- install_timeout = float(params.get("timeout", 3000)) |
- logging.info("Starting unattended install watch process. " |
- "Timeout set to %ds (%d min)", install_timeout, |
- install_timeout/60) |
+ migrate_background = params.get("migrate_background") == "yes" |
+ if migrate_background: |
+ mig_timeout = float(params.get("mig_timeout", "3600")) |
+ mig_protocol = params.get("migration_protocol", "tcp") |
+ |
+ logging.info("Waiting for installation to finish. Timeout set to %d s " |
+ "(%d min)", install_timeout, install_timeout/60) |
+ error.context("waiting for installation to finish") |
+ |
start_time = time.time() |
- time_elapsed = 0 |
- while time_elapsed < install_timeout: |
- if not vm.is_alive(): |
- raise error.TestError("Guest died before end of OS install") |
+ while (time.time() - start_time) < install_timeout: |
+ vm.verify_alive() |
client = socket.socket(socket.AF_INET, socket.SOCK_STREAM) |
- addr = vm.get_address() |
- if addr is not None: |
- try: |
- client.connect((addr, port)) |
- msg = client.recv(1024) |
- if msg == 'done': |
- if post_install_delay: |
- logging.debug("Post install delay specified, " |
- "waiting %ss...", post_install_delay) |
- time.sleep(post_install_delay) |
- break |
- except socket.error: |
- pass |
- time.sleep(1) |
+ try: |
+ client.connect((vm.get_address(), port)) |
+ if client.recv(1024) == "done": |
+ break |
+ except (socket.error, kvm_vm.VMAddressError): |
+ pass |
+ if migrate_background: |
+ # Drop the params which may break the migration |
+ # Better method is to use dnsmasq to do the |
+ # unattended installation |
+ if vm.params.get("initrd"): |
+ vm.params["initrd"] = None |
+ if vm.params.get("kernel"): |
+ vm.params["kernel"] = None |
+ if vm.params.get("extra_params"): |
+ vm.params["extra_params"] = re.sub("--append '.*'", "", |
+ vm.params["extra_params"]) |
+ vm.migrate(timeout=mig_timeout, protocol=mig_protocol) |
+ else: |
+ time.sleep(1) |
client.close() |
- end_time = time.time() |
- time_elapsed = int(end_time - start_time) |
- |
- if time_elapsed < install_timeout: |
- logging.info('Guest reported successful installation after %ds ' |
- '(%d min)', time_elapsed, time_elapsed/60) |
else: |
- raise error.TestFail('Timeout elapsed while waiting for install to ' |
- 'finish.') |
+ raise error.TestFail("Timeout elapsed while waiting for install to " |
+ "finish") |
+ |
+ time_elapsed = time.time() - start_time |
+ logging.info("Guest reported successful installation after %d s (%d min)", |
+ time_elapsed, time_elapsed/60) |
+ |
+ if post_install_delay: |
+ logging.debug("Post install delay specified, waiting %s s...", |
+ post_install_delay) |
+ time.sleep(post_install_delay) |