Skip to contentSkip to conversation

iotests: fix source directory location

PATCH In review John Snow 3 participants 7 messages May 26, 2022 – Jul 11, 2022

lore
Share & tools
lore

John Snow

author
#0 lore raw

PATCH 1/1 iotests: fix source directory location

If you invoke the check script from outside of the tests/qemu-iotests directory, the directories initialized as source_iotests and build_iotests will be incorrect.

We can use the location of the source file itself to be more accurate.

---
 tests/qemu-iotests/testenv.py | 4 ++--
 1 file changed, 2 insertions(+), 2 deletions(-)
tests/qemu-iotests/testenv.py +2 -2
index a864c74b123..9b0f01e84db 100644
@@ -217,10 +217,10 @@ def __init__(self, imgfmt: str, imgproto: str, aiomode: str,
             self.build_iotests = os.path.dirname(os.path.abspath(sys.argv[0]))
         else:
             # called from the source tree
-            self.source_iotests = os.getcwd()
+            self.source_iotests = str(Path(__file__, '..').resolve())
             self.build_iotests = self.source_iotests
 
-        self.build_root = os.path.join(self.build_iotests, '..', '..')
+        self.build_root = str(Path(self.build_iotests, '../..').resolve())
 
         self.init_directories()
         self.init_binaries()
Signature · 1 line
2.34.1
#1 lore raw
Quoted 17 lines · John Snow

If you invoke the check script from outside of the tests/qemu-iotests directory, the directories initialized as source_iotests and build_iotests will be incorrect.

We can use the location of the source file itself to be more accurate.

---
 tests/qemu-iotests/testenv.py | 4 ++--
 1 file changed, 2 insertions(+), 2 deletions(-)
tests/qemu-iotests/testenv.py +0 -0
index a864c74b123..9b0f01e84db 100644

tests/qemu-iotests/testenv.py def __init__(self, imgfmt: str, imgproto: str, aiomode: str, · line 220

Quoted 5 lines
tests/qemu-iotests/testenv.py +1 -1
@@ -217,10 +217,10 @@ def __init__(self, imgfmt: str, imgproto: str, aiomode: str,
             self.build_iotests = os.path.dirname(os.path.abspath(sys.argv[0]))
         else:
             # called from the source tree
-            self.source_iotests = os.getcwd()
+            self.source_iotests = str(Path(__file__, '..').resolve())

Path(__file__).parent

tests/qemu-iotests/testenv.py def __init__(self, imgfmt: str, imgproto: str, aiomode: str, · line 223

Quoted 4 lines
tests/qemu-iotests/testenv.py +1 -1
             self.build_iotests = self.source_iotests
 
-        self.build_root = os.path.join(self.build_iotests, '..', '..')
+        self.build_root = str(Path(self.build_iotests, '../..').resolve())

Path(self.build_iotests).parent.parent

to be portable

Quoted 7 lines
tests/qemu-iotests/testenv.py +0 -0
         self.init_directories()
         self.init_binaries()
Signature · 1 line
2.34.1

With regards,
Daniel

Signature · 3 lines
|: 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 :|
author
#2 lore raw
Quoted 31 lines · Daniel P. Berrangé
Quoted 6 lines · John Snow

If you invoke the check script from outside of the tests/qemu-iotests directory, the directories initialized as source_iotests and build_iotests will be incorrect.

We can use the location of the source file itself to be more accurate.

Review

Quoted 7 lines
---
 tests/qemu-iotests/testenv.py | 4 ++--
 1 file changed, 2 insertions(+), 2 deletions(-)
(quoted diff) +0 -0

b/tests/qemu-iotests/testenv.py

tests/qemu-iotests/testenv.py def __init__(self, imgfmt: str, imgproto: str,

Quoted 4 lines

index a864c74b123..9b0f01e84db 100644

tests/qemu-iotests/testenv.py +0 -0
@@ -217,10 +217,10 @@ def __init__(self, imgfmt: str, imgproto: str,

aiomode: str,

tests/qemu-iotests/testenv.py def __init__(self, imgfmt: str, imgproto: str, · line 217

Quoted 1 line
tests/qemu-iotests/testenv.py +0 -0
             self.build_iotests =

os.path.dirname(os.path.abspath(sys.argv[0]))

tests/qemu-iotests/testenv.py def __init__(self, imgfmt: str, imgproto: str, aiomode: str, · line 220

Quoted 4 lines
tests/qemu-iotests/testenv.py +1 -1
         else:
             # called from the source tree
-            self.source_iotests = os.getcwd()
+            self.source_iotests = str(Path(__file__, '..').resolve())

Path(__file__).parent

Quoted 2 lines
tests/qemu-iotests/testenv.py +0 -0
             self.build_iotests = self.source_iotests
 
Quoted 8 lines

tests/qemu-iotests/testenv.py def __init__(self, imgfmt: str, imgproto: str, · line 223

Quoted 2 lines
tests/qemu-iotests/testenv.py +1 -1
-        self.build_root = os.path.join(self.build_iotests, '..', '..')
+        self.build_root = str(Path(self.build_iotests,

'../..').resolve())

Path(self.build_iotests).parent.parent

to be portable

With windows? I think Path() is meant to be a fully portable class as-is, but I'll double-check my assumption. I use ".." elsewhere in code already checked in, so if it's a problem I ought to fix it everywhere.

author
#3 lore raw
Quoted 36 lines · John Snow
Quoted 32 lines · Daniel P. Berrangé
Quoted 17 lines · John Snow

If you invoke the check script from outside of the tests/qemu-iotests directory, the directories initialized as source_iotests and build_iotests will be incorrect.

We can use the location of the source file itself to be more accurate.

---
 tests/qemu-iotests/testenv.py | 4 ++--
 1 file changed, 2 insertions(+), 2 deletions(-)
tests/qemu-iotests/testenv.py +0 -0
index a864c74b123..9b0f01e84db 100644

tests/qemu-iotests/testenv.py def __init__(self, imgfmt: str, imgproto: str, aiomode: str, · line 220

Quoted 5 lines
tests/qemu-iotests/testenv.py +1 -1
@@ -217,10 +217,10 @@ def __init__(self, imgfmt: str, imgproto: str, aiomode: str,
             self.build_iotests = os.path.dirname(os.path.abspath(sys.argv[0]))
         else:
             # called from the source tree
-            self.source_iotests = os.getcwd()
+            self.source_iotests = str(Path(__file__, '..').resolve())

Path(__file__).parent

Quoted 4 lines
tests/qemu-iotests/testenv.py +1 -1
             self.build_iotests = self.source_iotests
 
-        self.build_root = os.path.join(self.build_iotests, '..', '..')
+        self.build_root = str(Path(self.build_iotests, '../..').resolve())
Quoted 6 lines
Quoted 3 lines

Path(self.build_iotests).parent.parent

to be portable

With windows? I think Path() is meant to be a fully portable class as-is, but I'll double-check my assumption. I use ".." elsewhere in code already checked in, so if it's a problem I ought to fix it everywhere.

Found a Windows box, it works there too. Good enough?

--js

#4 lore raw
Quoted 37 lines · John Snow
Quoted 36 lines · John Snow
Quoted 32 lines · Daniel P. Berrangé
Quoted 17 lines · John Snow

If you invoke the check script from outside of the tests/qemu-iotests directory, the directories initialized as source_iotests and build_iotests will be incorrect.

We can use the location of the source file itself to be more accurate.

---
 tests/qemu-iotests/testenv.py | 4 ++--
 1 file changed, 2 insertions(+), 2 deletions(-)
tests/qemu-iotests/testenv.py +0 -0
index a864c74b123..9b0f01e84db 100644

tests/qemu-iotests/testenv.py def __init__(self, imgfmt: str, imgproto: str, aiomode: str, · line 220

Quoted 5 lines
tests/qemu-iotests/testenv.py +1 -1
@@ -217,10 +217,10 @@ def __init__(self, imgfmt: str, imgproto: str, aiomode: str,
             self.build_iotests = os.path.dirname(os.path.abspath(sys.argv[0]))
         else:
             # called from the source tree
-            self.source_iotests = os.getcwd()
+            self.source_iotests = str(Path(__file__, '..').resolve())

Path(__file__).parent

Quoted 4 lines
tests/qemu-iotests/testenv.py +1 -1
             self.build_iotests = self.source_iotests
 
-        self.build_root = os.path.join(self.build_iotests, '..', '..')
+        self.build_root = str(Path(self.build_iotests, '../..').resolve())
Quoted 8 lines
Quoted 6 lines
Quoted 3 lines

Path(self.build_iotests).parent.parent

to be portable

With windows? I think Path() is meant to be a fully portable class as-is, but I'll double-check my assumption. I use ".." elsewhere in code already checked in, so if it's a problem I ought to fix it everywhere.

Found a Windows box, it works there too. Good enough?

I don't mind

With regards,
Daniel

Signature · 3 lines
|: 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 :|
#5 lore raw
In reply to John Snow

Am 26.05.2022 um 16:21 hat John Snow geschrieben:

Quoted 38 lines
Quoted 35 lines · Daniel P. Berrangé
Quoted 6 lines · John Snow

If you invoke the check script from outside of the tests/qemu-iotests directory, the directories initialized as source_iotests and build_iotests will be incorrect.

We can use the location of the source file itself to be more accurate.

Review

Quoted 7 lines
---
 tests/qemu-iotests/testenv.py | 4 ++--
 1 file changed, 2 insertions(+), 2 deletions(-)
(quoted diff) +0 -0

b/tests/qemu-iotests/testenv.py

tests/qemu-iotests/testenv.py def __init__(self, imgfmt: str, imgproto: str,

Quoted 4 lines

index a864c74b123..9b0f01e84db 100644

tests/qemu-iotests/testenv.py +0 -0
@@ -217,10 +217,10 @@ def __init__(self, imgfmt: str, imgproto: str,

aiomode: str,

tests/qemu-iotests/testenv.py def __init__(self, imgfmt: str, imgproto: str, · line 217

Quoted 1 line
tests/qemu-iotests/testenv.py +0 -0
             self.build_iotests =

os.path.dirname(os.path.abspath(sys.argv[0]))

tests/qemu-iotests/testenv.py def __init__(self, imgfmt: str, imgproto: str, aiomode: str, · line 220

Quoted 4 lines
tests/qemu-iotests/testenv.py +1 -1
         else:
             # called from the source tree
-            self.source_iotests = os.getcwd()
+            self.source_iotests = str(Path(__file__, '..').resolve())

Path(__file__).parent

tests/qemu-iotests/testenv.py def __init__(self, imgfmt: str, imgproto: str, aiomode: str,

Quoted 4 lines
tests/qemu-iotests/testenv.py +1 -1
             self.build_iotests = self.source_iotests
 
-        self.build_root = os.path.join(self.build_iotests, '..', '..')
+        self.build_root = str(Path(self.build_iotests,

'../..').resolve())

Quoted 8 lines
Quoted 4 lines

Path(self.build_iotests).parent.parent

to be portable

With windows? I think Path() is meant to be a fully portable class as-is, but I'll double-check my assumption. I use ".." elsewhere in code already checked in, so if it's a problem I ought to fix it everywhere.

I don't see any potential problem with the second hunk because we're dealing with the path of a directory there, but "regular_file.py/.." looks a bit fishy to me and doesn't work if you ask the kernel. Is this guaranteed to work in Python or is it an implementation detail of Path that may change?

Kevin

author
#6 lore raw
Quoted 51 lines · Kevin Wolf

Am 26.05.2022 um 16:21 hat John Snow geschrieben:

Quoted 9 lines
Quoted 6 lines · Daniel P. Berrangé
Quoted 5 lines · John Snow

If you invoke the check script from outside of the tests/qemu-iotests directory, the directories initialized as source_iotests and build_iotests will be incorrect.

We can use the location of the source file itself to be more

accurate.

Quoted 14 lines
Quoted 14 lines

Review

Quoted 8 lines
---
 tests/qemu-iotests/testenv.py | 4 ++--
 1 file changed, 2 insertions(+), 2 deletions(-)
(quoted diff) +0 -0

b/tests/qemu-iotests/testenv.py

tests/qemu-iotests/testenv.py def __init__(self, imgfmt: str, imgproto: str,

Quoted 4 lines

index a864c74b123..9b0f01e84db 100644

tests/qemu-iotests/testenv.py +0 -0
@@ -217,10 +217,10 @@ def __init__(self, imgfmt: str, imgproto: str,

aiomode: str,

Quoted 6 lines
Quoted 6 lines

tests/qemu-iotests/testenv.py def __init__(self, imgfmt: str, imgproto: str, · line 217

Quoted 1 line
tests/qemu-iotests/testenv.py +0 -0
             self.build_iotests =

os.path.dirname(os.path.abspath(sys.argv[0]))

Quoted 4 lines
tests/qemu-iotests/testenv.py +1 -1
         else:
             # called from the source tree
-            self.source_iotests = os.getcwd()
+            self.source_iotests = str(Path(__file__,

'..').resolve())

Quoted 6 lines
Quoted 6 lines

Path(__file__).parent

Quoted 3 lines
tests/qemu-iotests/testenv.py +0 -1
             self.build_iotests = self.source_iotests
 
-        self.build_root = os.path.join(self.build_iotests, '..',

'..')

Quoted 11 lines
Quoted 7 lines

tests/qemu-iotests/testenv.py def __init__(self, imgfmt: str, imgproto: str, · line 223

Quoted 1 line
tests/qemu-iotests/testenv.py +1 -0
+        self.build_root = str(Path(self.build_iotests,

'../..').resolve())

Path(self.build_iotests).parent.parent

to be portable

With windows? I think Path() is meant to be a fully portable class as-is, but I'll double-check my assumption. I use ".." elsewhere in code already checked in, so if it's a problem I ought to fix it everywhere.

Quoted 6 lines

I don't see any potential problem with the second hunk because we're dealing with the path of a directory there, but "regular_file.py/.." looks a bit fishy to me and doesn't work if you ask the kernel. Is this guaranteed to work in Python or is it an implementation detail of Path that may change?

... I apparently never hit send on this draft reply:

Good question, I don't know. I just know that when starting from __file__, it seems to work in that manner. I used that trick when I added the PYTHONPATH stuff directly into testenv a while back and never thought more of it.

If it makes people uneasy to look at, I can just use .parent for the Principle of Least Surprise.