From 79d4b7162af292f037c3a504a8a1314ec4251f38 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Marek=20Marczykowski-G=C3=B3recki?= Date: Fri, 30 Oct 2020 15:39:57 +0100 Subject: [PATCH] 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. --- qubes/tests/integ/basic.py | 8 +++--- qubes/tests/integ/mime.py | 4 +-- qubes/tests/integ/network.py | 4 +-- qubes/tests/integ/network_ipv6.py | 4 +-- qubes/tests/integ/qrexec.py | 40 +++++++++++++++--------------- qubes/tests/integ/vm_qrexec_gui.py | 24 +++++++++--------- 6 files changed, 42 insertions(+), 42 deletions(-) diff --git a/qubes/tests/integ/basic.py b/qubes/tests/integ/basic.py index 39fb9b61..31a9d10f 100644 --- a/qubes/tests/integ/basic.py +++ b/qubes/tests/integ/basic.py @@ -580,12 +580,12 @@ class TC_30_Gui_daemon(qubes.tests.SystemTestCase): self.loop.run_until_complete(testvm2.create_on_disk()) self.app.save() - self.loop.run_until_complete(asyncio.wait([ + self.loop.run_until_complete(asyncio.gather( testvm1.start(), - testvm2.start()])) - self.loop.run_until_complete(asyncio.wait([ + testvm2.start())) + self.loop.run_until_complete(asyncio.gather( self.wait_for_session(testvm1), - self.wait_for_session(testvm2)])) + self.wait_for_session(testvm2))) window_title = 'user@{}'.format(testvm1.name) self.loop.run_until_complete(testvm1.run( 'zenity --text-info --editable --title={}'.format(window_title))) diff --git a/qubes/tests/integ/mime.py b/qubes/tests/integ/mime.py index 2dbbfc8b..c66c9b70 100644 --- a/qubes/tests/integ/mime.py +++ b/qubes/tests/integ/mime.py @@ -65,9 +65,9 @@ class TC_50_MimeHandlers: self.target_vm.template_for_dispvms = True 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.target_vm.start()])) + self.target_vm.start())) for result in itertools.chain(done, not_done): # catch any exceptions result.result() diff --git a/qubes/tests/integ/network.py b/qubes/tests/integ/network.py index f9c28bc9..45918adf 100644 --- a/qubes/tests/integ/network.py +++ b/qubes/tests/integ/network.py @@ -350,9 +350,9 @@ class VmNetworkingMixin(object): self.testvm2.netvm = self.proxy self.app.save() - self.loop.run_until_complete(asyncio.wait([ + self.loop.run_until_complete(asyncio.gather( self.testvm1.start(), - self.testvm2.start()])) + self.testvm2.start())) self.assertNotEqual(self.run_cmd(self.testvm1, self.ping_cmd.format(target=self.testvm2.ip)), 0) diff --git a/qubes/tests/integ/network_ipv6.py b/qubes/tests/integ/network_ipv6.py index 702e9e64..51a0783a 100644 --- a/qubes/tests/integ/network_ipv6.py +++ b/qubes/tests/integ/network_ipv6.py @@ -307,9 +307,9 @@ class VmIPv6NetworkingMixin(VmNetworkingMixin): self.testvm2.netvm = self.proxy self.app.save() - self.loop.run_until_complete(asyncio.wait([ + self.loop.run_until_complete(asyncio.gather( self.testvm1.start(), - self.testvm2.start()])) + self.testvm2.start())) self.assertNotEqual(self.run_cmd(self.testvm1, self.ping_cmd.format(target=self.testvm2.ip6)), 0) diff --git a/qubes/tests/integ/qrexec.py b/qubes/tests/integ/qrexec.py index 2776e3de..dc7f0201 100644 --- a/qubes/tests/integ/qrexec.py +++ b/qubes/tests/integ/qrexec.py @@ -123,12 +123,12 @@ class TC_00_QrexecMixin(object): def test_052_qrexec_vm_service_eof(self): """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.testvm2.start()])) - self.loop.run_until_complete(asyncio.wait([ + self.testvm2.start())) + self.loop.run_until_complete(asyncio.gather( self.wait_for_session(self.testvm1), - self.wait_for_session(self.testvm2)])) + self.wait_for_session(self.testvm2))) self.create_remote_file(self.testvm2, '/etc/qubes-rpc/test.EOF', '#!/bin/sh\n/bin/cat\n') @@ -153,9 +153,9 @@ class TC_00_QrexecMixin(object): def test_053_qrexec_vm_service_eof_reverse(self): """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.testvm2.start()])) + self.testvm2.start())) self.create_remote_file(self.testvm2, '/etc/qubes-rpc/test.EOF', '#!/bin/sh\n' 'echo test; exec >&-; cat >/dev/null') @@ -219,9 +219,9 @@ class TC_00_QrexecMixin(object): self.assertEqual(e.exception.returncode, 3) 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.testvm2.start()])) + self.testvm2.start())) with self.qrexec_policy('test.Retcode', self.testvm1, self.testvm2): self.create_remote_file(self.testvm2, '/etc/qubes-rpc/test.Retcode', @@ -254,9 +254,9 @@ class TC_00_QrexecMixin(object): handling anything else. """ - self.loop.run_until_complete(asyncio.wait([ + self.loop.run_until_complete(asyncio.gather( self.testvm1.start(), - self.testvm2.start()])) + self.testvm2.start())) self.create_remote_file(self.testvm2, '/etc/qubes-rpc/test.write', '''\ # first write a lot of data @@ -381,9 +381,9 @@ class TC_00_QrexecMixin(object): def test_080_qrexec_service_argument_allow_default(self): """Qrexec service call with argument""" - self.loop.run_until_complete(asyncio.wait([ + self.loop.run_until_complete(asyncio.gather( self.testvm1.start(), - self.testvm2.start()])) + self.testvm2.start())) self.create_remote_file(self.testvm2, '/etc/qubes-rpc/test.Argument', '/usr/bin/printf %s "$1"') @@ -397,9 +397,9 @@ class TC_00_QrexecMixin(object): def test_081_qrexec_service_argument_allow_specific(self): """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.testvm2.start()])) + self.testvm2.start())) self.create_remote_file(self.testvm2, '/etc/qubes-rpc/test.Argument', '/usr/bin/printf %s "$1"') @@ -416,9 +416,9 @@ class TC_00_QrexecMixin(object): def test_082_qrexec_service_argument_deny_specific(self): """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.testvm2.start()])) + self.testvm2.start())) self.create_remote_file(self.testvm2, '/etc/qubes-rpc/test.Argument', '/usr/bin/printf %s "$1"') @@ -436,9 +436,9 @@ class TC_00_QrexecMixin(object): def test_083_qrexec_service_argument_specific_implementation(self): """Qrexec service call with argument - argument specific implementatation""" - self.loop.run_until_complete(asyncio.wait([ + self.loop.run_until_complete(asyncio.gather( self.testvm1.start(), - self.testvm2.start()])) + self.testvm2.start())) self.create_remote_file(self.testvm2, '/etc/qubes-rpc/test.Argument', @@ -457,9 +457,9 @@ class TC_00_QrexecMixin(object): def test_084_qrexec_service_argument_extra_env(self): """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.testvm2.start()])) + self.testvm2.start())) self.create_remote_file(self.testvm2, '/etc/qubes-rpc/test.Argument', '/usr/bin/printf "%s %s" ' diff --git a/qubes/tests/integ/vm_qrexec_gui.py b/qubes/tests/integ/vm_qrexec_gui.py index 4d20ffb5..e321447b 100644 --- a/qubes/tests/integ/vm_qrexec_gui.py +++ b/qubes/tests/integ/vm_qrexec_gui.py @@ -166,9 +166,9 @@ class TC_00_AppVMMixin(object): self.wait_for_window(title, show=False) def test_100_qrexec_filecopy(self): - self.loop.run_until_complete(asyncio.wait([ + self.loop.run_until_complete(asyncio.gather( self.testvm1.start(), - self.testvm2.start()])) + self.testvm2.start())) self.loop.run_until_complete(self.testvm1.run_for_stdio( 'cp /etc/passwd /tmp/passwd')) @@ -195,9 +195,9 @@ class TC_00_AppVMMixin(object): self.fail('source file got removed') def test_105_qrexec_filemove(self): - self.loop.run_until_complete(asyncio.wait([ + self.loop.run_until_complete(asyncio.gather( self.testvm1.start(), - self.testvm2.start()])) + self.testvm2.start())) self.loop.run_until_complete(self.testvm1.run_for_stdio( 'cp /etc/passwd /tmp/passwd')) @@ -254,9 +254,9 @@ class TC_00_AppVMMixin(object): self.fail('source file got removed') 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.testvm2.start()])) + self.testvm2.start())) with self.qrexec_policy('qubes.Filecopy', self.testvm1, self.testvm2, allow=False): @@ -275,9 +275,9 @@ class TC_00_AppVMMixin(object): # The operation should not hang when qrexec-agent is down on target # machine, see QubesOS/qubes-issues#5347. - self.loop.run_until_complete(asyncio.wait([ + self.loop.run_until_complete(asyncio.gather( self.testvm1.start(), - self.testvm2.start()])) + self.testvm2.start())) with self.qrexec_policy('qubes.Filecopy', self.testvm1, self.testvm2): try: @@ -318,9 +318,9 @@ class TC_00_AppVMMixin(object): @unittest.skipUnless(spawn.find_executable('xdotool'), "xdotool not installed") 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.testvm2.start()])) + self.testvm2.start())) self.loop.run_until_complete(self.wait_for_session(self.testvm1)) @@ -373,9 +373,9 @@ class TC_00_AppVMMixin(object): """Test time synchronization mechanism""" if self.template.startswith('whonix-'): 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.testvm2.start(),])) + self.testvm2.start())) start_time = subprocess.check_output(['date', '-u', '+%s']) try: