]> git-server-git.apps.pok.os.sepia.ceph.com Git - ceph.git/commitdiff
qa: fix test_rbd_wnbd.py, properly retrieving the drive letter
authorLucian Petrut <lpetrut@cloudbasesolutions.com>
Wed, 21 Dec 2022 13:58:07 +0000 (15:58 +0200)
committerLucian Petrut <lpetrut@cloudbasesolutions.com>
Fri, 23 Dec 2022 15:55:25 +0000 (17:55 +0200)
Instead of trying to use the first partiton which may be reserved
by Windows, we'll fetch the first non-empty drive letter from
the disk that we've just mounted.

While at it, we're ensuring that the drive letter is actually a
letter and not a null character, which the Powershell command
returns in case of empty drive letters.

Signed-off-by: Lucian Petrut <lpetrut@cloudbasesolutions.com>
qa/workunits/windows/test_rbd_wnbd.py

index 092a8ae14891f4cc67e470369bfd83fc00fc9f19..c926b9c79992a9b9685caf1feee8114fca5e36ad 100644 (file)
@@ -360,11 +360,14 @@ class RbdImage(object):
         # Retrieve the drive letter.
         cmd = (
             "powershell.exe", "-command",
-            f"(Get-Partition -DiskNumber {self.disk_number})[0].DriveLetter")
+            f"(Get-Partition -DiskNumber {self.disk_number}"
+            " | ? { $_.DriveLetter }).DriveLetter")
         result = execute(*cmd)
 
+        # The PowerShell command will place a null character if no drive letter
+        # is available. For example, we can receive "\x00\r\n".
         self.drive_letter = result.stdout.decode().strip()
-        if len(self.drive_letter) != 1:
+        if not self.drive_letter.isalpha() or len(self.drive_letter) != 1:
             raise CephTestException(
                 "Invalid drive letter received: %s" % self.drive_letter)