Skip to content

Commit e924cd0

Browse files
authored
Merge pull request #6518 from nanli1/add_case_for_packet_stress_test_with_user_type_iface
add case packet stress test with user type iface, combine from qemu case
2 parents 26b4054 + b18b10f commit e924cd0

File tree

4 files changed

+882
-0
lines changed

4 files changed

+882
-0
lines changed
Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
- virtual_network.qemu_test.packet_stress:
2+
type = packet_stress_test
3+
start_vm = no
4+
take_regular_screendumps = 'no'
5+
variants:
6+
- user_type_iface:
7+
iface_type = 'user'
8+
mode = 'virtio'
9+
net_mtu = 12000
10+
vm_image_paths = RHEL_IMAGE_ONLY.EXAMPLE
11+
stress_file = './../../../../../provider/virtual_network/script/packet_stress_test.c'
12+
iface_list_2 = {'type_name': 'user', 'model': 'virtio'}
Lines changed: 145 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,145 @@
1+
# ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
2+
#
3+
# Copyright Redhat
4+
#
5+
# SPDX-License-Identifier: GPL-2.0
6+
# Author: Nannan Li<[email protected]>
7+
#
8+
# ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
9+
import os
10+
import time
11+
12+
from avocado.utils import process
13+
14+
from virttest import utils_package
15+
from virttest import virsh
16+
from virttest import utils_net
17+
from virttest import utils_misc
18+
from virttest.libvirt_xml import vm_xml
19+
from virttest.utils_libvirt import libvirt_vmxml
20+
21+
from provider.virtual_network import network_base
22+
23+
virsh_opt = {"debug": True, "ignore_status": False}
24+
25+
26+
def transfer_file(vm_object, source_path):
27+
"""
28+
Transfer stress file to guest.
29+
30+
:params vm_object, vm object
31+
:params source_path, the source path that's transferred to guest.
32+
:return dest_path, destination path in guest.
33+
"""
34+
if not vm_object.is_alive():
35+
virsh.start(vm_object.name)
36+
session = vm_object.wait_for_login()
37+
38+
dest_path = "/var/%s" % os.path.basename(source_path)
39+
vm_object.copy_files_to(
40+
host_path=source_path, guest_path=dest_path)
41+
42+
def _file_exists():
43+
if not session.cmd("cat %s" % dest_path, ignore_all_errors=True):
44+
return True
45+
utils_misc.wait_for(lambda: _file_exists(), 15)
46+
47+
session.close()
48+
49+
return dest_path
50+
51+
52+
def run(test, params, env):
53+
"""
54+
Packet buffer stress test for user - only for linux.
55+
"""
56+
def setup_test():
57+
"""
58+
Prepare the test environment with required guest type and interface.
59+
60+
:return vm_list: list of vm names.
61+
"""
62+
test.log.info("TEST_SETUP: Prepare specific guest os version and interface.")
63+
vm_list = network_base.prepare_vms_with_iface(
64+
params, vm_image_path=vm_image_paths, iface_list=iface_list)
65+
66+
return vm_list
67+
68+
def run_test(vm_list):
69+
"""
70+
Set MTU value in guest interface and run stress test.
71+
"""
72+
for vm_name in vm_list:
73+
test.log.debug("TEST_STEP: Transfer stress file to guest: %s", vm_name)
74+
env.create_vm(vm_type='libvirt', target="", name=vm_name, params=params, bindir=test.bindir)
75+
vm = env.get_vm(vm_name)
76+
dest_path = transfer_file(vm, stress_file)
77+
78+
test.log.debug("TEST_STEP: Replace interface with %s type" % iface_type)
79+
session = vm.wait_for_login(timeout=360)
80+
iface_name = utils_net.get_linux_ifname(session=session)[0]
81+
iface_mac = utils_net.get_linux_mac(session, iface_name)
82+
virsh.detach_interface(vm_name, "--type %s --mac %s" % (basic_iface_type, iface_mac),
83+
flagstr='--live', **virsh_opt)
84+
85+
iface = libvirt_vmxml.create_vm_device_by_type('interface', iface_list_2)
86+
virsh.attach_device(vm.name, iface.xml, flagstr='--config', **virsh_opt)
87+
test.log.debug("Test with vm xml:%s", vm_xml.VMXML.new_from_dumpxml(vm_name))
88+
session.close()
89+
90+
test.log.debug("TEST_STEP: Set MTU value in guest: %s", vm_name)
91+
virsh.destroy(vm_name, **virsh_opt)
92+
virsh.start(vm_name, **virsh_opt)
93+
session = vm.wait_for_login(timeout=360)
94+
network_base.set_guest_iface_mtu(test, session, mtu=net_mtu)
95+
96+
test.log.debug("TEST_STEP: Compile and execute the stress script.")
97+
utils_package.package_install(["gcc"], session, 360)
98+
session.cmd("gcc %s -o %s" % (dest_path, tmp_exe_file))
99+
session.sendline("%s &" % tmp_exe_file)
100+
time.sleep(60)
101+
102+
result = process.getstatusoutput(
103+
"ps -aux|grep /usr/bin/gnome-calculator |grep -v grep",
104+
timeout=60,
105+
shell=True,
106+
)[0]
107+
if result == 0:
108+
test.fail("Virtual machine has security issues")
109+
session.send_ctrl("^c")
110+
test.log.info("send ctrl+c command to exit the current process.")
111+
112+
test.log.debug("TEST_STEP: Check guest work normally and no crash occurred.")
113+
vm.verify_kernel_crash()
114+
vm.verify_dmesg()
115+
116+
def teardown_test(vm_list):
117+
"""
118+
Clean data.
119+
"""
120+
test.log.debug("TEST_TEARDOWN: Recover the env.")
121+
if vm_list:
122+
for vm_name in vm_list:
123+
if vm_name != params.get("main_vm"):
124+
virsh.destroy(vm_name)
125+
virsh.undefine(vm_name, options='--nvram')
126+
127+
iface_type = params.get("iface_type")
128+
basic_iface_type = params.get("basic_iface_type", "network")
129+
130+
iface_list = eval(params.get('iface_list', '[]'))
131+
iface_list_2 = eval(params.get('iface_list_2', '{}'))
132+
vm_image_paths = eval(params.get('vm_image_paths', '{}'))
133+
net_mtu = params.get('net_mtu')
134+
stress_file = params.get('stress_file')
135+
stress_file = os.path.join(os.path.dirname(__file__), stress_file)
136+
tmp_exe_file = params.get("tmp_exe_file", "/tmp/test")
137+
vm_list = []
138+
139+
try:
140+
141+
vm_list = setup_test()
142+
run_test(vm_list)
143+
144+
finally:
145+
teardown_test(vm_list)

provider/virtual_network/network_base.py

Lines changed: 69 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
import logging
22
import math
3+
import os
34
import re
45
import shutil
56

@@ -11,8 +12,10 @@
1112
from virttest import utils_net
1213
from virttest import utils_package
1314
from virttest import virsh
15+
from virttest.utils_libvirt import libvirt_vmxml
1416
from virttest.libvirt_xml import network_xml
1517
from virttest.libvirt_xml import vm_xml
18+
from provider.bootc_image_builder import bootc_image_build_utils
1619

1720
VIRSH_ARGS = {'ignore_status': False, 'debug': True}
1821

@@ -457,3 +460,69 @@ def _get_access_info(netperf_address):
457460
s_func("systemctl start firewalld")
458461
# TODO: Start firewalld on guest
459462
process.run("systemctl start firewalld", ignore_status=True)
463+
464+
465+
def prepare_single_vm(params, vm_name, disk_path='', iface_list=[]):
466+
"""
467+
Prepare single vm with specified disk image and interface.
468+
469+
:params vm_name: name of the vm.
470+
:params disk_path: path of the disk image.
471+
:params iface_list: list of interface for vm.
472+
"""
473+
if vm_name not in virsh.dom_list().stdout_text:
474+
params.update(
475+
{"vm_name_bootc": vm_name,
476+
"vm_disk_image_path": disk_path,
477+
"iso_install_path": os.path.join(os.path.dirname(disk_path) + f"/{vm_name}.iso"),
478+
"firmware": "efi"
479+
})
480+
if "win" in vm_name:
481+
params.update({"disk_image_type": "anaconda-iso"})
482+
else:
483+
params.update({"disk_image_type": "qcow2"})
484+
bootc_image_build_utils.virt_install_vm(params)
485+
486+
vmxml = vm_xml.VMXML.new_from_inactive_dumpxml(vm_name)
487+
vmxml.del_device('interface', by_tag=True)
488+
if iface_list:
489+
if not isinstance(iface_list, list):
490+
iface_list = [iface_list]
491+
for index, iface_attrs in enumerate(iface_list):
492+
libvirt_vmxml.modify_vm_device(vmxml, 'interface', iface_attrs, index=index)
493+
LOG.debug(f'Test with vm xml:\n{vm_xml.VMXML.new_from_inactive_dumpxml(vm_name)}')
494+
495+
496+
def prepare_vms_with_iface(params, vm_image_path=[], iface_list=[]):
497+
"""
498+
Prepare several vms with specified disk image path and interface.
499+
500+
:params vm_image_path: list of disk image path.
501+
:params iface_list: list of interface.
502+
"""
503+
vm_list = []
504+
for image_path in vm_image_path:
505+
guest_version = os.path.basename(image_path)
506+
vm_name = "".join([re.findall("Win|RHEL", guest_version, re.IGNORECASE)[0], "_vm"])
507+
LOG.debug("TEST_LOOP: Test '%s' with guest version '%s'.", vm_name, guest_version)
508+
509+
prepare_single_vm(params, vm_name, image_path, iface_list)
510+
vm_list.append(vm_name)
511+
return vm_list
512+
513+
514+
def set_guest_iface_mtu(test, vm_session, iface_name='', mtu=1500):
515+
"""
516+
Set guest interface MTU.
517+
518+
:params vm_session: libvirt domain object session.
519+
:params iface_name: name of the interface.
520+
:params mtu: MTU value
521+
"""
522+
if not iface_name:
523+
iface_name = utils_net.get_linux_ifname(session=vm_session)[0]
524+
525+
cmd = 'sudo ifconfig {0} mtu {1} up'.format(iface_name, mtu)
526+
status, output = vm_session.cmd_status_output(cmd)
527+
if status:
528+
test.fail("Fail to set mtu on guest interface: %s." % output)

0 commit comments

Comments
 (0)