Esempio n. 1
0
    def fetch_lsm(self, with_lsm):
        '''
        Attempt to fetch libstoragemgmt (LSM) metadata, and return to the caller
        as a dict. An empty dict is passed back to the caller if the target path
        is not a block device, or lsm is unavailable on the host. Otherwise the
        json returned will provide LSM attributes, and any associated errors that
        lsm encountered when probing the device.
        '''
        if not with_lsm or not self.exists or not self.is_device:
            return {}

        lsm_disk = LSMDisk(self.path)

        return lsm_disk.json_report()
Esempio n. 2
0
def lsm_info(monkeypatch):
    def mock_query_lsm(_, func, path):
        query_map = {
            'serial_num_get': "S2X9NX0H935283",
            'link_type_get': 6,
            'rpm_get': 0,
            'link_speed_get': 6000,
            'health_status_get': 2,
            'led_status_get': 36,
        }
        return query_map.get(func, 'Unknown')

    # mocked states and settings taken from the libstoragemgmt code base
    # c_binding/include/libstoragemgmt/libstoragemgmt_types.h at
    # https://github.com/libstorage/libstoragemgmt/
    mock_health_map = {
        -1: "Unknown",
        0: "Fail",
        1: "Warn",
        2: "Good",
    }
    mock_transport_map = {
        -1: "Unavailable",
        0: "Fibre Channel",
        2: "IBM SSA",
        3: "Serial Bus",
        4: "SCSI RDMA",
        5: "iSCSI",
        6: "SAS",
        7: "ADT (Tape)",
        8: "ATA/SATA",
        9: "USB",
        10: "SCSI over PCI-E",
        11: "PCI-E",
    }

    class MockLEDStates():
        LED_STATUS_UNKNOWN = 1
        LED_STATUS_IDENT_ON = 2
        LED_STATUS_IDENT_OFF = 4
        LED_STATUS_IDENT_UNKNOWN = 8
        LED_STATUS_FAULT_ON = 16
        LED_STATUS_FAULT_OFF = 32
        LED_STATUS_FAULT_UNKNOWN = 64

    monkeypatch.setattr(LSMDisk, '_query_lsm', mock_query_lsm)
    monkeypatch.setattr(lsmdisk, 'health_map', mock_health_map)
    monkeypatch.setattr(lsmdisk, 'transport_map', mock_transport_map)
    monkeypatch.setattr(lsmdisk, 'lsm_Disk', MockLEDStates)

    return LSMDisk('/dev/sda')