[rhel6-branch 1/2] edd: do not traceback when can not find the respective pci device.

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



Resolves: rhbz#723344
---
 storage/devicelibs/edd.py            |   15 +++++++++------
 tests/mock/disk.py                   |    9 +++++++++
 tests/storage/devicelibs/edd_test.py |   17 +++++++++++++++--
 3 files changed, 33 insertions(+), 8 deletions(-)

diff --git a/storage/devicelibs/edd.py b/storage/devicelibs/edd.py
index 1ac40a6..9563af6 100644
--- a/storage/devicelibs/edd.py
+++ b/storage/devicelibs/edd.py
@@ -104,9 +104,12 @@ class EddMatcher(object):
                 'chan' : self.edd.channel,
                 'dev' : self.edd.ata_device
                 }
-            block_entries = os.listdir(path)
-            if len(block_entries) == 1:
-                name = block_entries[0]
+            if os.path.isdir(path):
+                block_entries = os.listdir(path)
+                if len(block_entries) == 1:
+                    name = block_entries[0]
+            else:
+                log.warning("edd: directory does not exist: %s" % path)
         elif self.edd.type == "SCSI":
             pattern = "/sys/devices/pci0000:00/0000:%(pci_dev)s/virtio*/block" % \
                 {'pci_dev' : self.edd.pci_dev}
@@ -157,7 +160,7 @@ def collect_mbrs(devices):
             mbrsig = struct.unpack('I', os.read(fd, 4))
             os.close(fd)
         except OSError as e:
-            log.warning("Error reading mbrsig from disk %s: %s" %
+            log.warning("edd: error reading mbrsig from disk %s: %s" %
                         (dev.name, str(e)))
             continue
 
@@ -202,11 +205,11 @@ def get_edd_dict(devices):
         name = matcher.devname_from_pci_dev()
         # next try to compare mbr signatures
         if name:
-            log.debug("matched 0x%x to %s using pci_dev" % (edd_number, name))
+            log.debug("edd: matched 0x%x to %s using pci_dev" % (edd_number, name))
         else:
             name = matcher.match_via_mbrsigs(mbr_dict)
             if name:
-                log.info("matched 0x%x to %s using MBR sig" % (edd_number, name))
+                log.info("edd: matched 0x%x to %s using MBR sig" % (edd_number, name))
 
         if name:
             old_edd_number = edd_dict.get(name)
diff --git a/tests/mock/disk.py b/tests/mock/disk.py
index 424e08c..fbd6181 100644
--- a/tests/mock/disk.py
+++ b/tests/mock/disk.py
@@ -25,6 +25,7 @@ _orig_glob_glob = glob.glob
 _orig_open = open
 _orig_os_listdir = os.listdir
 _orig_os_path_exists = os.path.exists
+_orig_os_path_isdir = os.path.isdir
 
 class DiskIO(object):
     """Simple object to simplify mocking of file operations in Mock
@@ -117,6 +118,12 @@ class DiskIO(object):
         path = os.path.join(self._pwd, path)
         return self.fs.has_key(path)
 
+    def os_path_isdir(self, path):
+        if not path.endswith("/"):
+            path += "/"
+        path += "*"
+        return len(fnmatch.filter(self.fs.keys(), path)) > 0
+
     def os_remove(self, path):
         path = os.path.join(self._pwd, path)
         try:
@@ -137,6 +144,7 @@ class DiskIO(object):
         module.glob.glob = self.glob_glob
         module.os.listdir = self.os_listdir
         module.os.path.exists = self.os_path_exists
+        module.os.path.isdir = self.os_path_isdir
 
     @staticmethod
     def restore_module(module):
@@ -144,3 +152,4 @@ class DiskIO(object):
         module.glob.glob = _orig_glob_glob
         module.os.listdir = _orig_os_listdir
         module.os.path.exists = _orig_os_path_exists
+        module.os.path.isdir = _orig_os_path_isdir
diff --git a/tests/storage/devicelibs/edd_test.py b/tests/storage/devicelibs/edd_test.py
index ab87307..e4cf09b 100644
--- a/tests/storage/devicelibs/edd_test.py
+++ b/tests/storage/devicelibs/edd_test.py
@@ -66,6 +66,15 @@ class EddTestCase(mock.TestCase):
         path = analyzer.devname_from_pci_dev()
         self.assertEqual(path, "vda")
 
+    def test_bad_device_path(self):
+        from storage.devicelibs import edd
+        fs = EddTestFS(edd).sda_vda_no_pcidev()
+        edd_dict = edd.collect_edd_data()
+
+        analyzer = edd.EddMatcher(edd_dict[0x80])
+        path = analyzer.devname_from_pci_dev()
+        self.assertEqual(path, None)
+
     def test_get_edd_dict_1(self):
         """ Test get_edd_dict()'s pci_dev matching. """
         from storage.devicelibs import edd
@@ -85,8 +94,6 @@ class EddTestCase(mock.TestCase):
                          {'sda' : 0x80,
                           'vda' : 0x81})
 
-
-
 class EddTestFS(object):
     def __init__(self, target_module):
         self.fs = mock.DiskIO()
@@ -119,6 +126,12 @@ class EddTestFS(object):
 
         return self.fs
 
+    def sda_vda_no_pcidev(self):
+        self.sda_vda()
+        entries = [e for e in self.fs.fs if e.startswith("/sys/devices/pci")]
+        map(self.fs.os_remove, entries)
+        return self.fs
+
     def vda_vdb(self):
         self.fs["/sys/firmware/edd/int13_dev80"] = self.fs.Dir()
         self.fs["/sys/firmware/edd/int13_dev80/host_bus"] = "PCI 	00:05.0  channel: 0\n"
-- 
1.7.6

_______________________________________________
Anaconda-devel-list mailing list
Anaconda-devel-list@xxxxxxxxxx
https://www.redhat.com/mailman/listinfo/anaconda-devel-list


[Index of Archives]     [Kickstart]     [Fedora Users]     [Fedora Legacy List]     [Fedora Maintainers]     [Fedora Desktop]     [Fedora SELinux]     [Big List of Linux Books]     [Yosemite News]     [Yosemite Photos]     [KDE Users]     [Fedora Tools]
  Powered by Linux