Example #1
0
    def _kernel_install_src(self, base_tree, config, config_list=None,
                           patch_list=None, need_reboot=True):
        if not utils.is_url(base_tree):
            base_tree = os.path.join(self.bindir, base_tree)
        if not utils.is_url(config):
            config = os.path.join(self.bindir, config)
        kernel = self.job.kernel(base_tree, self.outputdir)
        if patch_list:
            patches = []
            for p in patch_list.split():
                # Make sure all the patches are in local.
                if not utils.is_url(p):
                    continue
                dst = os.path.join(self.bindir, os.path.basename(p))
                local_patch = utils.get_file(p, dst)
                patches.append(local_patch)
            kernel.patch(*patches)
        kernel.config(config, config_list)
        kernel.build()
        kernel.install()

        if need_reboot:
            kernel.boot()
        else:
            kernel.add_to_bootloader()
    def _kernel_install_src(self, base_tree, config, config_list=None,
                            patch_list=None, need_reboot=True):
        if not utils.is_url(base_tree):
            base_tree = os.path.join(self.bindir, base_tree)
        if not utils.is_url(config):
            config = os.path.join(self.bindir, config)
        kernel = self.job.kernel(base_tree, self.outputdir)
        if patch_list:
            patches = []
            for p in patch_list:
                # Make sure all the patches are in local.
                if not utils.is_url(p):
                    continue
                dst = os.path.join(self.bindir, os.path.basename(p))
                local_patch = utils.get_file(p, dst)
                patches.append(local_patch)
            kernel.patch(*patches)
        kernel.config(config, config_list)
        kernel.build()
        kernel.install()

        if need_reboot:
            kernel.boot()
        else:
            kernel.add_to_bootloader()
Example #3
0
 def consume_one_config(self, config_option):
     if os.path.exists(config_option) or utils.is_url(config_option):
         if os.path.exists(config_option):
             cfg = open(config_option, 'r')
         if utils.is_url(config_option):
             cfg = utils.urlopen(config_option)
         # read the file
         for line in cfg.readlines():
             self.configs.append(line)
     else:
         self.configs.append(config_option)
Example #4
0
 def consume_one_config(self, config_option):
     if os.path.exists(config_option) or utils.is_url(config_option):
         if os.path.exists(config_option):
             cfg = open(config_option, 'r')
         if utils.is_url(config_option):
             cfg = utils.urlopen(config_option)
         # read the file
         for line in cfg.readlines():
             self.configs.append(line)
     else:
         self.configs.append(config_option)
Example #5
0
    def fetch(self, args):
        """
        fetch a remote control file or packages

        """
        if not len(args):
            self.help()

        url = args.pop(0)
        if not utils.is_url(url):
            logging.info("Not a remote url, nothing to fetch (%s)", url)
            self.help()

        if len(args):
            name = args.pop(0)
        else:
            name = ""

        logging.info("Fetching file %s:%s", url, name)
        autodir = os.path.abspath(os.environ['AUTODIR'])
        tmpdir = os.path.join(autodir, 'tmp')
        tests_out_dir = GLOBAL_CONFIG.get_config_value('COMMON',
                                                       'test_output_dir',
                                                       default=tmpdir)
        pkg_dir = os.path.join(tests_out_dir, 'packages')
        install_dir = os.path.join(FETCHDIRTEST, name)

        pkgmgr = packages.PackageManager(tests_out_dir,
            run_function_dargs={'timeout':3600})
        pkgmgr.install_pkg(name, 'test', pkg_dir, install_dir,
            repo_url=url)

        raise SystemExit(0)
Example #6
0
    def fetch(self, args):
        """
        fetch a remote control file or packages

        """
        if not len(args):
            self.help()

        url = args.pop(0)
        if not utils.is_url(url):
            logging.info("Not a remote url, nothing to fetch (%s)", url)
            self.help()

        if len(args):
            name = args.pop(0)
        else:
            name = ""

        logging.info("Fetching file %s:%s", url, name)
        autodir = os.path.abspath(os.environ['AUTODIR'])
        tmpdir = os.path.join(autodir, 'tmp')
        tests_out_dir = GLOBAL_CONFIG.get_config_value('COMMON',
                                                       'test_output_dir',
                                                       default=tmpdir)
        pkg_dir = os.path.join(tests_out_dir, 'packages')
        install_dir = os.path.join(FETCHDIRTEST, name)

        pkgmgr = packages.PackageManager(tests_out_dir,
                                         run_function_dargs={'timeout': 3600})
        pkgmgr.install_pkg(name, 'test', pkg_dir, install_dir, repo_url=url)

        raise SystemExit(0)
Example #7
0
    def fetch(self, args):
        """
        fetch a remote control file or packages

        """
        if not len(args):
            self.help()

        url = args.pop(0)
        if not utils.is_url(url):
            logging.info("Not a remote url, nothing to fetch (%s)", url)
            self.help()

        if len(args):
            name = args.pop(0)
        else:
            name = ""

        logging.info("Fetching file %s:%s", url, name)
        pkg_dir = os.path.join(output_dir, 'packages')
        install_dir = os.path.join(FETCHDIRTEST, name)

        pkgmgr = packages.PackageManager(output_dir,
            run_function_dargs={'timeout':3600})
        pkgmgr.install_pkg(name, 'test', pkg_dir, install_dir,
            repo_url=url)

        raise SystemExit(0)
Example #8
0
    def __init__(self, address, netperf_path, md5sum="", local_path="",
                 client="ssh", port="22", username="******", password="******",
                 check_command=None):
        """
        Class NetperfPackage just represent the netperf package
        Init NetperfPackage class.

        :param address: Remote host or guest address
        :param netperf_path: Remote netperf path
        :param me5sum: Local netperf package me5sum
        :param local_path: Local netperf (path or link) path
        :param client: The client to use ('ssh', 'telnet' or 'nc')
        :param port: Port to connect to
        :param username: Username (if required)
        :param password: Password (if required)
        """
        super(NetperfPackage, self).__init__(address, client, username,
                                             password, port, netperf_path)

        self.local_netperf = local_path
        self.pack_suffix = ""
        if client == "nc":
            self.prompt = r"^\w:\\.*>\s*$"
            self.linesep = "\r\n"
        else:
            self.prompt = "^\[.*\][\#\$]\s*$"
            self.linesep = "\n"
            if self.remote_path.endswith("tar.bz2"):
                self.pack_suffix = ".tar.bz2"
                self.decomp_cmd = "tar jxvf"
            elif self.remote_path.endswith("tar.gz"):
                self.pack_suffix = ".tar.gz"
                self.decomp_cmd = "tar zxvf"

            self.netperf_dir = self.remote_path.rstrip(self.pack_suffix)
            self.netperf_base_dir = os.path.dirname(self.remote_path)
            self.netperf_exec = os.path.basename(self.remote_path)

        logging.debug("Create remote session")
        self.session = remote.remote_login(self.client, self.address,
                                           self.port, self.username,
                                           self.password, self.prompt,
                                           self.linesep, timeout=360)

        self.build_tool = True
        if check_command:
            netperf_status = self.session.cmd_status("which %s" %
                                                     check_command)
            if netperf_status == 0:
                self.build_tool = False

        if self.build_tool:
            if utils.is_url(local_path):
                logging.debug("Download URL file to local path")
                tmp_dir = data_dir.get_download_dir()
                self.local_netperf = utils.unmap_url_cache(tmp_dir, local_path,
                                                           md5sum)
            self.push_file(self.local_netperf)
Example #9
0
 def dlink_preprcess(download_link):
     """
     Preprocess the download link
     """
     if not download_link:
         raise error.TestNAError("Can not get the netperf download_link")
     if not utils.is_url(download_link):
         download_link = utils_misc.get_path(data_dir.get_deps_dir(),
                                             download_link)
     return download_link
Example #10
0
 def dlink_preprcess(download_link):
     """
     Preprocess the download link
     """
     if not download_link:
         raise error.TestNAError("Can not get the netperf download_link")
     if not utils.is_url(download_link):
         download_link = utils_misc.get_path(data_dir.get_deps_dir(),
                                             download_link)
     return download_link
Example #11
0
    def pull_file(self, netperf_source=None):
        """
        Copy file from remote to local.
        """

        if utils.is_url(netperf_source):
            logging.debug("Download URL file to local path")
            tmp_dir = data_dir.get_download_dir()
            self.netperf_source = utils.unmap_url_cache(
                tmp_dir, netperf_source, self.md5sum)
        else:
            self.netperf_source = netperf_source
        return self.netperf_source
    def pull_file(self, netperf_source=None):
        """
        Copy file from remote to local.
        """

        if utils.is_url(netperf_source):
            logging.debug("Download URL file to local path")
            tmp_dir = data_dir.get_download_dir()
            self.netperf_source = utils.unmap_url_cache(tmp_dir, netperf_source,
                                                        self.md5sum)
        else:
            self.netperf_source = netperf_source
        return self.netperf_source
Example #13
0
    def __init__(self, address, netperf_path, md5sum="", local_path="",
                 client="ssh", port="22", username="******", password="******"):
        """
        Class NetperfPackage just represent the netperf package
        Init NetperfPackage class.

        :param address: Remote host or guest address
        :param netperf_path: Remote netperf path
        :param me5sum: Local netperf package me5sum
        :param local_path: Local netperf (path or link) path
        :param client: The client to use ('ssh', 'telnet' or 'nc')
        :param port: Port to connect to
        :param username: Username (if required)
        :param password: Password (if required)
        """
        super(NetperfPackage, self).__init__(address, client, username,
                                             password, port, netperf_path)

        self.local_netperf = local_path
        self.pack_suffix = ""
        if client == "nc":
            self.prompt = r"^\w:\\.*>\s*$"
            self.linesep = "\r\n"
        else:
            self.prompt = "^\[.*\][\#\$]\s*$"
            self.linesep = "\n"
            if self.remote_path.endswith("tar.bz2"):
                self.pack_suffix = ".tar.bz2"
                self.decomp_cmd = "tar jxvf"
            elif self.remote_path.endswith("tar.gz"):
                self.pack_suffix = ".tar.gz"
                self.decomp_cmd = "tar zxvf"

            self.netperf_dir = self.remote_path.rstrip(self.pack_suffix)
            self.netperf_base_dir = os.path.dirname(self.remote_path)
            self.netperf_exec = os.path.basename(self.remote_path)

        if utils.is_url(local_path):
            logging.debug("Download URL file to local path")
            tmp_dir = data_dir.get_download_dir()
            self.local_netperf = utils.unmap_url_cache(tmp_dir, local_path,
                                                       md5sum)
        self.push_file(self.local_netperf)

        logging.debug("Create remote session")
        self.session = remote.remote_login(self.client, self.address,
                                           self.port, self.username,
                                           self.password, self.prompt,
                                           self.linesep, timeout=360)
Example #14
0
 def env_setup(session, ip_addr, username, shell_port, password):
     """
     Test env setup
     """
     error.context("Setup env for %s" % ip_addr)
     ssh_cmd(session, "service iptables stop; true")
     netperf_links = params["netperf_links"].split()
     remote_dir = params.get("remote_dir", "/var/tmp")
     for netperf_link in netperf_links:
         if utils.is_url(netperf_link):
             download_dir = data_dir.get_download_dir()
             md5sum = params.get("pkg_md5sum")
             netperf_dir = utils.unmap_url_cache(download_dir, netperf_link,
                                                 md5sum)
         elif netperf_link:
             netperf_dir = os.path.join(data_dir.get_root_dir(),
                                        "shared/%s" % netperf_link)
         remote.scp_to_remote(ip_addr, shell_port, username, password,
                              netperf_dir, remote_dir)
     ssh_cmd(session, params.get("setup_cmd"))
Example #15
0
 def env_setup(session, ip_addr, username, shell_port, password):
     """
     Test env setup
     """
     error.context("Setup env for %s" % ip_addr)
     ssh_cmd(session, "service iptables stop; true")
     netperf_links = params["netperf_links"].split()
     remote_dir = params.get("remote_dir", "/var/tmp")
     for netperf_link in netperf_links:
         if utils.is_url(netperf_link):
             download_dir = data_dir.get_download_dir()
             md5sum = params.get("pkg_md5sum")
             netperf_dir = utils.unmap_url_cache(download_dir,
                                                 netperf_link, md5sum)
         elif netperf_link:
             netperf_dir = os.path.join(data_dir.get_root_dir(),
                                        "shared/%s" % netperf_link)
         remote.scp_to_remote(ip_addr, shell_port, username, password,
                              netperf_dir, remote_dir)
     ssh_cmd(session, params.get("setup_cmd"))
Example #16
0
 def _copy_file_to_test_dir(file_name, dest_dir):
     if not utils.is_url(file_name):
         file_name = os.path.join(test.bindir, file_name)
     dest = os.path.join(dest_dir, os.path.basename(file_name))
     # return the absolute path of file.
     return os.path.basename(utils.get_file(file_name, dest))
Example #17
0
    def netload_kill_problem(session_serial):
        setup_cmd = params.get("setup_cmd")
        clean_cmd = params.get("clean_cmd")
        firewall_flush = params.get("firewall_flush", "service iptables stop")
        error.context("Stop firewall in guest and host.", logging.info)
        try:
            utils.run(firewall_flush)
        except Exception:
            logging.warning("Could not stop firewall in host")

        try:
            session_serial.cmd(firewall_flush)
        except Exception:
            logging.warning("Could not stop firewall in guest")

        netperf_links = params["netperf_links"].split()
        remote_dir = params.get("remote_dir", "/var/tmp")
        # netperf_links support multi links. In case we need apply patchs to
        # netperf or need copy other files.
        for netperf_link in netperf_links:
            if utils.is_url(netperf_link):
                download_dir = data_dir.get_download_dir()
                netperf_link = utils.unmap_url_cache(download_dir,
                                                     netperf_link)
                netperf_dir = download_dir
            elif netperf_link:
                netperf_link = utils_misc.get_path(data_dir.get_deps_dir(),
                                                   netperf_link)
            vm.copy_files_to(netperf_link, remote_dir)
            utils.force_copy(netperf_link, remote_dir)

        guest_ip = vm.get_address(0)
        server_ip = utils_net.get_correspond_ip(guest_ip)

        error.context("Setup and run netperf server in host and guest",
                      logging.info)
        session_serial.cmd(setup_cmd % remote_dir, timeout=200)
        utils.run(setup_cmd % remote_dir, timeout=200)

        try:
            session_serial.cmd(clean_cmd)
        except Exception:
            pass
        session_serial.cmd(params.get("netserver_cmd") % remote_dir)

        utils.run(clean_cmd, ignore_status=True)
        utils.run(params.get("netserver_cmd") % remote_dir)
        p_size = params.get("packet_size", "1500")
        host_netperf_cmd = params.get("netperf_cmd") % (remote_dir,
                                                        "TCP_STREAM",
                                                        guest_ip,
                                                        p_size)
        guest_netperf_cmd = params.get("netperf_cmd") % (remote_dir,
                                                         "TCP_STREAM",
                                                         server_ip,
                                                         p_size)
        try:
            error.context("Start heavy network load host <=> guest.",
                          logging.info)
            session_serial.sendline(guest_netperf_cmd)
            utils.BgJob(host_netperf_cmd)

            # Wait for create big network usage.
            time.sleep(10)
            msg = "During netperf running, Check that we can kill VM with signal 0"
            error.context(msg, logging.info)
            kill_and_check(vm)

        finally:
            error.context("Clean up netperf server in host and guest.",
                          logging.info)
            utils.run(clean_cmd, ignore_status=True)
            try:
                session_serial.cmd(clean_cmd)
            except Exception:
                pass
Example #18
0
 def _copy_file_to_test_dir(file_path):
     if utils.is_url(file_path):
         return file_path
     file_abs_path = os.path.join(test.bindir, file_path)
     dest = os.path.join(sub_test_path, os.path.basename(file_abs_path))
     return os.path.basename(utils.get_file(file_path, dest))
Example #19
0
    def netload_kill_problem(session_serial):
        setup_cmd = params.get("setup_cmd")
        clean_cmd = params.get("clean_cmd")
        firewall_flush = params.get("firewall_flush", "service iptables stop")
        error.context("Stop firewall in guest and host.", logging.info)
        try:
            utils.run(firewall_flush)
        except Exception:
            logging.warning("Could not stop firewall in host")

        try:
            session_serial.cmd(firewall_flush)
        except Exception:
            logging.warning("Could not stop firewall in guest")

        netperf_links = params["netperf_links"].split()
        remote_dir = params.get("remote_dir", "/var/tmp")
        # netperf_links support multi links. In case we need apply patchs to
        # netperf or need copy other files.
        for netperf_link in netperf_links:
            if utils.is_url(netperf_link):
                download_dir = data_dir.get_download_dir()
                netperf_link = utils.unmap_url_cache(download_dir,
                                                     netperf_link)
                netperf_dir = download_dir
            elif netperf_link:
                netperf_link = utils_misc.get_path(data_dir.get_deps_dir(),
                                                   netperf_link)
            vm.copy_files_to(netperf_link, remote_dir)
            utils.force_copy(netperf_link, remote_dir)

        guest_ip = vm.get_address(0)
        server_ip = utils_net.get_correspond_ip(guest_ip)

        error.context("Setup and run netperf server in host and guest",
                      logging.info)
        session_serial.cmd(setup_cmd % remote_dir, timeout=200)
        utils.run(setup_cmd % remote_dir, timeout=200)

        try:
            session_serial.cmd(clean_cmd)
        except Exception:
            pass
        session_serial.cmd(params.get("netserver_cmd") % remote_dir)

        utils.run(clean_cmd, ignore_status=True)
        utils.run(params.get("netserver_cmd") % remote_dir)
        p_size = params.get("packet_size", "1500")
        host_netperf_cmd = params.get("netperf_cmd") % (
            remote_dir, "TCP_STREAM", guest_ip, p_size)
        guest_netperf_cmd = params.get("netperf_cmd") % (
            remote_dir, "TCP_STREAM", server_ip, p_size)
        try:
            error.context("Start heavy network load host <=> guest.",
                          logging.info)
            session_serial.sendline(guest_netperf_cmd)
            utils.BgJob(host_netperf_cmd)

            # Wait for create big network usage.
            time.sleep(10)
            msg = "During netperf running, Check that we can kill VM with signal 0"
            error.context(msg, logging.info)
            kill_and_check(vm)

        finally:
            error.context("Clean up netperf server in host and guest.",
                          logging.info)
            utils.run(clean_cmd, ignore_status=True)
            try:
                session_serial.cmd(clean_cmd)
            except Exception:
                pass
Example #20
0
def run(test, params, env):
    """
    Run netperf on server and client side, we need run this case on two
    machines. If dsthost is not set will start netperf server on local
    host and log a error message.:
    1) Start one vm guest os as client.
    2) Start a reference machine (dsthost) as server.
    3) Setup netperf on guest and reference machine (dsthost).
    4) Run netserver on server using control.server.
    5) Run netperf client command in guest several time with different
       message size.
    6) Compare UDP performance to make sure it is acceptable.

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

    def get_remote_host_session():
        dsthostssh = remote.remote_login("ssh", dsthost, 22, "root",
                                         passwd, "#", timeout=30)
        if dsthostssh:
            dsthostssh.set_status_test_command("echo $?")
            return dsthostssh
        else:
            return None

    def scp_to_remote(local_path="", remote_path=""):
        remote.scp_to_remote(dsthost, 22, "root", passwd, local_path,
                             remote_path)
        vm.copy_files_to(local_path, remote_path)

    vm = env.get_vm(params["main_vm"])
    vm.verify_alive()

    session = vm.wait_for_login(timeout=int(params.get("login_timeout", 360)))

    dsthost = params.get("dsthost")
    if not dsthost:
        dsthost = utils_net.get_ip_address_by_interface(params.get("netdst"))
        logging.error("dsthost is not set, use localhost ip %s" % dsthost)
    else:
        logging.info("Dest host is %s" % dsthost)
    passwd = params.get("hostpasswd")
    test_timeout = float(params.get("test_timeout", "1200"))

    error.context("Create session connection to remote machine")
    dsthostssh = utils_misc.wait_for(get_remote_host_session, 120, 0, 2)
    if not dsthostssh:
        raise error.TestError("Could not login into remote host %s " % dsthost)

    # Get range of message size.
    message_size_range = params.get("message_size_range")
    message_size = message_size_range.split()
    start_size = int(message_size[0])
    end_size = int(message_size[1])
    step = int(message_size[2])
    m_size = start_size

    error.context("Copy netperf to dsthost and guest vm.")
    netperf_links = params["netperf_links"].split()
    remote_dir = params.get("remote_dir", "/var/tmp")
    for netperf_link in netperf_links:
        if utils.is_url(netperf_link):
            download_dir = data_dir.get_download_dir()
            md5sum = params.get("pkg_md5sum")
            netperf_dir = utils.unmap_url_cache(download_dir,
                                                netperf_link, md5sum)
        elif netperf_link:
            netperf_dir = os.path.join(test.virtdir, netperf_link)
        scp_to_remote(netperf_dir, remote_dir)

    # Setup netpref.
    error.context("Set up netperf on reference machine.", logging.info)
    cmd = params.get("setup_cmd")
    (status, output) = dsthostssh.cmd_status_output(cmd % remote_dir,
                                                    timeout=test_timeout)
    if status != 0:
        raise error.TestError("Fail to setup netperf on reference machine.")
    error.context("Setup netperf on guest os.", logging.info)
    (status, output) = session.cmd_status_output(cmd % remote_dir,
                                                 timeout=test_timeout)
    if status != 0:
        raise error.TestError("Fail to setup netperf on guest os.")

    # Start netperf server in dsthost.
    cmd = "killall netserver"
    dsthostssh.cmd_status_output(cmd)
    cmd = params.get("netserver_cmd")
    txt = "Run netserver on server (dsthost) using control.server."
    error.context(txt, logging.info)
    (status, output) = dsthostssh.cmd_status_output(cmd)
    if status != 0:
        txt = "Fail to start netperf server on remote machine."
        txt += " Command output: %s" % output
        raise error.TestError(txt)

    throughput = []

    # Run netperf with message size defined in range.
    msg = "Detail result for netperf udp test with different message size.\n"
    while(m_size <= end_size):
        test_protocol = params.get("test_protocol", "UDP_STREAM")
        cmd = params.get("netperf_cmd") % (dsthost, test_protocol, m_size)
        txt = "Run netperf client command in guest: %s" % cmd
        error.context(txt, logging.info)
        (status, output) = session.cmd_status_output(cmd)
        if status != 0:
            txt = "Fail to execute netperf client side command in guest."
            txt += " Command output: %s" % output
            raise error.TestError(txt)
        if test_protocol == "UDP_STREAM":
            speed_index = 6
        elif test_protocol == "UDP_RR":
            speed_index = 7
        else:
            error.TestNAError("Protocol %s is not support" % test_protocol)

        line_tokens = output.splitlines()[speed_index].split()
        if not line_tokens:
            raise error.TestError("Output format is not expected")
        throughput.append(float(line_tokens[5]))

        msg += output
        m_size += step
    file(os.path.join(test.debugdir, "udp_results"), "w").write(msg)

    failratio = float(params.get("failratio", 0.3))
    error.context("Compare UDP performance.", logging.info)
    for i in range(len(throughput) - 1):
        if abs(throughput[i] - throughput[i + 1]) > throughput[i] * failratio:
            txt = "The gap between adjacent throughput is greater than"
            txt += "%f." % failratio
            txt += "Please refer to log file for details:\n %s" % msg
            raise error.TestFail(txt)
    logging.info("The UDP performance as measured via netperf is ok.")
    logging.info("Throughput of netperf command: %s" % throughput)
    logging.debug("Output of netperf command:\n %s" % msg)
    error.context("Kill netperf server on server (dsthost).")

    try:
        remote_files = "%s/netperf*" % remote_dir
        dsthostssh.cmd("killall -9 netserver", ignore_all_errors=True)
        dsthostssh.cmd("rm -rf %s" % remote_files, ignore_all_errors=True)
        session.cmd("rm -rf %s" % remote_files, ignore_all_errors=True)
        session.close()
        dsthostssh.close()
    except Exception:
        pass
Example #21
0
def run_netperf_udp(test, params, env):
    """
    Run netperf on server and client side, we need run this case on two
    machines. If dsthost is not set will start netperf server on local
    host and log a error message.:
    1) Start one vm guest os as client.
    2) Start a reference machine (dsthost) as server.
    3) Setup netperf on guest and reference machine (dsthost).
    4) Run netserver on server using control.server.
    5) Run netperf client command in guest several time with different
       message size.
    6) Compare UDP performance to make sure it is acceptable.

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

    def get_remote_host_session():
        dsthostssh = remote.remote_login("ssh", dsthost, 22, "root",
                                         passwd, "#", timeout=30)
        if dsthostssh:
            dsthostssh.set_status_test_command("echo $?")
            return dsthostssh
        else:
            return None

    def scp_to_remote(local_path="", remote_path=""):
        remote.scp_to_remote(dsthost, 22, "root", passwd, local_path,
                             remote_path)
        vm.copy_files_to(local_path, remote_path)

    vm = env.get_vm(params["main_vm"])
    vm.verify_alive()

    session = vm.wait_for_login(timeout=int(params.get("login_timeout", 360)))

    dsthost = params.get("dsthost")
    if not dsthost:
        dsthost = utils_net.get_ip_address_by_interface(params.get("netdst"))
        logging.error("dsthost is not set, use localhost ip %s" % dsthost)
    else:
        logging.info("Dest host is %s" % dsthost)
    passwd = params.get("hostpasswd")
    test_timeout = float(params.get("test_timeout", "1200"))

    error.context("Create session connection to remote machine")
    dsthostssh = utils_misc.wait_for(get_remote_host_session, 120, 0, 2)
    if not dsthostssh:
        raise error.TestError("Could not login into remote host %s " % dsthost)

    # Get range of message size.
    message_size_range = params.get("message_size_range")
    message_size = message_size_range.split()
    start_size = int(message_size[0])
    end_size = int(message_size[1])
    step = int(message_size[2])
    m_size = start_size

    error.context("Copy netperf to dsthost and guest vm.")
    netperf_links = params["netperf_links"].split()
    remote_dir = params.get("remote_dir", "/var/tmp")
    for netperf_link in netperf_links:
        if utils.is_url(netperf_link):
            download_dir = data_dir.get_download_dir()
            md5sum = params.get("pkg_md5sum")
            netperf_dir = utils.unmap_url_cache(download_dir,
                                                netperf_link, md5sum)
        elif netperf_link:
            netperf_dir = os.path.join(test.virtdir, netperf_link)
        scp_to_remote(netperf_dir, remote_dir)

    # Setup netpref.
    error.context("Set up netperf on reference machine.", logging.info)
    cmd = params.get("setup_cmd")
    (status, output) = dsthostssh.cmd_status_output(cmd % remote_dir,
                                                    timeout=test_timeout)
    if status != 0:
        raise error.TestError("Fail to setup netperf on reference machine.")
    error.context("Setup netperf on guest os.", logging.info)
    (status, output) = session.cmd_status_output(cmd % remote_dir,
                                                 timeout=test_timeout)
    if status != 0:
        raise error.TestError("Fail to setup netperf on guest os.")

    # Start netperf server in dsthost.
    cmd = "killall netserver"
    dsthostssh.cmd_status_output(cmd)
    cmd = params.get("netserver_cmd")
    txt = "Run netserver on server (dsthost) using control.server."
    error.context(txt, logging.info)
    (status, output) = dsthostssh.cmd_status_output(cmd)
    if status != 0:
        txt = "Fail to start netperf server on remote machine."
        txt += " Command output: %s" % output
        raise error.TestError(txt)

    throughput = []

    # Run netperf with message size defined in range.
    msg = "Detail result for netperf udp test with different message size.\n"
    while(m_size <= end_size):
        test_protocol = params.get("test_protocol", "UDP_STREAM")
        cmd = params.get("netperf_cmd") % (dsthost, test_protocol, m_size)
        txt = "Run netperf client command in guest: %s" % cmd
        error.context(txt, logging.info)
        (status, output) = session.cmd_status_output(cmd)
        if status != 0:
            txt = "Fail to execute netperf client side command in guest."
            txt += " Command output: %s" % output
            raise error.TestError(txt)
        if test_protocol == "UDP_STREAM":
            speed_index = 6
        elif test_protocol == "UDP_RR":
            speed_index = 7
        else:
            error.TestNAError("Protocol %s is not support" % test_protocol)

        line_tokens = output.splitlines()[speed_index].split()
        if not line_tokens:
            raise error.TestError("Output format is not expected")
        throughput.append(float(line_tokens[5]))

        msg += output
        m_size += step
    file(os.path.join(test.debugdir, "udp_results"), "w").write(msg)

    failratio = float(params.get("failratio", 0.3))
    error.context("Compare UDP performance.", logging.info)
    for i in range(len(throughput) - 1):
        if abs(throughput[i] - throughput[i + 1]) > throughput[i] * failratio:
            txt = "The gap between adjacent throughput is greater than"
            txt += "%f." % failratio
            txt += "Please refer to log file for details:\n %s" % msg
            raise error.TestFail(txt)
    logging.info("The UDP performance as measured via netperf is ok.")
    logging.info("Throughput of netperf command: %s" % throughput)
    logging.debug("Output of netperf command:\n %s" % msg)
    error.context("Kill netperf server on server (dsthost).")

    try:
        remote_files = "%s/netperf*" % remote_dir
        dsthostssh.cmd("killall -9 netserver", ignore_all_errors=True)
        dsthostssh.cmd("rm -rf %s" % remote_files, ignore_all_errors=True)
        session.cmd("rm -rf %s" % remote_files, ignore_all_errors=True)
        session.close()
        dsthostssh.close()
    except Exception:
        pass
Example #22
0
        asset_info = virttest.asset.get_file_asset(asset_name, src_path,
                                                   dst_path)
        if asset_info is None:
            raise error.TestError('Could not find %s' % image)
    else:
        asset_info = virttest.asset.get_asset_info(asset_name)

    # Do not force extraction if integrity information is available
    if asset_info['sha1_url']:
        force = params.get("force_copy", "no") == "yes"
    else:
        force = params.get("force_copy", "yes") == "yes"

    try:
        error.context("Copy image '%s'" % image, logging.info)
        if utils.is_url(asset_info['url']):
            virttest.asset.download_file(asset_info,
                                         interactive=False,
                                         force=force)
        else:
            utils.get_file(asset_info['url'], asset_info['destination'])

    finally:
        sub_type = params.get("sub_type")
        if sub_type:
            error.context("Run sub test '%s'" % sub_type, logging.info)
            params['image_name'] += "-error"
            params['boot_once'] = "c"
            vm.create(params=params)
            virttest.utils_test.run_virt_sub_test(test, params, env,
                                                  params.get("sub_type"))
Example #23
0
        asset_info = virttest.asset.get_file_asset(asset_name, src_path,
                                                   dst_path)
        if asset_info is None:
            raise error.TestError('Could not find %s' % image)
    else:
        asset_info = virttest.asset.get_asset_info(asset_name)

    # Do not force extraction if integrity information is available
    if asset_info['sha1_url']:
        force = params.get("force_copy", "no") == "yes"
    else:
        force = params.get("force_copy", "yes") == "yes"

    try:
        error.context("Copy image '%s'" % image, logging.info)
        if utils.is_url(asset_info['url']):
            virttest.asset.download_file(asset_info, interactive=False,
                                         force=force)
        else:
            utils.get_file(asset_info['url'], asset_info['destination'])

    finally:
        sub_type = params.get("sub_type")
        if sub_type:
            error.context("Run sub test '%s'" % sub_type, logging.info)
            params['image_name'] += "-error"
            params['boot_once'] = "c"
            vm.create(params=params)
            virttest.utils_test.run_virt_sub_test(test, params, env,
                                                  params.get("sub_type"))
Example #24
0
 def _copy_file_to_test_dir(file_name, dest_dir):
     if not utils.is_url(file_name):
         file_name = os.path.join(test.bindir, file_name)
     dest = os.path.join(dest_dir, os.path.basename(file_name))
     # return the absolute path of file.
     return os.path.basename(utils.get_file(file_name, dest))