Skip to content

Commit 3e3a5f1

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 3e3a5f1

2 files changed

Lines changed: 104 additions & 0 deletions

File tree

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
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'

qemu/tests/vsock_bridge_test.py

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

0 commit comments

Comments
 (0)