def test_opeators(self): self.assertEqual(subject, "1:0:0:1") self.assertFalse(subject == 123) self.assertRaises(TypeError, subject.__lt__, None) self.assertGreaterEqual(subject, HCTL.from_string("1:0:0:0")) self.assertGreater(subject, HCTL.from_string("1:0:0:0")) self.assertEqual([i for i in subject], [1, 0, 0, 1]) self.assertRaises(ValueError, subject.from_string, None) self.assertEqual(repr(subject), "<1:0:0:1>") self.assertEqual(HCT(1, 0, 0)[1], subject) self.assertEqual(HCT(1, 0, 0), HCT(1, 0, 0))
def _append_device_by_type(self, hctl_str, dev_path, scsi_type): if scsi_type == SCSI_TYPE_STORAGE_CONTROLLER: self.controllers.append(SysfsSCSIDevice(dev_path, HCTL.from_string(hctl_str))) elif scsi_type == SCSI_TYPE_DISK: block_dev_names = get_sd_paths(dev_path) if block_dev_names == []: self.sg_disks.append(SysfsSCSIDevice(dev_path, HCTL.from_string(hctl_str))) else: sd_disk = SysfsSDDisk(dev_path, HCTL.from_string(hctl_str), block_dev_names) self.sd_disks.append(sd_disk) self.sg_disks.append(sd_disk) self.block_devices.append(sd_disk) self.block_devno_to_device[sd_disk.get_block_devno()] = sd_disk
def _get_hctl(self): from infi.dtypes.hctl import HCTL if self.is_iscsi_session: h, c, t = self._get_hct_iscsi() if (h, c, t) == (-1, 0, -1): return None else: return HCTL(h, c, t, self._get_path_lun_iscsi()) else: h, c, t = self._get_hct_fc(self.initiator_port_name, self.target_port_name) if (h, c, t) == (-1, 0, -1): return None else: return HCTL(h, c, t, self._get_path_lun_fc())
def _append_device_by_type(self, hctl_str, dev_path, scsi_type): if scsi_type == SCSI_TYPE_STORAGE_CONTROLLER: self.controllers.append(SysfsSCSIDevice(dev_path, HCTL.from_string(hctl_str))) elif scsi_type == SCSI_TYPE_ENCLOSURE: self.enclosures.append(SysfsEnclosureDevice(dev_path, HCTL.from_string(hctl_str))) elif scsi_type == SCSI_TYPE_DISK: block_dev_names = self._sd_structures.get(hctl_str) if not block_dev_names: self.sg_disks.append(SysfsSCSIDevice(dev_path, HCTL.from_string(hctl_str))) else: sd_disk = SysfsSDDisk(dev_path, HCTL.from_string(hctl_str), block_dev_names) self.sd_disks.append(sd_disk) self.sg_disks.append(sd_disk) self.block_devices.append(sd_disk) self.block_devno_to_device[sd_disk.get_block_devno()] = sd_disk
def get_hctl(self): from pyVmomi import vim from infi.storagemodel.errors import RescanIsNeeded from pyVmomi import vim scsi_topology_adapters = self._properties.get( SCSI_TOPOLOGY_PROPERTY_PATH, []) expected_vmhba = self._path_data_object.adapter.split('-')[-1] # adapter.key is key-vim.host.ScsiTopology.Interface-vmhba0 # path_data_object.adapter is key-vim.host.FibreChannelHba-vmhba2 for adapter in [ adapter for adapter in scsi_topology_adapters if adapter.key.split('-')[-1] == expected_vmhba ]: for target in adapter.target: our_transport = self._path_data_object.transport target_transport = target.transport if (isinstance(our_transport, vim.HostInternetScsiTargetTransport) and isinstance(target_transport, vim.HostInternetScsiTargetTransport) and our_transport.iScsiName == target_transport.iScsiName) or \ (isinstance(our_transport, vim.HostFibreChannelTargetTransport) and isinstance(target_transport, vim.HostFibreChannelTargetTransport) and our_transport.portWorldWideName == target_transport.portWorldWideName): for lun in target.lun: # lun.scsiLun = "key-vim.host.ScsiLun-020c0000006742b0f000004e2b0000000000000000496e66696e69" # self._lun_key = 'key-vim.host.ScsiDisk-02000200006742b0f000004e2b0000000000000069496e66696e69' if lun.scsiLun.rsplit('-', 1)[-1] == self._lun_key.rsplit( '-', 1)[-1]: return HCTL(expected_vmhba, 0, target.target, lun.lun) logger.exception( "failed to find SCSI target for path object {}".format( self._path_data_object)) raise RescanIsNeeded()
def get_hctl(self): from infi.dtypes.hctl import HCTL scsi_address = self._pdo_information.ScsiAddress try: return HCTL(scsi_address.PortNumber, scsi_address.ScsiPathId, scsi_address.TargetId, scsi_address.Lun) except AttributeError: # we lost a PDO raise RescanIsNeeded()
def _append_device_by_type(self, hctl_str, dev_path, scsi_type): if scsi_type == SCSI_TYPE_STORAGE_CONTROLLER: self.controllers.append( SysfsSCSIDevice(dev_path, HCTL.from_string(hctl_str))) elif scsi_type == SCSI_TYPE_ENCLOSURE: self.enclosures.append( SysfsEnclosureDevice(dev_path, HCTL.from_string(hctl_str))) elif scsi_type == SCSI_TYPE_DISK: block_dev_names = self._sd_structures.get(hctl_str) if not block_dev_names: self.sg_disks.append( SysfsSCSIDevice(dev_path, HCTL.from_string(hctl_str))) else: sd_disk = SysfsSDDisk(dev_path, HCTL.from_string(hctl_str), block_dev_names) self.sd_disks.append(sd_disk) self.sg_disks.append(sd_disk) self.block_devices.append(sd_disk) self.block_devno_to_device[sd_disk.get_block_devno()] = sd_disk
def get_hctl(self): """Returns a `infi.dtypes.hctl.HCTL` object""" driver = execute_assert_success( ["/usr/sbin/lsdev", "-F", "parent", "-l", self._name]).get_stdout().strip() host = self._get_host_by_driver(driver) target, lun = execute_assert_success([ "/usr/sbin/lsattr", "-F", "value", "-a", "ww_name", "-a", "lun_id", "-E", "-l", self._name ]).get_stdout().strip().split("\n") target = int(target, 16) lun = int(lun, 16) >> 48 return HCTL(host, 0, target, lun)
def test_fc_mapping_gone(self, get_storage_model): from . import FiberChannelMappingNotExists, MultipleFiberChannelMappingNotExist i_wwn = ":".join(["01"] * 8) t_wwn = ":".join(["02"] * 8) get_storage_model.return_value = MockModel() SCSIModel._devices = [Disk("1")] SCSIModel._devices[0].connectivity = FCConectivityMock(i_wwn, t_wwn) SCSIModel._devices[0].hctl = HCTL(1, 0, 0, 1) self.assertFalse(FiberChannelMappingNotExists(i_wwn, t_wwn, 1)()) self.assertFalse( MultipleFiberChannelMappingNotExist([i_wwn], [t_wwn], [1, 2])()) SCSIModel._devices = [] self.assertTrue(FiberChannelMappingNotExists(i_wwn, t_wwn, 1)()) self.assertTrue( MultipleFiberChannelMappingNotExist([i_wwn], [t_wwn], [1, 2]))
def test_sysfs(self, open_mock, listdir_mock, exists_mock, islink_mock, get_hctl_for_sd_device_mock): if name == "nt": raise SkipTest listdir_map = { '/sys/class/scsi_device': [ '2:0:0:0', '3:0:0:0', '3:0:1:1', '3:0:1:2', '4:0:0:0', '4:0:1:1', '4:0:1:2', '5:0:0:0' ], # SCSI Disks: '/sys/class/scsi_device/2:0:0:0/device/block': ['sda'], '/sys/class/scsi_device/2:0:0:0/device/scsi_generic': ['sg0'], '/sys/class/scsi_device/3:0:0:0/device/block': ['sde'], '/sys/class/scsi_device/3:0:0:0/device/scsi_generic': ['sg4'], '/sys/class/scsi_device/3:0:1:1/device/block': ['sdf'], '/sys/class/scsi_device/3:0:1:1/device/scsi_generic': ['sg2'], '/sys/class/scsi_device/3:0:1:2/device/block': ['sdg'], '/sys/class/scsi_device/3:0:1:2/device/scsi_generic': ['sg5'], '/sys/class/scsi_device/4:0:0:0/device/block': ['sdb'], '/sys/class/scsi_device/4:0:0:0/device/scsi_generic': ['sg1'], '/sys/class/scsi_device/4:0:1:1/device/block': ['sdc'], '/sys/class/scsi_device/4:0:1:1/device/scsi_generic': ['sg7'], '/sys/class/scsi_device/4:0:1:2/device/block': ['sdd'], '/sys/class/scsi_device/4:0:1:2/device/scsi_generic': ['sg6'], # SCSI Storage Controllers: '/sys/class/scsi_device/5:0:0:0/device/scsi_generic': ['sg3'], # Block Devices: '/sys/block': ['sda', 'sde', 'sdf', 'sdg', 'sdb', 'sdc', 'sdd'], # Device names: '/dev': [ 'sg0', 'sg4', 'sg2', 'sg5', 'sg1', 'sg7', 'sg6', 'sg3', 'sda', 'sde', 'sdf', 'sdg', 'sdb', 'sdc', 'sdd' ] } file_map = { '/sys/class/scsi_device/2:0:0:0/device/type': '0', '/sys/class/scsi_device/2:0:0:0/device/vendor': 'VMware', '/sys/class/scsi_device/2:0:0:0/device/block/sda/size': '16777216', '/sys/class/scsi_device/2:0:0:0/device/block/sda/dev': '8:0', '/sys/class/scsi_device/2:0:0:0/device/queue_depth': '64', '/sys/class/scsi_device/3:0:0:0/device/type': '0', '/sys/class/scsi_device/3:0:0:0/device/vendor': 'NFINIDAT', '/sys/class/scsi_device/3:0:0:0/device/block/sde/size': '2097156', '/sys/class/scsi_device/3:0:0:0/device/block/sde/dev': '8:4', '/sys/class/scsi_device/3:0:0:0/device/queue_depth': '32', '/sys/class/scsi_device/3:0:1:1/device/type': '0', '/sys/class/scsi_device/3:0:1:1/device/vendor': 'NEXSAN', '/sys/class/scsi_device/3:0:1:1/device/block/sdf/size': '1953792', '/sys/class/scsi_device/3:0:1:1/device/block/sdf/dev': '8:5', '/sys/class/scsi_device/3:0:1:1/device/queue_depth': '32', '/sys/class/scsi_device/3:0:1:2/device/type': '0', '/sys/class/scsi_device/3:0:1:2/device/vendor': 'NEXSAN', '/sys/class/scsi_device/3:0:1:2/device/block/sdg/size': '1953792', '/sys/class/scsi_device/3:0:1:2/device/block/sdg/dev': '8:6', '/sys/class/scsi_device/3:0:1:2/device/queue_depth': '32', '/sys/class/scsi_device/4:0:0:0/device/type': '0', '/sys/class/scsi_device/4:0:0:0/device/vendor': 'NFINIDAT', '/sys/class/scsi_device/4:0:0:0/device/block/sdb/size': '2097156', '/sys/class/scsi_device/4:0:0:0/device/block/sdb/dev': '8:1', '/sys/class/scsi_device/4:0:0:0/device/queue_depth': '32', '/sys/class/scsi_device/4:0:1:1/device/type': '0', '/sys/class/scsi_device/4:0:1:1/device/vendor': 'NEXSAN', '/sys/class/scsi_device/4:0:1:1/device/block/sdc/size': '1953792', '/sys/class/scsi_device/4:0:1:1/device/block/sdc/dev': '8:2', '/sys/class/scsi_device/4:0:1:1/device/queue_depth': '32', '/sys/class/scsi_device/4:0:1:2/device/type': '0', '/sys/class/scsi_device/4:0:1:2/device/vendor': 'NEXSAN', '/sys/class/scsi_device/4:0:1:2/device/block/sdd/size': '1953792', '/sys/class/scsi_device/4:0:1:2/device/block/sdd/dev': '8:3', '/sys/class/scsi_device/4:0:1:2/device/queue_depth': '32', '/sys/class/scsi_device/5:0:0:0/device/type': '12', '/sys/class/scsi_device/5:0:0:0/device/vendor': 'NFINIDAT', '/sys/class/scsi_device/5:0:0:0/device/queue_depth': '32', '/sys/block/sda/dev': '8:0', '/sys/block/sda/size': '16777216', '/sys/block/sde/dev': '8:4', '/sys/block/sde/size': '2097156', '/sys/block/sdf/dev': '8:5', '/sys/block/sdf/size': '1953792', '/sys/block/sdg/dev': '8:6', '/sys/block/sdg/size': '1953792', '/sys/block/sdb/dev': '8:1', '/sys/block/sdb/size': '2097156', '/sys/block/sdc/dev': '8:2', '/sys/block/sdc/size': '1953792', '/sys/block/sdd/dev': '8:3', '/sys/block/sdd/size': '1953792', } get_sd_hctl_map = { '/dev/sda': HCTL.from_string('2:0:0:0'), '/dev/sde': HCTL.from_string('3:0:0:0'), '/dev/sdf': HCTL.from_string('3:0:1:1'), '/dev/sdg': HCTL.from_string('3:0:1:2'), '/dev/sdb': HCTL.from_string('4:0:0:0'), '/dev/sdc': HCTL.from_string('4:0:1:1'), '/dev/sdd': HCTL.from_string('4:0:1:2'), } def create_file_context_manager(*args, **kwargs): path = args[0] file_mock = Mock() file_mock.read = Mock(return_value=file_map[path]) cm = Mock() cm.__enter__ = Mock(return_value=file_mock) cm.__exit__ = Mock() return cm disk_properties = { 'sda': dict(queue_depth=64, sysfs_size=16777216, hctl='2:0:0:0', vendor='VMware'), 'sde': dict(queue_depth=32, sysfs_size=2097156, hctl='3:0:0:0', vendor='NFINIDAT'), 'sdf': dict(queue_depth=32, sysfs_size=1953792, hctl='3:0:1:1', vendor='NEXSAN'), 'sdg': dict(queue_depth=32, sysfs_size=1953792, hctl='3:0:1:2', vendor='NEXSAN'), 'sdb': dict(queue_depth=32, sysfs_size=2097156, hctl='4:0:0:0', vendor='NFINIDAT'), 'sdc': dict(queue_depth=32, sysfs_size=1953792, hctl='4:0:1:1', vendor='NEXSAN'), 'sdd': dict(queue_depth=32, sysfs_size=1953792, hctl='4:0:1:2', vendor='NEXSAN'), } listdir_mock.side_effect = listdir_map.get open_mock.side_effect = create_file_context_manager exists_mock.return_value = True islink_mock.return_value = False get_hctl_for_sd_device_mock.side_effect = get_sd_hctl_map.get sysfs = Sysfs() disks = sysfs.get_all_sd_disks() self.assertEqual(7, len(disks)) for disk in disks: block_dev = disk.get_block_device_name() self.assertTrue(block_dev in disk_properties) self.assertEqual( HCTL.from_string(disk_properties[block_dev]['hctl']), disk.get_hctl()) self.assertEqual(disk_properties[block_dev]['queue_depth'], disk.get_queue_depth()) self.assertEqual(disk_properties[block_dev]['sysfs_size'] * 512, disk.get_size_in_bytes()) self.assertEqual(disk_properties[block_dev]['vendor'], disk.get_vendor())
def find_hctl_by_slot(self, slot): dev_path = os.path.join(self._basepath, slot, 'device') if os.path.exists(dev_path): hctl = os.path.basename(os.readlink(dev_path)) return HCTL.from_string(hctl) return None
def test_from_hct_and_lun(self): self.assertEqual(HCTL.from_hct_and_lun(HCT(1, 2, 3), 4), HCTL(1, 2, 3, 4))
def get_hctl(self): # TODO make sure which is base 16 and which isn't! return HCTL(int(self.controller), int(self.controller), int(self.target, 16), int(self.disk))
def test_sysfs(self, open_mock, listdir_mock, exists_mock, islink_mock, get_hctl_for_sd_device_mock): if name == "nt": raise SkipTest listdir_map = { '/sys/class/scsi_device': [ '2:0:0:0', '3:0:0:0', '3:0:1:1', '3:0:1:2', '4:0:0:0', '4:0:1:1', '4:0:1:2', '5:0:0:0' ], # SCSI Disks: '/sys/class/scsi_device/2:0:0:0/device/block': [ 'sda' ], '/sys/class/scsi_device/2:0:0:0/device/scsi_generic': [ 'sg0' ], '/sys/class/scsi_device/3:0:0:0/device/block': [ 'sde' ], '/sys/class/scsi_device/3:0:0:0/device/scsi_generic': [ 'sg4' ], '/sys/class/scsi_device/3:0:1:1/device/block': [ 'sdf' ], '/sys/class/scsi_device/3:0:1:1/device/scsi_generic': [ 'sg2' ], '/sys/class/scsi_device/3:0:1:2/device/block': [ 'sdg' ], '/sys/class/scsi_device/3:0:1:2/device/scsi_generic': [ 'sg5' ], '/sys/class/scsi_device/4:0:0:0/device/block': [ 'sdb' ], '/sys/class/scsi_device/4:0:0:0/device/scsi_generic': [ 'sg1' ], '/sys/class/scsi_device/4:0:1:1/device/block': [ 'sdc' ], '/sys/class/scsi_device/4:0:1:1/device/scsi_generic': [ 'sg7' ], '/sys/class/scsi_device/4:0:1:2/device/block': [ 'sdd' ], '/sys/class/scsi_device/4:0:1:2/device/scsi_generic': [ 'sg6' ], # SCSI Storage Controllers: '/sys/class/scsi_device/5:0:0:0/device/scsi_generic': [ 'sg3' ], # Block Devices: '/sys/block': ['sda','sde','sdf','sdg','sdb','sdc','sdd'], # Device names: '/dev' : ['sg0','sg4','sg2','sg5','sg1','sg7','sg6','sg3','sda','sde','sdf','sdg','sdb','sdc','sdd'] } file_map = { '/sys/class/scsi_device/2:0:0:0/device/type': '0', '/sys/class/scsi_device/2:0:0:0/device/vendor': 'VMware', '/sys/class/scsi_device/2:0:0:0/device/block/sda/size': '16777216', '/sys/class/scsi_device/2:0:0:0/device/block/sda/dev': '8:0', '/sys/class/scsi_device/2:0:0:0/device/queue_depth': '64', '/sys/class/scsi_device/3:0:0:0/device/type': '0', '/sys/class/scsi_device/3:0:0:0/device/vendor': 'NFINIDAT', '/sys/class/scsi_device/3:0:0:0/device/block/sde/size': '2097156', '/sys/class/scsi_device/3:0:0:0/device/block/sde/dev': '8:4', '/sys/class/scsi_device/3:0:0:0/device/queue_depth': '32', '/sys/class/scsi_device/3:0:1:1/device/type': '0', '/sys/class/scsi_device/3:0:1:1/device/vendor': 'NEXSAN', '/sys/class/scsi_device/3:0:1:1/device/block/sdf/size': '1953792', '/sys/class/scsi_device/3:0:1:1/device/block/sdf/dev': '8:5', '/sys/class/scsi_device/3:0:1:1/device/queue_depth': '32', '/sys/class/scsi_device/3:0:1:2/device/type': '0', '/sys/class/scsi_device/3:0:1:2/device/vendor': 'NEXSAN', '/sys/class/scsi_device/3:0:1:2/device/block/sdg/size': '1953792', '/sys/class/scsi_device/3:0:1:2/device/block/sdg/dev': '8:6', '/sys/class/scsi_device/3:0:1:2/device/queue_depth': '32', '/sys/class/scsi_device/4:0:0:0/device/type': '0', '/sys/class/scsi_device/4:0:0:0/device/vendor': 'NFINIDAT', '/sys/class/scsi_device/4:0:0:0/device/block/sdb/size': '2097156', '/sys/class/scsi_device/4:0:0:0/device/block/sdb/dev': '8:1', '/sys/class/scsi_device/4:0:0:0/device/queue_depth': '32', '/sys/class/scsi_device/4:0:1:1/device/type': '0', '/sys/class/scsi_device/4:0:1:1/device/vendor': 'NEXSAN', '/sys/class/scsi_device/4:0:1:1/device/block/sdc/size': '1953792', '/sys/class/scsi_device/4:0:1:1/device/block/sdc/dev': '8:2', '/sys/class/scsi_device/4:0:1:1/device/queue_depth': '32', '/sys/class/scsi_device/4:0:1:2/device/type': '0', '/sys/class/scsi_device/4:0:1:2/device/vendor': 'NEXSAN', '/sys/class/scsi_device/4:0:1:2/device/block/sdd/size': '1953792', '/sys/class/scsi_device/4:0:1:2/device/block/sdd/dev': '8:3', '/sys/class/scsi_device/4:0:1:2/device/queue_depth': '32', '/sys/class/scsi_device/5:0:0:0/device/type': '12', '/sys/class/scsi_device/5:0:0:0/device/vendor': 'NFINIDAT', '/sys/class/scsi_device/5:0:0:0/device/queue_depth': '32', '/sys/block/sda/dev' : '8:0', '/sys/block/sda/size' : '16777216', '/sys/block/sde/dev' : '8:4', '/sys/block/sde/size' : '2097156', '/sys/block/sdf/dev' : '8:5', '/sys/block/sdf/size' : '1953792', '/sys/block/sdg/dev' : '8:6', '/sys/block/sdg/size' : '1953792', '/sys/block/sdb/dev' : '8:1', '/sys/block/sdb/size' : '2097156', '/sys/block/sdc/dev' : '8:2', '/sys/block/sdc/size' : '1953792', '/sys/block/sdd/dev' : '8:3', '/sys/block/sdd/size' : '1953792', } get_sd_hctl_map = { '/dev/sda' : HCTL.from_string('2:0:0:0'), '/dev/sde' : HCTL.from_string('3:0:0:0'), '/dev/sdf' : HCTL.from_string('3:0:1:1'), '/dev/sdg' : HCTL.from_string('3:0:1:2'), '/dev/sdb' : HCTL.from_string('4:0:0:0'), '/dev/sdc' : HCTL.from_string('4:0:1:1'), '/dev/sdd' : HCTL.from_string('4:0:1:2'), } def create_file_context_manager(*args, **kwargs): path = args[0] file_mock = Mock() file_mock.read = Mock(return_value=file_map[path]) cm = Mock() cm.__enter__ = Mock(return_value=file_mock) cm.__exit__ = Mock() return cm disk_properties = { 'sda': dict(queue_depth=64, sysfs_size=16777216, hctl='2:0:0:0', vendor='VMware'), 'sde': dict(queue_depth=32, sysfs_size=2097156, hctl='3:0:0:0', vendor='NFINIDAT'), 'sdf': dict(queue_depth=32, sysfs_size=1953792, hctl='3:0:1:1', vendor='NEXSAN'), 'sdg': dict(queue_depth=32, sysfs_size=1953792, hctl='3:0:1:2', vendor='NEXSAN'), 'sdb': dict(queue_depth=32, sysfs_size=2097156, hctl='4:0:0:0', vendor='NFINIDAT'), 'sdc': dict(queue_depth=32, sysfs_size=1953792, hctl='4:0:1:1', vendor='NEXSAN'), 'sdd': dict(queue_depth=32, sysfs_size=1953792, hctl='4:0:1:2', vendor='NEXSAN'), } listdir_mock.side_effect = listdir_map.get open_mock.side_effect = create_file_context_manager exists_mock.return_value = True islink_mock.return_value = False get_hctl_for_sd_device_mock.side_effect = get_sd_hctl_map.get sysfs = Sysfs() disks = sysfs.get_all_sd_disks() self.assertEquals(7, len(disks)) for disk in disks: block_dev = disk.get_block_device_name() self.assertTrue(block_dev in disk_properties) self.assertEquals(HCTL.from_string(disk_properties[block_dev]['hctl']), disk.get_hctl()) self.assertEquals(disk_properties[block_dev]['queue_depth'], disk.get_queue_depth()) self.assertEquals(disk_properties[block_dev]['sysfs_size'] * 512, disk.get_size_in_bytes()) self.assertEquals(disk_properties[block_dev]['vendor'], disk.get_vendor())
def get_hctl(self): from infi.dtypes.hctl import HCTL return HCTL(*defer(self.get_ioctl_interface().scsi_get_address)())
def __init__(self, sysfs, multipath_object_path): from infi.dtypes.hctl import HCTL self.multipath_object_path = multipath_object_path self.hctl = HCTL(*self.multipath_object_path.hctl) self.sysfs_device = sysfs.find_scsi_disk_by_hctl(self.hctl)
def test_fromstring(self): self.assertEqual(subject, HCTL.from_string("1:0:0:1")) self.assertNotEqual(subject, HCTL.from_string("1:0:0:2")) self.assertLessEqual(subject, HCTL.from_string("1:0:0:2"))
def get_hctl(self): """Returns a `infi.dtypes.hctl.HCTL` instance""" host = AixSCSIDevice._get_host_by_driver(self._driver) return HCTL(host, 0, self._target, self._lun)
def test_sysfs(self, open_mock, listdir_mock, exists_mock, islink_mock): if name == "nt": raise SkipTest listdir_map = { "/sys/class/scsi_device": [ "2:0:0:0", "3:0:0:0", "3:0:1:1", "3:0:1:2", "4:0:0:0", "4:0:1:1", "4:0:1:2", "5:0:0:0", ], # SCSI Disks: "/sys/class/scsi_device/2:0:0:0/device/block": ["sda"], "/sys/class/scsi_device/2:0:0:0/device/scsi_generic": ["sg0"], "/sys/class/scsi_device/3:0:0:0/device/block": ["sde"], "/sys/class/scsi_device/3:0:0:0/device/scsi_generic": ["sg4"], "/sys/class/scsi_device/3:0:1:1/device/block": ["sdf"], "/sys/class/scsi_device/3:0:1:1/device/scsi_generic": ["sg2"], "/sys/class/scsi_device/3:0:1:2/device/block": ["sdg"], "/sys/class/scsi_device/3:0:1:2/device/scsi_generic": ["sg5"], "/sys/class/scsi_device/4:0:0:0/device/block": ["sdb"], "/sys/class/scsi_device/4:0:0:0/device/scsi_generic": ["sg1"], "/sys/class/scsi_device/4:0:1:1/device/block": ["sdc"], "/sys/class/scsi_device/4:0:1:1/device/scsi_generic": ["sg7"], "/sys/class/scsi_device/4:0:1:2/device/block": ["sdd"], "/sys/class/scsi_device/4:0:1:2/device/scsi_generic": ["sg6"], # SCSI Storage Controllers: "/sys/class/scsi_device/5:0:0:0/device/scsi_generic": ["sg3"], # Block Devices: "/sys/block": [], } file_map = { "/sys/class/scsi_device/2:0:0:0/device/type": "0", "/sys/class/scsi_device/2:0:0:0/device/vendor": "VMware", "/sys/class/scsi_device/2:0:0:0/device/block/sda/size": "16777216", "/sys/class/scsi_device/2:0:0:0/device/block/sda/dev": "8:0", "/sys/class/scsi_device/2:0:0:0/device/queue_depth": "64", "/sys/class/scsi_device/3:0:0:0/device/type": "0", "/sys/class/scsi_device/3:0:0:0/device/vendor": "NFINIDAT", "/sys/class/scsi_device/3:0:0:0/device/block/sde/size": "2097156", "/sys/class/scsi_device/3:0:0:0/device/block/sde/dev": "8:4", "/sys/class/scsi_device/3:0:0:0/device/queue_depth": "32", "/sys/class/scsi_device/3:0:1:1/device/type": "0", "/sys/class/scsi_device/3:0:1:1/device/vendor": "NEXSAN", "/sys/class/scsi_device/3:0:1:1/device/block/sdf/size": "1953792", "/sys/class/scsi_device/3:0:1:1/device/block/sdf/dev": "8:5", "/sys/class/scsi_device/3:0:1:1/device/queue_depth": "32", "/sys/class/scsi_device/3:0:1:2/device/type": "0", "/sys/class/scsi_device/3:0:1:2/device/vendor": "NEXSAN", "/sys/class/scsi_device/3:0:1:2/device/block/sdg/size": "1953792", "/sys/class/scsi_device/3:0:1:2/device/block/sdg/dev": "8:6", "/sys/class/scsi_device/3:0:1:2/device/queue_depth": "32", "/sys/class/scsi_device/4:0:0:0/device/type": "0", "/sys/class/scsi_device/4:0:0:0/device/vendor": "NFINIDAT", "/sys/class/scsi_device/4:0:0:0/device/block/sdb/size": "2097156", "/sys/class/scsi_device/4:0:0:0/device/block/sdb/dev": "8:1", "/sys/class/scsi_device/4:0:0:0/device/queue_depth": "32", "/sys/class/scsi_device/4:0:1:1/device/type": "0", "/sys/class/scsi_device/4:0:1:1/device/vendor": "NEXSAN", "/sys/class/scsi_device/4:0:1:1/device/block/sdc/size": "1953792", "/sys/class/scsi_device/4:0:1:1/device/block/sdc/dev": "8:2", "/sys/class/scsi_device/4:0:1:1/device/queue_depth": "32", "/sys/class/scsi_device/4:0:1:2/device/type": "0", "/sys/class/scsi_device/4:0:1:2/device/vendor": "NEXSAN", "/sys/class/scsi_device/4:0:1:2/device/block/sdd/size": "1953792", "/sys/class/scsi_device/4:0:1:2/device/block/sdd/dev": "8:3", "/sys/class/scsi_device/4:0:1:2/device/queue_depth": "32", "/sys/class/scsi_device/5:0:0:0/device/type": "12", "/sys/class/scsi_device/5:0:0:0/device/vendor": "NFINIDAT", "/sys/class/scsi_device/5:0:0:0/device/queue_depth": "32", } def create_file_context_manager(*args, **kwargs): path = args[0] file_mock = Mock() file_mock.read = Mock(return_value=file_map[path]) cm = Mock() cm.__enter__ = Mock(return_value=file_mock) cm.__exit__ = Mock() return cm disk_properties = { "sda": dict(queue_depth=64, sysfs_size=16777216, hctl="2:0:0:0", vendor="VMware"), "sde": dict(queue_depth=32, sysfs_size=2097156, hctl="3:0:0:0", vendor="NFINIDAT"), "sdf": dict(queue_depth=32, sysfs_size=1953792, hctl="3:0:1:1", vendor="NEXSAN"), "sdg": dict(queue_depth=32, sysfs_size=1953792, hctl="3:0:1:2", vendor="NEXSAN"), "sdb": dict(queue_depth=32, sysfs_size=2097156, hctl="4:0:0:0", vendor="NFINIDAT"), "sdc": dict(queue_depth=32, sysfs_size=1953792, hctl="4:0:1:1", vendor="NEXSAN"), "sdd": dict(queue_depth=32, sysfs_size=1953792, hctl="4:0:1:2", vendor="NEXSAN"), } listdir_mock.side_effect = listdir_map.get open_mock.side_effect = create_file_context_manager exists_mock.return_value = True islink_mock.return_value = False sysfs = Sysfs() disks = sysfs.get_all_sd_disks() self.assertEquals(7, len(disks)) for disk in disks: block_dev = disk.get_block_device_name() self.assertTrue(block_dev in disk_properties) self.assertEquals(HCTL.from_string(disk_properties[block_dev]["hctl"]), disk.get_hctl()) self.assertEquals(disk_properties[block_dev]["queue_depth"], disk.get_queue_depth()) self.assertEquals(disk_properties[block_dev]["sysfs_size"] * 512, disk.get_size_in_bytes()) self.assertEquals(disk_properties[block_dev]["vendor"], disk.get_vendor())