当前位置: 首页>>代码示例>>Python>>正文


Python utils_net.get_host_ip_address函数代码示例

本文整理汇总了Python中virttest.utils_net.get_host_ip_address函数的典型用法代码示例。如果您正苦于以下问题:Python get_host_ip_address函数的具体用法?Python get_host_ip_address怎么用?Python get_host_ip_address使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。


在下文中一共展示了get_host_ip_address函数的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。

示例1: config_control

    def config_control(control_path):
        """
        Edit the control file to adapt the current environment.

        Replace CLIENTIP with guestip, and replace SERVERIP with hostip.

        :return: Path of a temp file which contains the result of replacing.
        """
        pattern2repl_dict = {r'CLIENTIP': vm.get_address(),
                             r'SERVERIP': utils_net.get_host_ip_address(params)}
        control_file = open(control_path)
        lines = control_file.readlines()
        control_file.close()

        for pattern, repl in pattern2repl_dict.items():
            for index in range(len(lines)):
                line = lines[index]
                lines[index] = re.sub(pattern, repl, line)

        fd, temp_control_path = tempfile.mkstemp(prefix="control",
                                                 dir=data_dir.get_tmp_dir())
        os.close(fd)

        temp_control = open(temp_control_path, "w")
        temp_control.writelines(lines)
        temp_control.close()
        return temp_control_path
开发者ID:Keepod,项目名称:virt-test,代码行数:27,代码来源:__init__.py

示例2: run

def run(test, params, env):
    """
    Test steps:

    1) Check the environment and get the params from params.
    2) while(loop_time < timeout):
            ttcp command.
    3) clean up.
    """
    # Find the ttcp command.
    try:
        path.find_command("ttcp")
    except path.CmdNotFoundError:
        test.cancel("Not find ttcp command on host.")
    # Get VM.
    vms = env.get_all_vms()
    for vm in vms:
        session = vm.wait_for_login()
        status, _ = session.cmd_status_output("which ttcp")
        if status:
            test.cancel("Not find ttcp command on guest.")
    # Get parameters from params.
    timeout = int(params.get("LB_ttcp_timeout", "300"))
    ttcp_server_command = params.get("LB_ttcp_server_command",
                                     "ttcp -s -r -v -D -p5015")
    ttcp_client_command = params.get("LB_ttcp_client_command",
                                     "ttcp -s -t -v -D -p5015 -b65536 -l65536 -n1000 -f K")

    host_session = aexpect.ShellSession("sh")

    try:
        current_time = int(time.time())
        end_time = current_time + timeout
        # Start the loop from current_time to end_time.
        while current_time < end_time:
            for vm in vms:
                session = vm.wait_for_login()
                host_session.sendline(ttcp_server_command)

                cmd = ("%s %s" % (ttcp_client_command, utils_net.get_host_ip_address(params)))

                def _ttcp_good():
                    status, output = session.cmd_status_output(cmd)
                    logging.debug(output)
                    if status:
                        return False
                    return True

                if not utils_misc.wait_for(_ttcp_good, timeout=60):
                    status, output = session.cmd_status_output(cmd)
                    if status:
                        test.fail("Failed to run ttcp command on guest.\n"
                                  "Detail: %s." % output)
                remote.handle_prompts(host_session, None, None, r"[\#\$]\s*$")
                current_time = int(time.time())
    finally:
        # Clean up.
        host_session.close()
        session.close()
开发者ID:balamuruhans,项目名称:tp-libvirt,代码行数:59,代码来源:libvirt_bench_ttcp_from_guest_to_host.py

示例3: _ttcp_good

 def _ttcp_good():
     status, output = session.cmd_status_output("%s %s" %
                                                (ttcp_client_command,
                                                 utils_net.get_host_ip_address(params)))
     logging.debug(output)
     if status:
         return False
     return True
开发者ID:libvirt-qe,项目名称:tp-libvirt,代码行数:8,代码来源:libvirt_bench_ttcp_from_guest_to_host.py

示例4: run

def run(test, params, env):
    """
    Verify open bios info.

    Step:
     1. Boot guest with qemu cli including "-prom-env 'auto-boot?=false'".
     2. SLOF will not boot automatically, it will go to the SLOF user
        interface directly, and the effect of "-prom-env 'auto-boot?=false'"
        is same with pressing "s" key during boot.
     3. In the SLOF terminal, input "boot" or "reset-all".
     4. SLOF will boot up successfully.
     5. Ping external host ip inside guest successfully.

    :param test: Qemu test object.
    :param params: Dictionary with the test.
    :param env: Dictionary with test environment.
    """
    def _send_custom_key():
        """ Send custom keyword to SLOF's user interface. """
        logging.info('Sending \"%s\" to SLOF user interface.' % send_key)
        for key in send_key:
            key = 'minus' if key == '-' else key
            vm.send_key(key)
        vm.send_key('ret')

    vm = env.get_vm(params["main_vm"])
    send_key = params.get('send_key')
    end_str = params.get('slof_end_str', '0 >')
    vm.verify_alive()
    content, next_pos = slof.wait_for_loaded(vm, test, end_str=end_str)
    logging.info('SLOF stop at \'%s\'.' % end_str)

    error_context.context(
        "Enter to menu by sending \'%s\'." % send_key, logging.info)
    _send_custom_key()
    content, _ = slof.wait_for_loaded(vm, test, next_pos, 'Trying to load')

    error_context.context("Try to log into guest '%s'." % vm.name, logging.info)
    session = vm.wait_for_login(timeout=float(params["login_timeout"]))
    logging.info("log into guest '%s' successfully." % vm.name)

    error_context.context("Try to ping external host.", logging.info)
    extra_host_ip = utils_net.get_host_ip_address(params)
    session.cmd('ping %s -c 5' % extra_host_ip)
    logging.info("Ping host(%s) successfully." % extra_host_ip)

    session.close()
    vm.destroy(gracefully=True)
开发者ID:ldoktor,项目名称:tp-qemu,代码行数:48,代码来源:slof_open_bios.py

示例5: get_host_ip

def get_host_ip(test):
    """Get IP for host.

    Parameters
    ----------
    test : SpiceTest
        Spice test object.

    """
    try:
        ip = utils_net.get_host_ip_address(test.cfg)
    except utils_net.NetError:
        ips = utils_net.get_all_ips()
        ip = ips[0]
        logger.info("Take as a host IP: %s", ip)
    if test.kvm_g.listening_addr == "ipv6":
        ip = "[" + utils_misc.convert_ipv4_to_ipv6(ip) + "]"
    return ip
开发者ID:spiceqa,项目名称:tp-spice,代码行数:18,代码来源:utils.py

示例6: run

def run(test, params, env):
    """
    Verify SLOF info with maxmem options.

    Step:
     1. Boot a guest with "maxmem=512G".
      a. Check no errors from output of SLOF.
      b. Log in guest successfully.
      c. Ping external host ip successfully.
     2. Shutdown the guest then boot it again with "maxmem=1024G".
      a. Check no errors from output of SLOF.
      b. Log in guest successfully.
      c. Ping external host ip successfully.

    :param test: Qemu test object.
    :param params: Dictionary with the test parameters.
    :param env: Dictionary with test environment.
    """
    start_pos = 0
    for mem in params['maxmem_mem_list'].split():
        params['maxmem_mem'] = mem

        env_process.preprocess_vm(test, params, env, params["main_vm"])
        vm = env.get_vm(params["main_vm"])
        vm.verify_alive()
        content, next_pos = slof.wait_for_loaded(vm, test, start_pos)

        error_context.context("Check the output of SLOF.", logging.info)
        slof.check_error(test, content)

        error_context.context("Try to log into guest '%s'." % vm.name,
                              logging.info)
        timeout = float(params.get("login_timeout", 240))
        session = vm.wait_for_login(timeout=timeout)
        logging.info("log into guest '%s' successfully." % vm.name)

        error_context.context("Try to ping external host.", logging.info)
        extra_host_ip = utils_net.get_host_ip_address(params)
        session.cmd('ping %s -c 5' % extra_host_ip)
        logging.info("Ping host(%s) successfully." % extra_host_ip)

        session.close()
        vm.destroy(gracefully=True)
        start_pos = next_pos
开发者ID:ldoktor,项目名称:tp-qemu,代码行数:44,代码来源:slof_memory.py

示例7: gen_rv_file

def gen_rv_file(params, guest_vm, host_subj=None, cacert=None):
    """
    Generates vv file for remote-viewer

    :param params:          all parameters of the test
    :param guest_vm:        object of a guest VM
    :param host_subj:    subject of the host
    :param cacert:          location of certificate of host
    """
    full_screen = params.get("full_screen")
    proxy = params.get("spice_proxy")

    rv_file = open('rv_file.vv', 'w')
    rv_file.write("[virt-viewer]\n" +
                  "type=%s\n" % params.get("display") +
                  "host=%s\n" % utils_net.get_host_ip_address(params) +
                  "port=%s\n" % guest_vm.get_spice_var("spice_port"))

    ticket = params.get("spice_password", None)
    ticket_send = params.get("spice_password_send", None)
    qemu_ticket = params.get("qemu_password", None)
    if ticket_send:
        ticket = ticket_send
    if qemu_ticket:
        ticket = qemu_ticket
    if ticket:
        rv_file.write("password=%s\n" % ticket)

    if guest_vm.get_spice_var("spice_ssl") == "yes":
        rv_file.write("tls-port=%s\n" %
                      guest_vm.get_spice_var("spice_tls_port"))
        rv_file.write("tls-ciphers=DEFAULT\n")
    if host_subj:
        rv_file.write("host-subject=%s\n" % host_subj)
    if cacert:
        cert = open(cacert)
        ca = cert.read()
        ca = ca.replace('\n', r'\n')
        rv_file.write("ca=%s\n" % ca)
    if full_screen == "yes":
        rv_file.write("fullscreen=1\n")
    if proxy:
        rv_file.write("proxy=%s\n" % proxy)
开发者ID:Andrei-Stepanov,项目名称:virt-test,代码行数:43,代码来源:utils_spice.py

示例8: run

def run(test, params, env):
    """
    Test steps:

    1) Check the environment and get the params from params.
    2) while(loop_time < timeout):
            ttcp command.
    3) clean up.
    """
    # Find the ttcp command.
    try:
        os_dep.command("ttcp")
    except ValueError:
        raise error.TestNAError("Not find ttcp command on host.")
    # Get VM.
    vm = env.get_vm(params.get("main_vm", "virt-tests-vm1"))
    session = vm.wait_for_login()
    status, _ = session.cmd_status_output("which ttcp")
    if status:
        raise error.TestNAError("Not find ttcp command on guest.")
    # Get parameters from params.
    timeout = int(params.get("LB_ttcp_timeout", "600"))
    ttcp_server_command = params.get("LB_ttcp_server_command",
                                     "ttcp -s -r -v -D -p5015 &")
    ttcp_client_command = params.get("LB_ttcp_client_command",
                                     "ttcp -s -t -v -D -p5015 -b65536 -l65536 -n1000 -f K")

    try:
        current_time = int(time.time())
        end_time = current_time + timeout
        # Start the loop from current_time to end_time.
        while current_time < end_time:
            utils.run(ttcp_server_command)
            status, output = session.cmd_status_output("%s %s" %
                                                       (ttcp_client_command,
                                                        utils_net.get_host_ip_address(params)))
            if status:
                raise error.TestFail("Failed to run ttcp command on guest.\n"
                                     "Detail: %s." % output)
            current_time = int(time.time())
    finally:
        # Clean up.
        logging.debug("No clean up operation for this test.")
开发者ID:FengYang,项目名称:tp-libvirt,代码行数:43,代码来源:libvirt_bench_ttcp_from_guest_to_host.py

示例9: run

def run(test, params, env):
    """
    Verify SLOF info when LUN ID greater than 255.

    Step:
     1. Boot a guest with scsi system disk which lun=0
     2. Check no any errors from output of slof.
     3. Could login guest.
     4. Could ping external host ip.
     5. Shutdown guest.
     6. Change the lun id of scsi disk greater than 255(e.g 300).
     7. Boot this guest again.
     8. Repeat to do step 2 ~ 4.

    :param test: Qemu test object.
    :param params: Dictionary with the test parameters.
    :param env: Dictionary with test environment.
    """
    params['start_vm'] = 'yes'
    start_pos = 0
    for params['drive_lun_image1'] in params['lun_ids'].split():
        env_process.preprocess_vm(test, params, env, params["main_vm"])
        vm = env.get_vm(params["main_vm"])
        vm.verify_alive()
        content, next_pos = slof.wait_for_loaded(vm, test, start_pos)

        error_context.context("Check the output of SLOF.", logging.info)
        slof.check_error(test, content)

        error_context.context("Try to log into guest '%s'." % vm.name,
                              logging.info)
        timeout = float(params.get("login_timeout", 240))
        session = vm.wait_for_login(timeout=timeout)
        logging.info("log into guest '%s' successfully." % vm.name)

        error_context.context("Try to ping external host.", logging.info)
        extra_host_ip = utils_net.get_host_ip_address(params)
        session.cmd('ping %s -c 5' % extra_host_ip)
        logging.info("Ping host(%s) successfully." % extra_host_ip)
        session.close()
        vm.destroy(gracefully=True)
        start_pos = next_pos
开发者ID:ldoktor,项目名称:tp-qemu,代码行数:42,代码来源:slof_greater_lun_id.py

示例10: launch_rv

def launch_rv(client_vm, guest_vm, params):
    """
    Launches rv_binary with args based on spice configuration
    inside client_session on background.
    remote-viewer will try to connect from vm1 from vm2

    @param client_vm - vm object
    @param guest_vm - vm object
    @param params
    """
    rv_binary = params.get("rv_binary", "remote-viewer")
    host_ip = utils_net.get_host_ip_address(params)
    if guest_vm.get_spice_var("listening_addr") == "ipv6":
        host_ip = "[" + utils_misc.convert_ipv4_to_ipv6(host_ip) + "]"
    check_spice_info = params.get("spice_info")
    ssltype = params.get("ssltype")
    test_type = params.get("test_type")
    host_port = None
    full_screen = params.get("full_screen")
    disable_audio = params.get("disable_audio", "no")
    display = params.get("display")
    ticket = None
    ticket_send = params.get("spice_password_send")
    qemu_ticket = params.get("qemu_password")
    gencerts = params.get("gencerts")
    certdb = params.get("certdb")
    smartcard = params.get("smartcard")
    menu = params.get("rv_menu", None)
    #cmd var keeps final remote-viewer command line to be executed on client
    cmd = rv_binary + " --display=:0.0"

    #If qemu_ticket is set, set the password of the VM using the qemu-monitor
    if qemu_ticket:
        guest_vm.monitor.cmd("set_password spice %s" % qemu_ticket)
        logging.info("Sending to qemu monitor: set_password spice %s"
                     % qemu_ticket)

    client_session = client_vm.wait_for_login(
            timeout=int(params.get("login_timeout", 360)))

    if display == "spice":
        ticket = guest_vm.get_spice_var("spice_password")

        if guest_vm.get_spice_var("spice_ssl") == "yes":
            host_tls_port = guest_vm.get_spice_var("spice_tls_port")
            host_port = guest_vm.get_spice_var("spice_port")
            cacert = "%s/%s" % (guest_vm.get_spice_var("spice_x509_prefix"),
                               guest_vm.get_spice_var("spice_x509_cacert_file"))
            #cacert subj is in format for create certificate(with '/' delimiter)
            #remote-viewer needs ',' delimiter. And also is needed to remove
            #first character (it's '/')
            host_subj = guest_vm.get_spice_var("spice_x509_server_subj")
            host_subj = host_subj.replace('/', ',')[1:]
            if ssltype == "invalid_explicit_hs":
                host_subj = "Invalid Explicit HS"
            else:
                host_subj += host_ip

            # If it's invalid implicit, a remote-viewer connection
            # will be attempted with the hostname, since ssl certs were
            # generated with the ip address
            hostname = socket.gethostname()
            if ssltype == "invalid_implicit_hs":
                spice_url = " spice://%s?tls-port=%s\&port=%s" % (hostname,
                                              host_tls_port, host_port)
            else:
                spice_url = " spice://%s?tls-port=%s\&port=%s" % (host_ip,
                                              host_tls_port, host_port)

            if menu == "yes":
                line = spice_url
            else:
                cmd += spice_url

            cmd += " --spice-ca-file=%s" % cacert

            if params.get("spice_client_host_subject") == "yes":
                cmd += " --spice-host-subject=\"%s\"" % host_subj

            #client needs cacert file
            client_session.cmd("rm -rf %s && mkdir -p %s" % (
                               guest_vm.get_spice_var("spice_x509_prefix"),
                               guest_vm.get_spice_var("spice_x509_prefix")))
            remote.copy_files_to(client_vm.get_address(), 'scp',
                                      params.get("username"),
                                      params.get("password"),
                                      params.get("shell_port"),
                                      cacert, cacert)
        else:
            host_port = guest_vm.get_spice_var("spice_port")
            if menu == "yes":
                #line to be sent through monitor once r-v is started
                #without spice url
                line = "spice://%s?port=%s" % (host_ip, host_port)
            else:
                cmd += " spice://%s?port=%s" % (host_ip, host_port)

    elif display == "vnc":
        raise NotImplementedError("remote-viewer vnc")

#.........这里部分代码省略.........
开发者ID:LeiCui,项目名称:virt-test,代码行数:101,代码来源:rv_connect.py

示例11: run

def run(test, params, env):
    """
    QEMU flow caches stress test test

    1) Make sure nf_conntrack is disabled in host and guest.
       If nf_conntrack is enabled in host, skip this case.
    2) Boot guest with vhost=on/off.
    3) Enable multi queues support in guest (optional).
    4) After installation of netperf, run netserver in host.
    5) Run netperf TCP_CRR protocal test in guest.
    6) Transfer file between guest and host.
    7) Check the md5 of copied file.

    This is a sample QEMU test, so people can get used to some of the test APIs.

    :param test: QEMU test object.
    :param params: Dictionary with the test parameters.
    :param env: Dictionary with test environment.
    """
    msg = "Make sure nf_conntrack is disabled in host and guest."
    error_context.context(msg, logging.info)
    if "nf_conntrack" in process.system_output("lsmod"):
        err = "nf_conntrack load in host, skip this case"
        test.cancel(err)

    params["start_vm"] = "yes"
    error_context.context("Boot up guest", logging.info)
    env_process.preprocess_vm(test, params, env, params["main_vm"])
    vm = env.get_vm(params["main_vm"])
    vm.verify_alive()

    timeout = int(params.get("login_timeout", 360))
    session = vm.wait_for_login(timeout=timeout)
    if "nf_conntrack" in session.cmd_output("lsmod"):
        msg = "Unload nf_conntrack module in guest."
        error_context.context(msg, logging.info)
        black_str = "#disable nf_conntrack\\nblacklist nf_conntrack\\n" \
                    "blacklist nf_conntrack_ipv6\\nblacklist xt_conntrack\\n" \
                    "blacklist nf_conntrack_ftp\\nblacklist xt_state\\n" \
                    "blacklist iptable_nat\\nblacklist ipt_REDIRECT\\n" \
                    "blacklist nf_nat\\nblacklist nf_conntrack_ipv4"
        cmd = "echo -e '%s' >> /etc/modprobe.d/blacklist.conf" % black_str
        session.cmd(cmd)
        session = vm.reboot(session, timeout=timeout)
        if "nf_conntrack" in session.cmd_output("lsmod"):
            err = "Fail to unload nf_conntrack module in guest."
            test.error(err)

    netperf_link = utils_misc.get_path(data_dir.get_deps_dir("netperf"),
                                       params["netperf_link"])
    md5sum = params.get("pkg_md5sum")
    win_netperf_link = params.get("win_netperf_link")
    if win_netperf_link:
        win_netperf_link = utils_misc.get_path(data_dir.get_deps_dir("netperf"),
                                               win_netperf_link)
    win_netperf_md5sum = params.get("win_netperf_md5sum")
    server_path = params.get("server_path", "/var/tmp/")
    client_path = params.get("client_path", "/var/tmp/")
    win_netperf_path = params.get("win_netperf_path", "c:\\")
    client_num = params.get("netperf_client_num", 520)
    netperf_timeout = int(params.get("netperf_timeout", 600))
    netperf_client_ip = vm.get_address()
    host_ip = utils_net.get_host_ip_address(params)
    netperf_server_ip = params.get("netperf_server_ip", host_ip)

    username = params.get("username", "root")
    password = params.get("password", "123456")
    passwd = params.get("hostpasswd", "123456")
    client = params.get("shell_client", "ssh")
    port = params.get("shell_port", "22")
    prompt = params.get("shell_prompt", r"^[email protected]*[\#\$]\s*$|#")
    linesep = params.get(
        "shell_linesep", "\n").encode().decode('unicode_escape')
    status_test_command = params.get("status_test_command", "echo $?")

    compile_option_client = params.get("compile_option_client", "")
    compile_option_server = params.get("compile_option_server", "")

    if int(params.get("queues", 1)) > 1 and params.get("os_type") == "linux":
        error_context.context("Enable multi queues support in guest.",
                              logging.info)
        guest_mac = vm.get_mac_address()
        ifname = utils_net.get_linux_ifname(session, guest_mac)
        cmd = "ethtool -L %s combined  %s" % (ifname, params.get("queues"))
        status, out = session.cmd_status_output(cmd)
        msg = "Fail to enable multi queues support in guest."
        msg += "Command %s fail output: %s" % (cmd, out)
        test.error(msg)

    if params.get("os_type") == "linux":
        session.cmd("iptables -F", ignore_all_errors=True)
        g_client_link = netperf_link
        g_client_path = client_path
        g_md5sum = md5sum
    elif params.get("os_type") == "windows":
        g_client_link = win_netperf_link
        g_client_path = win_netperf_path
        g_md5sum = win_netperf_md5sum

    error_context.context("Setup netperf in guest and host", logging.info)
#.........这里部分代码省略.........
开发者ID:bssrikanth,项目名称:tp-qemu,代码行数:101,代码来源:flow_caches_stress_test.py

示例12: run

def run(test, params, env):
    """
    Test hotplug of NIC devices

    1) Boot up guest with one or multi nics
    2) Add multi host network devices through monitor cmd and
       check if they are added
    3) Add multi nic devices through monitor cmd and check if they are added
    4) Check if new interface gets ip address
    5) Disable primary link of guest
    6) Ping guest new ip from host
    7) Delete nic device and netdev if user config "do_random_unhotplug"
    8) Ping guest's new ip address after guest pause/resume
    9) Re-enable primary link of guest and hotunplug the plug nics

    BEWARE OF THE NETWORK BRIDGE DEVICE USED FOR THIS TEST ("nettype=bridge"
    and "netdst=<bridgename>" param).  The virt-test default bridge virbr0,
    leveraging libvirt, works fine for the purpose of this test. When using
    other bridges, the timeouts which usually happen when the bridge
    topology changes (that is, devices get added and removed) may cause random
    failures.

    :param test:   QEMU test object.
    :param params: Dictionary with the test parameters.
    :param env:    Dictionary with test environment.
    """
    def renew_ip_address(session, mac, is_linux_guest=True):
        if not is_linux_guest:
            utils_net.restart_windows_guest_network_by_key(session,
                                                           "macaddress",
                                                           mac)
            return None
        ifname = utils_net.get_linux_ifname(session, mac)
        p_cfg = "/etc/sysconfig/network-scripts/ifcfg-%s" % ifname
        cfg_con = "DEVICE=%s\nBOOTPROTO=dhcp\nONBOOT=yes" % ifname
        make_conf = "test -f %s || echo '%s' > %s" % (p_cfg, cfg_con, p_cfg)
        arp_clean = "arp -n|awk '/^[1-9]/{print \"arp -d \" $1}'|sh"
        session.cmd_output_safe(make_conf)
        session.cmd_output_safe("ifconfig %s up" % ifname)
        session.cmd_output_safe("dhclient -r", timeout=240)
        session.cmd_output_safe("dhclient %s" % ifname, timeout=240)
        session.cmd_output_safe(arp_clean)
        return None

    def get_hotplug_nic_ip(vm, nic, session, is_linux_guest=True):
        def __get_address():
            try:
                index = [
                    _idx for _idx, _nic in enumerate(
                        vm.virtnet) if _nic == nic][0]
                return vm.wait_for_get_address(index, timeout=90)
            except IndexError:
                raise error.TestError(
                    "Nic '%s' not exists in VM '%s'" %
                    (nic["nic_name"], vm.name))
            except (virt_vm.VMIPAddressMissingError,
                    virt_vm.VMAddressVerificationError):
                renew_ip_address(session, nic["mac"], is_linux_guest)
            return

        nic_ip = utils_misc.wait_for(__get_address, timeout=360)
        if nic_ip:
            return nic_ip
        cached_ip = vm.address_cache.get(nic["mac"])
        arps = utils.system_output("arp -aen")
        logging.debug("Can't get IP address:")
        logging.debug("\tCached IP: %s" % cached_ip)
        logging.debug("\tARP table: %s" % arps)
        return None

    def ping_hotplug_nic(ip, mac, session, is_linux_guest):
        status, output = utils_test.ping(ip, 10, timeout=30)
        if status != 0:
            if not is_linux_guest:
                return status, output
            ifname = utils_net.get_linux_ifname(session, mac)
            add_route_cmd = "route add %s dev %s" % (ip, ifname)
            del_route_cmd = "route del %s dev %s" % (ip, ifname)
            logging.warn("Failed to ping %s from host.")
            logging.info("Add route and try again")
            session.cmd_output_safe(add_route_cmd)
            status, output = utils_test.ping(hotnic_ip, 10, timeout=30)
            logging.info("Del the route.")
            status, output = session.cmd_output_safe(del_route_cmd)
        return status, output

    login_timeout = int(params.get("login_timeout", 360))
    vm = env.get_vm(params["main_vm"])
    vm.verify_alive()
    primary_nic = [nic for nic in vm.virtnet]
    guest_is_linux = ("linux" == params.get("os_type", ""))
    host_ip_addr = utils_net.get_host_ip_address(params)
    if guest_is_linux:
        # Modprobe the module if specified in config file
        module = params.get("modprobe_module")
        if module:
            s_session = vm.wait_for_serial_login(timeout=login_timeout)
            s_session.cmd_output_safe("modprobe %s" % module)
            s_session.close()
    nic_hotplug_count = int(params.get("nic_hotplug_count", 1))
#.........这里部分代码省略.........
开发者ID:EIChaoYang,项目名称:tp-qemu,代码行数:101,代码来源:nic_hotplug.py

示例13: run

def run(test, params, env):
    """
    Test Steps:

    1. boot up guest with sndbuf=1048576 or other value.
    2. Transfer file between host and guest.
    3. Run netperf between host and guest.
    4. During netperf testing, from an external host ping the host whitch
       booting the guest.

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

    dst_ses = None
    try:
        error.context("Transfer file between host and guest", logging.info)
        utils_test.run_file_transfer(test, params, env)

        dsthost = params.get("dsthost")
        login_timeout = int(params.get("login_timeout", 360))
        if dsthost:
            params_host = params.object_params("dsthost")
            dst_ses = remote.wait_for_login(params_host.get("shell_client"),
                                            dsthost,
                                            params_host.get("shell_port"),
                                            params_host.get("username"),
                                            params_host.get("password"),
                                            params_host.get("shell_prompt"),
                                            timeout=login_timeout)
        else:
            vm = env.get_vm(params["main_vm"])
            vm.verify_alive()
            dst_ses = vm.wait_for_login(timeout=login_timeout)
            dsthost = vm.get_address()

        bg_stress_test = params.get("background_stress_test", 'netperf_stress')
        error.context("Run subtest %s between host and guest." % bg_stress_test,
                      logging.info)
        s_thread = ""
        wait_time = float(params.get("wait_bg_time", 60))
        bg_stress_run_flag = params.get("bg_stress_run_flag")
        env[bg_stress_run_flag] = False
        stress_thread = utils.InterruptedThread(
            utils_test.run_virt_sub_test, (test, params, env),
            {"sub_type": bg_stress_test})
        stress_thread.start()
        if not utils_misc.wait_for(lambda: env.get(bg_stress_run_flag),
                                   wait_time, 0, 1,
                                   "Wait %s test start" % bg_stress_test):
            err = "Fail to start netperf test between guest and host"
            raise error.TestError(err)

        ping_timeout = int(params.get("ping_timeout", 60))
        host_ip = utils_net.get_host_ip_address(params)
        txt = "Ping %s from %s during netperf testing" % (host_ip, dsthost)
        error.context(txt, logging.info)
        status, output = utils_test.ping(host_ip, session=dst_ses,
                                         timeout=ping_timeout)
        if status != 0:
            raise error.TestFail("Ping returns non-zero value %s" % output)

        package_lost = utils_test.get_loss_ratio(output)
        package_lost_ratio = float(params.get("package_lost_ratio", 5))
        txt = "%s%% packeage lost when ping %s from %s." % (package_lost,
                                                            host_ip,
                                                            dsthost)
        if package_lost > package_lost_ratio:
            raise error.TestFail(txt)
        logging.info(txt)

    finally:
        try:
            stress_thread.join(60)
        except Exception:
            pass
        if dst_ses:
            dst_ses.close()
开发者ID:CongLi,项目名称:tp-qemu,代码行数:80,代码来源:virtual_nic_send_buffer.py

示例14: launch_rv

def launch_rv(client_vm, guest_vm, params):
    """
    Launches rv_binary with args based on spice configuration
    inside client_session on background.
    remote-viewer will try to connect from vm1 from vm2

    :param client_vm - vm object
    :param guest_vm - vm object
    :param params
    """
    rv_binary = params.get("rv_binary", "remote-viewer")
    rv_ld_library_path = params.get("rv_ld_library_path")
    display = params.get("display")

    proxy = params.get("spice_proxy", None)
    if proxy:
        try:
            socket.inet_aton(params.get("proxy_ip", None))
        except socket.error:
            raise error.TestNAError("Parameter proxy_ip not changed from default values")

    host_ip = utils_net.get_host_ip_address(params)
    host_port = None
    if guest_vm.get_spice_var("listening_addr") == "ipv6":
        host_ip = "[" + utils_misc.convert_ipv4_to_ipv6(host_ip) + "]"
    host_tls_port = None

    disable_audio = params.get("disable_audio", "no")
    full_screen = params.get("full_screen")

    check_spice_info = params.get("spice_info")
    ssltype = params.get("ssltype")
    test_type = params.get("test_type")

    # cmd var keeps final remote-viewer command line
    # to be executed on client
    cmd = rv_binary
    if client_vm.params.get("os_type") != "windows":
        cmd = cmd + " --display=:0.0"

    # If qemu_ticket is set, set the password
    #  of the VM using the qemu-monitor
    ticket = None
    ticket_send = params.get("spice_password_send")
    qemu_ticket = params.get("qemu_password")
    if qemu_ticket:
        guest_vm.monitor.cmd("set_password spice %s" % qemu_ticket)
        logging.info("Sending to qemu monitor: set_password spice %s" % qemu_ticket)

    gencerts = params.get("gencerts")
    certdb = params.get("certdb")
    smartcard = params.get("smartcard")
    host_subj = None
    cacert = None

    rv_parameters_from = params.get("rv_parameters_from", "cmd")
    if rv_parameters_from == "file":
        cmd += " ~/rv_file.vv"

    client_session = client_vm.wait_for_login(timeout=int(params.get("login_timeout", 360)))

    if display == "spice":

        ticket = guest_vm.get_spice_var("spice_password")

        if guest_vm.get_spice_var("spice_ssl") == "yes":

            # client needs cacert file
            cacert = "%s/%s" % (
                guest_vm.get_spice_var("spice_x509_prefix"),
                guest_vm.get_spice_var("spice_x509_cacert_file"),
            )
            client_session.cmd(
                "rm -rf %s && mkdir -p %s"
                % (guest_vm.get_spice_var("spice_x509_prefix"), guest_vm.get_spice_var("spice_x509_prefix"))
            )
            remote.copy_files_to(
                client_vm.get_address(),
                "scp",
                params.get("username"),
                params.get("password"),
                params.get("shell_port"),
                cacert,
                cacert,
            )

            host_tls_port = guest_vm.get_spice_var("spice_tls_port")
            host_port = guest_vm.get_spice_var("spice_port")

            # cacert subj is in format for create certificate(with '/' delimiter)
            # remote-viewer needs ',' delimiter. And also is needed to remove
            # first character (it's '/')
            host_subj = guest_vm.get_spice_var("spice_x509_server_subj")
            host_subj = host_subj.replace("/", ",")[1:]
            if ssltype == "invalid_explicit_hs":
                host_subj = "Invalid Explicit HS"
            else:
                host_subj += host_ip

            # If it's invalid implicit, a remote-viewer connection
#.........这里部分代码省略.........
开发者ID:MiriamDeng,项目名称:tp-qemu,代码行数:101,代码来源:rv_connect.py

示例15: setup_service

        br_name = params.get("priv_brname", 'autotest-prbr0')

    for setup_target in params.get("setup_targets", "").split():
        setup_service(setup_target)

    access_targets = params.get("access_targets", "localhost").split()
    deny_target = params.get("deny_target", "localhost")
    all_target = params.get("extra_target", "").split() + vms_tags
    target_port = params["target_port"]
    vm = env.get_vm(vms_tags[0])
    nic = vm.virtnet[0]
    if_name = nic.ifname
    params_nic = params.object_params("nic1")
    if params["netdst"] == "private":
        params_nic["netdst"] = params_nic.get("priv_brname", "atbr0")
    host_ip = utils_net.get_host_ip_address(params_nic)
    if deny_target in vms_tags:
        deny_vm = env.get_vm(deny_target)
        deny_vm_ip = deny_vm.wait_for_get_address(0)
    elif deny_target == "localhost":
        deny_vm_ip = host_ip
    if "NW_DST" in acl_extra_options:
        acl_extra_options = re.sub("NW_DST", deny_vm_ip, acl_extra_options)
    acl_extra_options = re.sub("TARGET_PORT", target_port, acl_extra_options)

    access_sys = {}
    for target in all_target:
        if target not in access_targets:
            if target in vms_tags:
                os_type = params["os_type"]
            else:
开发者ID:CongLi,项目名称:tp-qemu,代码行数:31,代码来源:openflow_acl_test.py


注:本文中的virttest.utils_net.get_host_ip_address函数示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。