linux_stress.py 2.3 KB
Newer Older
1
import time
2 3 4
import logging

from avocado.core import exceptions
5 6 7 8 9 10 11 12 13

from virttest import utils_test


def run(test, params, env):
    """
    General stress test for linux:
       1). Install stress if need
       2). Start stress process
14 15
       3). If no stress_duration defined, keep stress until test_timeout;
       otherwise execute below steps after sleeping stress_duration long
16 17 18 19 20 21 22 23 24
       4). Stop stress process
       5). Uninstall stress
       6). Verify guest kernel crash

    :param test: kvm test object
    :param params: Dictionary with the test parameters
    :param env: Dictionary with test environment
    """

25
    stress_duration = int(params.get("stress_duration", "0"))
26 27 28 29 30
    # NOTE: stress_duration = 0 ONLY for some legacy test cases using
    # autotest stress.control as their sub test.
    # Please DO define stress_duration to make sure the clean action
    # being performed, if your case can not be controlled by time,
    # use utils_test.VMStress() directly
31 32 33 34 35 36 37 38 39 40 41 42 43 44
    stress_type = params.get("stress_type", "stress")
    vms = env.get_all_vms()
    up_time = {}
    error = False
    stress_server = {}

    for vm in vms:
        try:
            up_time[vm.name] = vm.uptime()
            stress_server[vm.name] = utils_test.VMStress(vm, stress_type, params)
            stress_server[vm.name].load_stress_tool()
        except exceptions.TestError as err_msg:
            error = True
            logging.error(err_msg)
45 46 47

    if stress_duration:
        time.sleep(stress_duration)
48 49 50 51 52 53 54 55 56 57 58 59 60 61 62
        for vm in vms:
            try:
                s_ping, o_ping = utils_test.ping(vm.get_address(), count=5, timeout=20)
                if s_ping != 0:
                    error = True
                    logging.error("%s seem to have gone out of network", vm.name)
                    continue
                uptime = vm.uptime()
                if up_time[vm.name] > uptime:
                    error = True
                    logging.error("%s seem to have rebooted during the stress run", vm.name)
                stress_server[vm.name].unload_stress()
                stress_server[vm.name].clean()
                vm.verify_dmesg()
            except exceptions.TestError as err_msg:
63
                error = True
64
                logging.error(err_msg)
65 66 67

    if error:
        test.fail("Run failed: see error messages above")