Skip to content

Commit

Permalink
tests: add test for custom-persist feature
Browse files Browse the repository at this point in the history
Create a bunch of files/dirs and check if expected files remained and
unexpected did not.

QubesOS/qubes-issues#1006
  • Loading branch information
marmarek committed Feb 13, 2025
1 parent 2c9232f commit 0af5907
Showing 1 changed file with 54 additions and 0 deletions.
54 changes: 54 additions & 0 deletions qubes/tests/integ/basic.py
Original file line number Diff line number Diff line change
Expand Up @@ -880,6 +880,60 @@ def test_010_os_metadata(self):
self.assertEqual(tpl.features.get("os-distribution"), "kali")
self.assertEqual(tpl.features.get("os-distribution-like"), "debian")

def test_020_custom_persist(self):
self.testvm = self.app.add_new_vm(
"AppVM",
label="red",
name=self.make_vm_name("vm"),
)
self.loop.run_until_complete(self.testvm.create_on_disk())
self.testvm.features["service.custom-persist"] = "1"
self.testvm.features["custom-persist.downloads"] = (
"/home/user/Downloads"
)
self.testvm.features["custom-persist.local_lib"] = "/usr/local/lib"
self.testvm.features["custom-persist.new_dir"] = "/home/user/new_dir"
self.app.save()

# start first time,
self.loop.run_until_complete(self.testvm.start())
# do some changes
# TODO: check /home/user/new_dir permissions?
self.loop.run_until_complete(
self.testvm.run_for_stdio(
"echo test1 > /home/user/Downloads/download.txt &&"
"mkdir -p /home/user/new_dir &&"
"echo test2 > /home/user/new_dir/new_file.txt &&"
"echo test3 > /home/user/Documents/doc.txt &&"
"echo TEST4=test4 >> /home/user/.bashrc &&"
"ln -s /bin/true /usr/local/bin/true-copy &&"
"mkdir -p /usr/local/lib/subdir &&"
"echo touch /etc/test5.flag >> /rw/config/rc.local",
user="root",
)
)
self.loop.run_until_complete(self.testvm.shutdown(wait=True))
# and then start again to compare what survived
self.loop.run_until_complete(self.testvm.start())
try:
self.loop.run_until_complete(
self.testvm.run_for_stdio(
"stat /home/user/Downloads/download.txt &&"
"stat /home/user/new_dir/new_file.txt &&"
"! stat /home/user/Documents/doc.txt &&"
"! grep TEST4=test4 /home/user/.bashrc &&"
"! stat /usr/local/bin/true-copy &&"
"stat /usr/local/lib/subdir &&"
"! stat /etc/test5.flag",
user="root",
)
)
except subprocess.CalledProcessError as e:
self.fail(
f"Too much / too little files persisted: {e.stdout}"
f"{e.stderr}"
)

def test_110_rescue_console(self):
self.loop.run_until_complete(self._test_110_rescue_console())

Expand Down

0 comments on commit 0af5907

Please sign in to comment.