Skip to content

Commit e54ed61

Browse files
committed
tests: add a test for no-revisions volume
QubesOS/qubes-issues#8767
1 parent bc20def commit e54ed61

File tree

1 file changed

+59
-0
lines changed

1 file changed

+59
-0
lines changed

qubes/tests/integ/storage.py

Lines changed: 59 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -379,6 +379,65 @@ async def _test_005_size_after_clone(self):
379379
await qubes.utils.coro_maybe(testvol2.import_volume(testvol))
380380
self.assertEqual(testvol2.size, size)
381381

382+
def test_006_no_revisions(self):
383+
"""Test if no-revisions volume persists data, and blocks parallel
384+
access"""
385+
return self.loop.run_until_complete(self._test_006_no_revisions())
386+
387+
async def _test_006_no_revisions(self):
388+
size = 32 * 1024 * 1024
389+
volume_config = {
390+
"pool": self.pool.name,
391+
"size": size,
392+
"save_on_stop": True,
393+
"rw": True,
394+
"revisions_to_keep": -1,
395+
}
396+
testvol = self.vm1.storage.init_volume("testvol", volume_config)
397+
await qubes.utils.coro_maybe(testvol.create())
398+
volume2_config = {
399+
"pool": self.pool.name,
400+
"size": size,
401+
"snap_on_start": True,
402+
"source": testvol.vid,
403+
"rw": True,
404+
}
405+
testvol2 = self.vm2.storage.init_volume("testvol2", volume2_config)
406+
await qubes.utils.coro_maybe(testvol2.create())
407+
del testvol
408+
del testvol2
409+
self.app.save()
410+
await self.vm1.start()
411+
await self.wait_for_session(self.vm1)
412+
# non-volatile image not clean
413+
await self.vm1.run_for_stdio(
414+
"head -c {} /dev/zero 2>&1 | diff -q /dev/xvde - 2>&1".format(size),
415+
user="root",
416+
)
417+
418+
await self.vm1.run_for_stdio("echo test123 > /dev/xvde", user="root")
419+
await self.vm1.shutdown(wait=True)
420+
await self.vm1.start()
421+
# non-volatile image volatile
422+
with self.assertRaises(subprocess.CalledProcessError):
423+
await self.vm1.run_for_stdio(
424+
"head -c {} /dev/zero 2>&1 | diff -q /dev/xvde - 2>&1".format(
425+
size
426+
),
427+
user="root",
428+
)
429+
430+
# should not work
431+
with self.assertRaises(qubes.exc.QubesException):
432+
await self.vm2.start()
433+
# now shutdown vm1 and starting vm2 should work
434+
await self.vm1.shutdown(wait=True)
435+
await self.vm2.start()
436+
stdout, stderr = await self.vm2.run_for_stdio(
437+
"head -c 7 /dev/xvde", user="root"
438+
)
439+
self.assertEqual(stdout, b"test123")
440+
382441

383442
class StorageFile(StorageTestMixin, qubes.tests.SystemTestCase):
384443
def init_pool(self):

0 commit comments

Comments
 (0)