From d676576600d2798d62c2fa099825d82e9aecb302 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Marek=20Marczykowski-G=C3=B3recki?= Date: Fri, 1 Sep 2017 12:58:20 +0200 Subject: [PATCH] tests: fix qvm-sync-clock test for asyncio and new time sync API qvm-sync-clock in dom0 now synchronize only dom0 time. For VM time, qvm-sync-clock needs to be called in VM. Also, both will communicate with qubesd, so must be called asynchronously from tests. --- qubes/tests/integ/vm_qrexec_gui.py | 27 +++++++++++---------------- 1 file changed, 11 insertions(+), 16 deletions(-) diff --git a/qubes/tests/integ/vm_qrexec_gui.py b/qubes/tests/integ/vm_qrexec_gui.py index e7ba3dfc..482b571e 100644 --- a/qubes/tests/integ/vm_qrexec_gui.py +++ b/qubes/tests/integ/vm_qrexec_gui.py @@ -735,8 +735,7 @@ class TC_00_AppVMMixin(object): if self.template.startswith('whonix-'): self.skipTest('qvm-sync-clock disabled for Whonix VMs') self.loop.run_until_complete(asyncio.wait([ - self.testvm1.start(), - self.testvm2.start()])) + self.testvm1.start()])) start_time = subprocess.check_output(['date', '-u', '+%s']) try: @@ -745,27 +744,23 @@ class TC_00_AppVMMixin(object): # break vm and dom0 time, to check if qvm-sync-clock would fix it subprocess.check_call(['sudo', 'date', '-s', '2001-01-01T12:34:56'], stdout=subprocess.DEVNULL) - self.loop.run_until_complete(asyncio.wait([ + self.loop.run_until_complete( self.testvm1.run_for_stdio('date -s 2001-01-01T12:34:56', - user='root'), - self.testvm2.run_for_stdio('date -s 2001-01-01T12:34:56', - user='root'), - ])) + user='root')) - subprocess.check_call(['qvm-sync-clock'], stdout=subprocess.DEVNULL) - # qvm-sync-clock is asynchronous - it spawns qubes.SetDateTime - # service, send it timestamp value and exists without waiting for - # actual time set + p = self.loop.run_until_complete( + asyncio.create_subprocess_exec('sudo', 'qvm-sync-clock', + stdout=asyncio.subprocess.DEVNULL)) + self.loop.run_until_complete(p.wait()) + self.assertEqual(p.returncode, 0) + self.loop.run_until_complete( + self.testvm1.run_for_stdio('qvm-sync-clock', + user='root')) - self.loop.run_until_complete(asyncio.sleep(1)) vm_time, _ = self.loop.run_until_complete( self.testvm1.run_for_stdio('date -u +%s')) self.assertAlmostEquals(int(vm_time), int(start_time), delta=30) - vm_time, _ = self.loop.run_until_complete( - self.testvm2.run_for_stdio('date -u +%s')) - self.assertAlmostEquals(int(vm_time), int(start_time), delta=30) - dom0_time, _ = subprocess.check_output(['date', '-u', '+%s']) self.assertAlmostEquals(int(dom0_time), int(start_time), delta=30)