[master 8/13] edd: Eradicate fsroot entirely.

vathpela installerbot-noreply at redhat.com
Fri Nov 6 20:00:37 UTC 2015


From: Peter Jones <pjones at redhat.com>

This gets rid of EddEntry._sysfsroot and the sysfsroot property
entirely, because we don't need these at all any more with our Path
object.

This also tries to limit how much we manually interpolate the fsroot.

Signed-off-by: Peter Jones <pjones at redhat.com>
---
 blivet/devicelibs/edd.py          | 255 +++++++++++++++++++++-----------------
 tests/devicelibs_test/edd_test.py |  55 ++++----
 2 files changed, 162 insertions(+), 148 deletions(-)

diff --git a/blivet/devicelibs/edd.py b/blivet/devicelibs/edd.py
index 73c7d22..b05b5d5 100644
--- a/blivet/devicelibs/edd.py
+++ b/blivet/devicelibs/edd.py
@@ -23,7 +23,6 @@
 #            Ales Kozumplik <akozumpl at redhat.com>
 #
 
-import glob
 import logging
 import os
 import re
@@ -61,18 +60,17 @@
 # anchoring tab that would go between them...
 re_interface_unknown = re.compile(r'^(\S*)\s*unknown: (\S*) (\S*)\s*$')
 
-fsroot = ""
-
-
 class EddEntry(object):
 
     """ This object merely collects what the /sys/firmware/edd/* entries can
         provide.
     """
 
-    def __init__(self, sysfspath):
+    def __init__(self, sysfspath, root=None):
+        self.root = util.Path(root or "", root="")
+
         # some misc data from various files...
-        self._sysfspath = sysfspath
+        self.sysfspath = util.Path(sysfspath, root=self.root)
         """ sysfspath is the path we're probing
         """
 
@@ -85,7 +83,7 @@ def __init__(self, sysfspath):
             that this is a particular device.  Used for logging later.
         """
 
-        self.version = util.get_sysfs_attr(self.sysfspath, "version", root=fsroot)
+        self.version = util.get_sysfs_attr(self.sysfspath, "version")
         """ The edd version this entry claims conformance with, from
             /sys/firmware/edd/int13_devXX/version """
 
@@ -194,14 +192,10 @@ def __init__(self, sysfspath):
 
         self.load()
 
-    @property
-    def sysfspath(self):
-        return "%s/%s" % (fsroot, self._sysfspath[1:])
-
     def _fmt(self, line_pad, separator):
-        s = "%(t)spath: %(_sysfspath)s version: %(version)s %(nl)s" \
-            "mbr_signature: %(mbr_sig)s sectors: %(sectors)s"
-        if self.type is not None:
+        s = "%(t)spath: %(sysfspath)s version: %(version)s %(nl)s" \
+            "%(t)smbr_signature: %(mbr_sig)s sectors: %(sectors)s"
+        if self.type != None:
             s += " %(type)s"
         if self.sysfslink is not None:
             s += "%(nl)s%(t)ssysfs pci path: %(sysfslink)s"
@@ -231,12 +225,41 @@ def _fmt(self, line_pad, separator):
             s += "%(nl)s%(t)ssas_address: %(sas_address)s sas_lun: %(sas_lun)s"
 
         d = copy.copy(self.__dict__)
-        d['_sysfspath'] = self._sysfspath
-        d['t'] = line_pad
-        d['nl'] = separator
+        d['t']=line_pad
+        d['nl']=separator
 
         return s % d
 
+    def __gt__(self, other):
+        if not isinstance(self, other.__class__) and \
+           not isinstance(other, self.__class__):
+            return self.__class__ > other.__class__
+        ldict = copy.copy(self.__dict__)
+        rdict = copy.copy(other.__dict__)
+        del ldict["root"]
+        del rdict["root"]
+        return ldict > rdict
+
+    def __eq__(self, other):
+        if not isinstance(self, other.__class__) and \
+           not isinstance(other, self.__class__):
+            return self.__class__ == other.__class__
+        ldict = copy.copy(self.__dict__)
+        rdict = copy.copy(other.__dict__)
+        del ldict["root"]
+        del rdict["root"]
+        return ldict == rdict
+
+    def __lt__(self, other):
+        if not isinstance(self, other.__class__) and \
+           not isinstance(other, self.__class__):
+            return self.__class__ < other.__class__
+        ldict = copy.copy(self.__dict__)
+        rdict = copy.copy(other.__dict__)
+        del ldict["root"]
+        del rdict["root"]
+        return ldict < rdict
+
     def __str__(self):
         return self._fmt('\t', '\n')
 
@@ -244,7 +267,7 @@ def __repr__(self):
         return "<EddEntry%s>" % (self._fmt(' ', ''),)
 
     def load(self):
-        interface = util.get_sysfs_attr(self.sysfspath, "interface", root=fsroot)
+        interface = util.get_sysfs_attr(self.sysfspath, "interface")
         # save this so we can log it from the matcher.
         self.interface = interface
         if interface:
@@ -296,22 +319,22 @@ def load(self):
                         self.sas_lun = int(unknown_match.group(2), base=16)
                     else:
                         log.warning("edd: can not match interface for %s: %s",
-                                    self._sysfspath, interface)
+                                    self.sysfspath, interface)
                 else:
                     log.warning("edd: can not match interface for %s: %s",
-                                self._sysfspath, interface)
+                                self.sysfspath, interface)
             except AttributeError as e:
                 if e.args == "'NoneType' object has no attribute 'group'":
                     log.warning("edd: can not match interface for %s: %s",
-                                self._sysfspath, interface)
+                                self.sysfspath, interface)
                 else:
                     raise e
 
-        self.mbr_sig = util.get_sysfs_attr(self.sysfspath, "mbr_signature", root=fsroot)
-        sectors = util.get_sysfs_attr(self.sysfspath, "sectors", root=fsroot)
+        self.mbr_sig = util.get_sysfs_attr(self.sysfspath, "mbr_signature")
+        sectors = util.get_sysfs_attr(self.sysfspath, "sectors")
         if sectors:
             self.sectors = int(sectors)
-        hbus = util.get_sysfs_attr(self.sysfspath, "host_bus", root=fsroot)
+        hbus = util.get_sysfs_attr(self.sysfspath, "host_bus")
         if hbus:
             match = re_host_bus_pci.match(hbus)
             if match:
@@ -320,7 +343,7 @@ def load(self):
                 self.channel = int(match.group(3))
             else:
                 log.warning("edd: can not match host_bus for %s: %s",
-                            self._sysfspath, hbus)
+                            self.sysfspath, hbus)
 
 
 class EddMatcher(object):
@@ -329,21 +352,22 @@ class EddMatcher(object):
 
         Assuming, heuristic analysis and guessing hapens here.
     """
-
-    def __init__(self, edd_entry):
+    def __init__(self, edd_entry, root=None):
         self.edd = edd_entry
+        self.root = root
 
     def devname_from_ata_pci_dev(self):
-        pattern = '%s/sys/block/*' % (fsroot,)
-        testdata_log.debug("sysfs glob: %s", pattern[len(fsroot):])
-        for path in glob.iglob(pattern):
-            testdata_log.debug("sysfs glob match: %s", path[len(fsroot):])
-            link = os.readlink(path)
-            testdata_log.debug("sysfs link: \"%s\" -> \"%s\"",
-                               path[len(fsroot):], link)
+        pattern = util.Path('/sys/block/*', root=self.root)
+        testdata_log.debug("sysfs glob: %s", pattern)
+        for path in pattern.glob():
+            testdata_log.debug("sysfs glob match: %s", path)
+            emptyslash = util.Path("/", root=self.root)
+            path = util.Path(path, root=self.root)
+            link = util.sysfs_readlink(path=emptyslash, link=path)
+            testdata_log.debug("sysfs link: \"%s\" -> \"%s\"", path, link)
             # just add /sys/block/ at the beginning so it's always valid
             # paths in the filesystem...
-            components = ['%s/sys/block' % (fsroot,)] + link.split('/')
+            components = ['/sys/block'] + link.split('/')
             if len(components) != 11:
                 continue
             # ATA and SATA paths look like:
@@ -376,8 +400,9 @@ def devname_from_ata_pci_dev(self):
             ata_port = components[5]
             ata_port_idx = int(components[5][3:])
 
-            fn = components[0:6] + ['ata_port', ata_port]
-            port_no = int(util.get_sysfs_attr(os.path.join(*fn), 'port_no', root=fsroot))
+            fn = util.Path(util.join_paths(components[0:6] \
+                                           + ['ata_port', ata_port]), root=self.root)
+            port_no = int(util.get_sysfs_attr(fn, 'port_no'))
 
             if self.edd.type == "ATA":
                 # On ATA, port_no is kernel's ata_port->local_port_no, which
@@ -391,20 +416,20 @@ def devname_from_ata_pci_dev(self):
                 if port_no != self.edd.ata_device + 1:
                     continue
 
-            fn = components[0:6] + ['link%d' % (ata_port_idx,), ]
-            exp = [r'^'] + fn + [r'dev%d\.(\d+)(\.(\d+)){0,1}$' % (ata_port_idx,)]
-            exp = os.path.join(*exp)
+            fn = components[0:6] + ['link%d' % (ata_port_idx,),]
+            exp = [r'.*']+fn+[r'dev%d\.(\d+)(\.(\d+)){0,1}$' % (ata_port_idx,)]
+            exp = util.join_paths(exp)
             expmatcher = re.compile(exp)
-            pmp_glob = fn + ['dev%d.*.*' % (ata_port_idx,)]
-            pmp_glob = os.path.join(*pmp_glob)
-            dev_glob = fn + ['dev%d.*' % (ata_port_idx,)]
-            dev_glob = os.path.join(*dev_glob)
-            for ataglob in [pmp_glob, dev_glob]:
+
+            pmp = util.join_paths(fn + ['dev%d.*.*' % (ata_port_idx,)])
+            pmp = util.Path(pmp, root=self.root)
+            dev = util.join_paths(fn + ['dev%d.*' % (ata_port_idx,)])
+            dev = util.Path(dev, root=self.root)
+            for ataglob in [pmp, dev]:
                 testdata_log.debug("sysfs glob: %s", ataglob)
-                for atapath in glob.glob(ataglob):
-                    testdata_log.debug("sysfs glob match: %s",
-                                       atapath[len(fsroot):])
-                    match = expmatcher.match(atapath)
+                for atapath in ataglob.glob():
+                    testdata_log.debug("sysfs glob match: %s", atapath)
+                    match = expmatcher.match(atapath.ondisk)
                     if match is None:
                         continue
 
@@ -418,42 +443,43 @@ def devname_from_ata_pci_dev(self):
                         channel = int(match.group(1))
                         if (self.edd.channel == 255 and channel == 0) or \
                                 (self.edd.channel == channel):
-                            self.edd.sysfslink = link
-                            return path[len(fsroot):].split('/')[-1]
+                            self.edd.sysfslink = util.Path(link, root=self.root)
+                            return path.split('/')[-1]
                     else:
                         pmp = int(match.group(1))
                         if self.edd.ata_pmp == pmp:
-                            self.edd.sysfslink = link
-                            return path[len(fsroot):].split('/')[-1]
+                            self.edd.sysfslink = util.Path(link, root=self.root)
+                            return path.split('/')[-1]
+
         return None
 
     def devname_from_scsi_pci_dev(self):
         name = None
-        tmpl0 = "%(fsroot)s/sys/devices/pci0000:00/0000:%(pci_dev)s/" \
+        tmpl0 = "/sys/devices/pci0000:00/0000:%(pci_dev)s/" \
                 "host%(chan)d/target%(chan)d:0:%(dev)d/" \
                 "%(chan)d:0:%(dev)d:%(lun)d/block"
         # channel appears to be a total like on VirtIO SCSI devices.
-        tmpl1 = "%(fsroot)s/sys/devices/pci0000:00/0000:%(pci_dev)s/virtio*/" \
+        tmpl1 = "/sys/devices/pci0000:00/0000:%(pci_dev)s/virtio*/" \
                 "host*/target*:0:%(dev)d/*:0:%(dev)d:%(lun)d/block"
         args = {
-            'fsroot': fsroot,
-            'pci_dev': self.edd.pci_dev,
-            'chan': self.edd.channel,
-            'dev': self.edd.scsi_id,
-            'lun': self.edd.scsi_lun,
+            'pci_dev' : self.edd.pci_dev,
+            'chan' : self.edd.channel,
+            'dev' : self.edd.scsi_id,
+            'lun' : self.edd.scsi_lun,
         }
-        path = tmpl0 % args
-        pattern = tmpl1 % args
-        testdata_log.debug("sysfs glob: %s", pattern[len(fsroot):])
-        matching_paths = glob.glob(pattern)
+        path = util.Path(tmpl0 % args, root=self.root)
+        pattern = util.Path(tmpl1 % args, root=self.root)
+        testdata_log.debug("sysfs glob: %s", pattern)
+        matching_paths = list(pattern.glob())
         for mp in matching_paths:
-            testdata_log.debug("sysfs glob match: %s", mp[len(fsroot):])
-        if os.path.isdir(path):
-            block_entries = os.listdir(path)
+            testdata_log.debug("sysfs glob match: %s", mp)
+        if os.path.isdir(path.ondisk):
+            block_entries = os.listdir(path.ondisk)
             if len(block_entries) == 1:
-                self.edd.sysfslink = "..%s/%s" % (
-                    path[len(fsroot) + len("/sys"):],
-                    block_entries[0])
+                entry = util.Path(block_entries[0], root=self.root)
+                systop = util.Path(path.path, root=path.root+"/sys/")
+                link = util.Path("../", root=self.root) + systop.path + entry
+                self.edd.sysfslink = link
                 name = block_entries[0]
         elif len(matching_paths) > 1:
             log.error("edd: Too many devices match for pci dev %s channel %s "
@@ -461,12 +487,14 @@ def devname_from_scsi_pci_dev(self):
                       self.edd.scsi_id, self.edd.scsi_lun)
             for matching_path in matching_paths:
                 log.error("edd:   %s", matching_path)
-        elif len(matching_paths) == 1 and os.path.exists(matching_paths[0]):
-            block_entries = os.listdir(matching_paths[0])
+        elif len(matching_paths) == 1 and \
+                os.path.exists(matching_paths[0].ondisk):
+            block_entries = os.listdir(matching_paths[0].ondisk)
             if len(block_entries) == 1:
-                self.edd.sysfslink = "..%s/%s" % (
-                    matching_paths[0][len(fsroot) + len("/sys"):],
-                    block_entries[0])
+                entry = util.Path(block_entries[0], root=self.root)
+                systop = util.Path(path.ondisk, root=path.root+"/sys/")
+                link = util.Path("../", root=self.root) + systop.path + entry
+                self.edd.sysfslink = link
                 name = block_entries[0]
         else:
             log.warning("edd: Could not find SCSI device for pci dev %s "
@@ -475,27 +503,26 @@ def devname_from_scsi_pci_dev(self):
         return name
 
     def devname_from_virt_pci_dev(self):
-        args = {
-            'fsroot': fsroot,
-            'pci_dev': self.edd.pci_dev
-        }
-        pattern = "%(fsroot)s/sys/devices/pci0000:00/0000:%(pci_dev)s/virtio*"
-        matching_paths = tuple(glob.glob(pattern % args))
-        testdata_log.debug("sysfs glob: %s",
-                           (pattern % args)[len(fsroot):])
+        pattern = util.Path("/sys/devices/pci0000:00/0000:%s/virtio*" %
+                            (self.edd.pci_dev,), root=self.root)
+        testdata_log.debug("sysfs glob: %s", pattern)
+        matching_paths = tuple(pattern.glob())
         for mp in matching_paths:
-            testdata_log.debug("sysfs glob match: %s", mp[len(fsroot):])
+            testdata_log.debug("sysfs glob match: %s", mp)
 
         if len(matching_paths) == 1 and os.path.exists(matching_paths[0]):
             # Normal VirtIO devices just have the block link right there...
-            newpath = os.path.join(matching_paths[0], 'block')
+            newpath = util.Path(matching_paths[0], root=self.root) + "/block"
             block_entries = []
             if os.path.exists(newpath):
                 block_entries = os.listdir(newpath)
             if len(block_entries) == 1:
-                self.edd.sysfslink = "..%s/%s" % (
-                    matching_paths[0][len(fsroot) + len("/sys"):],
-                    block_entries[0])
+                systop = util.Path(matching_paths[0], root=self.root+"/sys/")
+                entry = util.Path(block_entries[0], root=self.root)
+                link = util.Path("..", root=self.root) \
+                    + systop.path \
+                    + block_entries[0]
+                self.edd.sysfslink = link
                 return block_entries[0]
             else:
                 # Virtio SCSI looks like scsi but with a virtio%d/ stuck in
@@ -512,7 +539,7 @@ def devname_from_pci_dev(self):
         unsupported = ("ATAPI", "USB", "1394", "I2O", "RAID", "FIBRE", "SAS")
         if self.edd.type in unsupported:
             log.warning("edd: interface type %s is not implemented (%s)",
-                        self.edd.type, self.edd._sysfspath)
+                        self.edd.type, self.edd.sysfspath)
             log.warning("edd: interface details: %s", self.edd.interface)
         if self.edd.type in ("ATA", "SATA") and \
                 self.edd.ata_device is not None:
@@ -520,11 +547,11 @@ def devname_from_pci_dev(self):
         elif self.edd.type == "SCSI":
             name = self.devname_from_scsi_pci_dev()
         if self.edd.sysfslink:
-            path = "/".join([fsroot, "sys/block", self.edd.sysfslink,
-                             "device"])
-            link = os.readlink(path)
-            testdata_log.debug("sysfs link: \"%s\" -> \"%s\"",
-                               path[len(fsroot):], link)
+            path = util.Path("/sys/block/", root=self.root) \
+                + self.edd.sysfslink \
+                + "/device"
+            link = os.readlink(path.ondisk)
+            testdata_log.debug("sysfs link: \"%s\" -> \"%s\"", path, link)
 
         return name
 
@@ -534,29 +561,26 @@ def match_via_mbrsigs(self, mbr_dict):
             This will obviously fail for a fresh drive/image, but in extreme
             cases can also show false positives for randomly matching data.
         """
-        sysblock = "%s/%s" % (fsroot, "/sys/block")
+        sysblock=util.Path("/sys/block/", root=self.root)
         for (name, mbr_sig) in mbr_dict.items():
             if mbr_sig == self.edd.mbr_sig:
-                self.edd.sysfslink = util.sysfs_readlink(sysblock, link=name,
-                                                         root=fsroot)
+                self.edd.sysfslink = util.sysfs_readlink(sysblock, link=name)
                 return name
         return None
 
-
-def collect_edd_data():
+def collect_edd_data(root=None):
     edd_data_dict = {}
-    globstr = os.path.join(fsroot, "sys/firmware/edd/int13_dev*")
-    testdata_log.debug("sysfs glob: %s", globstr[len(fsroot):])
-    for path in glob.glob(globstr):
-        testdata_log.debug("sysfs glob match: %s", path[len(fsroot):])
+    globstr = util.Path("/sys/firmware/edd/int13_dev*/", root=root)
+    testdata_log.debug("sysfs glob: %s", globstr)
+    for path in globstr.glob():
+        testdata_log.debug("sysfs glob match: %s", path)
         match = re_bios_device_number.match(path)
         biosdev = int("0x%s" % (match.group(1),), base=16)
-        log.debug("edd: found device 0x%x at %s", biosdev, path[len(fsroot):])
-        edd_data_dict[biosdev] = EddEntry(path[len(fsroot):])
+        log.debug("edd: found device 0x%x at %s", biosdev, path)
+        edd_data_dict[biosdev] = EddEntry(path, root=root)
     return edd_data_dict
 
-
-def collect_mbrs(devices):
+def collect_mbrs(devices, root=None):
     """ Read MBR signatures from devices.
 
         Returns a dict mapping device names to their MBR signatures. It is not
@@ -565,10 +589,8 @@ def collect_mbrs(devices):
     mbr_dict = {}
     for dev in devices:
         try:
-            path = dev.name.split('/')
-            path = os.path.join("dev", *path)
-            path = "%s/%s" % (fsroot, path)
-            fd = util.eintr_retry_call(os.open, path, os.O_RDONLY)
+            path = util.Path("/dev", root=root) + dev.name
+            fd = util.eintr_retry_call(os.open, path.ondisk, os.O_RDONLY)
             # The signature is the unsigned integer at byte 440:
             os.lseek(fd, 440, 0)
             data = util.eintr_retry_call(os.read, fd, 4)
@@ -601,8 +623,7 @@ def collect_mbrs(devices):
     log.info("edd: collected mbr signatures: %s", mbr_dict)
     return mbr_dict
 
-
-def get_edd_dict(devices):
+def get_edd_dict(devices, root=None):
     """ Generates the 'device name' -> 'edd number' mapping.
 
         The EDD kernel module that exposes /sys/firmware/edd is thoroughly
@@ -616,14 +637,14 @@ def get_edd_dict(devices):
         of 'mbr_signature' to a real MBR signature found on the existing block
         devices.
     """
-    mbr_dict = collect_mbrs(devices)
-    edd_entries_dict = collect_edd_data()
+    mbr_dict = collect_mbrs(devices, root=root)
+    edd_entries_dict = collect_edd_data(root=root)
     edd_dict = {}
     for (edd_number, edd_entry) in edd_entries_dict.items():
-        matcher = EddMatcher(edd_entry)
+        matcher = EddMatcher(edd_entry, root=root)
         # first try to match through the pci dev etc.
         name = matcher.devname_from_pci_dev()
-        log.debug("edd: data extracted from 0x%x:\n%s", edd_number, edd_entry)
+        log.debug("edd: data extracted from 0x%x:%r", edd_number, edd_entry)
         if name:
             log.info("edd: matched 0x%x to %s using PCI dev", edd_number, name)
         # next try to compare mbr signatures
diff --git a/tests/devicelibs_test/edd_test.py b/tests/devicelibs_test/edd_test.py
index cbcc483..50fb4a4 100644
--- a/tests/devicelibs_test/edd_test.py
+++ b/tests/devicelibs_test/edd_test.py
@@ -22,23 +22,12 @@ def __init__(self, sysfspath, **kw):
         for (name, value) in kw.items():
             self.__dict__[name] = value
 
-    @property
-    def sysfspath(self):
-        return "%s/%s" % (edd.fsroot, self._sysfspath[1:])
-
     def load(self):
         pass
 
     def __repr__(self):
         return "<FakeEddEntry%s>" % (self._fmt(' ', ''),)
 
-    def __lt__(self, other):
-        return self.__dict__ < other.__dict__
-
-    def __eq__(self, other):
-        return self.__dict__ == other.__dict__
-
-
 class EddTestCase(unittest.TestCase):
 
     def __init__(self, *args, **kwds):
@@ -106,12 +95,18 @@ def check(left, right_object):
         check(warnings, edd.log.warning)
         check(errors, edd.log.error)
 
-    def _set_fs_root(self, edd_module, fsroot):
-        if fsroot is None:
-            edd_module.fsroot = ""
+    def root(self, name):
+        if name is None:
+            return ""
         else:
-            dirname = os.path.dirname(inspect.getfile(edd_module))
-            edd_module.fsroot = os.path.join(dirname, "../../tests/devicelibs_test/edd_data/", fsroot)
+            if name.endswith("/"):
+                name = name[:-1]
+            if name.startswith("/"):
+                name = name[1:]
+            dirname = os.path.dirname(inspect.getfile(edd))
+            return os.path.join(dirname,
+                                "../../tests/devicelibs_test/edd_data/",
+                                name)
 
     def debug(self, *args):
         fmt = "edd_test: "
@@ -122,7 +117,6 @@ def debug(self, *args):
 
     def test_collect_edd_data_sata_usb(self):
         # test with sata sda, usb sdb
-        self._set_fs_root(edd, "sata_usb")
         self._edd_logger.debug("starting test %s", self._testMethodName)
         edd.testdata_log.debug("starting test %s", self._testMethodName)
         fakeedd = {
@@ -130,22 +124,22 @@ def test_collect_edd_data_sata_usb(self):
                                sectors=312581808, host_bus="PCI", type="SATA",
                                pci_dev="00:1f.2", channel=255, ata_device=1,
                                interface="SATA    \tdevice: 1",
-                               sysfspath="/sys/firmware/edd/int13_dev80"),
+                               sysfspath="/sys/firmware/edd/int13_dev80/"),
             0x81: FakeEddEntry(version="0x21", mbr_sig="0x96a20d28",
                                sectors=31293440, host_bus="PCI", type="USB",
                                pci_dev="ff:ff.255", channel=255,
                                usb_serial=0x30302e31,
                                interface="USB     \tserial_number: 30302e31",
-                               sysfspath="/sys/firmware/edd/int13_dev81"),
+                               sysfspath="/sys/firmware/edd/int13_dev81/"),
         }
 
-        edd_dict = edd.collect_edd_data()
+        edd_dict = edd.collect_edd_data(root=self.root("sata_usb"))
         self.debug('edd_dict: %s', edd_dict)
         debugs = [
             ("edd: found device 0x%x at %s", 0x80,
-             '/sys/firmware/edd/int13_dev80'),
+             '/sys/firmware/edd/int13_dev80/'),
             ("edd: found device 0x%x at %s", 0x81,
-             '/sys/firmware/edd/int13_dev81'),
+             '/sys/firmware/edd/int13_dev81/'),
         ]
         lib.assertVerboseEqual(len(edd_dict), 2)
         lib.assertVerboseEqual(fakeedd[0x80], edd_dict[0x80])
@@ -154,7 +148,6 @@ def test_collect_edd_data_sata_usb(self):
 
     def test_get_edd_dict_sata_usb(self):
         # test with sata sda, usb sdb
-        self._set_fs_root(edd, "sata_usb")
         self._edd_logger.debug("starting test %s", self._testMethodName)
         edd.testdata_log.debug("starting test %s", self._testMethodName)
         devices = (FakeDevice("sda"),
@@ -165,7 +158,7 @@ def test_get_edd_dict_sata_usb(self):
                                sectors=312581808, host_bus="PCI", type="SATA",
                                pci_dev="00:1f.2", channel=255, ata_device=1,
                                interface="SATA    \tdevice: 1",
-                               sysfspath="/sys/firmware/edd/int13_dev80",
+                               sysfspath="/sys/firmware/edd/int13_dev80/",
                                sysfslink="../devices/pci0000:00/0000:00:1f.2/"
                                "ata2/host1/target1:0:0/1:0:0:0/block/sda"),
             0x81: FakeEddEntry(version="0x21", mbr_sig="0x96a20d28",
@@ -173,24 +166,24 @@ def test_get_edd_dict_sata_usb(self):
                                pci_dev="ff:ff.255", channel=255,
                                usb_serial=0x30302e31,
                                interface="USB     \tserial_number: 30302e31",
-                               sysfspath="/sys/firmware/edd/int13_dev81",
+                               sysfspath="/sys/firmware/edd/int13_dev81/",
                                sysfslink="../devices/pci0000:00/0000:00:1d.0/"
                                "usb4/4-1/4-1.2/4-1.2:1.0/host6/target6:0:0/"
                                "6:0:0:0/block/sdb"),
         }
 
-        edd_dict = edd.get_edd_dict(devices)
+        edd_dict = edd.get_edd_dict(devices, root=self.root("sata_usb"))
         self.debug('edd_dict: %s', edd_dict)
         lib.assertVerboseEqual(len(edd_dict), 2)
         lib.assertVerboseEqual(edd_dict["sda"], 0x80)
         lib.assertVerboseEqual(edd_dict["sdb"], 0x81)
         debugs = [
-            ("edd: data extracted from 0x%x:\n%s", 0x80, fakeedd[0x80]),
-            ("edd: data extracted from 0x%x:\n%s", 0x81, fakeedd[0x81]),
+            ("edd: data extracted from 0x%x:%r", 0x80, fakeedd[0x80]),
+            ("edd: data extracted from 0x%x:%r", 0x81, fakeedd[0x81]),
             ("edd: found device 0x%x at %s", 0x80,
-             '/sys/firmware/edd/int13_dev80'),
+             '/sys/firmware/edd/int13_dev80/'),
             ("edd: found device 0x%x at %s", 0x81,
-             '/sys/firmware/edd/int13_dev81'),
+             '/sys/firmware/edd/int13_dev81/'),
         ]
         infos = [
             ("edd: MBR signature on %s is zero. new disk image?", "sda"),
@@ -200,7 +193,7 @@ def test_get_edd_dict_sata_usb(self):
         ]
         warnings = [
             ("edd: interface type %s is not implemented (%s)", "USB",
-                "/sys/firmware/edd/int13_dev81"),
+                "/sys/firmware/edd/int13_dev81/"),
             ("edd: interface details: %s", "USB     \tserial_number: 30302e31"),
         ]
         self.check_logs(debugs=debugs, infos=infos, warnings=warnings)


-- 
To view this commit on github, visit https://github.com/rhinstaller/blivet/commit/edb51ddeef77502209877e2fce255362090f3950


More information about the anaconda-patches mailing list