Skip to contentSkip to conversation

qemu-iotests: Fix supported_oses check

PATCH Superseded Fam Zheng 2 participants 2 messages Jan 15, 2015

v1 of 2 Superseded Latest is v2 →

lore
Share & tools
lore

Fam Zheng

author
#0 lore raw

PATCH 1/1 qemu-iotests: Fix supported_oses check

There is a bug in the recently added sys.platform test and we no longer run python tests, because "linux2" is the value to compare here. So do a prefix match, although the python documentation claims Linux is always linux2.

---
 tests/qemu-iotests/iotests.py | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)
tests/qemu-iotests/iotests.py +1 -1
index 87002e0..4011725 100644
@@ -288,7 +288,7 @@ def main(supported_fmts=[], supported_oses=['linux']):
     if supported_fmts and (imgfmt not in supported_fmts):
         notrun('not suitable for this image format: %s' % imgfmt)
 
-    if sys.platform not in supported_oses:
+    if not any([sys.platform.startswith(x) for x in supported_oses]):
         notrun('not suitable for this OS: %s' % sys.platform)
 
     # We need to filter out the time taken from the output so that qemu-iotest
Signature · 1 line
1.9.3
#1 lore raw
Quoted 4 lines · Fam Zheng

There is a bug in the recently added sys.platform test and we no longer run python tests, because "linux2" is the value to compare here. So do a prefix match, although the python documentation claims Linux is always linux2.

It would be good to mention that the docs explicitly suggest using startswith().

When reviewing this I wasn't sure whether the startswith() comparison is safe, but knowing the Python docs suggest it means I can be sure this patch is correct.

Quoted 10 lines
---
 tests/qemu-iotests/iotests.py | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)
tests/qemu-iotests/iotests.py +0 -0
index 87002e0..4011725 100644

tests/qemu-iotests/iotests.py def main(supported_fmts=[], supported_oses=['linux']): · line 292

Quoted 6 lines
tests/qemu-iotests/iotests.py +1 -1
@@ -288,7 +288,7 @@ def main(supported_fmts=[], supported_oses=['linux']):
     if supported_fmts and (imgfmt not in supported_fmts):
         notrun('not suitable for this image format: %s' % imgfmt)
 
-    if sys.platform not in supported_oses:
+    if not any([sys.platform.startswith(x) for x in supported_oses]):
         notrun('not suitable for this OS: %s' % sys.platform)

Please don't use any(), we've avoided it to stay compatible with old Python interpreters:

if True not in [sys.platform.startswith(x) for x in supported_oses]: