nodedev: Fold StorageDevice into NodeDevice

This commit is contained in:
Cole Robinson 2019-06-05 16:00:25 -04:00
parent eeb7babef7
commit 8d13125564
2 changed files with 19 additions and 69 deletions

View File

@ -119,31 +119,17 @@ class TestNodeDev(unittest.TestCase):
self.assertEqual(dev.bus, "0")
self.assertEqual(dev.target, "0")
def testStorageDevice1(self):
def testStorageDevice(self):
devname = "storage_serial_SATA_WDC_WD1600AAJS__WD_WCAP95119685"
vals = {"name": "storage_serial_SATA_WDC_WD1600AAJS__WD_WCAP95119685",
"parent": "pci_8086_27c0_scsi_host_scsi_device_lun0",
"devnodes": [
{"path": "/dev/sda", "node_type": "dev"}
],
"device_type": NodeDevice.CAPABILITY_TYPE_STORAGE,
"block": "/dev/sda", "bus": "scsi", "drive_type": "disk",
"model": "WDC WD1600AAJS-2", "vendor": "ATA",
"size": 160041885696, "removable": False,
"hotpluggable": False, "media_available": None,
"media_size": None, "media_label": None}
self._testCompare(devname, vals)
dev = self._nodeDevFromName(devname)
self.assertEqual(dev.block, "/dev/sda")
self.assertEqual(dev.drive_type, "disk")
self.assertEqual(dev.media_available, None)
def testStorageDevice2(self):
devname = "storage_serial_SanDisk_Cruzer_Micro_2004453082054CA1BEEE_0_0"
vals = {"name": "storage_serial_SanDisk_Cruzer_Micro_2004453082054CA1BEEE_0_0",
"parent": "usb_device_781_5151_2004453082054CA1BEEE_if0_scsi_host_0_scsi_device_lun0",
"device_type": NodeDevice.CAPABILITY_TYPE_STORAGE,
"block": "/dev/sdb", "bus": "usb", "drive_type": "disk",
"model": "Cruzer Micro", "vendor": "SanDisk", "size": None,
"removable": True, "hotpluggable": True,
"media_available": True, "media_size": 12345678}
self._testCompare(devname, vals)
devname = "storage_model_DVDRAM_GSA_U1200N"
dev = self._nodeDevFromName(devname)
self.assertEqual(dev.media_label, "Fedora12_media")
self.assertEqual(dev.media_available, 1)
def testSCSIBus(self):
devname = "pci_8086_2829_scsi_host_1"

View File

@ -169,20 +169,22 @@ class NodeDevice(XMLBuilder):
:returns: Device description string
"""
ret = self.name
if self.device_type == "net":
if self.interface:
ret = _("Interface %s") % self.interface
return _("Interface %s") % self.interface
return self.name
if self.device_type == "pci":
devstr = "%.4X:%.2X:%.2X:%X" % (int(self.domain),
int(self.bus),
int(self.slot),
int(self.function))
ret = "%s %s %s" % (devstr, self._vendor_name, self._product_name)
return "%s %s %s" % (devstr,
self._vendor_name, self._product_name)
if self.device_type == "usb_device":
ret = self._usb_pretty_name()
return self._usb_pretty_name()
return ret
return self.name
########################
@ -225,51 +227,15 @@ class NodeDevice(XMLBuilder):
target = XMLProperty("./capability/target")
lun = XMLProperty("./capability/lun")
class StorageDevice(NodeDevice):
# type='storage' options
block = XMLProperty("./capability/block")
bus = XMLProperty("./capability/bus")
drive_type = XMLProperty("./capability/drive_type")
size = XMLProperty("./capability/size", is_int=True)
model = XMLProperty("./capability/model")
vendor = XMLProperty("./capability/vendor")
hotpluggable = XMLProperty(
"./capability/capability[@type='hotpluggable']", is_bool=True)
removable = XMLProperty(
"./capability/capability[@type='removable']", is_bool=True)
media_size = XMLProperty(
"./capability/capability[@type='removable']/media_size", is_int=True)
media_label = XMLProperty(
"./capability/capability[@type='removable']/media_label")
_media_available = XMLProperty(
media_available = XMLProperty(
"./capability/capability[@type='removable']/media_available",
is_int=True)
def _get_media_available(self):
m = self._media_available
if m is None:
return None
return bool(m)
def _set_media_available(self, val):
self._media_available = val
media_available = property(_get_media_available, _set_media_available)
def pretty_name(self):
desc = ""
if self.drive_type:
desc = self.drive_type
if self.block:
desc = ": ".join((desc, self.block))
elif self.model:
desc = ": ".join((desc, self.model))
else:
desc = ": ".join((desc, self.name))
return desc
class SCSIBus(NodeDevice):
@ -359,9 +325,7 @@ def _AddressStringToNodedev(conn, addrstr):
def _typeToDeviceClass(t):
if t == NodeDevice.CAPABILITY_TYPE_STORAGE:
return StorageDevice
elif t == NodeDevice.CAPABILITY_TYPE_SCSIBUS:
if t == NodeDevice.CAPABILITY_TYPE_SCSIBUS:
return SCSIBus
elif t == NodeDevice.CAPABILITY_TYPE_DRM:
return DRMDevice