@samitouri / QOSamiQemu / commits / 039b057c09

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

Peter Maydell committed May 1, 2026 at 12:55 UTC 039b057c09c6a9742b91b8f29604651ba3fdb558
1 file changed +8 -5
tests/functional/qemu_test/asset.py
+8 -5
@@ -223,11 +223,14 @@ class Asset:
223 raise AssetError(self, "Download retries exceeded", transient=True)
224
225 try:
226 - # Set these just for informational purposes
227 - os.setxattr(str(tmp_cache_file), "user.qemu-asset-url",
228 - self.url.encode('utf8'))
229 - os.setxattr(str(tmp_cache_file), "user.qemu-asset-hash",
230 - self.hash.encode('utf8'))
226 + # Set these just for informational purposes. Note that
227 + # setxattr is Linux-only; as this is only informational
228 + # we can simply skip it on other platforms.
229 + if hasattr(os, "setxattr"):
230 + os.setxattr(str(tmp_cache_file), "user.qemu-asset-url",
231 + self.url.encode('utf8'))
232 + os.setxattr(str(tmp_cache_file), "user.qemu-asset-hash",
233 + self.hash.encode('utf8'))
234 except OSError as e:
235 self.log.debug("Unable to set xattr on %s: %s", tmp_cache_file, e)
236