def execute(self, cmd): """ execute a scsi command :param cmd: a scsi command """ dir = iscsi.SCSI_XFER_NONE xferlen = 0 if len(cmd.datain): dir = iscsi.SCSI_XFER_READ xferlen = len(cmd.datain) if len(cmd.dataout): dir = iscsi.SCSI_XFER_WRITE xferlen = len(cmd.dataout) task = iscsi.Task(cmd.cdb, dir, xferlen) self._iscsi.command( self._iscsi_url.lun, task, cmd.dataout, cmd.datain) if task.status == scsi_enum_command.SCSI_STATUS.CHECK_CONDITION: # No sense information propagated. raise self.CheckCondition(cmd.sense) if task.status == scsi_enum_command.SCSI_STATUS.GOOD: return raise RuntimeError
def test_empty_cdb(self): with self.assertRaises(ValueError): iscsi.Task(None, iscsi.SCSI_XFER_READ, 96)
def test_basic(self): task = iscsi.Task(b"\x12\x00\x00\x00\x60\x00", iscsi.SCSI_XFER_READ, 96) self.assertIsNotNone(task)
def test_bytearray(self): task = iscsi.Task(bytearray(b"\x12\x00\x00\x00\x60\x00"), iscsi.SCSI_XFER_READ, 96) self.assertIsNotNone(task)
def test_command(self): context = iscsi.Context("foobar") task = iscsi.Task(b"\x12\x00\x00\x00\x60\x00", iscsi.SCSI_XFER_READ, 96) data_in = bytearray(96) context.command(0, task, None, data_in)