[PATCH] tests/functional/qemu_test/asset.py: Don't use setxattr when it doesn't exist

Peter Maydell posted 1 patch 4 weeks, 1 day ago
Patches applied successfully (tree, apply log)
git fetch https://github.com/patchew-project/qemu tags/patchew/20260501115506.3792110-1-peter.maydell@linaro.org
Maintainers: Thomas Huth <th.huth+qemu@posteo.eu>, "Philippe Mathieu-Daudé" <philmd@linaro.org>, "Daniel P. Berrangé" <berrange@redhat.com>
tests/functional/qemu_test/asset.py | 13 ++++++++-----
1 file changed, 8 insertions(+), 5 deletions(-)
[PATCH] tests/functional/qemu_test/asset.py: Don't use setxattr when it doesn't exist
Posted by Peter Maydell 4 weeks, 1 day ago
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>
---
 tests/functional/qemu_test/asset.py | 13 ++++++++-----
 1 file changed, 8 insertions(+), 5 deletions(-)

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)
 
-- 
2.43.0
Re: [PATCH] tests/functional/qemu_test/asset.py: Don't use setxattr when it doesn't exist
Posted by Peter Maydell 2 weeks, 5 days ago
On Fri, 1 May 2026 at 12:55, Peter Maydell <peter.maydell@linaro.org> wrote:
>
> 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>

Is anybody going to pick this up via their tree, or should
I just put it into target-arm.next ?

thanks
-- PMM
Re: [PATCH] tests/functional/qemu_test/asset.py: Don't use setxattr when it doesn't exist
Posted by Thomas Huth 2 weeks, 4 days ago
On 11/05/2026 16.47, Peter Maydell wrote:
> On Fri, 1 May 2026 at 12:55, Peter Maydell <peter.maydell@linaro.org> wrote:
>>
>> 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>
> 
> Is anybody going to pick this up via their tree, or should
> I just put it into target-arm.next ?

I currently don't have any other patches in my queue, so it would be great 
if Daniel or you could take it.

  Thanks,
   Thomas
Re: [PATCH] tests/functional/qemu_test/asset.py: Don't use setxattr when it doesn't exist
Posted by Daniel P. Berrangé 2 weeks, 5 days ago
On Mon, May 11, 2026 at 03:47:33PM +0100, Peter Maydell wrote:
> On Fri, 1 May 2026 at 12:55, Peter Maydell <peter.maydell@linaro.org> wrote:
> >
> > 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>
> 
> Is anybody going to pick this up via their tree, or should
> I just put it into target-arm.next ?

I have it for my misc queue, but if you want to send a PR now then
consider it to havve

  Acked-by: Daniel P. Berrangé <berrange@redhat.com>

With regards,
Daniel
-- 
|: https://berrange.com       ~~        https://hachyderm.io/@berrange :|
|: https://libvirt.org          ~~          https://entangle-photo.org :|
|: https://pixelfed.art/berrange   ~~    https://fstop138.berrange.com :|


Re: [PATCH] tests/functional/qemu_test/asset.py: Don't use setxattr when it doesn't exist
Posted by Peter Maydell 2 weeks, 5 days ago
On Mon, 11 May 2026 at 16:16, Daniel P. Berrangé <berrange@redhat.com> wrote:
>
> On Mon, May 11, 2026 at 03:47:33PM +0100, Peter Maydell wrote:
> > On Fri, 1 May 2026 at 12:55, Peter Maydell <peter.maydell@linaro.org> wrote:
> > >
> > > 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>
> >
> > Is anybody going to pick this up via their tree, or should
> > I just put it into target-arm.next ?
>
> I have it for my misc queue, but if you want to send a PR now then
> consider it to havve
>
>   Acked-by: Daniel P. Berrangé <berrange@redhat.com>

I probably won't have a full pullreq ready to send until the
end of the week, so feel free to keep it in your queue.

thanks
-- PMM
Re: [PATCH] tests/functional/qemu_test/asset.py: Don't use setxattr when it doesn't exist
Posted by Thomas Huth 4 weeks ago
Am Fri,  1 May 2026 12:55:06 +0100
schrieb Peter Maydell <peter.maydell@linaro.org>:

> 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>
> ---
>  tests/functional/qemu_test/asset.py | 13 ++++++++-----
>  1 file changed, 8 insertions(+), 5 deletions(-)
> 
> 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)
>  

Reviewed-by: Thomas Huth <th.huth+qemu@posteo.eu>
Re: [PATCH] tests/functional/qemu_test/asset.py: Don't use setxattr when it doesn't exist
Posted by Alex Bennée 4 weeks, 1 day ago
Peter Maydell <peter.maydell@linaro.org> writes:

> 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>
> ---
>  tests/functional/qemu_test/asset.py | 13 ++++++++-----
>  1 file changed, 8 insertions(+), 5 deletions(-)
>
> 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'))

Well TIL:

  attr -g qemu-asset-url /home/alex/.cache/qemu/download/ff9d7dd7c6bdba325bd85ee85c02db61ff653e129558aeffe6aff55bffb6763a
  Attribute "qemu-asset-url" had a 73 byte value for /home/alex/.cache/qemu/download/ff9d7dd7c6bdba325bd85ee85c02db61ff653e129558aeffe6aff55bffb6763a:
  https://qemu-advcal.gitlab.io/qac-best-of-multiarch/download/day20.tar.xz

Reviewed-by: Alex Bennée <alex.bennee@linaro.org>

>          except OSError as e:
>              self.log.debug("Unable to set xattr on %s: %s", tmp_cache_file, e)

-- 
Alex Bennée
Virtualisation Tech Lead @ Linaro
Re: [PATCH] tests/functional/qemu_test/asset.py: Don't use setxattr when it doesn't exist
Posted by Daniel P. Berrangé 4 weeks, 1 day ago
On Fri, May 01, 2026 at 12:55:06PM +0100, Peter Maydell wrote:
> 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>
> ---
>  tests/functional/qemu_test/asset.py | 13 ++++++++-----
>  1 file changed, 8 insertions(+), 5 deletions(-)

Reviewed-by: Daniel P. Berrangé <berrange@redhat.com>


Daniel