Skip to content

Commit 95021c5

Browse files
committed
virtual_network: add case for migrating guest while netperf
xxxx-95876 - [virtual network][virtual-nic-device] Migrate guest while running netperf Signed-off-by: nanli <nanli@redhat.com>
1 parent a302a6f commit 95021c5

File tree

6 files changed

+178
-14
lines changed

6 files changed

+178
-14
lines changed
1.48 MB
Binary file not shown.

deps/netperf/netperf.exe

140 KB
Binary file not shown.
Lines changed: 45 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,45 @@
1+
- virtual_network.qemu_test.migrate_with_netperf:
2+
type = migrate_with_netperf
3+
create_vm_libvirt = "yes"
4+
kill_vm_libvirt = "yes"
5+
start_vm = "yes"
6+
take_regular_screendumps = no
7+
storage_type = 'nfs'
8+
setup_local_nfs = 'yes'
9+
disk_type = "file"
10+
disk_source_protocol = "netfs"
11+
nfs_mount_options = "soft,timeo=50,retrans=3"
12+
virsh_migratedest_state = running
13+
virsh_migrate__options = "--live --p2p --verbose"
14+
virsh_migrate_connect_uri = "qemu:///system"
15+
migration_setup = "yes"
16+
ssh_remote_auth = True
17+
mnt_path_name = ${nfs_mount_dir}
18+
nfs_server_ip = "${migrate_source_host}"
19+
migrate_desturi_port = "22"
20+
migrate_desturi_type = "ssh"
21+
migrate_speed = 15
22+
migrate_vm_back = "yes"
23+
migration_type = "precopy"
24+
virsh_migrate_extra = ""
25+
# Netperf parameters
26+
netperf_timeout = "60"
27+
netperf_client = "${migrate_dest_host}"
28+
netperf_server = "${main_vm}"
29+
test_protocol = "TCP_STREAM"
30+
netperf_iterations = 10
31+
action_during_mig = [{"func": "network_base.exec_netperf_test", "func_param": {"params": params.get('params'), "env": params.get('env')}, "iterations": ${netperf_iterations}}]
32+
os_type = "linux"
33+
firewall_cmd = "systemctl stop firewalld"
34+
netperf_ver = "netperf-2.7.1-1"
35+
netperf_source = "${netperf_ver}.tar.bz2"
36+
Windows:
37+
os_type = "windows"
38+
firewall_cmd = "netsh firewall set opmode mode=disable"
39+
netperf_source = "netperf.exe"
40+
variants:
41+
- tcp:
42+
migration_protocol = "tcp"
43+
migrate_desturi_type = "tcp"
44+
virsh_migrate_desturi = "qemu+tcp://${migrate_dest_host}/system"
45+
virsh_migrate_options = "--live --p2p --verbose"
Lines changed: 73 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,73 @@
1+
# ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
2+
#
3+
# Copyright Redhat
4+
#
5+
# SPDX-License-Identifier: GPL-2.0
6+
#
7+
# Author: Nannan Li <nanli@redhat.com>
8+
#
9+
# ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
10+
11+
from virttest.libvirt_xml.vm_xml import VMXML
12+
13+
from provider.migration import base_steps
14+
from provider.virtual_network import network_base
15+
16+
17+
def run(test, params, env):
18+
"""
19+
Test migration with netperf stress
20+
21+
:param test: test object
22+
:param params: Dictionary with the test parameters
23+
:param env: Dictionary with test environment.
24+
"""
25+
26+
def run_test():
27+
"""
28+
Test migration with netperf stress
29+
"""
30+
test.log.info("TEST_STEP 1: Guest xml is: %s\n", VMXML.new_from_dumpxml(vm_name))
31+
32+
test.log.info("TEST_STEP 2: Starting migration with netperf stress")
33+
migration_obj.setup_connection()
34+
if not vm.is_alive():
35+
vm.start()
36+
migration_obj.run_migration()
37+
38+
test.log.info("TEST_STEP 3: Testing network connectivity on destination host")
39+
backup_uri = vm.connect_uri
40+
vm.connect_uri = dest_uri
41+
42+
session = vm.wait_for_login(timeout=login_timeout)
43+
ips = {'outside_ip': outside_ip}
44+
network_base.ping_check(params, ips, session)
45+
session.close()
46+
vm.connect_uri = backup_uri
47+
48+
if migrate_vm_back:
49+
test.log.info("TEST_STEP 4: Migrating VM back to source host")
50+
migration_obj.run_migration_back()
51+
52+
def teardown_test():
53+
"""
54+
Cleanup test environment
55+
"""
56+
migration_obj.cleanup_connection()
57+
58+
vm_name = params.get("main_vm")
59+
vm = env.get_vm(vm_name)
60+
dest_uri = params.get("virsh_migrate_desturi")
61+
migrate_vm_back = params.get_boolean("migrate_vm_back", True)
62+
login_timeout = params.get_numeric("login_timeout", "240")
63+
outside_ip = params.get("outside_ip", "8.8.8.8")
64+
65+
# Add required objects to params for action_during_mig
66+
params.update({"params": params, "test": test, "env": env})
67+
68+
migration_obj = base_steps.MigrationBase(test, vm, params)
69+
70+
try:
71+
run_test()
72+
finally:
73+
teardown_test()

provider/migration/migration_base.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@
77
from avocado.core import exceptions
88
from avocado.utils import process
99

10+
from provider.virtual_network import network_base # pylint: disable=W0611
1011
from virttest import remote
1112
from virttest import virsh # pylint: disable=W0611
1213
from virttest import utils_misc # pylint: disable=W0611

provider/virtual_network/network_base.py

Lines changed: 59 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,8 @@
77
import aexpect
88
from avocado.core import exceptions
99
from avocado.utils import process
10+
11+
from virttest import data_dir
1012
from virttest import remote
1113
from virttest import utils_misc
1214
from virttest import utils_net
@@ -448,9 +450,22 @@ def exec_netperf_test(params, env):
448450
netperf_server = params.get("netperf_server")
449451
extra_cmd_opts = params.get("extra_cmd_opts", "")
450452
netperf_timeout = params.get("netperf_timeout", "60")
451-
test_protocol = params.get("test_protocol")
453+
test_protocol = params.get("test_protocol", "TCP_STREAM")
454+
os_type = params.get("os_type", "linux")
455+
456+
# Command configuration parameters
457+
firewall_cmd = params.get("firewall_cmd", "systemctl stop firewalld")
458+
restore_firewall_cmd = params.get("restore_firewall_cmd", "systemctl start firewalld")
459+
kill_netserver_cmd = params.get("kill_netserver_cmd", "killall netserver")
460+
netserver_cmd = params.get("netserver_cmd", "netserver")
461+
netperf_bin = params.get("netperf_bin", "netperf")
462+
netperf_opts = params.get("netperf_opts", "-C -c")
463+
cleanup_netserver_cmd = params.get("cleanup_netserver_cmd", "killall netserver")
464+
netperf_src = os.path.join(data_dir.get_deps_dir("netperf"), params.get("netperf_src"))
465+
netperf_ver = params.get("netperf_ver")
452466
vms = params.get('vms').split()
453467
vm_objs = {vm_i: env.get_vm(vm_i) for vm_i in vms}
468+
454469
before_test_cores = process.run("coredumpctl list", ignore_status=True, verbose=True).stdout_text
455470

456471
def _get_access_info(netperf_address):
@@ -474,20 +489,42 @@ def _get_access_info(netperf_address):
474489
s_func, s_ip, s_session = _get_access_info(netperf_server)
475490

476491
try:
477-
if not utils_package.package_install("netperf", c_session):
478-
raise exceptions.TestError("Unable to install netperf in the client host!")
479-
if not utils_package.package_install("netperf", s_session):
480-
raise exceptions.TestError("Unable to install netperf in the server host!")
481-
c_func("systemctl stop firewalld")
482-
s_func("systemctl stop firewalld")
492+
# Install netperf
493+
if os_type == "windows":
494+
if os.path.exists(netperf_src) and netperf_server in vms:
495+
vm = vm_objs.get(netperf_server)
496+
remote.copy_files_to(vm.get_address(), "scp",
497+
params.get("username"), params.get("password") , 22,
498+
netperf_src, "C:\\netperf.exe", 600)
499+
LOG.debug("Copied netperf.exe to Windows guest")
500+
else:
483501

502+
if os.path.exists(netperf_src):
503+
if c_session:
504+
c_session.cmd("cd /tmp && tar -xjf " + netperf_src + " && cd %s && make" % netperf_ver, ignore_all_errors=True)
505+
if s_session:
506+
s_session.cmd("cd /tmp && tar -xjf " + netperf_src + " && cd %s && make" % netperf_ver, ignore_all_errors=True)
507+
else:
508+
# Fallback to package manager
509+
if not utils_package.package_install("netperf", c_session):
510+
raise exceptions.TestError("Unable to install netperf in the client host!")
511+
if not utils_package.package_install("netperf", s_session):
512+
raise exceptions.TestError("Unable to install netperf in the server host!")
513+
514+
# Disable firewall
515+
c_func(firewall_cmd, ignore_status=True)
516+
s_func(firewall_cmd, ignore_status=True)
517+
518+
# Start netserver
484519
LOG.debug("Start netserver...")
485-
if s_ip == netperf_server:
486-
s_func("killall netserver", ignore_status=True)
487-
s_func("netserver")
520+
if kill_netserver_cmd:
521+
s_func(kill_netserver_cmd, ignore_status=True)
488522

523+
s_func(netserver_cmd, ignore_status=True)
524+
525+
# Run netperf client
489526
LOG.debug("Run netperf command...")
490-
test_cmd = f"netperf -H {s_ip} -l {netperf_timeout} -C -c -t {test_protocol} {extra_cmd_opts}"
527+
test_cmd = f"{netperf_bin} -H {s_ip} -l {netperf_timeout} -t {test_protocol} {netperf_opts} {extra_cmd_opts}"
491528
c_func(test_cmd, timeout=120)
492529

493530
for vm in vm_objs.values():
@@ -505,11 +542,19 @@ def _get_access_info(netperf_address):
505542

506543
finally:
507544
LOG.info("Test teardown: Cleanup env.")
508-
s_func("killall netserver")
509-
s_func("systemctl start firewalld")
510-
# TODO: Start firewalld on guest
545+
# Cleanup netserver
546+
s_func(cleanup_netserver_cmd)
547+
548+
# Restore firewall
549+
s_func(restore_firewall_cmd)
511550
process.run("systemctl start firewalld", ignore_status=True)
512551

552+
# Cleanup sessions
553+
if c_session:
554+
c_session.close()
555+
if s_session:
556+
s_session.close()
557+
513558

514559
def prepare_single_vm(params, vm_name, disk_path='', iface_list=[]):
515560
"""

0 commit comments

Comments
 (0)