Skip to content

Commit 5a8d024

Browse files
committed
tests/functional/test_vnc: Skip test if VNC support is not available
These tests currently fail if VNC support has not been compiled into the QEMU binary. Let's add some checks to skip the tests in that case instead. Message-ID: <[email protected]> Reviewed-by: Daniel P. Berrangé <[email protected]> Signed-off-by: Thomas Huth <[email protected]>
1 parent c3612d0 commit 5a8d024

File tree

1 file changed

+22
-4
lines changed

1 file changed

+22
-4
lines changed

tests/functional/test_vnc.py

Lines changed: 22 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,7 @@
1212

1313
import socket
1414
from typing import List
15+
from qemu.machine.machine import VMLaunchFailure
1516

1617
from qemu_test import QemuSystemTest
1718
from qemu_test.ports import Ports
@@ -32,7 +33,14 @@ class Vnc(QemuSystemTest):
3233
def test_no_vnc_change_password(self):
3334
self.vm.add_args('-nodefaults', '-S')
3435
self.vm.launch()
35-
self.assertFalse(self.vm.qmp('query-vnc')['return']['enabled'])
36+
37+
query_vnc_response = self.vm.qmp('query-vnc')
38+
if 'error' in query_vnc_response:
39+
self.assertEqual(query_vnc_response['error']['class'],
40+
'CommandNotFound')
41+
self.skipTest('VNC support not available')
42+
self.assertFalse(query_vnc_response['return']['enabled'])
43+
3644
set_password_response = self.vm.qmp('change-vnc-password',
3745
password='new_password')
3846
self.assertIn('error', set_password_response)
@@ -41,9 +49,19 @@ def test_no_vnc_change_password(self):
4149
self.assertEqual(set_password_response['error']['desc'],
4250
'Could not set password')
4351

52+
def launch_guarded(self):
53+
try:
54+
self.vm.launch()
55+
except VMLaunchFailure as excp:
56+
if "-vnc: invalid option" in excp.output:
57+
self.skipTest("VNC support not available")
58+
else:
59+
self.log.info("unhandled launch failure: %s", excp.output)
60+
raise excp
61+
4462
def test_change_password_requires_a_password(self):
4563
self.vm.add_args('-nodefaults', '-S', '-vnc', ':1,to=999')
46-
self.vm.launch()
64+
self.launch_guarded()
4765
self.assertTrue(self.vm.qmp('query-vnc')['return']['enabled'])
4866
set_password_response = self.vm.qmp('change-vnc-password',
4967
password='new_password')
@@ -55,7 +73,7 @@ def test_change_password_requires_a_password(self):
5573

5674
def test_change_password(self):
5775
self.vm.add_args('-nodefaults', '-S', '-vnc', ':1,to=999,password=on')
58-
self.vm.launch()
76+
self.launch_guarded()
5977
self.assertTrue(self.vm.qmp('query-vnc')['return']['enabled'])
6078
self.vm.cmd('change-vnc-password',
6179
password='new_password')
@@ -66,7 +84,7 @@ def do_test_change_listen(self, a, b, c):
6684
self.assertFalse(check_connect(c))
6785

6886
self.vm.add_args('-nodefaults', '-S', '-vnc', f'{VNC_ADDR}:{a - 5900}')
69-
self.vm.launch()
87+
self.launch_guarded()
7088
self.assertEqual(self.vm.qmp('query-vnc')['return']['service'], str(a))
7189
self.assertTrue(check_connect(a))
7290
self.assertFalse(check_connect(b))

0 commit comments

Comments
 (0)