def _get_device_id(self): """ Please keep this implementation in sync with get_device_id() in src/common/blkdev.cc """ props = [ 'ID_VENDOR', 'ID_MODEL', 'ID_MODEL_ENC', 'ID_SERIAL_SHORT', 'ID_SERIAL', 'ID_SCSI_SERIAL' ] p = disk.udevadm_property(self.abspath, props) if p.get('ID_MODEL', '').startswith('LVM PV '): p['ID_MODEL'] = p.get('ID_MODEL_ENC', '').replace('\\x20', ' ').strip() if 'ID_VENDOR' in p and 'ID_MODEL' in p and 'ID_SCSI_SERIAL' in p: dev_id = '_'.join( [p['ID_VENDOR'], p['ID_MODEL'], p['ID_SCSI_SERIAL']]) elif 'ID_MODEL' in p and 'ID_SERIAL_SHORT' in p: dev_id = '_'.join([p['ID_MODEL'], p['ID_SERIAL_SHORT']]) elif 'ID_SERIAL' in p: dev_id = p['ID_SERIAL'] if dev_id.startswith('MTFD'): # Micron NVMes hide the vendor dev_id = 'Micron_' + dev_id else: # the else branch should fallback to using sysfs and ioctl to # retrieve device_id on FreeBSD. Still figuring out if/how the # python ioctl implementation does that on FreeBSD dev_id = '' dev_id.replace(' ', '_') return dev_id
def _get_device_id(self): """ Please keep this implementation in sync with get_device_id() in src/common/blkdev.cc """ props = ['ID_VENDOR', 'ID_MODEL', 'ID_MODEL_ENC', 'ID_SERIAL_SHORT', 'ID_SERIAL', 'ID_SCSI_SERIAL'] p = disk.udevadm_property(self.abspath, props) if p.get('ID_MODEL','').startswith('LVM PV '): p['ID_MODEL'] = p.get('ID_MODEL_ENC', '').replace('\\x20', ' ').strip() if 'ID_VENDOR' in p and 'ID_MODEL' in p and 'ID_SCSI_SERIAL' in p: dev_id = '_'.join([p['ID_VENDOR'], p['ID_MODEL'], p['ID_SCSI_SERIAL']]) elif 'ID_MODEL' in p and 'ID_SERIAL_SHORT' in p: dev_id = '_'.join([p['ID_MODEL'], p['ID_SERIAL_SHORT']]) elif 'ID_SERIAL' in p: dev_id = p['ID_SERIAL'] if dev_id.startswith('MTFD'): # Micron NVMes hide the vendor dev_id = 'Micron_' + dev_id else: # the else branch should fallback to using sysfs and ioctl to # retrieve device_id on FreeBSD. Still figuring out if/how the # python ioctl implementation does that on FreeBSD dev_id = '' dev_id.replace(' ', '_') return dev_id
def test_property_filter(self, stub_call): output = """ID_MODEL=SK_hynix_SC311_SATA_512GB ID_PART_TABLE_TYPE=gpt ID_SERIAL_SHORT=MS83N71801150416A""".split() stub_call((output, [], 0)) result = disk.udevadm_property('dev/sda', ['ID_MODEL', 'ID_SERIAL_SHORT']) assert result['ID_MODEL'] == 'SK_hynix_SC311_SATA_512GB' assert 'ID_PART_TABLE_TYPE' not in result
def _get_device_id(self): props = ['ID_MODEL','ID_SERIAL_SHORT'] dev_id = disk.udevadm_property(self.abspath, props) if all([prop in dev_id and dev_id[prop] for prop in props]): values = [dev_id[prop].replace(' ', '_') for prop in props] return '_'.join(values) else: # the else branch should fallback to using sysfs and ioctl to # retrieve device_id on FreeBSD. Still figuring out if/how the # python ioctl implementation does that on FreeBSD return '' return ''
def test_fail_on_broken_output(self, stub_call): output = ["ID_MODEL:SK_hynix_SC311_SATA_512GB"] stub_call((output, [], 0)) with pytest.raises(ValueError): disk.udevadm_property('dev/sda')