Skip to contentSkip to conversation

test: make cached assets for functional tests read-only

PATCH In review Daniel P. Berrangé 3 participants 5 messages Oct 21, 2024 – Oct 25, 2024

lore
Share & tools
lore
#0 lore raw

PATCH 1/1 test: make cached assets for functional tests read-only

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
index e47bfac035..f126cd5863 100644
@@ -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
Reviewed-by on v1 1/1
#1 lore raw
Quoted 7 lines · 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:

Quoted 7 lines

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(+)
Reviewed-by Tested-by on v1 1/1
#2 lore raw
In reply to Daniel P. Berrangé
Quoted 7 lines · 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:

Quoted 7 lines

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(+)
#3 lore raw
Quoted 11 lines · Thomas Huth
Quoted 10 lines · 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

Quoted 7 lines
Quoted 4 lines

---
  tests/functional/qemu_test/asset.py | 3 +++

  1 file changed, 3 insertions(+)

Actually, if you start with a clean cache, or if you manually do:

chmod a-w ~/.cache/qemu/download/*

a couple of tests are failing now. Could you please have a look?

Thanks
Thomas

#4 lore raw
Quoted 21 lines · Thomas Huth
Quoted 20 lines · Thomas Huth
Quoted 18 lines · 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(+)
Quoted 8 lines
Quoted 2 lines

Actually, if you start with a clean cache, or if you manually do:

chmod a-w ~/.cache/qemu/download/*

a couple of tests are failing now. Could you please have a look?

Oooh, I thought I tested with all targets enabled, but I guess I must have missed something.

With regards,
Daniel

Signature · 3 lines
|: https://berrange.com      -o-    https://www.flickr.com/photos/dberrange :|
|: https://libvirt.org         -o-            https://fstop138.berrange.com :|
|: https://entangle-photo.org    -o-    https://www.instagram.com/dberrange :|