예제 #1
0
def linux_sg(device):
    handle = create_os_file(device)
    executer = create_platform_command_executer(handle, timeout=SG_TIMEOUT_IN_MS)
    try:
        yield executer
    finally:
        handle.close()
예제 #2
0
def aix(device):
    handle = create_os_file(device)
    executer = create_platform_command_executer(handle)
    try:
        yield executer
    finally:
        handle.close()
예제 #3
0
    def test_inquiry_command_on_path(self, path, command):
        from infi.asi import create_platform_command_executer, AsiCheckConditionError
        from infi.asi.coroutines.sync_adapter import sync_wait
        from os import open, O_RDWR
        from infi.asi.unix import UnixFile

        for scsi_id_path in glob('/sys/class/scsi_disk/*'):
            if scsi_id_path.split('/')[-1] == path.split('/')[-1]:
                block_device = glob(scsi_id_path + '/device/block/*')[0].split('/')[-1]
                if not block_device.startswith('sd'):
                    raise unittest.SkipTest()
                break

        f = UnixFile(open(path, O_RDWR))
        executer = create_platform_command_executer(f)
        cdb = command()
        try:
            _ = sync_wait(cdb.execute(executer))
        except AsiCheckConditionError as e:
            # Some devices does not support some pages
            # for example, VMware on hba02 does not support 0x83
            if e.sense_obj.sense_key == 'ILLEGAL_REQUEST' \
                        and e.sense_obj.additional_sense_code.code_name == 'INVALID FIELD IN CDB':
                pass
            else:
                raise
        f.close()
예제 #4
0
    def test_inquiry_command_on_path(self, path, command):
        from infi.asi import create_platform_command_executer, AsiCheckConditionError
        from infi.asi.coroutines.sync_adapter import sync_wait
        from os import open, O_RDWR
        from infi.asi.unix import UnixFile

        for scsi_id_path in glob('/sys/class/scsi_disk/*'):
            if scsi_id_path.split('/')[-1] == path.split('/')[-1]:
                block_device = glob(scsi_id_path +
                                    '/device/block/*')[0].split('/')[-1]
                if not block_device.startswith('sd'):
                    raise unittest.SkipTest()
                break

        f = UnixFile(open(path, O_RDWR))
        executer = create_platform_command_executer(f)
        cdb = command()
        try:
            _ = sync_wait(cdb.execute(executer))
        except AsiCheckConditionError as e:
            # Some devices does not support some pages
            # for example, VMware on hba02 does not support 0x83
            if e.sense_obj.sense_key == 'ILLEGAL_REQUEST' \
                        and e.sense_obj.additional_sense_code.code_name == 'INVALID FIELD IN CDB':
                pass
            else:
                raise
        f.close()
예제 #5
0
def asi_context(sg_device):
    from infi.asi import create_platform_command_executer, create_os_file
    handle = create_os_file("/dev/{}".format(sg_device))
    executer = create_platform_command_executer(handle, timeout=TIMEOUT)
    try:
        yield executer
    finally:
        handle.close()
예제 #6
0
 def asi_context(self):
     from infi.asi.win32 import OSFile
     from infi.asi import create_platform_command_executer
     handle = OSFile(self.get_pdo())
     executer = create_platform_command_executer(handle)
     try:
         yield executer
     finally:
         handle.close()
예제 #7
0
 def asi_context(self):
     from infi.asi import create_platform_command_executer, create_os_file
     handle = create_os_file(self.get_pdo())
     executer = create_platform_command_executer(handle)
     executer.call = defer(executer.call)
     try:
         yield executer
     finally:
         handle.close()
예제 #8
0
 def asi_context(self):
     from infi.asi import create_platform_command_executer, create_os_file
     handle = create_os_file(self._get_access_path())
     executer = create_platform_command_executer(handle)
     executer.call = gevent_wrapper.defer(executer.call)
     try:
         yield executer
     finally:
         handle.close()
 def asi_context(self):
     from infi.asi import create_platform_command_executer, create_os_file
     handle = create_os_file(self._get_access_path())
     executer = create_platform_command_executer(handle)
     executer.call = gevent_wrapper.defer(executer.call)
     try:
         yield executer
     finally:
         handle.close()
예제 #10
0
 def asi_context(self):
     from infi.asi import create_platform_command_executer, create_os_file
     handle = create_os_file(self.get_pdo())
     executer = create_platform_command_executer(handle)
     executer.call = defer(executer.call)
     try:
         yield executer
     finally:
         handle.close()
예제 #11
0
    def asi_context(self):
        from infi.asi import create_platform_command_executer, create_os_file

        handle = create_os_file(self.get_scsi_access_path())
        executer = create_platform_command_executer(handle, timeout=QUERY_TIMEOUT_IN_SECONDS)
        executer.call = gevent_wrapper.defer(executer.call)
        try:
            yield executer
        finally:
            handle.close()
예제 #12
0
    def asi_context(self):
        from infi.asi import create_platform_command_executer, create_os_file

        handle = create_os_file(self.get_scsi_access_path())
        executer = create_platform_command_executer(handle, timeout=QUERY_TIMEOUT_IN_SECONDS)
        executer.call = gevent_wrapper.defer(executer.call)
        try:
            yield executer
        finally:
            handle.close()
 def asi_context(self):
     import os
     from infi.asi.unix import OSFile
     from infi.asi import create_platform_command_executer
     from .scsi import SG_TIMEOUT_IN_MS
     handle = OSFile(os.open(os.path.join("/dev", self.sysfs_device.get_scsi_generic_device_name()), os.O_RDWR))
     executer = create_platform_command_executer(handle, timeout=SG_TIMEOUT_IN_MS)
     try:
         yield executer
     finally:
         handle.close()
예제 #14
0
    def asi_context(self):
        import os
        from infi.asi.unix import OSFile
        from infi.asi import create_platform_command_executer

        handle = OSFile(os.open(self.get_scsi_access_path(), os.O_RDWR))
        executer = create_platform_command_executer(handle, timeout=SG_TIMEOUT_IN_MS)
        try:
            yield executer
        finally:
            handle.close()
    def asi_context(self):
        import os
        from infi.asi import create_platform_command_executer, create_os_file

        handle = create_os_file(self.device_path)
        executer = create_platform_command_executer(handle, timeout=QUERY_TIMEOUT)
        executer.call = gevent_wrapper.defer(executer.call)
        try:
            yield executer
        finally:
            handle.close()
 def asi_context(self):
     import os
     from infi.asi import create_platform_command_executer, create_os_file
     from .scsi import SG_TIMEOUT_IN_MS
     path = os.path.join("/dev", self.sysfs_device.get_scsi_generic_device_name())
     handle = create_os_file(path)
     executer = create_platform_command_executer(handle, timeout=SG_TIMEOUT_IN_MS)
     executer.call = gevent_wrapper.defer(executer.call)
     try:
         yield executer
     finally:
         handle.close()
예제 #17
0
 def asi_context(self):
     import os
     from infi.asi import create_platform_command_executer, create_os_file
     from .scsi import SG_TIMEOUT_IN_MS
     path = os.path.join("/dev",
                         self.sysfs_device.get_scsi_generic_device_name())
     handle = create_os_file(path)
     executer = create_platform_command_executer(handle,
                                                 timeout=SG_TIMEOUT_IN_MS)
     executer.call = gevent_wrapper.defer(executer.call)
     try:
         yield executer
     finally:
         handle.close()
예제 #18
0
def test_report_luns_command():
    from infi.asi.unix import UnixFile
    import os
    if not os.path.exists("/dev/sg1"):
        return
    from infi.asi.coroutines.sync_adapter import sync_wait
    from infi.asi.cdb.report_luns import ReportLunsCommand
    from infi.asi import create_platform_command_executer
    handle = UnixFile(os.open("/dev/sg1", os.O_RDWR))
    executer = create_platform_command_executer(handle)
    cdb = ReportLunsCommand(select_report=0)
    result = sync_wait(cdb.execute(executer))
    assert result.lun_list != []
    assert 0 in result.lun_list
예제 #19
0
    def asi_context(self):
        import os
        from infi.asi import create_platform_command_executer, create_os_file

        # if sgen is not loaded we can't open the device
        if not os.path.exists(self.get_block_access_path()) and os.path.exists(self.get_block_access_path().strip(":array_ctrl")):
            msg = "can't query device {} since block access path doesn't exist (sgen is not loaded)".format(self.get_display_name())
            raise ScsiGenericNotLoaded(msg)

        handle = create_os_file(self.get_block_access_path())
        executer = create_platform_command_executer(handle, timeout=QUERY_TIMEOUT)
        executer.call = gevent_wrapper.defer(executer.call)
        try:
            yield executer
        finally:
            handle.close()
예제 #20
0
def test_report_luns_command():
    from infi.os_info import get_platform_string
    from infi.asi.unix import UnixFile
    import os
    if 'ubuntu' not in get_platform_string() or not os.path.exists("/dev/sg1"):
        # on some of our other environments, sg0 is the cdrom and sg1 is the local disk, and on others it's the
        # other way around. just test this on Ubuntu only.
        return
    from infi.asi.coroutines.sync_adapter import sync_wait
    from infi.asi.cdb.report_luns import ReportLunsCommand
    from infi.asi import create_platform_command_executer
    handle = UnixFile(os.open("/dev/sg1", os.O_RDWR))
    executer = create_platform_command_executer(handle)
    cdb = ReportLunsCommand(select_report=0)
    result = sync_wait(cdb.execute(executer))
    assert result.lun_list != []
    assert 0 in result.lun_list
예제 #21
0
def test_report_luns_command():
    from infi.os_info import get_platform_string
    from infi.asi.unix import UnixFile
    import os
    if 'ubuntu' not in get_platform_string() or not os.path.exists("/dev/sg1"):
        # on some of our other environments, sg0 is the cdrom and sg1 is the local disk, and on others it's the
        # other way around. just test this on Ubuntu only.
        return
    from infi.asi.coroutines.sync_adapter import sync_wait
    from infi.asi.cdb.report_luns import ReportLunsCommand
    from infi.asi import create_platform_command_executer
    handle = UnixFile(os.open("/dev/sg1", os.O_RDWR))
    executer = create_platform_command_executer(handle)
    cdb = ReportLunsCommand(select_report=0)
    result = sync_wait(cdb.execute(executer))
    assert result.lun_list != []
    assert 0 in result.lun_list
예제 #22
0
    def asi_context(self):
        import os
        from infi.asi import create_platform_command_executer, create_os_file

        # if sgen is not loaded we can't open the device
        if not os.path.exists(self.get_block_access_path()) and os.path.exists(
                self.get_block_access_path().strip(":array_ctrl")):
            msg = "can't query device {} since block access path doesn't exist (sgen is not loaded)".format(
                self.get_display_name())
            raise ScsiGenericNotLoaded(msg)

        handle = create_os_file(self.get_block_access_path())
        executer = create_platform_command_executer(handle,
                                                    timeout=QUERY_TIMEOUT)
        executer.call = gevent_wrapper.defer(executer.call)
        try:
            yield executer
        finally:
            handle.close()
예제 #23
0
def run_cmd(os_file, cmd, helper=None):
    executer = create_platform_command_executer(os_file)
    cdb = cmd(helper) if helper else cmd()
    data = sync_wait(cdb.execute(executer))
    return data
예제 #24
0
class OSFile(object):
    def __init__(self, fd):
        self.fd = fd

    def read(self, size):
        return os.read(self.fd, size)

    def write(self, buffer):
        return os.write(self.fd, buffer)

    def close(self):
        os.close(self.fd)


f = OSFile(os.open(path, os.O_RDWR))

try:

    executer = create_platform_command_executer(f)
    possible_commands = {10: ReadCapacity10Command, 16: ReadCapacity16Command}

    cdb = possible_commands[cdb_size](logical_block_address=0, pmi=0)
    data = sync_wait(cdb.execute(executer))

    print(repr(data))

    f.close()
except:
    print_exc()
예제 #25
0
try:
    available_commands = {
        "standard": StandardInquiryCommand,
        "0x80": vpd_pages.UnitSerialNumberVPDPageCommand,
        "0x83": vpd_pages.DeviceIdentificationVPDPageCommand,
    }

    if sys.argv[2] not in available_commands:
        raise ValueError("available commands: %s" % repr(available_commands.keys()))
            
    path = sys.argv[1]

    f = create_os_file(path, async=True)

    command = available_commands[sys.argv[2]]

    executer = create_platform_command_executer(f)
    cdb = command()
    execution1 = cdb.execute(executer)
    execution2 = cdb.execute(executer)
    execution3 = cdb.execute(executer)

    data1, data2, data3 = async_wait(execution1, execution2, execution3)
    
    print("\n\n".join([repr(data1), repr(data2), repr(data3)]))

    f.close()
except:
    print_exc()
예제 #26
0
def run_cmd(os_file, cmd, helper=None):
    executer = create_platform_command_executer(os_file)
    cdb = cmd(helper) if helper else cmd()
    data = sync_wait(cdb.execute(executer))
    return data