1import logging
2from autotest_lib.client.common_lib import error
3from autotest_lib.client.virt import virt_env_process
4
5
6@error.context_aware
7def run_stress_boot(test, params, env):
8    """
9    Boots VMs until one of them becomes unresponsive, and records the maximum
10    number of VMs successfully started:
11    1) boot the first vm
12    2) boot the second vm cloned from the first vm, check whether it boots up
13       and all booted vms respond to shell commands
14    3) go on until cannot create VM anymore or cannot allocate memory for VM
15
16    @param test:   kvm test object
17    @param params: Dictionary with the test parameters
18    @param env:    Dictionary with test environment.
19    """
20    error.base_context("waiting for the first guest to be up", logging.info)
21    vm = env.get_vm(params["main_vm"])
22    vm.verify_alive()
23    login_timeout = float(params.get("login_timeout", 240))
24    session = vm.wait_for_login(timeout=login_timeout)
25
26    num = 2
27    sessions = [session]
28
29    # Boot the VMs
30    try:
31        while num <= int(params.get("max_vms")):
32            # Clone vm according to the first one
33            error.base_context("booting guest #%d" % num, logging.info)
34            vm_name = "vm%d" % num
35            vm_params = vm.params.copy()
36            curr_vm = vm.clone(vm_name, vm_params)
37            env.register_vm(vm_name, curr_vm)
38            virt_env_process.preprocess_vm(test, vm_params, env, vm_name)
39            params["vms"] += " " + vm_name
40
41            sessions.append(curr_vm.wait_for_login(timeout=login_timeout))
42            logging.info("Guest #%d booted up successfully", num)
43
44            # Check whether all previous shell sessions are responsive
45            for i, se in enumerate(sessions):
46                error.context("checking responsiveness of guest #%d" % (i + 1),
47                              logging.debug)
48                se.cmd(params.get("alive_test_cmd"))
49            num += 1
50    finally:
51        for se in sessions:
52            se.close()
53        logging.info("Total number booted: %d" % (num -1))
54