Skip to content

Commit

Permalink
passt file transfer tests via tcp/udp
Browse files Browse the repository at this point in the history
Add a new case to support passt file transfer test via tcp/udp

Signed-off-by: Lei Yang <[email protected]>
  • Loading branch information
yanglei-rh committed Sep 3, 2024
1 parent 050920b commit b0b1fda
Show file tree
Hide file tree
Showing 2 changed files with 148 additions and 0 deletions.
27 changes: 27 additions & 0 deletions qemu/tests/cfg/passt_transfer_tests.cfg
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
- passt_transfer_tests:
virt_test_type = qemu
type = passt_transfer_tests
image_snapshot = yes
vms = "avocado-vt-vm1 vm2"
tmp_dir = "/var/tmp/"
fw_stop_cmd = systemctl stop firewalld || nft flush ruleset || iptables -F
file_md5_check_timeout = 600
filesize = 4294967296
dd_cmd = "dd if=/dev/zero of=%s bs=%d count=1"
variants:
- with_tcp_ipv4:
receive_cmd = socat -u TCP-LISTEN:%d,reuseaddr OPEN:%s,create
sent_cmd = socat -u FILE:%s TCP:%s:%d
- with_udp_ipv4:
filesize = 51200
receive_cmd = socat -u UDP4-LISTEN:%d,reuseaddr OPEN:%s,create & echo $! >/tmp/socat.pid && sleep 60 && kill -9 $(cat /tmp/socat.pid)
sent_cmd = socat -u FILE:%s UDP4:%s:%d
- with_tcp_ipv6:
ipv6 = yes
receive_cmd = socat -u TCP6-LISTEN:%d,reuseaddr OPEN:%s,create
sent_cmd = socat -u FILE:%s TCP6:[%s]:%d
- with_udp_ipv6:
ipv6 = yes
filesize = 51200
receive_cmd = socat -u UDP6-LISTEN:%d,reuseaddr OPEN:%s,create & echo $! >/tmp/socat.pid && sleep 60 && kill -9 $(cat /tmp/socat.pid)
sent_cmd = socat -u FILE:%s UDP6:[%s]:%d
121 changes: 121 additions & 0 deletions qemu/tests/passt_transfer_tests.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,121 @@
import os
import time
import re

from avocado.utils import crypto, process
from virttest import utils_misc
from virttest import utils_net
from virttest import error_context


def get_file_md5sum(dest_path, param, timeout):
pass


@error_context.context_aware
def run(test, params, env):
"""
Test Step
1. boot up two virtual machine with passt device
2. For linux guest,Transfer data via tcp&udp:
host-->guest1 & host-->guest2 & guest<-->guest2
3. after data transfer, check data have no change
Params:
:param test: QEMU test object
:param params: Dictionary with the test parameters
:param env: Dictionary with test environment.
"""
def get_file_md5sum(file_name, session, timeout):
"""
Get file md5sum from guest.
"""
test.log.info("Get md5sum of the file:'%s'", file_name)
s, o = session.cmd_status_output("md5sum %s" % file_name, timeout=timeout)
if s != 0:
test.error("Get file md5sum failed as %s" % o)
return re.findall(r"\w{32}", o)[0]

timeout = int(params.get("login_timeout", '360'))
receive_cmd = params.get("receive_cmd")
sent_cmd = params.get("sent_cmd")
tmp_dir = params["tmp_dir"]
filesize = int(params.get("filesize"))
dd_cmd = params["dd_cmd"]
file_md5_check_timeout = int(params.get("file_md5_check_timeout", '600'))
fw_stop_cmd = params["fw_stop_cmd"]

sessions = {}
ifname = {}
vms = []

error_context.context("Boot vms for test", test.log.info)
for vm_name in params.get("vms", "avocado-vt-vm1 vm2").split():
vms.append(env.get_vm(vm_name))

for vm in vms:
vm.verify_alive()
sessions[vm] = vm.wait_for_serial_login(timeout=timeout)

if params.get_boolean("ipv6"):
gateway_address = utils_net.get_default_gateway(ip_ver='ipv6')
address = "::1"
ifname[vm] = utils_net.get_linux_ifname(sessions[vm],
vm.get_mac_address())
gateway = f"{gateway_address}%{ifname[vm]}"
else:
gateway = utils_net.get_default_gateway(ip_ver='ipv4')
address = "localhost"
# prepare test data
guest_path = (tmp_dir + "src-%s" % utils_misc.generate_random_string(8))
dest_path = (tmp_dir + "dst-%s" % utils_misc.generate_random_string(8))
host_path = os.path.join(test.tmpdir, "tmp-%s" %
utils_misc.generate_random_string(8))
test.log.info("Test setup: Creating %dbytes file on host", filesize)
process.run(dd_cmd % (host_path, filesize), shell=True)

try:
src_md5 = (crypto.hash_file(host_path, algorithm="md5"))
error_context.context("md5 value of data from src: %s" % src_md5,
test.log.info)
# transfer data from host to guest
host2guest_port = 10001
for vm in vms:
error_context.context("Transfer data from host to %s" % vm.name,
test.log.info)
sessions[vm].cmd_output_safe(fw_stop_cmd)
sessions[vm].sendline(receive_cmd % (host2guest_port, guest_path))
time.sleep(5)
process.run(sent_cmd % (host_path, address, host2guest_port), shell=True)
dst_md5 = get_file_md5sum(guest_path, sessions[vm],
timeout=file_md5_check_timeout)
error_context.context("md5 value of data in %s: %s" % (vm.name, dst_md5),
test.log.info)
if dst_md5 != src_md5:
test.fail("File changed after transfer host -> %s" % vm.name)
host2guest_port += 1

# transfer data between guest2guest
guest2guest_port = 10001
for vm1 in vms:
for vm2 in vms:
if vm1 != vm2:
error_context.context("Transferring data from %s to %s" %
(vm1.name, vm2.name), test.log.info)
sessions[vm1].sendline(receive_cmd % (guest2guest_port, dest_path))
time.sleep(5)
sessions[vm2].sendline(sent_cmd % (guest_path, gateway, guest2guest_port))
dst_md5 = get_file_md5sum(dest_path, sessions[vm1],
timeout=file_md5_check_timeout)
error_context.context("md5 value of data in %s: %s" % (vm.name, dst_md5),
test.log.info)
if dst_md5 != src_md5:
test.fail("File changed transfer %s -> %s" % (vm1.name, vm2.name))
guest2guest_port += 1

finally:
process.system("rm -rf %s" % host_path, timeout=timeout,
ignore_status=True)
for vm in vms:
sessions[vm].cmd("rm -rf %s %s || true" % (guest_path, dest_path),
timeout=timeout, ignore_all_errors=True)
sessions[vm].close()

0 comments on commit b0b1fda

Please sign in to comment.