Skip to content

Commit 6bb95dc

Browse files
committed
vsock_bridge_test: Add script to test vsock bridge functionality
ID:4316 Signed-off-by: Leidong Wang <leidwang@redhat.com>
1 parent 46fefae commit 6bb95dc

2 files changed

Lines changed: 114 additions & 0 deletions

File tree

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,24 @@
1+
- vsock_bridge_test:
2+
type = vsock_bridge_test
3+
only Windows
4+
clone_master = yes
5+
master_images_clone = image1
6+
remove_image_image1 = yes
7+
cdroms += " virtio"
8+
virtio_win_media_type = iso
9+
required_virtio_win_prewhql = [0.1.294, )
10+
required_virtio_win = [1.9.49.0, )
11+
vsock_module = vhost_vsock
12+
vsocks = vhost_vsock0
13+
driver_name = viosock
14+
test_tool = "vstbridge.exe"
15+
i386:
16+
openssh_src_path = WIN_UTILS:\OpenSSH-Win32
17+
x86_64:
18+
openssh_src_path = WIN_UTILS:\OpenSSH-Win64
19+
openssh_dst_path = "C:\OpenSSH"
20+
install_config_openssh = 'powershell -command "${openssh_dst_path}\install-sshd.ps1"'
21+
start_openssh_service = sc start sshd
22+
install_openssh = yes
23+
conn_cmd = 'ssh -o ProxyCommand="socat - VSOCK-CONNECT:%s:22" Administrator@0.0.0.0'
24+
expect_output = "C:\\Users\\Administrator>"

qemu/tests/vsock_bridge_test.py

Lines changed: 90 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,90 @@
1+
import logging
2+
3+
import aexpect
4+
from virttest import error_context, utils_logfile, utils_misc
5+
6+
from provider.win_driver_utils import get_driver_inf_path
7+
8+
LOG_JOB = logging.getLogger("avocado.test")
9+
10+
11+
def setup_openssh_service(session, params):
12+
"""
13+
Setup openssh server
14+
15+
:param session: QEMU test object
16+
:param params: Dictionary with the test parameters
17+
"""
18+
19+
LOG_JOB.info("Copy OpenSSH installer")
20+
openssh_src_path = utils_misc.set_winutils_letter(
21+
session, params["openssh_src_path"]
22+
)
23+
openssh_dst_path = params["openssh_dst_path"]
24+
session.cmd_status_output(
25+
"xcopy %s %s /s /e /i /y" % (openssh_src_path, openssh_dst_path)
26+
)
27+
28+
LOG_JOB.info("Install OpenSSH")
29+
session.cmd_status_output(params["install_config_openssh"])
30+
31+
32+
@error_context.context_aware
33+
def run(test, params, env):
34+
"""
35+
Vsock bridge service test
36+
37+
1. Boot guest with vhost-vsock-pci device
38+
2. Install OpenSSH in VM
39+
3. Install vsock bridge service in VM
40+
4. Start OpenSSH and vsock bridge service in VM
41+
5. Connect VM via vsock bridge service
42+
43+
:param test: QEMU test object
44+
:param params: Dictionary with the test parameters
45+
:param env: Dictionary with test environment
46+
"""
47+
48+
vm = env.get_vm(params["main_vm"])
49+
vm.verify_alive()
50+
session = vm.wait_for_login()
51+
52+
test_tool = params["test_tool"]
53+
virtio_win_media_type = params["virtio_win_media_type"]
54+
driver_name = params["driver_name"]
55+
56+
LOG_JOB.info("Install and start openssh server service in guest")
57+
setup_openssh_service(session, params)
58+
59+
LOG_JOB.info("Install vstbridge service in guest")
60+
path = get_driver_inf_path(session, test, virtio_win_media_type, driver_name)
61+
test_tool_src_path = path[: path.rfind("\\")] + "\\" + test_tool
62+
session.cmd_output("xcopy %s C:\\" % test_tool_src_path)
63+
session.cmd_output("C:\\%s -i" % test_tool)
64+
session = vm.reboot(session)
65+
66+
LOG_JOB.info("Start OpenSSH service after reboot VM")
67+
session.cmd_status_output(params["start_openssh_service"])
68+
69+
LOG_JOB.info("Connect VM via vsock bridge service")
70+
vsock_dev = params["vsocks"].split()[0]
71+
guest_cid = vm.devices.get(vsock_dev).get_param("guest-cid")
72+
conn_cmd = params["conn_cmd"] % guest_cid
73+
vsock_session = aexpect.Expect(
74+
conn_cmd,
75+
auto_close=False,
76+
output_func=utils_logfile.log_line,
77+
output_params=("vsock_%s_%s" % (guest_cid, 22),),
78+
)
79+
try:
80+
if vsock_session.read_until_last_line_matches("yes/no"):
81+
vsock_session.sendline("yes")
82+
if vsock_session.read_until_last_line_matches("password"):
83+
vsock_session.sendline(params["password"])
84+
if params["expect_output"] not in vsock_session.get_output():
85+
test.log.info("Connect to VM via vsock bridge successfully")
86+
except Exception as e:
87+
test.fail("Can not connect to VM via vsock bridge service due to %s" % e)
88+
89+
vsock_session.close()
90+
session.close()

0 commit comments

Comments
 (0)