本文整理汇总了Python中virttest.utils_test.get_loss_ratio函数的典型用法代码示例。如果您正苦于以下问题:Python get_loss_ratio函数的具体用法?Python get_loss_ratio怎么用?Python get_loss_ratio使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。
在下文中一共展示了get_loss_ratio函数的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: ping
def ping(test, os_type, match_error, dest, count, session, same_vlan):
"""
In 'session' ping 'dest'.
If the two guests are in the same vlan, loss ratio should be 0%.
Otherwise, loss ratio should be 100%.
:param test: QEMU test object
:param dest: dest ip address
:param count: ping count
:param session: in which guest to do ping test
:param same_vlan: whether the two guests are in the same vlan
"""
if os_type == "linux":
status, output = utils_test.ping(dest, count,
timeout=int(count) * 1.50,
session=session)
loss_ratio = utils_test.get_loss_ratio(output)
ping_result_check(test, loss_ratio, same_vlan)
logging.debug("%s" % output)
elif os_type == "windows": # TODO, not supported by now
status, output = utils_test.ping(dest, count, timeout=60,
session=session)
if match_error in str(output):
ratio = 100
else:
loss_ratio = utils_test.get_loss_ratio(output)
ping_result_check(test, loss_ratio, same_vlan)
示例2: set_link_test
def set_link_test(linkid):
"""
Issue set_link commands and test its function
@param linkid: id of netdev or devices to be tested
"""
ip = vm.get_address(0)
error.context("Disable guest link by set_link", logging.info)
vm.set_link(linkid, up=False)
error.context("Ping guest from host", logging.info)
s, o = utils_test.ping(ip, count=10, timeout=20)
if utils_test.get_loss_ratio(o) != 100:
raise error.TestFail("Still can ping the %s after down %s" %
(ip, linkid))
error.context("Re-enable guest link by set_link", logging.info)
vm.set_link(linkid, up=True)
# Waiting for guest network up again.
session = vm.wait_for_login(timeout=timeout)
session.close()
error.context("Ping guest from host", logging.info)
s, o = utils_test.ping(ip, count=10, timeout=20)
# we use 100% here as the notification of link status changed may be
# delayed in guest driver
if utils_test.get_loss_ratio(o) == 100:
raise error.TestFail("Packet loss during ping %s after up %s" %
(ip, linkid))
示例3: ping
def ping(session, nic, dst_ip, strick_check, flood_minutes):
d_packet_size = [1, 4, 48, 512, 1440, 1500, 1505, 4054, 4055, 4096, 4192, 8878, 9000, 32767, 65507]
packet_size = params.get("packet_size", "").split() or d_packet_size
for size in packet_size:
error.context("Ping with packet size %s" % size, logging.info)
status, output = utils_test.ping(dst_ip, 10, interface=nic, packetsize=size, timeout=30, session=session)
if strict_check:
ratio = utils_test.get_loss_ratio(output)
if ratio != 0:
raise error.TestFail("Loss ratio is %s for packet size" " %s" % (ratio, size))
else:
if status != 0:
raise error.TestFail("Ping returns non-zero value %s" % output)
error.context("Flood ping test", logging.info)
utils_test.ping(
dst_ip, None, interface=nic, flood=True, output_func=None, timeout=flood_minutes * 60, session=session
)
error.context("Final ping test", logging.info)
counts = params.get("ping_counts", 100)
status, output = utils_test.ping(dst_ip, counts, interface=nic, timeout=float(counts) * 1.5, session=session)
if strick_check == "yes":
ratio = utils_test.get_loss_ratio(output)
if ratio != 0:
raise error.TestFail("Packet loss ratio is %s after flood" % ratio)
else:
if status != 0:
raise error.TestFail("Ping returns non-zero value %s" % output)
示例4: guest_netwok_connecting_check
def guest_netwok_connecting_check(guest_ip, link_up, change_queues=False):
"""
Check whether guest network is connective by ping
"""
if link_up:
vm.wait_for_login()
guest_ip = vm.get_address()
if change_queues:
env["run_change_queues"] = False
bg_thread = utils.InterruptedThread(change_queues_number_repeatly,
(guest_ifname,))
bg_thread.start()
utils_misc.wait_for(lambda: env["run_change_queues"], 30, 0, 2,
"wait queues change start")
_, output = utils_test.ping(guest_ip, count=10, timeout=20)
if not link_up and utils_test.get_loss_ratio(output) != 100:
err_msg = "guest network still connecting after down the link"
raise error.TestFail(err_msg)
elif link_up and utils_test.get_loss_ratio(output) == 100:
err_msg = "All packets lost during ping guest ip after link up"
raise error.TestFail(err_msg)
else:
logging.info("Guest network connecting is exactly as expected")
if change_queues:
env["run_change_queues"] = False
bg_thread.join()
示例5: guest_netwok_connecting_check
def guest_netwok_connecting_check(guest_ip, link_up, change_queues=False):
"""
Check whether guest network is connective by ping
"""
if change_queues:
env["run_change_queues"] = False
bg_thread = utils_misc.InterruptedThread(
change_queues_number_repeatly, (guest_ifname,))
bg_thread.start()
utils_misc.wait_for(lambda: env["run_change_queues"], 30, 0, 2,
"wait queues change start")
time.sleep(0.5)
output = utils_test.ping(guest_ip, 10, interface=host_interface,
timeout=20, session=None)[1]
if not link_up and utils_test.get_loss_ratio(output) < 80:
err_msg = "guest network still connecting after down the link"
test.fail(err_msg)
elif link_up and utils_test.get_loss_ratio(output) > 20:
err_msg = "All packets lost during ping guest ip after link up"
test.fail(err_msg)
if change_queues:
env["run_change_queues"] = False
bg_thread.join()
示例6: run
def run(test, params, env):
"""
Boot guest with iommu_platform, then do ping test
1) Boot a VM with iommu_platform=on
2) add intel_iommu=on in guest kernel line
3) reboot guest
4) do ping test
:param test: QEMU test object.
:param params: Dictionary with the test parameters.
:param env: Dictionary with test environment.
"""
if utils_misc.get_cpu_vendor(verbose=False) != 'GenuineIntel':
test.cancel("This case only support Intel platform")
login_timeout = int(params.get("login_timeout", 360))
vm = env.get_vm(params["main_vm"])
vm.verify_alive()
session = vm.wait_for_login(timeout=login_timeout)
ping_count = int(params.get("ping_count", 10))
guest_ip = vm.get_address()
try:
status, output = utils_test.ping(guest_ip, ping_count,
timeout=float(ping_count) * 1.5)
if status != 0:
test.fail("Ping returns non-zero value %s" % output)
package_lost = utils_test.get_loss_ratio(output)
if package_lost != 0:
test.fail("%s packeage lost when ping guest ip %s " %
(package_lost, guest_ip))
finally:
session.close()
示例7: guest_netwok_connecting_check
def guest_netwok_connecting_check(guest_ip, link_up):
"""
Check whether guest network is connective by ping
"""
if link_up:
vm.wait_for_login()
guest_ip = vm.get_address()
s, o = utils_test.ping(guest_ip, count=10, timeout=20)
if not link_up and utils_test.get_loss_ratio(o) != 100:
err_msg = "guest network still connecting after down the link"
raise error.TestFail(err_msg)
elif link_up and utils_test.get_loss_ratio(o) == 100:
err_msg = "All packets lost during ping guest ip after link up"
raise error.TestFail(err_msg)
else:
logging.info("Guest network connecting is exactly as expected")
示例8: large_frame_ping
def large_frame_ping(count=100):
logging.info("Large frame ping")
_, output = utils_test.ping(guest_ip, count,
packetsize=max_icmp_pkt_size,
timeout=float(count) * 2)
ratio = utils_test.get_loss_ratio(output)
if ratio != 0:
test.fail("Loss ratio of large frame ping is %s" % ratio)
示例9: ping_test
def ping_test(dest_ip, ping_time, lost_raito, session=None):
status, output = utils_test.ping(dest=dest_ip, timeout=ping_time,
session=session)
packets_lost = utils_test.get_loss_ratio(output)
if packets_lost > lost_raito:
err = " %s%% packages lost during ping. " % packets_lost
err += "Ping command log:\n %s" % "\n".join(output.splitlines()[-3:])
raise error.TestFail(err)
示例10: verify_mtu
def verify_mtu():
logging.info("Verify the path MTU")
s, o = utils_test.ping(ip, 10, interface=ifname, packetsize=max_icmp_pkt_size, hint="do", timeout=15)
if s != 0:
logging.error(o)
raise error.TestFail("Path MTU is not as expected")
if utils_test.get_loss_ratio(o) != 0:
logging.error(o)
raise error.TestFail("Packet loss ratio during MTU " "verification is not zero")
示例11: launch_client
def launch_client(sessions, servers, server_ctl, clients,
l, nf_args, port, params):
"""
Launch netperf clients
"""
# Start netserver
error.context("Start Netserver on guest", logging.info)
remote_dir = params.get("remote_dir", "/var/tmp")
client_path = os.path.join(remote_dir, "netperf-2.6.0/src/netperf")
server_path = os.path.join(remote_dir, "netperf-2.6.0/src/netserver")
if params.get("os_type") == "windows":
winutils_vol = utils_misc.get_winutils_vol(server_ctl)
client_path = "%s:\\netperf" % winutils_vol
netserv_start_cmd = params.get("netserv_start_cmd") % winutils_vol
logging.info("Netserver start cmd is '%s'" % netserv_start_cmd)
if "NETSERVER.EXE" not in server_ctl.cmd_output("tasklist"):
server_ctl.cmd_output(netserv_start_cmd)
o_tasklist = server_ctl.cmd_output("tasklist")
if "NETSERVER.EXE" not in o_tasklist.upper():
msg = "Can not start netserver in Windows guest"
raise error.TestError(msg)
else:
logging.info("Netserver start cmd is '%s'" % server_path)
ssh_cmd(server_ctl, "pidof netserver || %s" % server_path)
logging.info("Netserver start successfully")
# start netperf
error.context("Start netperf client threads", logging.info)
client_threads = []
for client in clients:
test_timeout = len(clients) * l
server = servers[clients.index(client) % len(servers)]
netperf_cmd = "%s -H %s -l %s %s" % (client_path, server,
int(l), nf_args)
client_threads.append([ssh_cmd, (client, netperf_cmd, test_timeout)])
result_info = utils_misc.parallel(client_threads)
counts = 5
for server in servers:
if not re.findall("TEST.*to %s" % server, str(result_info)):
raise error.TestError("Nerperf stress on nic %s failed" % server)
logging.info("Network stress on %s successfully" % server)
status, output = utils_test.ping(server, counts,
timeout=float(counts) * 1.5)
if status != 0:
raise error.TestFail("Ping returns non-zero value %s" % output)
package_lost = utils_test.get_loss_ratio(output)
if package_lost != 0:
raise error.TestFail("%s packeage lost when ping server ip %s " %
(package_lost, server))
示例12: large_frame_ping
def large_frame_ping(count=100):
logging.info("Large frame ping")
_, o = utils_test.ping(ip, count, interface=ifname,
packetsize=max_icmp_pkt_size,
timeout=float(count) * 2)
ratio = utils_test.get_loss_ratio(o)
if ratio != 0:
raise error.TestFail("Loss ratio of large frame ping is %s" %
ratio)
示例13: set_link_test
def set_link_test(linkid):
"""
Issue set_link commands and test its function
@param linkid: id of netdev or devices to be tested
"""
ip = vm.get_address(0)
vm.set_link(linkid, up=False)
_, o = utils_test.ping(ip, count=10, timeout=20)
if utils_test.get_loss_ratio(o) != 100:
raise error.TestFail("Still can ping the %s after down %s" %
(ip, linkid))
vm.set_link(linkid, up=True)
_, o = utils_test.ping(ip, count=10, timeout=20)
# we use 100% here as the notification of link status changed may be
# delayed in guest driver
if utils_test.get_loss_ratio(o) == 100:
raise error.TestFail("Packet loss during ping %s after up %s" %
(ip, linkid))
示例14: size_increase_ping
def size_increase_ping(step=random.randrange(90, 110)):
logging.info("Size increase ping")
for size in range(0, max_icmp_pkt_size + 1, step):
logging.info("Ping %s with size %s", ip, size)
s, o = utils_test.ping(ip, 1, interface=ifname, packetsize=size, hint="do", timeout=1)
if s != 0:
s, o = utils_test.ping(
ip, 10, interface=ifname, packetsize=size, adaptive=True, hint="do", timeout=20
)
if utils_test.get_loss_ratio(o) > int(params.get("fail_ratio", 50)):
raise error.TestFail("Ping loss ratio is greater " "than 50% for size %s" % size)
示例15: verify_mtu
def verify_mtu():
logging.info("Verify the path MTU")
status, output = utils_test.ping(guest_ip, 10,
packetsize=max_icmp_pkt_size,
hint="do", timeout=15)
if status != 0:
logging.error(output)
test.fail("Path MTU is not as expected")
if utils_test.get_loss_ratio(output) != 0:
logging.error(output)
test.fail("Packet loss ratio during MTU "
"verification is not zero")