In order to resolve the question, 'how will the guest operating system tell the host operating system that the unattended install process finish', we took the simple approach and created a simple socket communication ack process: The test instantiates a server tcp socket on port 12323, and waits during a specified amount of time. For guests, the vast majority of the unattended install processes can deal with executing commands at the end of the install process. Let's take advantage of that and make clients tell the server about the end of the process using simple programs that can do that. The implementation of that strategy varies trough different operating systems. This is the kvm test implementation code, client programs will follow on later patches. Signed-off-by: Lucas Meneghel Rodrigues <lmr@xxxxxxxxxx> --- client/tests/kvm/kvm.py | 2 + client/tests/kvm/kvm_tests.py | 81 ++++++++++++++++++++++++++++++++++++++++- 2 files changed, 82 insertions(+), 1 deletions(-) diff --git a/client/tests/kvm/kvm.py b/client/tests/kvm/kvm.py index 070e463..db6899b 100644 --- a/client/tests/kvm/kvm.py +++ b/client/tests/kvm/kvm.py @@ -56,6 +56,8 @@ class kvm(test.test): "linux_s3": test_routine("kvm_tests", "run_linux_s3"), "stress_boot": test_routine("kvm_tests", "run_stress_boot"), "timedrift": test_routine("kvm_tests", "run_timedrift"), + "unattended_install": test_routine("kvm_tests", + "run_unattended_install"), } # Make it possible to import modules from the test's bindir diff --git a/client/tests/kvm/kvm_tests.py b/client/tests/kvm/kvm_tests.py index 9784ec9..f45fefc 100644 --- a/client/tests/kvm/kvm_tests.py +++ b/client/tests/kvm/kvm_tests.py @@ -1,4 +1,4 @@ -import time, os, logging, re, commands +import time, os, logging, re, commands, socket from autotest_lib.client.common_lib import utils, error import kvm_utils, kvm_subprocess, ppm_utils, scan_results @@ -9,6 +9,85 @@ KVM test definitions. """ +class UnattendedInstallWatcher: + """ + Mechanism to verify whether an unattended guest install actually did finish. + It opens a TCP socket and waits until it receives a message. If it does get + the expected message from the guest, it will finish gracefully. + """ + def __init__(self, timeout, msg): + self.port = 12323 + self.buf_size = 1024 + self.timeout = timeout + self.msg = msg + + + def check_answer(self, connection): + """ + Verify if client has sent the correct ACK message. + + @param connection: Tuple with client socket connection and address. + @return: True, in case the client has responded accordingly; False if + the string doesn't match the server expectations. + """ + (client, addr) = connection + msg = client.recv(self.buf_size) + logging.debug("Received '%s' from %s", msg, addr) + if msg == self.msg: + logging.info('Guest reported successful installation') + return True + else: + logging.error('Got invalid string from client: %s.' % msg) + return False + + + def run_server(self): + """ + Initializes and runs the server socket and listens for connections. + """ + server = socket.socket(socket.AF_INET, socket.SOCK_STREAM) + address = ('', self.port) + server.bind(address) + server.listen(1) + + while True: + try: + server.settimeout(self.timeout) + connection = server.accept() + if self.check_answer(connection): + break + except: + server.close() + raise + + +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") + watcher = UnattendedInstallWatcher(timeout=3000, msg='done') + try: + watcher.run_server() + except socket.timeout: + raise error.TestFail('Timeout elapsed while waiting for install to ' + 'finish.') + + logging.info("Unattended install finished successfuly") + + def run_boot(test, params, env): """ KVM reboot test: -- 1.6.2.5 -- To unsubscribe from this list: send the line "unsubscribe kvm" in the body of a message to majordomo@xxxxxxxxxxxxxxx More majordomo info at http://vger.kernel.org/majordomo-info.html