def _get_device_ids(self, dev_type): device_ids = [] if dev_type == hu.DISK: devs = hu.get_block_devices_from_udev_db() elif dev_type == hu.PARTITION: devs = hu.get_partitions_from_udev_db() for dev in devs: ids = hu.get_device_ids(dev) if ids: device_ids.append(ids) return device_ids
def test_get_device_ids(self, mock_udevreport): mock_udevreport.return_value = { 'DEVLINKS': ['/dev/disk/by-label/label', '/dev/disk/by-id/id', '/dev/disk/by-path/path']} part = '/dev/sda' desired = {'name': '/dev/sda', 'paths': ['disk/by-label/label', 'disk/by-id/id', 'disk/by-path/path']} result = hu.get_device_ids(part) mock_udevreport.assert_called_once_with(part) self.assertDictEqual(result, desired)
def _get_block_device_info(self, device): device_info = {'name': device, 'scsi': hu.scsi_address(device)} hu_device_info = hu.get_device_info(device) if hu_device_info: device_info.update(hu_device_info) ids = hu.get_device_ids(device) if not ids: # DEVLINKS not presented on virtual environment. # Let's keep it here for development purpose. devpath = device_info.get('uspec', {}).get('DEVPATH') if devpath: ids = [devpath] device_info['path'] = ids return {k: v for k, v in device_info.iteritems() if v}
def test_get_device_ids(self, mock_udevreport): mock_udevreport.return_value = { 'DEVLINKS': [ '/dev/disk/by-label/label', '/dev/disk/by-id/id', '/dev/disk/by-path/path' ] } part = '/dev/sda' desired = { 'name': '/dev/sda', 'paths': ['disk/by-label/label', 'disk/by-id/id', 'disk/by-path/path'] } result = hu.get_device_ids(part) mock_udevreport.assert_called_once_with(part) self.assertDictEqual(result, desired)
def _get_block_device_info(self, device): device_info = { 'name': device, 'scsi': hu.scsi_address(device) } hu_device_info = hu.get_device_info(device) if hu_device_info: device_info.update(hu_device_info) ids = hu.get_device_ids(device) if not ids: # DEVLINKS not presented on virtual environment. # Let's keep it here for development purpose. devpath = device_info.get('uspec', {}).get('DEVPATH') if devpath: ids = [devpath] device_info['path'] = ids return {k: v for k, v in device_info.iteritems() if v}