tests: fail the test early if VM fails to start

Make an exception in vm.start() actually interrupt the test. The
asyncio.wait() returns list of completed tasks, where exception may be
stored - but is not raised directly. Change to asyncio.gather() that will
propagate the exception by default.
As a side effect, avoid deprecated direct coroutine passing to
asyncio.wait(). This functionality in asyncio.gather() is not
deprecated.
This commit is contained in:
Marek Marczykowski-Górecki 2020-10-30 15:39:57 +01:00
parent e4a8caaaa2
commit 79d4b7162a
No known key found for this signature in database
GPG Key ID: 063938BA42CFA724
6 changed files with 42 additions and 42 deletions

View File

@ -580,12 +580,12 @@ class TC_30_Gui_daemon(qubes.tests.SystemTestCase):
self.loop.run_until_complete(testvm2.create_on_disk()) self.loop.run_until_complete(testvm2.create_on_disk())
self.app.save() self.app.save()
self.loop.run_until_complete(asyncio.wait([ self.loop.run_until_complete(asyncio.gather(
testvm1.start(), testvm1.start(),
testvm2.start()])) testvm2.start()))
self.loop.run_until_complete(asyncio.wait([ self.loop.run_until_complete(asyncio.gather(
self.wait_for_session(testvm1), self.wait_for_session(testvm1),
self.wait_for_session(testvm2)])) self.wait_for_session(testvm2)))
window_title = 'user@{}'.format(testvm1.name) window_title = 'user@{}'.format(testvm1.name)
self.loop.run_until_complete(testvm1.run( self.loop.run_until_complete(testvm1.run(
'zenity --text-info --editable --title={}'.format(window_title))) 'zenity --text-info --editable --title={}'.format(window_title)))

View File

@ -65,9 +65,9 @@ class TC_50_MimeHandlers:
self.target_vm.template_for_dispvms = True self.target_vm.template_for_dispvms = True
self.source_vm.default_dispvm = self.target_vm self.source_vm.default_dispvm = self.target_vm
done, not_done = self.loop.run_until_complete(asyncio.wait([ done, not_done = self.loop.run_until_complete(asyncio.gather(
self.source_vm.start(), self.source_vm.start(),
self.target_vm.start()])) self.target_vm.start()))
for result in itertools.chain(done, not_done): for result in itertools.chain(done, not_done):
# catch any exceptions # catch any exceptions
result.result() result.result()

View File

@ -350,9 +350,9 @@ class VmNetworkingMixin(object):
self.testvm2.netvm = self.proxy self.testvm2.netvm = self.proxy
self.app.save() self.app.save()
self.loop.run_until_complete(asyncio.wait([ self.loop.run_until_complete(asyncio.gather(
self.testvm1.start(), self.testvm1.start(),
self.testvm2.start()])) self.testvm2.start()))
self.assertNotEqual(self.run_cmd(self.testvm1, self.assertNotEqual(self.run_cmd(self.testvm1,
self.ping_cmd.format(target=self.testvm2.ip)), 0) self.ping_cmd.format(target=self.testvm2.ip)), 0)

View File

@ -307,9 +307,9 @@ class VmIPv6NetworkingMixin(VmNetworkingMixin):
self.testvm2.netvm = self.proxy self.testvm2.netvm = self.proxy
self.app.save() self.app.save()
self.loop.run_until_complete(asyncio.wait([ self.loop.run_until_complete(asyncio.gather(
self.testvm1.start(), self.testvm1.start(),
self.testvm2.start()])) self.testvm2.start()))
self.assertNotEqual(self.run_cmd(self.testvm1, self.assertNotEqual(self.run_cmd(self.testvm1,
self.ping_cmd.format(target=self.testvm2.ip6)), 0) self.ping_cmd.format(target=self.testvm2.ip6)), 0)

View File

@ -123,12 +123,12 @@ class TC_00_QrexecMixin(object):
def test_052_qrexec_vm_service_eof(self): def test_052_qrexec_vm_service_eof(self):
"""Test for EOF transmission VM(src)->VM(dst)""" """Test for EOF transmission VM(src)->VM(dst)"""
self.loop.run_until_complete(asyncio.wait([ self.loop.run_until_complete(asyncio.gather(
self.testvm1.start(), self.testvm1.start(),
self.testvm2.start()])) self.testvm2.start()))
self.loop.run_until_complete(asyncio.wait([ self.loop.run_until_complete(asyncio.gather(
self.wait_for_session(self.testvm1), self.wait_for_session(self.testvm1),
self.wait_for_session(self.testvm2)])) self.wait_for_session(self.testvm2)))
self.create_remote_file(self.testvm2, self.create_remote_file(self.testvm2,
'/etc/qubes-rpc/test.EOF', '/etc/qubes-rpc/test.EOF',
'#!/bin/sh\n/bin/cat\n') '#!/bin/sh\n/bin/cat\n')
@ -153,9 +153,9 @@ class TC_00_QrexecMixin(object):
def test_053_qrexec_vm_service_eof_reverse(self): def test_053_qrexec_vm_service_eof_reverse(self):
"""Test for EOF transmission VM(src)<-VM(dst)""" """Test for EOF transmission VM(src)<-VM(dst)"""
self.loop.run_until_complete(asyncio.wait([ self.loop.run_until_complete(asyncio.gather(
self.testvm1.start(), self.testvm1.start(),
self.testvm2.start()])) self.testvm2.start()))
self.create_remote_file(self.testvm2, '/etc/qubes-rpc/test.EOF', self.create_remote_file(self.testvm2, '/etc/qubes-rpc/test.EOF',
'#!/bin/sh\n' '#!/bin/sh\n'
'echo test; exec >&-; cat >/dev/null') 'echo test; exec >&-; cat >/dev/null')
@ -219,9 +219,9 @@ class TC_00_QrexecMixin(object):
self.assertEqual(e.exception.returncode, 3) self.assertEqual(e.exception.returncode, 3)
def test_065_qrexec_exit_code_vm(self): def test_065_qrexec_exit_code_vm(self):
self.loop.run_until_complete(asyncio.wait([ self.loop.run_until_complete(asyncio.gather(
self.testvm1.start(), self.testvm1.start(),
self.testvm2.start()])) self.testvm2.start()))
with self.qrexec_policy('test.Retcode', self.testvm1, self.testvm2): with self.qrexec_policy('test.Retcode', self.testvm1, self.testvm2):
self.create_remote_file(self.testvm2, '/etc/qubes-rpc/test.Retcode', self.create_remote_file(self.testvm2, '/etc/qubes-rpc/test.Retcode',
@ -254,9 +254,9 @@ class TC_00_QrexecMixin(object):
handling anything else. handling anything else.
""" """
self.loop.run_until_complete(asyncio.wait([ self.loop.run_until_complete(asyncio.gather(
self.testvm1.start(), self.testvm1.start(),
self.testvm2.start()])) self.testvm2.start()))
self.create_remote_file(self.testvm2, '/etc/qubes-rpc/test.write', '''\ self.create_remote_file(self.testvm2, '/etc/qubes-rpc/test.write', '''\
# first write a lot of data # first write a lot of data
@ -381,9 +381,9 @@ class TC_00_QrexecMixin(object):
def test_080_qrexec_service_argument_allow_default(self): def test_080_qrexec_service_argument_allow_default(self):
"""Qrexec service call with argument""" """Qrexec service call with argument"""
self.loop.run_until_complete(asyncio.wait([ self.loop.run_until_complete(asyncio.gather(
self.testvm1.start(), self.testvm1.start(),
self.testvm2.start()])) self.testvm2.start()))
self.create_remote_file(self.testvm2, '/etc/qubes-rpc/test.Argument', self.create_remote_file(self.testvm2, '/etc/qubes-rpc/test.Argument',
'/usr/bin/printf %s "$1"') '/usr/bin/printf %s "$1"')
@ -397,9 +397,9 @@ class TC_00_QrexecMixin(object):
def test_081_qrexec_service_argument_allow_specific(self): def test_081_qrexec_service_argument_allow_specific(self):
"""Qrexec service call with argument - allow only specific value""" """Qrexec service call with argument - allow only specific value"""
self.loop.run_until_complete(asyncio.wait([ self.loop.run_until_complete(asyncio.gather(
self.testvm1.start(), self.testvm1.start(),
self.testvm2.start()])) self.testvm2.start()))
self.create_remote_file(self.testvm2, '/etc/qubes-rpc/test.Argument', self.create_remote_file(self.testvm2, '/etc/qubes-rpc/test.Argument',
'/usr/bin/printf %s "$1"') '/usr/bin/printf %s "$1"')
@ -416,9 +416,9 @@ class TC_00_QrexecMixin(object):
def test_082_qrexec_service_argument_deny_specific(self): def test_082_qrexec_service_argument_deny_specific(self):
"""Qrexec service call with argument - deny specific value""" """Qrexec service call with argument - deny specific value"""
self.loop.run_until_complete(asyncio.wait([ self.loop.run_until_complete(asyncio.gather(
self.testvm1.start(), self.testvm1.start(),
self.testvm2.start()])) self.testvm2.start()))
self.create_remote_file(self.testvm2, '/etc/qubes-rpc/test.Argument', self.create_remote_file(self.testvm2, '/etc/qubes-rpc/test.Argument',
'/usr/bin/printf %s "$1"') '/usr/bin/printf %s "$1"')
@ -436,9 +436,9 @@ class TC_00_QrexecMixin(object):
def test_083_qrexec_service_argument_specific_implementation(self): def test_083_qrexec_service_argument_specific_implementation(self):
"""Qrexec service call with argument - argument specific """Qrexec service call with argument - argument specific
implementatation""" implementatation"""
self.loop.run_until_complete(asyncio.wait([ self.loop.run_until_complete(asyncio.gather(
self.testvm1.start(), self.testvm1.start(),
self.testvm2.start()])) self.testvm2.start()))
self.create_remote_file(self.testvm2, self.create_remote_file(self.testvm2,
'/etc/qubes-rpc/test.Argument', '/etc/qubes-rpc/test.Argument',
@ -457,9 +457,9 @@ class TC_00_QrexecMixin(object):
def test_084_qrexec_service_argument_extra_env(self): def test_084_qrexec_service_argument_extra_env(self):
"""Qrexec service call with argument - extra env variables""" """Qrexec service call with argument - extra env variables"""
self.loop.run_until_complete(asyncio.wait([ self.loop.run_until_complete(asyncio.gather(
self.testvm1.start(), self.testvm1.start(),
self.testvm2.start()])) self.testvm2.start()))
self.create_remote_file(self.testvm2, '/etc/qubes-rpc/test.Argument', self.create_remote_file(self.testvm2, '/etc/qubes-rpc/test.Argument',
'/usr/bin/printf "%s %s" ' '/usr/bin/printf "%s %s" '

View File

@ -166,9 +166,9 @@ class TC_00_AppVMMixin(object):
self.wait_for_window(title, show=False) self.wait_for_window(title, show=False)
def test_100_qrexec_filecopy(self): def test_100_qrexec_filecopy(self):
self.loop.run_until_complete(asyncio.wait([ self.loop.run_until_complete(asyncio.gather(
self.testvm1.start(), self.testvm1.start(),
self.testvm2.start()])) self.testvm2.start()))
self.loop.run_until_complete(self.testvm1.run_for_stdio( self.loop.run_until_complete(self.testvm1.run_for_stdio(
'cp /etc/passwd /tmp/passwd')) 'cp /etc/passwd /tmp/passwd'))
@ -195,9 +195,9 @@ class TC_00_AppVMMixin(object):
self.fail('source file got removed') self.fail('source file got removed')
def test_105_qrexec_filemove(self): def test_105_qrexec_filemove(self):
self.loop.run_until_complete(asyncio.wait([ self.loop.run_until_complete(asyncio.gather(
self.testvm1.start(), self.testvm1.start(),
self.testvm2.start()])) self.testvm2.start()))
self.loop.run_until_complete(self.testvm1.run_for_stdio( self.loop.run_until_complete(self.testvm1.run_for_stdio(
'cp /etc/passwd /tmp/passwd')) 'cp /etc/passwd /tmp/passwd'))
@ -254,9 +254,9 @@ class TC_00_AppVMMixin(object):
self.fail('source file got removed') self.fail('source file got removed')
def test_110_qrexec_filecopy_deny(self): def test_110_qrexec_filecopy_deny(self):
self.loop.run_until_complete(asyncio.wait([ self.loop.run_until_complete(asyncio.gather(
self.testvm1.start(), self.testvm1.start(),
self.testvm2.start()])) self.testvm2.start()))
with self.qrexec_policy('qubes.Filecopy', self.testvm1, self.testvm2, with self.qrexec_policy('qubes.Filecopy', self.testvm1, self.testvm2,
allow=False): allow=False):
@ -275,9 +275,9 @@ class TC_00_AppVMMixin(object):
# The operation should not hang when qrexec-agent is down on target # The operation should not hang when qrexec-agent is down on target
# machine, see QubesOS/qubes-issues#5347. # machine, see QubesOS/qubes-issues#5347.
self.loop.run_until_complete(asyncio.wait([ self.loop.run_until_complete(asyncio.gather(
self.testvm1.start(), self.testvm1.start(),
self.testvm2.start()])) self.testvm2.start()))
with self.qrexec_policy('qubes.Filecopy', self.testvm1, self.testvm2): with self.qrexec_policy('qubes.Filecopy', self.testvm1, self.testvm2):
try: try:
@ -318,9 +318,9 @@ class TC_00_AppVMMixin(object):
@unittest.skipUnless(spawn.find_executable('xdotool'), @unittest.skipUnless(spawn.find_executable('xdotool'),
"xdotool not installed") "xdotool not installed")
def test_130_qrexec_filemove_disk_full(self): def test_130_qrexec_filemove_disk_full(self):
self.loop.run_until_complete(asyncio.wait([ self.loop.run_until_complete(asyncio.gather(
self.testvm1.start(), self.testvm1.start(),
self.testvm2.start()])) self.testvm2.start()))
self.loop.run_until_complete(self.wait_for_session(self.testvm1)) self.loop.run_until_complete(self.wait_for_session(self.testvm1))
@ -373,9 +373,9 @@ class TC_00_AppVMMixin(object):
"""Test time synchronization mechanism""" """Test time synchronization mechanism"""
if self.template.startswith('whonix-'): if self.template.startswith('whonix-'):
self.skipTest('qvm-sync-clock disabled for Whonix VMs') self.skipTest('qvm-sync-clock disabled for Whonix VMs')
self.loop.run_until_complete(asyncio.wait([ self.loop.run_until_complete(asyncio.gather(
self.testvm1.start(), self.testvm1.start(),
self.testvm2.start(),])) self.testvm2.start()))
start_time = subprocess.check_output(['date', '-u', '+%s']) start_time = subprocess.check_output(['date', '-u', '+%s'])
try: try: