* [Qemu-devel] [PATCH for-3.1] qemu-iotests: Adapt to moved location of StringIO module in py3
@ 2018-07-17 23:40 Philippe Mathieu-Daudé
2018-07-18 7:27 ` Daniel P. Berrangé
2018-07-18 14:53 ` Eduardo Habkost
0 siblings, 2 replies; 8+ messages in thread
From: Philippe Mathieu-Daudé @ 2018-07-17 23:40 UTC (permalink / raw)
To: Fam Zheng, Kevin Wolf, Max Reitz, Eduardo Habkost
Cc: Philippe Mathieu-Daudé, qemu-devel, qemu-block,
Daniel P . Berrange
Since 356dc290f the Fedora image default to Python3.
This fixes:
$ make docker-test-block@fedora
[...]
045 [failed, exit status 1] - output mismatch (see 045.out.bad)
--- /tmp/qemu-test/src/tests/qemu-iotests/045.out 2018-07-17 16:56:18.000000000 +0000
+++ /tmp/qemu-test/build/tests/qemu-iotests/045.out.bad 2018-07-17 17:19:22.448409007 +0000
@@ -1,5 +1,6 @@
-...........
-----------------------------------------------------------------------
-Ran 11 tests
-
-OK
+Traceback (most recent call last):
+ File "045", line 178, in <module>
+ iotests.main(supported_fmts=['raw'])
+ File "/tmp/qemu-test/src/tests/qemu-iotests/iotests.py", line 682, in main
+ import StringIO
+ModuleNotFoundError: No module named 'StringIO'
132 [failed, exit status 1] - output mismatch (see 132.out.bad)
148 [failed, exit status 1] - output mismatch (see 148.out.bad)
152 [failed, exit status 1] - output mismatch (see 152.out.bad)
Failures: 045 132 148 152
Signed-off-by: Philippe Mathieu-Daudé <f4bug@amsat.org>
---
tests/qemu-iotests/iotests.py | 8 ++++++--
1 file changed, 6 insertions(+), 2 deletions(-)
diff --git a/tests/qemu-iotests/iotests.py b/tests/qemu-iotests/iotests.py
index 4e67fbbe96..2fc7165fb9 100644
--- a/tests/qemu-iotests/iotests.py
+++ b/tests/qemu-iotests/iotests.py
@@ -679,13 +679,17 @@ def main(supported_fmts=[], supported_oses=['linux'], supported_cache_modes=[],
# We need to filter out the time taken from the output so that qemu-iotest
# can reliably diff the results against master output.
- import StringIO
+ try:
+ from StringIO import StringIO
+ except ImportError:
+ from io import StringIO
+
if debug:
output = sys.stdout
verbosity = 2
sys.argv.remove('-d')
else:
- output = StringIO.StringIO()
+ output = StringIO()
logging.basicConfig(level=(logging.DEBUG if debug else logging.WARN))
--
2.18.0
^ permalink raw reply related [flat|nested] 8+ messages in thread
* Re: [Qemu-devel] [PATCH for-3.1] qemu-iotests: Adapt to moved location of StringIO module in py3
2018-07-17 23:40 [Qemu-devel] [PATCH for-3.1] qemu-iotests: Adapt to moved location of StringIO module in py3 Philippe Mathieu-Daudé
@ 2018-07-18 7:27 ` Daniel P. Berrangé
2018-07-18 14:53 ` Eduardo Habkost
1 sibling, 0 replies; 8+ messages in thread
From: Daniel P. Berrangé @ 2018-07-18 7:27 UTC (permalink / raw)
To: Philippe Mathieu-Daudé
Cc: Fam Zheng, Kevin Wolf, Max Reitz, Eduardo Habkost, qemu-devel,
qemu-block
On Tue, Jul 17, 2018 at 08:40:15PM -0300, Philippe Mathieu-Daudé wrote:
> Since 356dc290f the Fedora image default to Python3.
>
> This fixes:
>
> $ make docker-test-block@fedora
> [...]
> 045 [failed, exit status 1] - output mismatch (see 045.out.bad)
> --- /tmp/qemu-test/src/tests/qemu-iotests/045.out 2018-07-17 16:56:18.000000000 +0000
> +++ /tmp/qemu-test/build/tests/qemu-iotests/045.out.bad 2018-07-17 17:19:22.448409007 +0000
> @@ -1,5 +1,6 @@
> -...........
> -----------------------------------------------------------------------
> -Ran 11 tests
> -
> -OK
> +Traceback (most recent call last):
> + File "045", line 178, in <module>
> + iotests.main(supported_fmts=['raw'])
> + File "/tmp/qemu-test/src/tests/qemu-iotests/iotests.py", line 682, in main
> + import StringIO
> +ModuleNotFoundError: No module named 'StringIO'
> 132 [failed, exit status 1] - output mismatch (see 132.out.bad)
> 148 [failed, exit status 1] - output mismatch (see 148.out.bad)
> 152 [failed, exit status 1] - output mismatch (see 152.out.bad)
>
> Failures: 045 132 148 152
>
> Signed-off-by: Philippe Mathieu-Daudé <f4bug@amsat.org>
> ---
> tests/qemu-iotests/iotests.py | 8 ++++++--
> 1 file changed, 6 insertions(+), 2 deletions(-)
>
> diff --git a/tests/qemu-iotests/iotests.py b/tests/qemu-iotests/iotests.py
> index 4e67fbbe96..2fc7165fb9 100644
> --- a/tests/qemu-iotests/iotests.py
> +++ b/tests/qemu-iotests/iotests.py
> @@ -679,13 +679,17 @@ def main(supported_fmts=[], supported_oses=['linux'], supported_cache_modes=[],
>
> # We need to filter out the time taken from the output so that qemu-iotest
> # can reliably diff the results against master output.
> - import StringIO
> + try:
> + from StringIO import StringIO
> + except ImportError:
> + from io import StringIO
> +
> if debug:
> output = sys.stdout
> verbosity = 2
> sys.argv.remove('-d')
> else:
> - output = StringIO.StringIO()
> + output = StringIO()
>
> logging.basicConfig(level=(logging.DEBUG if debug else logging.WARN))
Reviewed-by: Daniel P. Berrangé <berrange@redhat.com>
Regards,
Daniel
--
|: 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 :|
^ permalink raw reply [flat|nested] 8+ messages in thread
* Re: [Qemu-devel] [PATCH for-3.1] qemu-iotests: Adapt to moved location of StringIO module in py3
2018-07-17 23:40 [Qemu-devel] [PATCH for-3.1] qemu-iotests: Adapt to moved location of StringIO module in py3 Philippe Mathieu-Daudé
2018-07-18 7:27 ` Daniel P. Berrangé
@ 2018-07-18 14:53 ` Eduardo Habkost
2018-07-18 15:02 ` Philippe Mathieu-Daudé
1 sibling, 1 reply; 8+ messages in thread
From: Eduardo Habkost @ 2018-07-18 14:53 UTC (permalink / raw)
To: Philippe Mathieu-Daudé
Cc: Fam Zheng, Kevin Wolf, Max Reitz, qemu-devel, qemu-block,
Daniel P . Berrange
On Tue, Jul 17, 2018 at 08:40:15PM -0300, Philippe Mathieu-Daudé wrote:
[...]
> - import StringIO
> + try:
> + from StringIO import StringIO
> + except ImportError:
> + from io import StringIO
Why do we need this? Python 2.7 has io.StringIO.
--
Eduardo
^ permalink raw reply [flat|nested] 8+ messages in thread
* Re: [Qemu-devel] [PATCH for-3.1] qemu-iotests: Adapt to moved location of StringIO module in py3
2018-07-18 14:53 ` Eduardo Habkost
@ 2018-07-18 15:02 ` Philippe Mathieu-Daudé
2018-07-18 15:05 ` Eduardo Habkost
0 siblings, 1 reply; 8+ messages in thread
From: Philippe Mathieu-Daudé @ 2018-07-18 15:02 UTC (permalink / raw)
To: Eduardo Habkost
Cc: Fam Zheng, Kevin Wolf, Max Reitz, qemu-devel, qemu-block,
Daniel P . Berrange
Hi Eduardo,
On 07/18/2018 11:53 AM, Eduardo Habkost wrote:
> On Tue, Jul 17, 2018 at 08:40:15PM -0300, Philippe Mathieu-Daudé wrote:
> [...]
>> - import StringIO
>> + try:
>> + from StringIO import StringIO
>> + except ImportError:
>> + from io import StringIO
>
> Why do we need this? Python 2.7 has io.StringIO.
Python 2 works fine, the problem is the Fedora Docker image uses Python
3 and the block tests started to fail...
Is this commit message clearer?
"Since 356dc290f the Fedora [Docker] image uses Python3 by default."
^ permalink raw reply [flat|nested] 8+ messages in thread
* Re: [Qemu-devel] [PATCH for-3.1] qemu-iotests: Adapt to moved location of StringIO module in py3
2018-07-18 15:02 ` Philippe Mathieu-Daudé
@ 2018-07-18 15:05 ` Eduardo Habkost
2018-07-18 15:22 ` Philippe Mathieu-Daudé
2018-07-18 15:28 ` [Qemu-devel] [Qemu-block] " John Snow
0 siblings, 2 replies; 8+ messages in thread
From: Eduardo Habkost @ 2018-07-18 15:05 UTC (permalink / raw)
To: Philippe Mathieu-Daudé
Cc: Fam Zheng, Kevin Wolf, Max Reitz, qemu-devel, qemu-block,
Daniel P . Berrange
On Wed, Jul 18, 2018 at 12:02:39PM -0300, Philippe Mathieu-Daudé wrote:
> Hi Eduardo,
>
> On 07/18/2018 11:53 AM, Eduardo Habkost wrote:
> > On Tue, Jul 17, 2018 at 08:40:15PM -0300, Philippe Mathieu-Daudé wrote:
> > [...]
> >> - import StringIO
> >> + try:
> >> + from StringIO import StringIO
> >> + except ImportError:
> >> + from io import StringIO
> >
> > Why do we need this? Python 2.7 has io.StringIO.
>
> Python 2 works fine, the problem is the Fedora Docker image uses Python
> 3 and the block tests started to fail...
My question is: why use StringIO.StringIO on Python 2 and
io.StringIO on Python 3, if io.StringIO works on both Python
versions?
--
Eduardo
^ permalink raw reply [flat|nested] 8+ messages in thread
* Re: [Qemu-devel] [PATCH for-3.1] qemu-iotests: Adapt to moved location of StringIO module in py3
2018-07-18 15:05 ` Eduardo Habkost
@ 2018-07-18 15:22 ` Philippe Mathieu-Daudé
2018-07-18 16:01 ` Eduardo Habkost
2018-07-18 15:28 ` [Qemu-devel] [Qemu-block] " John Snow
1 sibling, 1 reply; 8+ messages in thread
From: Philippe Mathieu-Daudé @ 2018-07-18 15:22 UTC (permalink / raw)
To: Eduardo Habkost; +Cc: Kevin Wolf, qemu-block, qemu-devel, Max Reitz, Fam Zheng
On 07/18/2018 12:05 PM, Eduardo Habkost wrote:
> On Wed, Jul 18, 2018 at 12:02:39PM -0300, Philippe Mathieu-Daudé wrote:
>> Hi Eduardo,
>>
>> On 07/18/2018 11:53 AM, Eduardo Habkost wrote:
>>> On Tue, Jul 17, 2018 at 08:40:15PM -0300, Philippe Mathieu-Daudé wrote:
>>> [...]
>>>> - import StringIO
>>>> + try:
>>>> + from StringIO import StringIO
>>>> + except ImportError:
>>>> + from io import StringIO
>>>
>>> Why do we need this? Python 2.7 has io.StringIO.
>>
>> Python 2 works fine, the problem is the Fedora Docker image uses Python
>> 3 and the block tests started to fail...
>
> My question is: why use StringIO.StringIO on Python 2 and
> io.StringIO on Python 3, if io.StringIO works on both Python
> versions?
Oh I missed your question because I was not aware of this, and looked
how this was handled in the tree (7a5d936b6fc and 5f90af8e6b).
TIL we can use "from io import StringIO" regardless the version, the
2->3 conversion looks a bit less absurd, thanks!
Phil.
^ permalink raw reply [flat|nested] 8+ messages in thread
* Re: [Qemu-devel] [Qemu-block] [PATCH for-3.1] qemu-iotests: Adapt to moved location of StringIO module in py3
2018-07-18 15:05 ` Eduardo Habkost
2018-07-18 15:22 ` Philippe Mathieu-Daudé
@ 2018-07-18 15:28 ` John Snow
1 sibling, 0 replies; 8+ messages in thread
From: John Snow @ 2018-07-18 15:28 UTC (permalink / raw)
To: Eduardo Habkost, Philippe Mathieu-Daudé
Cc: Kevin Wolf, Daniel P . Berrange, qemu-block, qemu-devel,
Max Reitz, Fam Zheng
On 07/18/2018 11:05 AM, Eduardo Habkost wrote:
> On Wed, Jul 18, 2018 at 12:02:39PM -0300, Philippe Mathieu-Daudé wrote:
>> Hi Eduardo,
>>
>> On 07/18/2018 11:53 AM, Eduardo Habkost wrote:
>>> On Tue, Jul 17, 2018 at 08:40:15PM -0300, Philippe Mathieu-Daudé wrote:
>>> [...]
>>>> - import StringIO
>>>> + try:
>>>> + from StringIO import StringIO
>>>> + except ImportError:
>>>> + from io import StringIO
>>>
>>> Why do we need this? Python 2.7 has io.StringIO.
>>
>> Python 2 works fine, the problem is the Fedora Docker image uses Python
>> 3 and the block tests started to fail...
>
> My question is: why use StringIO.StringIO on Python 2 and
> io.StringIO on Python 3, if io.StringIO works on both Python
> versions?
>
Holdover from when 2.6 was our requisite version, surely.
--js
^ permalink raw reply [flat|nested] 8+ messages in thread
* Re: [Qemu-devel] [PATCH for-3.1] qemu-iotests: Adapt to moved location of StringIO module in py3
2018-07-18 15:22 ` Philippe Mathieu-Daudé
@ 2018-07-18 16:01 ` Eduardo Habkost
0 siblings, 0 replies; 8+ messages in thread
From: Eduardo Habkost @ 2018-07-18 16:01 UTC (permalink / raw)
To: Philippe Mathieu-Daudé
Cc: Kevin Wolf, qemu-block, qemu-devel, Max Reitz, Fam Zheng
On Wed, Jul 18, 2018 at 12:22:19PM -0300, Philippe Mathieu-Daudé wrote:
> On 07/18/2018 12:05 PM, Eduardo Habkost wrote:
> > On Wed, Jul 18, 2018 at 12:02:39PM -0300, Philippe Mathieu-Daudé wrote:
> >> Hi Eduardo,
> >>
> >> On 07/18/2018 11:53 AM, Eduardo Habkost wrote:
> >>> On Tue, Jul 17, 2018 at 08:40:15PM -0300, Philippe Mathieu-Daudé wrote:
> >>> [...]
> >>>> - import StringIO
> >>>> + try:
> >>>> + from StringIO import StringIO
> >>>> + except ImportError:
> >>>> + from io import StringIO
> >>>
> >>> Why do we need this? Python 2.7 has io.StringIO.
> >>
> >> Python 2 works fine, the problem is the Fedora Docker image uses Python
> >> 3 and the block tests started to fail...
> >
> > My question is: why use StringIO.StringIO on Python 2 and
> > io.StringIO on Python 3, if io.StringIO works on both Python
> > versions?
>
> Oh I missed your question because I was not aware of this, and looked
> how this was handled in the tree (7a5d936b6fc and 5f90af8e6b).
>
> TIL we can use "from io import StringIO" regardless the version, the
> 2->3 conversion looks a bit less absurd, thanks!
Note that it's not always an obvious conversion: on Python 3 you
need to decide if you want a text file or binary file.
io.StringIO is a text file, io.BinaryIO is a binary file. See
https://www.mail-archive.com/qemu-devel@nongnu.org/msg545627.html
for an example where io.StringIO wasn't appropriate.
In the case of iotests.py it looks like the code expects a text
file, though.
--
Eduardo
^ permalink raw reply [flat|nested] 8+ messages in thread
end of thread, other threads:[~2018-07-18 16:01 UTC | newest]
Thread overview: 8+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2018-07-17 23:40 [Qemu-devel] [PATCH for-3.1] qemu-iotests: Adapt to moved location of StringIO module in py3 Philippe Mathieu-Daudé
2018-07-18 7:27 ` Daniel P. Berrangé
2018-07-18 14:53 ` Eduardo Habkost
2018-07-18 15:02 ` Philippe Mathieu-Daudé
2018-07-18 15:05 ` Eduardo Habkost
2018-07-18 15:22 ` Philippe Mathieu-Daudé
2018-07-18 16:01 ` Eduardo Habkost
2018-07-18 15:28 ` [Qemu-devel] [Qemu-block] " John Snow
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).