forked from autotest/virt-test
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathutils_spice.py
149 lines (121 loc) · 4.72 KB
/
utils_spice.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
"""
Common spice test utility functions.
"""
import os, logging, time
from autotest.client.shared import error
from aexpect import ShellCmdError, ShellStatusError, ShellTimeoutError
class RVConnectError(Exception):
"""Exception raised in case that remote-viewer fails to connect"""
pass
def wait_timeout(timeout=10):
"""
time.sleep(timeout) + logging.debug(timeout)
@param timeout=10
"""
logging.debug("Waiting (timeout=%ss)", timeout)
time.sleep(timeout)
def verify_established(client_vm, host, port, rv_binary):
"""
Parses netstat output for established connection on host:port
@param client_session - vm.wait_for_login()
@param host - host ip addr
@param port - port for client to connect
@param rv_binary - remote-viewer binary
"""
rv_binary = rv_binary.split(os.path.sep)[-1]
client_session = client_vm.wait_for_login(timeout=60)
# !!! -n means do not resolve port names
cmd = '(netstat -pn 2>&1| grep "^tcp.*:.*%s:%s.*ESTABLISHED.*%s.*") \
> /dev/null' % (host, str(port), rv_binary)
try:
netstat_out = client_session.cmd(cmd)
logging.info("netstat output: %s", netstat_out)
except ShellCmdError:
logging.error("Failed to get established connection from netstat")
raise RVConnectError()
else:
logging.info("%s connection to %s:%s successful.",
rv_binary, host, port)
client_session.close()
def start_vdagent(guest_session, test_timeout):
"""
Sending commands to start the spice-vdagentd service
@param guest_session: ssh session of the VM
@param test_timeout: timeout time for the cmds
"""
cmd = "service spice-vdagentd start"
try:
guest_session.cmd(cmd, print_func=logging.info,
timeout=test_timeout)
except ShellStatusError:
logging.debug("Status code of \"%s\" was not obtained, most likely"
"due to a problem with colored output" % cmd)
except:
raise error.TestFail("Guest Vdagent Daemon Start failed")
logging.debug("------------ End of guest checking for Spice Vdagent"
" Daemon ------------")
wait_timeout(3)
def restart_vdagent(guest_session, test_timeout):
"""
Sending commands to restart the spice-vdagentd service
@param guest_session: ssh session of the VM
@param test_timeout: timeout time for the cmds
"""
cmd = "service spice-vdagentd restart"
try:
guest_session.cmd(cmd, print_func=logging.info,
timeout=test_timeout)
except ShellCmdError:
raise error.TestFail("Couldn't restart spice vdagent process")
except:
raise error.TestFail("Guest Vdagent Daemon Check failed")
logging.debug("------------ End of Spice Vdagent"
" Daemon Restart ------------")
wait_timeout(3)
def stop_vdagent(guest_session, test_timeout):
"""
Sending commands to stop the spice-vdagentd service
@param guest_session: ssh session of the VM
@param test_timeout: timeout time for the cmds
"""
cmd = "service spice-vdagentd stop"
try:
guest_session.cmd(cmd, print_func=logging.info,
timeout=test_timeout)
except ShellStatusError:
logging.debug("Status code of \"%s\" was not obtained, most likely"
"due to a problem with colored output" % cmd)
except ShellCmdError:
raise error.TestFail("Couldn't turn off spice vdagent process")
except:
raise error.TestFail("Guest Vdagent Daemon Check failed")
logging.debug("------------ End of guest checking for Spice Vdagent"
" Daemon ------------")
wait_timeout(3)
def verify_vdagent(guest_session, test_timeout):
"""
Verifying vdagent is installed on a VM
@param guest_session: ssh session of the VM
@param test_timeout: timeout time for the cmds
"""
cmd = "rpm -qa | grep spice-vdagent"
try:
guest_session.cmd(cmd, print_func=logging.info, timeout=test_timeout)
finally:
logging.debug("----------- End of guest check to see if vdagent package"
" is available ------------")
wait_timeout(3)
def verify_virtio(guest_session, test_timeout):
"""
Verify Virtio linux driver is properly loaded.
@param guest_session: ssh session of the VM
@param test_timeout: timeout time for the cmds
"""
#cmd = "lsmod | grep virtio_console"
cmd = "ls /dev/virtio-ports/"
try:
guest_session.cmd(cmd, print_func=logging.info, timeout=test_timeout)
finally:
logging.debug("------------ End of guest check of the Virtio-Serial"
" Driver------------")
wait_timeout(3)