未验证 提交 84283342 编写于 作者: Y Yu Yihuang 提交者: GitHub

Merge pull request #2245 from yanglei-rh/bug1839693

Windows nic teaming test
- win_nics_teaming:
virt_test_type = qemu
only Win2016 Win2019
only x86_64
no macvtap
type = win_nics_teaming
nics = "nic1 nic2 nic3 nic4"
clone_master = yes
master_images_clone = image1
remove_image_image1 =yes
filesize = 8000
dd_cmd = "dd if=/dev/zero of=%s oflag=direct bs=1M count=${filesize}"
tmp_dir = "C:\\"
delete_cmd = "del /f %s"
setup_cmd = 'powershell -command "New-NetLbfoTeam -Name \"Team\" -TeamMembers \"%s\",\"%s\",\"%s\",\"%s\""'
import logging
import time
import os
import random
import aexpect
from avocado.utils import crypto, process
from virttest import utils_net
from virttest import utils_misc
def run(test, params, env):
"""
Nic teaming test in guest.
1) Start guest with four nic devices.
2) Setup Team in guest.
3) Execute file transfer from host to guest.
4) Repeatedly set enable/disable interfaces by 'netsh interface set'
5) Execute file transfer from guest to host.
:param test: Kvm test object.
:param params: Dictionary with the test parameters.
:param env: Dictionary with test environment.
"""
tmp_dir = params["tmp_dir"]
filesize = params.get_numeric("filesize")
dd_cmd = params["dd_cmd"]
delete_cmd = params["delete_cmd"]
login_timeout = params.get_numeric("login_timeout", 1200)
vm = env.get_vm(params["main_vm"])
vm.verify_alive()
session_serial = vm.wait_for_serial_login(timeout=login_timeout)
nics = params.objects("nics")
ifnames = ()
for i in range(len(nics)):
mac = vm.get_mac_address(i)
connection_id = utils_net.get_windows_nic_attribute(session_serial,
"macaddress",
mac,
"netconnectionid")
ifnames += (connection_id,)
# get params of teaming
setup_cmd = params["setup_cmd"]
status, output = session_serial.cmd_status_output(setup_cmd % ifnames)
if status:
test.fail("Failed to setup team nic from powershell,"
"status=%s, output=%s" % (status, output))
# prepare test data
guest_path = (tmp_dir + "src-%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, shell=True)
try:
netsh_set_cmd = "netsh interface set interface \"%s\" %s"
# transfer data
original_md5 = crypto.hash_file(host_path, algorithm="md5")
logging.info("md5 value of data original: %s" % original_md5)
logging.info("Failover test with file transfer")
transfer_thread = utils_misc.InterruptedThread(
vm.copy_files_to, (host_path, guest_path))
transfer_thread.start()
try:
while transfer_thread.isAlive():
for ifname in ifnames:
session_serial.cmd(netsh_set_cmd % (ifname, "disable"))
time.sleep(random.randint(1, 30))
session_serial.cmd(netsh_set_cmd % (ifname, "enable"))
time.sleep(random.randint(1, 30))
except aexpect.ShellProcessTerminatedError:
transfer_thread.join(suppress_exception=True)
raise
else:
transfer_thread.join()
os.remove(host_path)
logging.info('Cleaning temp file on host')
logging.info("Failover test 2 with file transfer")
transfer_thread = utils_misc.InterruptedThread(
vm.copy_files_from, (guest_path, host_path))
transfer_thread.start()
try:
nic_num = len(ifnames)
index = 0
while transfer_thread.isAlive():
index = index % nic_num
for i in range(nic_num):
session_serial.cmd(netsh_set_cmd % (ifnames[i], "enable"))
for j in range(nic_num):
if i != j:
session_serial.cmd(
netsh_set_cmd % (ifnames[j], "disable"))
time.sleep(random.randint(1, 5))
index += 1
except aexpect.ShellProcessTerminatedError:
transfer_thread.join(suppress_exception=True)
raise
else:
transfer_thread.join()
current_md5 = crypto.hash_file(host_path, algorithm="md5")
logging.info("md5 value of data current: %s" % current_md5)
if original_md5 != current_md5:
test.fail("File changed after transfer host -> guest "
"and guest -> host")
finally:
os.remove(host_path)
session_serial.cmd(delete_cmd % guest_path,
timeout=login_timeout, ignore_all_errors=True)
session_serial.close()
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册