[master 3/5] Make our edd matcher able to use a fake sysfs root.
vathpela
installerbot-noreply at redhat.com
Wed Oct 7 20:59:52 UTC 2015
From: Peter Jones <pjones at redhat.com>
Signed-off-by: Peter Jones <pjones at redhat.com>
---
blivet/devicelibs/edd.py | 28 +++++++++++++++++++---------
1 file changed, 19 insertions(+), 9 deletions(-)
diff --git a/blivet/devicelibs/edd.py b/blivet/devicelibs/edd.py
index 60d34ea..d98c9df 100644
--- a/blivet/devicelibs/edd.py
+++ b/blivet/devicelibs/edd.py
@@ -58,6 +58,8 @@
# 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.
@@ -300,12 +302,12 @@ def __init__(self, edd_entry):
self.edd = edd_entry
def devname_from_ata_pci_dev(self):
- pattern = '/sys/block/*'
+ pattern = '%s/sys/block/*' % (fsroot,)
for path in glob.iglob(pattern):
link = os.readlink(path)
# just add /sys/block/ at the beginning so it's always valid
# paths in the filesystem...
- components = ['/sys/block'] + link.split('/')
+ components = ['%s/sys/block' % (fsroot,)] + link.split('/')
if len(components) != 11:
continue
# ATA and SATA paths look like:
@@ -370,18 +372,19 @@ def devname_from_ata_pci_dev(self):
if (self.edd.channel == 255 and channel == 0) or \
(self.edd.channel == channel):
self.edd.sysfslink = link
- return path.split('/')[-1]
+ return path[len(fsroot):].split('/')[-1]
else:
pmp = int(match.group(1))
if self.edd.ata_pmp == pmp:
self.edd.sysfslink = link
- return path.split('/')[-1]
+ return path[len(fsroot):].split('/')[-1]
return None
def devname_from_scsi_pci_dev(self):
name = None
- path = "/sys/devices/pci0000:00/0000:%(pci_dev)s/host%(chan)d/"\
+ path = "%(fsroot)s/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" % {
+ 'fsroot' : fsroot,
'pci_dev' : self.edd.pci_dev,
'chan' : self.edd.channel,
'dev' : self.edd.scsi_id,
@@ -398,8 +401,10 @@ def devname_from_scsi_pci_dev(self):
def devname_from_virt_pci_dev(self):
name = None
- pattern = "/sys/devices/pci0000:00/0000:%(pci_dev)s/virtio*/block" % \
- {'pci_dev' : self.edd.pci_dev}
+ pattern = "%(fsroot)s/sys/devices/pci0000:00/0000:%(pci_dev)s/virtio*/block" % {
+ 'fsroot' : fsroot,
+ 'pci_dev' : self.edd.pci_dev
+ }
matching_paths = glob.glob(pattern)
if len(matching_paths) != 1 or not os.path.exists(matching_paths[0]):
return None
@@ -438,7 +443,10 @@ def match_via_mbrsigs(self, mbr_dict):
return None
def biosdev_to_edd_dir(biosdev):
- return "/sys/firmware/edd/int13_dev%x" % biosdev
+ return "%(fsroot)s/sys/firmware/edd/int13_dev%(biosdev)x" % {
+ 'fsroot' : fsroot,
+ 'biosdev' : biosdev
+ }
def collect_edd_data():
edd_data_dict = {}
@@ -462,7 +470,9 @@ def collect_mbrs(devices):
mbr_dict = {}
for dev in devices:
try:
- fd = util.eintr_retry_call(os.open, dev.path, os.O_RDONLY)
+ path = dev.name.split('/')
+ path = os.path.join(fsroot, *path)
+ fd = util.eintr_retry_call(os.open, path, os.O_RDONLY)
# The signature is the unsigned integer at byte 440:
os.lseek(fd, 440, 0)
mbrsig = struct.unpack('I', util.eintr_retry_call(os.read, fd, 4))
--
To view this commit on github, visit https://github.com/rhinstaller/blivet/commit/d7a6bdb8383baffea1db441610ee37afe16b83e9
More information about the anaconda-patches
mailing list