drive_mirror_simple.py 1.5 KB
Newer Older
X
Xu Tian 已提交
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44
import logging, time, random
from autotest.client.shared import error
from qemu.tests import drive_mirror

class DriveMirrorSimple(drive_mirror.DriveMirror):

    def __init__(self, test, params, env, tag):
        super(DriveMirrorSimple, self).__init__(test, params, env, tag)

    @error.context_aware
    def query_status(self):
        """
        query runing block mirroring job info;
        """
        error.context("query job status", logging.info)
        if not self.get_status():
            raise error.TestFail("No active job")


def run_drive_mirror_simple(test, params, env):
    """
    drive_mirror_simple test:
    1). launch block mirroring job w/o max speed
    2). query job status on the device before steady status(optinal)
    3). reset max job speed before steady status(optional)
    4). cancel active job on the device before steady status(optional)

    @param test: QEMU test object
    @param params: Dictionary with the test parameters
    @param env: Dictionary with test environment.
    """
    tag = params.get("source_images", "image1")
    repeats = int(params.get("repeat_times", 3))
    simple_test = DriveMirrorSimple(test, params, env, tag)
    try:
        for i in range(repeats):
            v_max,v_min = int(params.get("login_timeout", 360)) / 4, 0
            time.sleep(random.randint(v_min, v_max))
            simple_test.start()
            simple_test.action_before_steady()
            if simple_test.get_status():
                simple_test.cancel()
    finally:
        simple_test.clean()