Exemplo n.º 1
0
    def file_transfer(session, src, dst):
        username = params.get("username", "")
        password = params.get("password", "")
        src_path = "/tmp/1"
        dst_path = "/tmp/2"
        port = int(params["file_transfer_port"])

        cmd = "dd if=/dev/urandom of=%s bs=100M count=1" % src_path
        cmd = params.get("file_create_cmd", cmd)

        error.context("Create file by dd command, cmd: %s" % cmd, logging.info)
        session.cmd(cmd)

        transfer_timeout = int(params.get("transfer_timeout"))
        log_filename = "scp-from-%s-to-%s.log" % (src, dst)
        error.context("Transfer file from %s to %s" % (src, dst), logging.info)
        remote.scp_between_remotes(
            src,
            dst,
            port,
            password,
            password,
            username,
            username,
            src_path,
            dst_path,
            log_filename=log_filename,
            timeout=transfer_timeout,
        )
        src_path = dst_path
        dst_path = "/tmp/3"
        log_filename = "scp-from-%s-to-%s.log" % (dst, src)
        error.context("Transfer file from %s to %s" % (dst, src), logging.info)
        remote.scp_between_remotes(
            dst,
            src,
            port,
            password,
            password,
            username,
            username,
            src_path,
            dst_path,
            log_filename=log_filename,
            timeout=transfer_timeout,
        )
        error.context("Compare original file and transferred file", logging.info)

        cmd1 = "md5sum /tmp/1"
        cmd2 = "md5sum /tmp/3"
        md5sum1 = session.cmd(cmd1).split()[0]
        md5sum2 = session.cmd(cmd2).split()[0]
        if md5sum1 != md5sum2:
            raise error.TestError("File changed after transfer")
Exemplo n.º 2
0
    def file_transfer(session, src, dst):
        username = params.get("username", "")
        password = params.get("password", "")
        src_path = "/tmp/1"
        dst_path = "/tmp/2"
        port = int(params["file_transfer_port"])

        cmd = "dd if=/dev/urandom of=%s bs=100M count=1" % src_path
        cmd = params.get("file_create_cmd", cmd)

        error_context.context("Create file by dd command, cmd: %s" % cmd,
                              logging.info)
        session.cmd(cmd)

        transfer_timeout = int(params.get("transfer_timeout"))
        log_filename = "scp-from-%s-to-%s.log" % (src, dst)
        error_context.context("Transfer file from %s to %s" % (src, dst),
                              logging.info)
        remote.scp_between_remotes(src,
                                   dst,
                                   port,
                                   password,
                                   password,
                                   username,
                                   username,
                                   src_path,
                                   dst_path,
                                   log_filename=log_filename,
                                   timeout=transfer_timeout)
        src_path = dst_path
        dst_path = "/tmp/3"
        log_filename = "scp-from-%s-to-%s.log" % (dst, src)
        error_context.context("Transfer file from %s to %s" % (dst, src),
                              logging.info)
        remote.scp_between_remotes(dst,
                                   src,
                                   port,
                                   password,
                                   password,
                                   username,
                                   username,
                                   src_path,
                                   dst_path,
                                   log_filename=log_filename,
                                   timeout=transfer_timeout)
        error_context.context("Compare original file and transferred file",
                              logging.info)

        cmd1 = "md5sum /tmp/1"
        cmd2 = "md5sum /tmp/3"
        md5sum1 = session.cmd(cmd1).split()[0]
        md5sum2 = session.cmd(cmd2).split()[0]
        if md5sum1 != md5sum2:
            test.error("File changed after transfer")
Exemplo n.º 3
0
def run(test, params, env):
    """
    Test Step
        1. boot up two virtual machine
        2. Transfer data: host <--> guest1 <--> guest2 <-->host via ipv6
        3. after data transfer, check data have no change
    Params:
        :param test: QEMU test object
        :param params: Dictionary with the test parameters
        :param env: Dictionary with test environment.
    """
    timeout = int(params.get("login_timeout", '360'))
    client = params.get("file_transfer_client")
    port = params.get("file_transfer_port")
    password = params.get("password")
    username = params.get("username")
    tmp_dir = params.get("tmp_dir", "/tmp/")
    filesize = int(params.get("filesize", '4096'))
    dd_cmd = params.get("dd_cmd")
    file_trans_timeout = int(params.get("file_trans_timeout", '1200'))
    file_md5_check_timeout = int(params.get("file_md5_check_timeout", '600'))

    def get_linux_ipv6_linklocal_address(ifname, session=None):
        """
        Get host/guest ipv6 linklocal address via ifname
        """
        if session is not None:
            o = session.cmd_output("ifconfig %s" % ifname)
        else:
            o = utils.system_output("ifconfig %s" % ifname)
        ipv6_address_reg = re.compile(r"(fe80::[^\s|/]*)")
        if o:
            ipv6_linklocal_address = ipv6_address_reg.findall(o)
            if not ipv6_linklocal_address:
                raise error.TestError("Can't get %s linklocal address"
                                      % ifname)
            return ipv6_linklocal_address[0]
        else:
            return None

    def get_file_md5sum(file_name, session, timeout):
        """
        Get file md5sum from guest.
        """
        logging.info("Get md5sum of the file:'%s'" % file_name)
        try:
            o = session.cmd_output("md5sum %s" % file_name, timeout=timeout)
            file_md5sum = re.findall("\w+", o)[0]
        except IndexError:
            raise error.TestError("Could not get file md5sum in guest")
        return file_md5sum

    sessions = {}
    addresses = {}
    inet_name = {}
    vms = []

    error.context("Boot vms for test", logging.info)
    for vm_name in params.get("vms", "vm1 vm2").split():
        vms.append(env.get_vm(vm_name))

    # config ipv6 address host and guest.
    host_ifname = params.get("netdst")

    for vm in vms:
        vm.verify_alive()
        sessions[vm] = vm.wait_for_login(timeout=timeout)
        inet_name[vm] = utils_net.get_linux_ifname(sessions[vm],
                                                   vm.get_mac_address())
        addresses[vm] = get_linux_ipv6_linklocal_address(inet_name[vm],
                                                         sessions[vm])

    # prepare test data
    guest_path = (tmp_dir + "src-%s" % utils_misc.generate_random_string(8))
    dest_path = (tmp_dir + "dst-%s" % utils_misc.generate_random_string(8))
    host_path = os.path.join(test.tmpdir, "tmp-%s" %
                             utils_misc.generate_random_string(8))
    logging.info("Test setup: Creating %dMB file on host", filesize)
    utils.run(dd_cmd % (host_path, filesize))

    try:
        src_md5 = (utils.hash_file(host_path, method="md5"))
        # transfer data
        for vm in vms:
            error.context("Transfer data from host to %s" % vm.name,
                          logging.info)
            remote.copy_files_to(addresses[vm],
                                 client, username, password, port,
                                 host_path, guest_path,
                                 timeout=file_trans_timeout,
                                 interface=host_ifname)
            dst_md5 = get_file_md5sum(guest_path, sessions[vm],
                                      timeout=file_md5_check_timeout)
            if dst_md5 != src_md5:
                raise error.TestFail("File changed after transfer host -> %s"
                                     % vm.name)

        for vm_src in addresses:
            for vm_dst in addresses:
                if vm_src != vm_dst:
                    error.context("Transferring data from %s to %s" %
                                  (vm_src.name, vm_dst.name), logging.info)
                    remote.scp_between_remotes(addresses[vm_src],
                                               addresses[vm_dst],
                                               port, password, password,
                                               username, username,
                                               guest_path, dest_path,
                                               timeout=file_trans_timeout,
                                               src_inter=host_ifname,
                                               dst_inter=inet_name[vm_src])
                    dst_md5 = get_file_md5sum(dest_path, sessions[vm_dst],
                                              timeout=file_md5_check_timeout)
                    if dst_md5 != src_md5:
                        raise error.TestFail("File changed transfer %s -> %s"
                                             % (vm_src.name, vm_dst.name))

        for vm in vms:
            error.context("Transfer data from %s to host" % vm.name,
                          logging.info)
            remote.copy_files_from(addresses[vm],
                                   client, username, password, port,
                                   dest_path, host_path,
                                   timeout=file_trans_timeout,
                                   interface=host_ifname)
            error.context("Check whether the file changed after trans",
                          logging.info)
            dst_md5 = (utils.hash_file(host_path, method="md5"))
            if dst_md5 != src_md5:
                raise error.TestFail("File changed after transfer (md5sum mismatch)")
            utils.system_output("rm -rf %s" % host_path, timeout=timeout)

    finally:
        utils.system("rm -rf %s" % host_path, timeout=timeout,
                     ignore_status=True)
        for vm in vms:
            sessions[vm].cmd("rm -rf %s %s || true" % (guest_path, dest_path),
                             timeout=timeout, ignore_all_errors=True)
            sessions[vm].close()
Exemplo n.º 4
0
def run(test, params, env):
    """
    Test Step
        1. boot up two virtual machine
        2. Transfer data: host <--> guest1 <--> guest2 <-->host via ipv6
        3. after data transfer, check data have no change
    Params:
        :param test: QEMU test object
        :param params: Dictionary with the test parameters
        :param env: Dictionary with test environment.
    """
    timeout = int(params.get("login_timeout", '360'))
    client = params.get("file_transfer_client")
    port = params.get("file_transfer_port")
    password = params.get("password")
    username = params.get("username")
    tmp_dir = params.get("tmp_dir", "/tmp/")
    filesize = int(params.get("filesize", '4096'))
    dd_cmd = params.get("dd_cmd")
    file_trans_timeout = int(params.get("file_trans_timeout", '1200'))
    file_md5_check_timeout = int(params.get("file_md5_check_timeout", '600'))

    def get_linux_ipv6_linklocal_address(ifname, session=None):
        """
        Get host/guest ipv6 linklocal address via ifname
        """
        if session is not None:
            o = session.cmd_output("ifconfig %s" % ifname)
        else:
            o = utils.system_output("ifconfig %s" % ifname)
        ipv6_address_reg = re.compile(r"(fe80::[^\s|/]*)")
        if o:
            ipv6_linklocal_address = ipv6_address_reg.findall(o)
            if not ipv6_linklocal_address:
                raise error.TestError("Can't get %s linklocal address" %
                                      ifname)
            return ipv6_linklocal_address[0]
        else:
            return None

    def get_file_md5sum(file_name, session, timeout):
        """
        Get file md5sum from guest.
        """
        logging.info("Get md5sum of the file:'%s'" % file_name)
        try:
            o = session.cmd_output("md5sum %s" % file_name, timeout=timeout)
            file_md5sum = re.findall("\w+", o)[0]
        except IndexError:
            raise error.TestError("Could not get file md5sum in guest")
        return file_md5sum

    sessions = {}
    addresses = {}
    inet_name = {}
    vms = []

    error.context("Boot vms for test", logging.info)
    for vm_name in params.get("vms", "vm1 vm2").split():
        vms.append(env.get_vm(vm_name))

    # config ipv6 address host and guest.
    host_ifname = params.get("netdst")

    for vm in vms:
        vm.verify_alive()
        sessions[vm] = vm.wait_for_login(timeout=timeout)
        inet_name[vm] = utils_net.get_linux_ifname(sessions[vm],
                                                   vm.get_mac_address())
        addresses[vm] = get_linux_ipv6_linklocal_address(
            inet_name[vm], sessions[vm])

    # prepare test data
    guest_path = (tmp_dir + "src-%s" % utils_misc.generate_random_string(8))
    dest_path = (tmp_dir + "dst-%s" % utils_misc.generate_random_string(8))
    host_path = os.path.join(test.tmpdir,
                             "tmp-%s" % utils_misc.generate_random_string(8))
    logging.info("Test setup: Creating %dMB file on host", filesize)
    utils.run(dd_cmd % (host_path, filesize))

    try:
        src_md5 = (utils.hash_file(host_path, method="md5"))
        # transfer data
        for vm in vms:
            error.context("Transfer data from host to %s" % vm.name,
                          logging.info)
            remote.copy_files_to(addresses[vm],
                                 client,
                                 username,
                                 password,
                                 port,
                                 host_path,
                                 guest_path,
                                 timeout=file_trans_timeout,
                                 interface=host_ifname)
            dst_md5 = get_file_md5sum(guest_path,
                                      sessions[vm],
                                      timeout=file_md5_check_timeout)
            if dst_md5 != src_md5:
                raise error.TestFail("File changed after transfer host -> %s" %
                                     vm.name)

        for vm_src in addresses:
            for vm_dst in addresses:
                if vm_src != vm_dst:
                    error.context(
                        "Transferring data from %s to %s" %
                        (vm_src.name, vm_dst.name), logging.info)
                    remote.scp_between_remotes(addresses[vm_src],
                                               addresses[vm_dst],
                                               port,
                                               password,
                                               password,
                                               username,
                                               username,
                                               guest_path,
                                               dest_path,
                                               timeout=file_trans_timeout,
                                               src_inter=host_ifname,
                                               dst_inter=inet_name[vm_src])
                    dst_md5 = get_file_md5sum(dest_path,
                                              sessions[vm_dst],
                                              timeout=file_md5_check_timeout)
                    if dst_md5 != src_md5:
                        raise error.TestFail("File changed transfer %s -> %s" %
                                             (vm_src.name, vm_dst.name))

        for vm in vms:
            error.context("Transfer data from %s to host" % vm.name,
                          logging.info)
            remote.copy_files_from(addresses[vm],
                                   client,
                                   username,
                                   password,
                                   port,
                                   dest_path,
                                   host_path,
                                   timeout=file_trans_timeout,
                                   interface=host_ifname)
            error.context("Check whether the file changed after trans",
                          logging.info)
            dst_md5 = (utils.hash_file(host_path, method="md5"))
            if dst_md5 != src_md5:
                raise error.TestFail("File changed after transfer",
                                     "Files md5sum mismatch!")
            utils.system_output("rm -rf %s" % host_path, timeout=timeout)

    finally:
        utils.system("rm -rf %s" % host_path,
                     timeout=timeout,
                     ignore_status=True)
        for vm in vms:
            sessions[vm].cmd("rm -rf %s %s || true" % (guest_path, dest_path),
                             timeout=timeout,
                             ignore_all_errors=True)
            sessions[vm].close()
Exemplo n.º 5
0
def run(test, params, env):
    """
    Test Step
        1. boot up two virtual machine
        2. For linux guest,Transfer data:
              host <--> guest1 <--> guest2 <-->host via ipv6
           For windows guest,Transfer data:
              host <--> guest1&guest2 via ipv6
        3. after data transfer, check data have no change
    Params:
        :param test: QEMU test object
        :param params: Dictionary with the test parameters
        :param env: Dictionary with test environment.
    """
    timeout = int(params.get("login_timeout", '360'))
    client = params.get("file_transfer_client")
    port = params.get("file_transfer_port")
    password = params.get("password")
    username = params.get("username")
    tmp_dir = params["tmp_dir"]
    filesize = int(params.get("filesize", '4096'))
    dd_cmd = params["dd_cmd"]
    file_trans_timeout = int(params.get("file_trans_timeout", '1200'))
    file_md5_check_timeout = int(params.get("file_md5_check_timeout", '600'))

    def get_file_md5sum(file_name, session, timeout):
        """
        Get file md5sum from guest.
        """
        logging.info("Get md5sum of the file:'%s'" % file_name)
        try:
            o = session.cmd_output("md5sum %s" % file_name, timeout=timeout)
            file_md5sum = re.findall(r"\w+", o)[0]
        except IndexError:
            test.error("Could not get file md5sum in guest")
        return file_md5sum

    sessions = {}
    addresses = {}
    inet_name = {}
    vms = []

    error_context.context("Boot vms for test", logging.info)
    for vm_name in params.get("vms", "vm1 vm2").split():
        vms.append(env.get_vm(vm_name))

    # config ipv6 address host and guest.
    host_ifname = params.get("netdst")
    host_address = utils_net.get_host_ip_address(params,
                                                 ip_ver="ipv6",
                                                 linklocal=True)

    error_context.context("Get ipv6 address of host: %s" % host_address,
                          logging.info)
    for vm in vms:
        vm.verify_alive()
        sessions[vm] = vm.wait_for_login(timeout=timeout)
        if params.get("os_type") == "linux":
            inet_name[vm] = utils_net.get_linux_ifname(sessions[vm],
                                                       vm.get_mac_address())
        addresses[vm] = utils_net.get_guest_ip_addr(sessions[vm],
                                                    vm.get_mac_address(),
                                                    params.get("os_type"),
                                                    ip_version="ipv6",
                                                    linklocal=True)

        error_context.context(
            "Get ipv6 address of %s: %s" % (vm.name, addresses[vm]),
            logging.info)

    # prepare test data
    guest_path = (tmp_dir + "src-%s" % utils_misc.generate_random_string(8))
    dest_path = (tmp_dir + "dst-%s" % utils_misc.generate_random_string(8))
    host_path = os.path.join(test.tmpdir,
                             "tmp-%s" % utils_misc.generate_random_string(8))
    logging.info("Test setup: Creating %dMB file on host", filesize)
    process.run(dd_cmd % (host_path, filesize), shell=True)

    try:
        src_md5 = (crypto.hash_file(host_path, algorithm="md5"))
        error_context.context("md5 value of data from src: %s" % src_md5,
                              logging.info)
        # transfer data
        for vm in vms:
            error_context.context("Transfer data from host to %s" % vm.name,
                                  logging.info)
            remote.copy_files_to(addresses[vm],
                                 client,
                                 username,
                                 password,
                                 port,
                                 host_path,
                                 guest_path,
                                 timeout=file_trans_timeout,
                                 interface=host_ifname)
            dst_md5 = get_file_md5sum(guest_path,
                                      sessions[vm],
                                      timeout=file_md5_check_timeout)
            error_context.context(
                "md5 value of data in %s: %s" % (vm.name, dst_md5),
                logging.info)
            if dst_md5 != src_md5:
                test.fail("File changed after transfer host -> %s" % vm.name)

        if params.get("os_type") == "linux":
            for vm_src in addresses:
                for vm_dst in addresses:
                    if vm_src != vm_dst:
                        error_context.context(
                            "Transferring data from %s to %s" %
                            (vm_src.name, vm_dst.name), logging.info)
                        remote.scp_between_remotes(addresses[vm_src],
                                                   addresses[vm_dst],
                                                   port,
                                                   password,
                                                   password,
                                                   username,
                                                   username,
                                                   guest_path,
                                                   dest_path,
                                                   timeout=file_trans_timeout,
                                                   src_inter=host_ifname,
                                                   dst_inter=inet_name[vm_src])
                        dst_md5 = get_file_md5sum(
                            dest_path,
                            sessions[vm_dst],
                            timeout=file_md5_check_timeout)
                        error_context.context(
                            "md5 value of data in %s: %s" % (vm.name, dst_md5),
                            logging.info)
                        if dst_md5 != src_md5:
                            test.fail("File changed transfer %s -> %s" %
                                      (vm_src.name, vm_dst.name))

        for vm in vms:
            error_context.context("Transfer data from %s to host" % vm.name,
                                  logging.info)
            remote.copy_files_from(addresses[vm],
                                   client,
                                   username,
                                   password,
                                   port,
                                   guest_path,
                                   host_path,
                                   timeout=file_trans_timeout,
                                   interface=host_ifname)
            error_context.context("Check whether the file changed after trans",
                                  logging.info)
            dst_md5 = (crypto.hash_file(host_path, algorithm="md5"))
            error_context.context(
                "md5 value of data after copying to host: %s" % dst_md5,
                logging.info)

            if dst_md5 != src_md5:
                test.fail("File changed after transfer (md5sum mismatch)")
            process.system_output("rm -rf %s" % host_path, timeout=timeout)

    finally:
        process.system("rm -rf %s" % host_path,
                       timeout=timeout,
                       ignore_status=True)
        for vm in vms:
            if params.get("os_type") == "linux":
                sessions[vm].cmd("rm -rf %s %s || true" %
                                 (guest_path, dest_path),
                                 timeout=timeout,
                                 ignore_all_errors=True)
            else:
                sessions[vm].cmd("del /f %s" % guest_path,
                                 timeout=timeout,
                                 ignore_all_errors=True)
            sessions[vm].close()
Exemplo n.º 6
0
        interface_name = utils_net.get_linux_ifname(sessions[2],
                                                    vm.get_mac_address())

        tcpdump_cmd = tcpdump_cmd % (addresses[1], addresses[0],
                                     interface_name)
        t = utils.InterruptedThread(
            data_mon, (sessions[2], tcpdump_cmd, mon_process_timeout))

        logging.info("Tcpdump mon start ...")
        logging.info("Creating %dMB file on guest1", filesize)
        sessions[0].cmd(dd_cmd % (src_file, filesize), timeout=timeout)
        t.start()

        error.context("Transferring file guest1 -> guest2", logging.info)
        remote.scp_between_remotes(addresses[0], addresses[1], shell_port,
                                   password, password, username, username,
                                   src_file, dst_file)

        error.context("Check the src and dst file is same", logging.info)
        src_md5 = sessions[0].cmd_output(md5_check % src_file).split()[0]
        dst_md5 = sessions[1].cmd_output(md5_check % dst_file).split()[0]

        if dst_md5 != src_md5:
            debug_msg = "Files md5sum mismatch!"
            debug_msg += "source file md5 is '%s', after transfer md5 is '%s'"
            raise error.TestFail(debug_msg % (src_md5, dst_md5), logging.info)
        logging.info("Files md5sum match, file md5 is '%s'" % src_md5)

        error.context("Checking network private", logging.info)
        tcpdump_reg = "tcpdump.*%s.*%s" % (addresses[1], addresses[0])
        s = mon_session.cmd_status("pgrep -f '%s'" % tcpdump_reg)
Exemplo n.º 7
0
def run(test, params, env):
    """
    Transfer a file back and forth between multi VMs for long time.

    1) Boot up two VMs .
    2) Create a large file by dd on host.
    3) Copy this file to VM1.
    4) Compare copied file's md5 with original file.
    5) Copy this file from VM1 to VM2.
    6) Compare copied file's md5 with original file.
    7) Copy this file from VM2 to VM1.
    8) Compare copied file's md5 with original file.
    9) Repeat step 5-8

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

    def md5_check(session, orig_md5):
        msg = "Compare copied file's md5 with original file."
        error.context(msg, logging.info)
        md5_cmd = "md5sum %s | awk '{print $1}'" % guest_path
        s, o = session.cmd_status_output(md5_cmd)
        if s:
            msg = "Fail to get md5 value from guest. Output is %s" % o
            raise error.TestError(msg)
        new_md5 = o.splitlines()[-1]
        if new_md5 != orig_md5:
            msg = "File changed after transfer host -> VM1. Original md5 value"
            msg += " is %s. Current md5 value is %s" % (orig_md5, new_md5)
            raise error.TestFail(msg)

    vm1 = env.get_vm(params["main_vm"])
    vm1.verify_alive()
    login_timeout = int(params.get("login_timeout", 360))
    vm2 = env.get_vm(params["vms"].split()[-1])
    vm2.verify_alive()

    session_vm1 = vm1.wait_for_login(timeout=login_timeout)
    session_vm2 = vm2.wait_for_login(timeout=login_timeout)

    transfer_timeout = int(params.get("transfer_timeout", 1000))
    username = params["username"]
    password = params["password"]
    port = int(params["file_transfer_port"])
    tmp_dir = data_dir.get_tmp_dir()
    tmp_dir_guest = params.get("tmp_dir_guest", "/var/tmp")
    repeat_time = int(params.get("repeat_time", "10"))
    clean_cmd = params.get("clean_cmd", "rm -f")
    filesize = int(params.get("filesize", 4000))
    count = int(filesize / 10)
    if count == 0:
        count = 1

    host_path = os.path.join(tmp_dir, "tmp-%s" % utils_misc.generate_random_string(8))
    cmd = "dd if=/dev/zero of=%s bs=10M count=%d" % (host_path, count)
    guest_path = os.path.join(tmp_dir_guest, "file_transfer-%s" % utils_misc.generate_random_string(8))
    try:
        error.context("Creating %dMB file on host" % filesize, logging.info)
        utils.run(cmd)
        orig_md5 = utils.hash_file(host_path, method="md5")
        error.context("Transferring file host -> VM1, timeout: %ss" % transfer_timeout, logging.info)
        t_begin = time.time()
        vm1.copy_files_to(host_path, guest_path, timeout=transfer_timeout)
        t_end = time.time()
        throughput = filesize / (t_end - t_begin)
        logging.info("File transfer host -> VM1 succeed, " "estimated throughput: %.2fMB/s", throughput)
        md5_check(session_vm1, orig_md5)

        ip_vm1 = vm1.get_address()
        ip_vm2 = vm2.get_address()
        for i in range(repeat_time):
            log_vm1 = os.path.join(test.debugdir, "remote_scp_to_vm1_%s.log" % i)
            log_vm2 = os.path.join(test.debugdir, "remote_scp_to_vm2_%s.log" % i)

            msg = "Transferring file VM1 -> VM2, timeout: %ss." % transfer_timeout
            msg += " Repeat: %s/%s" % (i + 1, repeat_time)
            error.context(msg, logging.info)
            t_begin = time.time()
            s = remote.scp_between_remotes(
                src=ip_vm1,
                dst=ip_vm2,
                port=port,
                s_passwd=password,
                d_passwd=password,
                s_name=username,
                d_name=username,
                s_path=guest_path,
                d_path=guest_path,
                timeout=transfer_timeout,
                log_filename=log_vm2,
            )
            t_end = time.time()
            throughput = filesize / (t_end - t_begin)
            logging.info("File transfer VM1 -> VM2 succeed, " "estimated throughput: %.2fMB/s", throughput)
            md5_check(session_vm2, orig_md5)
            session_vm1.cmd("rm -rf %s" % guest_path)

            msg = "Transferring file VM2 -> VM1, timeout: %ss." % transfer_timeout
            msg += " Repeat: %s/%s" % (i + 1, repeat_time)

            error.context(msg, logging.info)
            t_begin = time.time()
            remote.scp_between_remotes(
                src=ip_vm2,
                dst=ip_vm1,
                port=port,
                s_passwd=password,
                d_passwd=password,
                s_name=username,
                d_name=username,
                s_path=guest_path,
                d_path=guest_path,
                timeout=transfer_timeout,
                log_filename=log_vm1,
            )
            t_end = time.time()
            throughput = filesize / (t_end - t_begin)
            logging.info("File transfer VM2 -> VM1 succeed, " "estimated throughput: %.2fMB/s", throughput)
            md5_check(session_vm1, orig_md5)
            session_vm2.cmd("%s %s" % (clean_cmd, guest_path))

    finally:
        try:
            session_vm1.cmd("%s %s" % (clean_cmd, guest_path))
        except Exception:
            pass
        try:
            session_vm2.cmd("%s %s" % (clean_cmd, guest_path))
        except Exception:
            pass
        try:
            os.remove(host_path)
        except OSError:
            pass
        if session_vm1:
            session_vm1.close()
        if session_vm2:
            session_vm2.close()
Exemplo n.º 8
0
        tcpdump_cmd = tcpdump_cmd % (addresses[1], addresses[0], interface_name)
        dthread = utils.InterruptedThread(data_mon, (sessions[2], tcpdump_cmd, mon_process_timeout))

        logging.info("Tcpdump mon start ...")
        logging.info("Creating %dMB file on guest1", filesize)
        sessions[0].cmd(dd_cmd % (src_file, filesize), timeout=timeout)
        dthread.start()

        error.context("Transferring file guest1 -> guest2", logging.info)
        if params.get("os_type") == "windows":
            cp_cmd = params["copy_cmd"]
            cp_cmd = cp_cmd % (addresses[1], params["file_transfer_port"], src_file, dst_file)
            sessions[0].cmd_output(cp_cmd)
        else:
            remote.scp_between_remotes(
                addresses[0], addresses[1], shell_port, password, password, username, username, src_file, dst_file
            )

        error.context("Check the src and dst file is same", logging.info)
        src_md5 = sessions[0].cmd_output(md5_check % src_file).split()[0]
        dst_md5 = sessions[1].cmd_output(md5_check % dst_file).split()[0]

        if dst_md5 != src_md5:
            debug_msg = "Files md5sum mismatch!"
            debug_msg += "source file md5 is '%s', after transfer md5 is '%s'"
            raise error.TestFail(debug_msg % (src_md5, dst_md5), logging.info)
        logging.info("Files md5sum match, file md5 is '%s'" % src_md5)

        error.context("Checking network private", logging.info)
        tcpdump_check_cmd = params["tcpdump_check_cmd"]
        tcpdump_kill_cmd = params["tcpdump_kill_cmd"]
Exemplo n.º 9
0
def run_multi_vms_file_transfer(test, params, env):
    """
    Transfer a file back and forth between multi VMs for long time.

    1) Boot up two VMs .
    2) Create a large file by dd on host.
    3) Copy this file to VM1.
    4) Compare copied file's md5 with original file.
    5) Copy this file from VM1 to VM2.
    6) Compare copied file's md5 with original file.
    7) Copy this file from VM2 to VM1.
    8) Compare copied file's md5 with original file.
    9) Repeat step 5-8

    @param test: KVM test object.
    @param params: Dictionary with the test parameters.
    @param env: Dictionary with test environment.
    """
    def md5_check(session, orig_md5):
        msg = "Compare copied file's md5 with original file."
        error.context(msg, logging.info)
        md5_cmd = "md5sum %s | awk '{print $1}'" % guest_path
        s, o = session.cmd_status_output(md5_cmd)
        if s:
            msg = "Fail to get md5 value from guest. Output is %s" % o
            raise error.TestError(msg)
        new_md5 = o.splitlines()[-1]
        if new_md5 != orig_md5:
            msg = "File changed after transfer host -> VM1. Original md5 value"
            msg += " is %s. Current md5 value is %s" % (orig_md5, new_md5)
            raise error.TestFail(msg)

    vm1 = env.get_vm(params["main_vm"])
    vm1.verify_alive()
    login_timeout = int(params.get("login_timeout", 360))
    vm2 = env.get_vm(params["vms"].split()[-1])
    vm2.verify_alive()

    session_vm1 = vm1.wait_for_login(timeout=login_timeout)
    session_vm2 = vm2.wait_for_login(timeout=login_timeout)

    transfer_timeout = int(params.get("transfer_timeout", 1000))
    username = params.get("username")
    password = params.get("password")
    port = int(params.get("file_transfer_port"))
    if (not port) or (not username) or (not password):
        raise error.TestError("Please set file_transfer_port, username,"
                               " password paramters for guest")
    tmp_dir = params.get("tmp_dir", "/tmp/")
    repeat_time = int(params.get("repeat_time", "10"))
    clean_cmd = params.get("clean_cmd", "rm -f")
    filesize = int(params.get("filesize", 4000))
    count = int(filesize / 10)
    if count == 0:
        count = 1

    host_path = os.path.join(tmp_dir, "tmp-%s" %
                             utils_misc.generate_random_string(8))
    cmd = "dd if=/dev/zero of=%s bs=10M count=%d" % (host_path, count)
    guest_path = (tmp_dir + "file_transfer-%s" %
                  utils_misc.generate_random_string(8))
    try:
        error.context("Creating %dMB file on host" % filesize, logging.info)
        utils.run(cmd)
        orig_md5 = utils.hash_file(host_path, method="md5")
        error.context("Transfering file host -> VM1, timeout: %ss" % \
                       transfer_timeout, logging.info)
        t_begin = time.time()
        vm1.copy_files_to(host_path, guest_path, timeout=transfer_timeout)
        t_end = time.time()
        throughput = filesize / (t_end - t_begin)
        logging.info("File transfer host -> VM1 succeed, "
                     "estimated throughput: %.2fMB/s", throughput)
        md5_check(session_vm1, orig_md5)

        ip_vm1 = vm1.get_address()
        ip_vm2 = vm2.get_address()
        for i in range(repeat_time):
            log_vm1 = os.path.join(test.debugdir, "remote_scp_to_vm1_%s.log" %i)
            log_vm2 = os.path.join(test.debugdir, "remote_scp_to_vm2_%s.log" %i)

            msg = "Transfering file VM1 -> VM2, timeout: %ss." % transfer_timeout
            msg += " Repeat: %s/%s" % (i + 1, repeat_time)
            error.context(msg, logging.info)
            t_begin = time.time()
            s = remote.scp_between_remotes(src=ip_vm1, dst=ip_vm2, port=port,
                                       s_passwd=password, d_passwd=password,
                                       s_name=username, d_name=username,
                                       s_path=guest_path, d_path=guest_path,
                                       timeout=transfer_timeout,
                                       log_filename=log_vm1)
            t_end = time.time()
            throughput = filesize / (t_end - t_begin)
            logging.info("File transfer VM1 -> VM2 succeed, "
                         "estimated throughput: %.2fMB/s", throughput)
            md5_check(session_vm2, orig_md5)
            session_vm1.cmd("rm -rf %s" % guest_path)

            msg = "Transfering file VM2 -> VM1, timeout: %ss." % transfer_timeout
            msg += " Repeat: %s/%s" % (i + 1, repeat_time)

            error.context(msg,  logging.info)
            t_begin = time.time()
            remote.scp_between_remotes(src=ip_vm2, dst=ip_vm1, port=port,
                                       s_passwd=password, d_passwd=password,
                                       s_name=username, d_name=username,
                                       s_path=guest_path, d_path=guest_path,
                                       timeout=transfer_timeout,
                                       log_filename=log_vm1)
            t_end = time.time()
            throughput = filesize / (t_end - t_begin)
            logging.info("File transfer VM2 -> VM1 succeed, "
                         "estimated throughput: %.2fMB/s", throughput)
            md5_check(session_vm1, orig_md5)
            session_vm2.cmd("%s %s" % (clean_cmd, guest_path))

    finally:
        try:
            session_vm1.cmd("%s %s" % (clean_cmd, guest_path))
        except Exception:
            pass
        try:
            session_vm2.cmd("%s %s" % (clean_cmd, guest_path))
        except Exception:
            pass
        try:
            os.remove(host_path)
        except OSError:
            pass
        if session_vm1:
            session_vm1.close()
        if session_vm2:
            session_vm2.close()
Exemplo n.º 10
0
def run(test, params, env):
    """
    Test Step:
        1. boot up three virtual machine
        2. transfer file from guest1 to guest2, check md5
        3. in guest 3 try to capture the packets(guest1 <-> guest2)
    Params:
        :param test: QEMU test object
        :param params: Dictionary with the test parameters
        :param env: Dictionary with test environment.
    """
    def data_mon(session, cmd, timeout):
        try:
            session.cmd(cmd, timeout)
        except ShellCmdError as e:
            if re.findall(catch_date % (addresses[1], addresses[0]), str(e)):
                test.fail("God! Capture the transfet data:'%s'" % str(e))
            logging.info("Guest3 catch data is '%s'" % str(e))

    timeout = int(params.get("login_timeout", '360'))
    password = params.get("password")
    username = params.get("username")
    shell_port = params.get("shell_port")
    tmp_dir = params.get("tmp_dir", "/tmp/")
    clean_cmd = params.get("clean_cmd", "rm -f")
    filesize = int(params.get("filesize", '100'))

    tcpdump_cmd = params.get("tcpdump_cmd")
    dd_cmd = params.get("dd_cmd")
    catch_date = params.get("catch_data", "%s.* > %s.ssh")
    md5_check = params.get("md5_check", "md5sum %s")
    mon_process_timeout = int(params.get("mon_process_timeout", "1200"))
    sessions = []
    addresses = []
    vms = []

    error_context.context("Init boot the vms")
    for vm_name in params.get("vms", "vm1 vm2 vm3").split():
        vms.append(env.get_vm(vm_name))
    for vm in vms:
        vm.verify_alive()
        sessions.append(vm.wait_for_login(timeout=timeout))
        addresses.append(vm.get_address())
    mon_session = vms[2].wait_for_login(timeout=timeout)
    mon_macaddr = vms[2].get_mac_address()

    src_file = (tmp_dir + "src-%s" % utils_misc.generate_random_string(8))
    dst_file = (tmp_dir + "dst-%s" % utils_misc.generate_random_string(8))

    try:
        # Before transfer, run tcpdump to try to catche data
        error_msg = "In guest3, try to capture the packets(guest1 <-> guest2)"
        error_context.context(error_msg, logging.info)
        if params.get("os_type") == "linux":
            if_func = utils_net.get_linux_ifname
            args = (mon_session, mon_macaddr)
        else:
            if_func = utils_net.get_windows_nic_attribute
            args = (mon_session, "macaddress", mon_macaddr, "netconnectionid")
        interface_name = if_func(*args)
        tcpdump_cmd = tcpdump_cmd % (addresses[1], addresses[0],
                                     interface_name)
        dthread = utils_misc.InterruptedThread(
            data_mon, (sessions[2], tcpdump_cmd, mon_process_timeout))

        logging.info("Tcpdump mon start ...")
        logging.info("Creating %dMB file on guest1", filesize)
        sessions[0].cmd(dd_cmd % (src_file, filesize), timeout=timeout)
        dthread.start()

        error_context.context("Transferring file guest1 -> guest2",
                              logging.info)
        if params.get("os_type") == "windows":
            cp_cmd = params["copy_cmd"]
            cp_cmd = cp_cmd % (addresses[1], params['file_transfer_port'],
                               src_file, dst_file)
            sessions[0].cmd_output(cp_cmd)
        else:
            remote.scp_between_remotes(addresses[0], addresses[1], shell_port,
                                       password, password, username, username,
                                       src_file, dst_file)

        error_context.context("Check the src and dst file is same",
                              logging.info)
        src_md5 = sessions[0].cmd_output(md5_check % src_file).split()[0]
        dst_md5 = sessions[1].cmd_output(md5_check % dst_file).split()[0]

        if dst_md5 != src_md5:
            debug_msg = "Files md5sum mismatch!"
            debug_msg += "source file md5 is '%s', after transfer md5 is '%s'"
            test.fail(debug_msg % (src_md5, dst_md5), logging.info)
        logging.info("Files md5sum match, file md5 is '%s'" % src_md5)

        error_context.context("Checking network private", logging.info)
        tcpdump_check_cmd = params["tcpdump_check_cmd"]
        tcpdump_kill_cmd = params["tcpdump_kill_cmd"]
        tcpdump_check_cmd = re.sub("ADDR0", addresses[0], tcpdump_check_cmd)
        tcpdump_check_cmd = re.sub("ADDR1", addresses[1], tcpdump_check_cmd)
        status = mon_session.cmd_status(tcpdump_check_cmd)
        if status:
            test.error("Tcpdump process terminate exceptly")
        mon_session.cmd(tcpdump_kill_cmd)
        dthread.join()

    finally:
        sessions[0].cmd(" %s %s " % (clean_cmd, src_file))
        sessions[1].cmd(" %s %s " % (clean_cmd, src_file))
        if mon_session:
            mon_session.close()
        for session in sessions:
            if session:
                session.close()
Exemplo n.º 11
0
def run(test, params, env):
    """
    Test Step:
        1. boot up three virtual machine
        2. transfer file from guest1 to guest2, check md5
        3. in guest 3 try to capture the packets(guest1 <-> guest2)
    Params:
        :param test: QEMU test object
        :param params: Dictionary with the test parameters
        :param env: Dictionary with test environment.
    """
    def data_mon(session, cmd, timeout):
        try:
            session.cmd(cmd, timeout)
        except ShellCmdError as e:
            if re.findall(catch_date % (addresses[1], addresses[0]), str(e)):
                test.fail("God! Capture the transfet data:'%s'" % str(e))
            logging.info("Guest3 catch data is '%s'" % str(e))

    timeout = int(params.get("login_timeout", '360'))
    password = params.get("password")
    username = params.get("username")
    shell_port = params.get("shell_port")
    tmp_dir = params.get("tmp_dir", "/tmp/")
    clean_cmd = params.get("clean_cmd", "rm -f")
    filesize = int(params.get("filesize", '100'))

    tcpdump_cmd = params.get("tcpdump_cmd")
    dd_cmd = params.get("dd_cmd")
    catch_date = params.get("catch_data", "%s.* > %s.ssh")
    md5_check = params.get("md5_check", "md5sum %s")
    mon_process_timeout = int(params.get("mon_process_timeout", "1200"))
    sessions = []
    addresses = []
    vms = []

    error_context.context("Init boot the vms")
    for vm_name in params.get("vms", "vm1 vm2 vm3").split():
        vms.append(env.get_vm(vm_name))
    for vm in vms:
        vm.verify_alive()
        sessions.append(vm.wait_for_login(timeout=timeout))
        addresses.append(vm.get_address())
    mon_session = vms[2].wait_for_login(timeout=timeout)
    mon_macaddr = vms[2].get_mac_address()

    src_file = (tmp_dir + "src-%s" % utils_misc.generate_random_string(8))
    dst_file = (tmp_dir + "dst-%s" % utils_misc.generate_random_string(8))

    try:
        # Before transfer, run tcpdump to try to catche data
        error_msg = "In guest3, try to capture the packets(guest1 <-> guest2)"
        error_context.context(error_msg, logging.info)
        if params.get("os_type") == "linux":
            if_func = utils_net.get_linux_ifname
            args = (mon_session, mon_macaddr)
        else:
            if_func = utils_net.get_windows_nic_attribute
            args = (mon_session, "macaddress", mon_macaddr, "netconnectionid")
        interface_name = if_func(*args)
        tcpdump_cmd = tcpdump_cmd % (addresses[1], addresses[0],
                                     interface_name)
        dthread = utils_misc.InterruptedThread(data_mon,
                                               (sessions[2],
                                                tcpdump_cmd,
                                                mon_process_timeout))

        logging.info("Tcpdump mon start ...")
        logging.info("Creating %dMB file on guest1", filesize)
        sessions[0].cmd(dd_cmd % (src_file, filesize), timeout=timeout)
        dthread.start()

        error_context.context("Transferring file guest1 -> guest2",
                              logging.info)
        if params.get("os_type") == "windows":
            cp_cmd = params["copy_cmd"]
            cp_cmd = cp_cmd % (addresses[1], params['file_transfer_port'],
                               src_file, dst_file)
            sessions[0].cmd_output(cp_cmd)
        else:
            remote.scp_between_remotes(addresses[0], addresses[1],
                                       shell_port, password, password,
                                       username, username, src_file, dst_file)

        error_context.context("Check the src and dst file is same",
                              logging.info)
        src_md5 = sessions[0].cmd_output(md5_check % src_file).split()[0]
        dst_md5 = sessions[1].cmd_output(md5_check % dst_file).split()[0]

        if dst_md5 != src_md5:
            debug_msg = "Files md5sum mismatch!"
            debug_msg += "source file md5 is '%s', after transfer md5 is '%s'"
            test.fail(debug_msg % (src_md5, dst_md5), logging.info)
        logging.info("Files md5sum match, file md5 is '%s'" % src_md5)

        error_context.context("Checking network private", logging.info)
        tcpdump_check_cmd = params["tcpdump_check_cmd"]
        tcpdump_kill_cmd = params["tcpdump_kill_cmd"]
        tcpdump_check_cmd = re.sub("ADDR0", addresses[0], tcpdump_check_cmd)
        tcpdump_check_cmd = re.sub("ADDR1", addresses[1], tcpdump_check_cmd)
        status = mon_session.cmd_status(tcpdump_check_cmd)
        if status:
            test.error("Tcpdump process terminate exceptly")
        mon_session.cmd(tcpdump_kill_cmd)
        dthread.join()

    finally:
        sessions[0].cmd(" %s %s " % (clean_cmd, src_file))
        sessions[1].cmd(" %s %s " % (clean_cmd, src_file))
        if mon_session:
            mon_session.close()
        for session in sessions:
            if session:
                session.close()
Exemplo n.º 12
0
def run(test, params, env):
    """
    Test Step
        1. boot up two virtual machine
        2. For linux guest,Transfer data:
              host <--> guest1 <--> guest2 <-->host via ipv6
           For windows guest,Transfer data:
              host <--> guest1&guest2 via ipv6
        3. after data transfer, check data have no change
    Params:
        :param test: QEMU test object
        :param params: Dictionary with the test parameters
        :param env: Dictionary with test environment.
    """
    timeout = int(params.get("login_timeout", '360'))
    client = params.get("file_transfer_client")
    port = params.get("file_transfer_port")
    password = params.get("password")
    username = params.get("username")
    tmp_dir = params["tmp_dir"]
    filesize = int(params.get("filesize", '4096'))
    dd_cmd = params["dd_cmd"]
    file_trans_timeout = int(params.get("file_trans_timeout", '1200'))
    file_md5_check_timeout = int(params.get("file_md5_check_timeout", '600'))

    def get_file_md5sum(file_name, session, timeout):
        """
        Get file md5sum from guest.
        """
        logging.info("Get md5sum of the file:'%s'" % file_name)
        s, o = session.cmd_status_output("md5sum %s" % file_name, timeout=timeout)
        if s != 0:
            test.error("Get file md5sum failed as %s" % o)
        return re.findall(r"\w{32}", o)[0]

    sessions = {}
    addresses = {}
    inet_name = {}
    vms = []

    error_context.context("Boot vms for test", logging.info)
    for vm_name in params.get("vms", "vm1 vm2").split():
        vms.append(env.get_vm(vm_name))

    # config ipv6 address host and guest.
    host_ifname = params.get("netdst")
    host_address = utils_net.get_host_ip_address(
        params, ip_ver="ipv6", linklocal=True)

    error_context.context("Get ipv6 address of host: %s" % host_address,
                          logging.info)
    for vm in vms:
        vm.verify_alive()
        sessions[vm] = vm.wait_for_login(timeout=timeout)
        if params.get("os_type") == "linux":
            inet_name[vm] = utils_net.get_linux_ifname(sessions[vm],
                                                       vm.get_mac_address())
        addresses[vm] = utils_net.get_guest_ip_addr(
            sessions[vm],
            vm.get_mac_address(),
            params.get("os_type"),
            ip_version="ipv6",
            linklocal=True)

        error_context.context("Get ipv6 address of %s: %s" % (vm.name, addresses[vm]),
                              logging.info)

    # prepare test data
    guest_path = (tmp_dir + "src-%s" % utils_misc.generate_random_string(8))
    dest_path = (tmp_dir + "dst-%s" % utils_misc.generate_random_string(8))
    host_path = os.path.join(test.tmpdir, "tmp-%s" %
                             utils_misc.generate_random_string(8))
    logging.info("Test setup: Creating %dMB file on host", filesize)
    process.run(dd_cmd % (host_path, filesize), shell=True)

    try:
        src_md5 = (crypto.hash_file(host_path, algorithm="md5"))
        error_context.context("md5 value of data from src: %s" % src_md5,
                              logging.info)
        # transfer data
        for vm in vms:
            error_context.context("Transfer data from host to %s" % vm.name,
                                  logging.info)
            remote.copy_files_to(addresses[vm],
                                 client, username, password, port,
                                 host_path, guest_path,
                                 timeout=file_trans_timeout,
                                 interface=host_ifname)
            dst_md5 = get_file_md5sum(guest_path, sessions[vm],
                                      timeout=file_md5_check_timeout)
            error_context.context("md5 value of data in %s: %s" % (vm.name, dst_md5),
                                  logging.info)
            if dst_md5 != src_md5:
                test.fail("File changed after transfer host -> %s" % vm.name)

        if params.get("os_type") == "linux":
            for vm_src in addresses:
                for vm_dst in addresses:
                    if vm_src != vm_dst:
                        error_context.context("Transferring data from %s to %s" %
                                              (vm_src.name, vm_dst.name),
                                              logging.info)
                        remote.scp_between_remotes(addresses[vm_src],
                                                   addresses[vm_dst],
                                                   port, password, password,
                                                   username, username,
                                                   guest_path, dest_path,
                                                   timeout=file_trans_timeout,
                                                   src_inter=host_ifname,
                                                   dst_inter=inet_name[vm_src])
                        dst_md5 = get_file_md5sum(dest_path, sessions[vm_dst],
                                                  timeout=file_md5_check_timeout)
                        error_context.context("md5 value of data in %s: %s" % (vm.name, dst_md5),
                                              logging.info)
                        if dst_md5 != src_md5:
                            test.fail("File changed transfer %s -> %s"
                                      % (vm_src.name, vm_dst.name))

        for vm in vms:
            error_context.context("Transfer data from %s to host" % vm.name,
                                  logging.info)
            remote.copy_files_from(addresses[vm],
                                   client, username, password, port,
                                   guest_path, host_path,
                                   timeout=file_trans_timeout,
                                   interface=host_ifname)
            error_context.context("Check whether the file changed after trans",
                                  logging.info)
            dst_md5 = (crypto.hash_file(host_path, algorithm="md5"))
            error_context.context("md5 value of data after copying to host: %s" % dst_md5,
                                  logging.info)

            if dst_md5 != src_md5:
                test.fail("File changed after transfer (md5sum mismatch)")
            process.system_output("rm -rf %s" % host_path, timeout=timeout)

    finally:
        process.system("rm -rf %s" % host_path, timeout=timeout,
                       ignore_status=True)
        for vm in vms:
            if params.get("os_type") == "linux":
                sessions[vm].cmd("rm -rf %s %s || true" % (guest_path, dest_path),
                                 timeout=timeout, ignore_all_errors=True)
            else:
                sessions[vm].cmd("del /f %s" % guest_path,
                                 timeout=timeout, ignore_all_errors=True)
            sessions[vm].close()