neil / rpms / udisks2

Forked from rpms/udisks2 a year ago
Clone
Tomas Bzatek 9e81bb
From 1358d1e5208d71d5a70f17a242eda00f079a9d0b Mon Sep 17 00:00:00 2001
Tomas Bzatek 9e81bb
From: Tomas Bzatek <tbzatek@redhat.com>
Tomas Bzatek 9e81bb
Date: Thu, 22 Apr 2021 18:20:48 +0200
Tomas Bzatek 9e81bb
Subject: [PATCH 2/2] tests: Handle missing /dev/disk/by-path gracefully
Tomas Bzatek 9e81bb
Tomas Bzatek 9e81bb
Limited testing environments may not have this path always available.
Tomas Bzatek 9e81bb
---
Tomas Bzatek 9e81bb
 src/tests/dbus-tests/test_drive_ata.py | 19 +++++++++++--------
Tomas Bzatek 9e81bb
 1 file changed, 11 insertions(+), 8 deletions(-)
Tomas Bzatek 9e81bb
Tomas Bzatek 9e81bb
diff --git a/src/tests/dbus-tests/test_drive_ata.py b/src/tests/dbus-tests/test_drive_ata.py
Tomas Bzatek 9e81bb
index e91bd02f..37740c60 100644
Tomas Bzatek 9e81bb
--- a/src/tests/dbus-tests/test_drive_ata.py
Tomas Bzatek 9e81bb
+++ b/src/tests/dbus-tests/test_drive_ata.py
Tomas Bzatek 9e81bb
@@ -20,14 +20,17 @@ DISK_PATH = "/dev/disk/by-path/"
Tomas Bzatek 9e81bb
 
Tomas Bzatek 9e81bb
 def _get_sata_disks():
Tomas Bzatek 9e81bb
     sata_disks = []
Tomas Bzatek 9e81bb
-    by_path = os.listdir(DISK_PATH)
Tomas Bzatek 9e81bb
-    for dev in by_path:
Tomas Bzatek 9e81bb
-        if "ata" in dev and "part" not in dev:
Tomas Bzatek 9e81bb
-            path = os.path.realpath(os.path.join(DISK_PATH, dev))
Tomas Bzatek 9e81bb
-            name = os.path.basename(path)
Tomas Bzatek 9e81bb
-            if name.startswith("sd"):
Tomas Bzatek 9e81bb
-                # ignore devices like CD drives etc.
Tomas Bzatek 9e81bb
-                sata_disks.append(name)
Tomas Bzatek 9e81bb
+    try:
Tomas Bzatek 9e81bb
+        by_path = os.listdir(DISK_PATH)
Tomas Bzatek 9e81bb
+        for dev in by_path:
Tomas Bzatek 9e81bb
+            if "ata" in dev and "part" not in dev:
Tomas Bzatek 9e81bb
+                path = os.path.realpath(os.path.join(DISK_PATH, dev))
Tomas Bzatek 9e81bb
+                name = os.path.basename(path)
Tomas Bzatek 9e81bb
+                if name.startswith("sd"):
Tomas Bzatek 9e81bb
+                    # ignore devices like CD drives etc.
Tomas Bzatek 9e81bb
+                    sata_disks.append(name)
Tomas Bzatek 9e81bb
+    except:
Tomas Bzatek 9e81bb
+        pass
Tomas Bzatek 9e81bb
     return sata_disks
Tomas Bzatek 9e81bb
 
Tomas Bzatek 9e81bb
 
Tomas Bzatek 9e81bb
-- 
Tomas Bzatek 9e81bb
2.30.2
Tomas Bzatek 9e81bb