Commit 039b057c09 for qemu.org
commit 039b057c09c6a9742b91b8f29604651ba3fdb558
Author: Peter Maydell <peter.maydell@linaro.org>
Date: Fri May 1 12:55:06 2026 +0100
tests/functional/qemu_test/asset.py: Don't use setxattr when it doesn't exist
The Python os.setxattr() API is Linux-specific, so trying to use
it on other OSes triggers a failure:
File "/Users/pm215/src/qemu/tests/functional/qemu_test/asset.py",
line 227, in fetch
os.setxattr(str(tmp_cache_file), "user.qemu-asset-url",
^^^^^^^^^^^
AttributeError: module 'os' has no attribute 'setxattr'
Since we only set the attributes here for informational
purposes, skip them when os.setxattr() isn't available.
Cc: qemu-stable@nongnu.org
Fixes: 9903217a4ed013 ("tests/functional: add a module for handling asset download & caching")
Signed-off-by: Peter Maydell <peter.maydell@linaro.org>
Reviewed-by: Daniel P. Berrangé <berrange@redhat.com>
Reviewed-by: Alex Bennée <alex.bennee@linaro.org>
Reviewed-by: Thomas Huth <th.huth+qemu@posteo.eu>
Message-id: 20260501115506.3792110-1-peter.maydell@linaro.org
diff --git a/tests/functional/qemu_test/asset.py b/tests/functional/qemu_test/asset.py
index 51a434b2b7..0abd89e0a3 100644
--- a/tests/functional/qemu_test/asset.py
+++ b/tests/functional/qemu_test/asset.py
@@ -223,11 +223,14 @@ def fetch(self):
raise AssetError(self, "Download retries exceeded", transient=True)
try:
- # Set these just for informational purposes
- os.setxattr(str(tmp_cache_file), "user.qemu-asset-url",
- self.url.encode('utf8'))
- os.setxattr(str(tmp_cache_file), "user.qemu-asset-hash",
- self.hash.encode('utf8'))
+ # Set these just for informational purposes. Note that
+ # setxattr is Linux-only; as this is only informational
+ # we can simply skip it on other platforms.
+ if hasattr(os, "setxattr"):
+ os.setxattr(str(tmp_cache_file), "user.qemu-asset-url",
+ self.url.encode('utf8'))
+ os.setxattr(str(tmp_cache_file), "user.qemu-asset-hash",
+ self.hash.encode('utf8'))
except OSError as e:
self.log.debug("Unable to set xattr on %s: %s", tmp_cache_file, e)