tests/functional: protect cached assets from modification
v2 cover tests/functional: protect cached assets from modification
Changed in v2:
* Make tuxrun tests actually work
Daniel P. Berrangé (2):
tests/functional: make tuxrun disk images writable tests/functional: make cached asset files read-only
tests/functional/qemu_test/asset.py | 3 +++ tests/functional/qemu_test/tuxruntest.py | 10 ++++++++-- 2 files changed, 11 insertions(+), 2 deletions(-)
Signature · 1 line
2.46.0
PATCH v2 1/2 tests/functional: make tuxrun disk images writable
The zstd command will preserve the input archive permissions on the output file. So when we decompress the readonly cached image, the resulting per-test run private disk image will also be readonly. We need it to be writable, so make it so.
--- tests/functional/qemu_test/tuxruntest.py | 10 ++++++++-- 1 file changed, 8 insertions(+), 2 deletions(-)
tests/functional/qemu_test/tuxruntest.py +8 -2
@@ -10,6 +10,7 @@ # SPDX-License-Identifier: GPL-2.0-or-later import os +import stat import time from qemu_test import QemuSystemTest
@@ -77,12 +78,17 @@ def fetch_tuxrun_assets(self, kernel_asset, rootfs_asset, dtb_asset=None): kernel_image = kernel_asset.fetch() disk_image_zst = rootfs_asset.fetch() + disk_image = self.workdir + "/rootfs.ext4" + run_cmd([self.zstd, "-f", "-d", disk_image_zst, - "-o", self.workdir + "/rootfs.ext4"]) + "-o", disk_image]) + # zstd copies source archive permissions for the output + # file, so must make this writable for QEMU + os.chmod(disk_image, stat.S_IRUSR | stat.S_IWUSR) dtb = dtb_asset.fetch() if dtb_asset is not None else None - return (kernel_image, self.workdir + "/rootfs.ext4", dtb) + return (kernel_image, disk_image, dtb) def prepare_run(self, kernel, disk, drive, dtb=None, console_index=0): """
Signature · 1 line
2.46.0
Re: [PATCH v2 1/2] tests/functional: make tuxrun disk images writable
Quoted 9 lines · Daniel P. Berrangé
The zstd command will preserve the input archive permissions on the output file. So when we decompress the readonly cached image, the resulting per-test run private disk image will also be readonly. We need it to be writable, so make it so.
Signed-off-by Daniel P. Berrangé <[email protected]>--- tests/functional/qemu_test/tuxruntest.py | 10 ++++++++-- 1 file changed, 8 insertions(+), 2 deletions(-)
Ah, so it was just about the new tuxrun tests that were likely not merged before ... Good to know that we can fix it in a central spot :-)
PATCH v2 2/2 tests/functional: make cached asset files read-only
In reply to Daniel P. BerrangéThis ensures that if a functional test runs QEMU with a writable disk pointing to a cached asset, an error will be reported, rather than silently modifying the cache file.
As an example, tweaking test_sbsaref.py to set snapshot=off, results in a clear error:
Command: ./build/qemu-system-aarch64 ...snip... -drive file=/var/home/berrange/.cache/qemu/download/44cdbae275ef1bb6dab1d5fbb59473d4f741e1c8ea8a80fd9e906b531d6ad461,format=raw,snapshot=off -cpu max,pauth=off
Output: qemu-system-aarch64: Could not open '/var/home/berrange/.cache/qemu/download/44cdbae275ef1bb6dab1d5fbb59473d4f741e1c8ea8a80fd9e906b531d6ad461': Permission denied
--- tests/functional/qemu_test/asset.py | 3 +++ 1 file changed, 3 insertions(+)
tests/functional/qemu_test/asset.py +3 -0
@@ -8,6 +8,7 @@ import hashlib import logging import os +import stat import subprocess import sys import unittest
@@ -143,6 +144,8 @@ def fetch(self): raise Exception("Hash of %s does not match %s" % (self.url, self.hash)) tmp_cache_file.replace(self.cache_file) + # Remove write perms to stop tests accidentally modifying them + os.chmod(self.cache_file, stat.S_IRUSR | stat.S_IRGRP) self.log.info("Cached %s at %s" % (self.url, self.cache_file)) return str(self.cache_file)
Signature · 1 line
2.46.0