You need to sign in or sign up before continuing.
drive_mirror_stress.py 3.5 KB
Newer Older
L
Lucas Meneghel Rodrigues 已提交
1 2
import time
import logging
3

X
Xu Tian 已提交
4
from virttest import utils_misc
5 6
from virttest import utils_test
from virttest import error_context
7

X
Xu Tian 已提交
8 9
from qemu.tests import drive_mirror

L
Lucas Meneghel Rodrigues 已提交
10

X
Xu Tian 已提交
11 12
class DriveMirrorStress(drive_mirror.DriveMirror):

13
    @error_context.context_aware
X
Xu Tian 已提交
14 15
    def load_stress(self):
        """
16
        load IO/CPU/Memory stress in guest;
X
Xu Tian 已提交
17
        """
18 19 20 21 22 23 24 25 26 27
        error_context.context("launch stress app in guest", logging.info)
        args = (self.test, self.params, self.env, self.params["stress_test"])
        bg_test = utils_test.BackgroundTest(utils_test.run_virt_sub_test, args)
        bg_test.start()
        if not utils_misc.wait_for(bg_test.is_alive, first=10, step=3, timeout=100):
            self.test.fail("background test start failed")
        if not utils_misc.wait_for(self.app_running, timeout=360, step=5):
            self.test.fail("stress app isn't running")
        # sleep 10s to ensure heavyload.exe make guest under heayload really;
        time.sleep(10)
X
Xu Tian 已提交
28 29
        return None

30
    @error_context.context_aware
X
Xu Tian 已提交
31 32 33 34 35 36
    def unload_stress(self):
        """
        stop stress app
        """
        def _unload_stress():
            session = self.get_session()
37
            cmd = self.params.get("stop_cmd")
X
Xu Tian 已提交
38
            session.sendline(cmd)
39 40
            session.close()
            return self.app_running()
X
Xu Tian 已提交
41

42 43 44 45 46 47
        error_context.context("stop stress app in guest", logging.info)
        stopped = utils_misc.wait_for(_unload_stress, first=2.0,
                                      text="wait stress app quit",
                                      step=1.0, timeout=120)
        if not stopped:
            logging.warn("stress app is still running")
X
Xu Tian 已提交
48

49
    def app_running(self):
X
Xu Tian 已提交
50 51 52 53
        """
        check stress app really run in background;
        """
        session = self.get_session()
54
        cmd = self.params.get("check_cmd")
X
Xu Tian 已提交
55
        status = session.cmd_status(cmd, timeout=120)
56
        session.close()
X
Xu Tian 已提交
57 58
        return status == 0

59
    @error_context.context_aware
X
Xu Tian 已提交
60 61 62 63
    def verify_steady(self):
        """
        verify offset not decreased, after block mirror job in steady status;
        """
64
        error_context.context("verify offset not decreased", logging.info)
X
Xu Tian 已提交
65 66 67 68 69 70 71 72 73
        params = self.parser_test_args()
        timeout = int(params.get("hold_on_timeout", 600))
        offset = self.get_status()["offset"]
        start = time.time()
        while time.time() < start + timeout:
            _offset = self.get_status()["offset"]
            if _offset < offset:
                msg = "offset decreased, offset last: %s" % offset
                msg += "offset now: %s" % _offset
74
                self.test.fail(msg)
X
Xu Tian 已提交
75 76 77
            offset = _offset


78
def run(test, params, env):
X
Xu Tian 已提交
79 80 81 82 83 84 85 86 87 88 89
    """
    drive_mirror_stress test:
    1). load stress in guest
    2). mirror block device
    3). stop vm when mirroring job really run(optional)
    4). wait for block job in steady status
    5). check offset not decreased(optional)
    6). reopen new target image(optional)
    7). quit stress app, reboot guest(optional);
    8). verify guest can response correctly

L
Lucas Meneghel Rodrigues 已提交
90 91 92
    :param test: QEMU test object
    :param params: Dictionary with the test parameters
    :param env: Dictionary with test environment.
X
Xu Tian 已提交
93 94 95 96 97 98 99 100 101 102 103
    """
    tag = params.get("source_image", "image1")
    stress_test = DriveMirrorStress(test, params, env, tag)
    try:
        stress_test.action_before_start()
        stress_test.start()
        stress_test.action_before_steady()
        stress_test.action_when_steady()
        stress_test.action_after_reopen()
    finally:
        stress_test.clean()