tests: fix asyncio usage in some tests

This commit is contained in:
Marek Marczykowski-Górecki 2017-07-25 05:36:00 +02:00
parent ba2b034843
commit 75394a1348
No known key found for this signature in database
GPG Key ID: 063938BA42CFA724
2 changed files with 31 additions and 17 deletions

View File

@ -867,7 +867,7 @@ class SystemTestCase(QubesTestCase):
while timeout > 0:
if not vm.is_running():
return
time.sleep(1)
self.loop.run_until_complete(asyncio.sleep(1))
timeout -= 1
self.fail("Timeout while waiting for VM {} shutdown".format(vm.name))

View File

@ -60,10 +60,10 @@ class TC_00_Basic(qubes.tests.SystemTestCase):
self.assertIsNotNone(vm)
self.assertEqual(vm.name, vmname)
self.assertEqual(vm.template, self.app.default_template)
vm.create_on_disk()
self.loop.run_until_complete(vm.create_on_disk())
with self.assertNotRaises(qubes.exc.QubesException):
vm.storage.verify()
self.loop.run_until_complete(vm.storage.verify())
class TC_01_Properties(qubes.tests.SystemTestCase):
@ -75,6 +75,7 @@ class TC_01_Properties(qubes.tests.SystemTestCase):
self.vm = self.app.add_new_vm(qubes.vm.appvm.AppVM, name=self.vmname,
template=self.app.default_template,
label='red')
self.loop.run_until_complete(self.vm.create_on_disk())
@unittest.expectedFailure
def test_030_clone(self):
@ -90,7 +91,7 @@ class TC_01_Properties(qubes.tests.SystemTestCase):
label='red')
testvm2.clone_properties(testvm1)
self.loop.run_until_complete(testvm2.clone_disk_files(testvm1))
self.assertTrue(testvm1.storage.verify())
self.assertTrue(self.loop.run_until_complete(testvm1.storage.verify()))
self.assertIn('source', testvm1.volumes['root'].config)
self.assertNotEquals(testvm2, None)
self.assertNotEquals(testvm2.volumes, {})
@ -215,13 +216,18 @@ class TC_02_QvmPrefs(qubes.tests.SystemTestCase):
self.app.save()
def pref_set(self, name, value, valid=True):
p = subprocess.Popen(
['qvm-prefs'] + self.sharedopts +
(['--'] if value != '-D' else []) + [self.testvm.name, name, value],
self.loop.run_until_complete(self._pref_set(name, value, valid))
@asyncio.coroutine
def _pref_set(self, name, value, valid=True):
cmd = ['qvm-prefs']
if value != '-D':
cmd.append('--')
cmd.extend((self.testvm.name, name, value))
p = yield from asyncio.create_subprocess_exec(*cmd,
stdout=subprocess.PIPE,
stderr=subprocess.PIPE,
)
(stdout, stderr) = p.communicate()
stderr=subprocess.PIPE)
(stdout, stderr) = yield from p.communicate()
if valid:
self.assertEqual(p.returncode, 0,
"qvm-prefs .. '{}' '{}' failed: {}{}".format(
@ -233,9 +239,14 @@ class TC_02_QvmPrefs(qubes.tests.SystemTestCase):
"property '{}'".format(value, name))
def pref_get(self, name):
p = subprocess.Popen(['qvm-prefs'] + self.sharedopts +
['--', self.testvm.name, name], stdout=subprocess.PIPE)
(stdout, _) = p.communicate()
self.loop.run_until_complete(self._pref_get(name))
@asyncio.coroutine
def _pref_get(self, name):
p = yield from asyncio.create_subprocess_exec(
'qvm-prefs', *self.sharedopts, '--', self.testvm.name, name,
stdout=subprocess.PIPE)
(stdout, _) = yield from p.communicate()
self.assertEqual(p.returncode, 0)
return stdout.strip()
@ -343,10 +354,13 @@ class TC_03_QvmRevertTemplateChanges(qubes.tests.SystemTestCase):
self.log.warning("template not modified, test result will be "
"unreliable")
self.assertNotEqual(self.test_template.volumes['root'].revisions, {})
with self.assertNotRaises(subprocess.CalledProcessError):
pool_vid = repr(self.test_template.volumes['root']).strip("'")
revert_cmd = ['qvm-block', 'revert', pool_vid]
subprocess.check_call(revert_cmd)
pool_vid = repr(self.test_template.volumes['root']).strip("'")
revert_cmd = ['qvm-block', 'revert', pool_vid]
p = self.loop.run_until_complete(asyncio.create_subprocess_exec(
*revert_cmd))
self.loop.run_until_complete(p.wait())
self.assertEqual(p.returncode, 0)
checksum_after = self.get_rootimg_checksum()
self.assertEqual(checksum_before, checksum_after)