Skip to contentSkip to conversation

qemu-iotests: Fix FilePaths cleanup

PATCH Superseded Nir Soffer 3 participants 6 messages Aug 20, 2020

v1 of 3 Superseded Latest is v3 →

lore
Share & tools
lore

Nir Soffer

author
#0 lore raw

PATCH 1/1 qemu-iotests: Fix FilePaths cleanup

If os.remove() fails to remove one of the paths, for example if the file was removed by the test, the cleanup loop would exit silently, without removing the rest of the files.

---
 dtc                           | 2 +-
 tests/qemu-iotests/iotests.py | 8 ++++----
 2 files changed, 5 insertions(+), 5 deletions(-)
dtc +1 -1
index 85e5d83984..88f18909db 160000
@@ -1 +1 @@
-Subproject commit 85e5d839847af54efab170f2b1331b2a6421e647
+Subproject commit 88f18909db731a627456f26d779445f84e449536
tests/qemu-iotests/iotests.py +4 -4
index 717b5b652c..16a04df8a3 100644
@@ -468,11 +468,11 @@ class FilePaths:
         return self.paths
 
     def __exit__(self, exc_type, exc_val, exc_tb):
-        try:
-            for path in self.paths:
+        for path in self.paths:
+            try:
                 os.remove(path)
-        except OSError:
-            pass
+            except OSError:
+                pass
         return False
 
 class FilePath(FilePaths):
Signature · 1 line
2.26.2
#1 lore raw
Quoted 16 lines · Nir Soffer

If os.remove() fails to remove one of the paths, for example if the file was removed by the test, the cleanup loop would exit silently, without removing the rest of the files.

---
 dtc                           | 2 +-
 tests/qemu-iotests/iotests.py | 8 ++++----
 2 files changed, 5 insertions(+), 5 deletions(-)
dtc +0 -0
index 85e5d83984..88f18909db 160000

dtc line 1

Quoted 2 lines
dtc +1 -1
@@ -1 +1 @@
-Subproject commit 85e5d839847af54efab170f2b1331b2a6421e647
+Subproject commit 88f18909db731a627456f26d779445f84e449536

This sneaked into the patch somehow, I did not change this.

Quoted 23 lines
tests/qemu-iotests/iotests.py +4 -5
index 717b5b652c..16a04df8a3 100644
@@ -468,11 +468,11 @@ class FilePaths:
         return self.paths
 
     def __exit__(self, exc_type, exc_val, exc_tb):
-        try:
-            for path in self.paths:
+        for path in self.paths:
+            try:
                 os.remove(path)
-        except OSError:
-            pass
+            except OSError:
+                pass
         return False
 
 class FilePath(FilePaths):
--

2.26.2

Reviewed-by on v1 1/1
#2 lore raw
In reply to Nir Soffer
Quoted 15 lines · Nir Soffer

If os.remove() fails to remove one of the paths, for example if the file was removed by the test, the cleanup loop would exit silently, without removing the rest of the files.

---
  dtc                           | 2 +-
  tests/qemu-iotests/iotests.py | 8 ++++----
  2 files changed, 5 insertions(+), 5 deletions(-)
dtc +0 -0
index 85e5d83984..88f18909db 160000

dtc line 1

Quoted 2 lines
dtc +1 -1
@@ -1 +1 @@
-Subproject commit 85e5d839847af54efab170f2b1331b2a6421e647
+Subproject commit 88f18909db731a627456f26d779445f84e449536

Modulo the unintended submodule bump,

Quoted 8 lines
tests/qemu-iotests/iotests.py +0 -0
index 717b5b652c..16a04df8a3 100644
@@ -468,11 +468,11 @@ class FilePaths:
          return self.paths
 
      def __exit__(self, exc_type, exc_val, exc_tb):

tests/qemu-iotests/iotests.py class FilePaths: · line 476

Quoted 10 lines
tests/qemu-iotests/iotests.py +4 -4
-        try:
-            for path in self.paths:
+        for path in self.paths:
+            try:
                  os.remove(path)
-        except OSError:
-            pass
+            except OSError:
+                pass
          return False
Signature · 3 lines
Eric Blake, Principal Software Engineer
Red Hat, Inc.           +1-919-301-3226
Virtualization:  qemu.org | libvirt.org
#3 lore raw
Quoted 5 lines · Eric Blake
Quoted 4 lines · Nir Soffer

If os.remove() fails to remove one of the paths, for example if the file was removed by the test, the cleanup loop would exit silently, without removing the rest of the files.

Quoted 8 lines
Quoted 5 lines

---
  dtc                           | 2 +-
  tests/qemu-iotests/iotests.py | 8 ++++----

  2 files changed, 5 insertions(+), 5 deletions(-)

By the way, what test did you hit this on? If possible, I'd like to add a Fixes: tag pointing to a commit that includes the problem.

Signature · 3 lines
Eric Blake, Principal Software Engineer
Red Hat, Inc.           +1-919-301-3226
Virtualization:  qemu.org | libvirt.org
Reviewed-by Max Reitz
#4 lore raw
Quoted 14 lines · Eric Blake
Quoted 12 lines · Eric Blake
Quoted 9 lines · Nir Soffer

If os.remove() fails to remove one of the paths, for example if the file was removed by the test, the cleanup loop would exit silently, without removing the rest of the files.

---
  dtc                           | 2 +-
  tests/qemu-iotests/iotests.py | 8 ++++----
  2 files changed, 5 insertions(+), 5 deletions(-)
Quoted 4 lines
Quoted 1 line

By the way, what test did you hit this on? If possible, I'd like to add a Fixes: tag pointing to a commit that includes the problem.

I did not hit this issue, found it while reviewing another patch, while trying to
understand what FilePath is doing.

The error was introduced in:

commit de263986b5dc7571d12a95305ffc7ddd2f349431

Author: John Snow <[email protected]>
Date:   Mon Jul 29 16:35:54 2019 -0400

iotests: teach FilePath to produce multiple paths

Use "FilePaths" instead of "FilePath" to request multiple files be cleaned up after we leave that object's scope.

This is not crucial; but it saves a little typing.

Message-id: [email protected]

#5 lore raw
Quoted 16 lines · Nir Soffer
Quoted 14 lines · Eric Blake
Quoted 12 lines · Eric Blake
Quoted 9 lines · Nir Soffer

If os.remove() fails to remove one of the paths, for example if the file was removed by the test, the cleanup loop would exit silently, without removing the rest of the files.

---
  dtc                           | 2 +-
  tests/qemu-iotests/iotests.py | 8 ++++----
  2 files changed, 5 insertions(+), 5 deletions(-)
Quoted 4 lines
Quoted 4 lines
Quoted 1 line

By the way, what test did you hit this on? If possible, I'd like to add a Fixes: tag pointing to a commit that includes the problem.

I'll send a v2 with a Fixes tag, and few other related fixes.

Quoted 22 lines

I did not hit this issue, found it while reviewing another patch, while trying to
understand what FilePath is doing.

The error was introduced in:

commit de263986b5dc7571d12a95305ffc7ddd2f349431

Author: John Snow <[email protected]>
Date:   Mon Jul 29 16:35:54 2019 -0400

iotests: teach FilePath to produce multiple paths

Use "FilePaths" instead of "FilePath" to request multiple files be cleaned up after we leave that object's scope.

This is not crucial; but it saves a little typing.

Message-id: [email protected]