예제 #1
0
    def test_unmount_tape_non_zero_returncode(self, mock_popen):
        attrs = {'communicate.return_value': ('output', 'error'), 'returncode': 1}
        mock_popen.return_value.configure_mock(**attrs)

        with self.assertRaises(RobotUnmountException):
            unmount_tape("device_to_unmount", 21, 42)

        cmd = 'mtx -f device_to_unmount unload 21 42'
        mock_popen.assert_called_once_with(cmd, shell=True, stderr=PIPE, stdout=PIPE)
예제 #2
0
    def test_unmount_tape_non_zero_returncode_and_drive_is_empty_error_msg(self, mock_popen):
        attrs = {'communicate.return_value': ('output', 'Data Transfer Element 42 is Empty'), 'returncode': 1}
        mock_popen.return_value.configure_mock(**attrs)

        with self.assertRaises(TapeUnmountedError):
            unmount_tape("device_to_unmount", 21, 42)

        cmd = 'mtx -f device_to_unmount unload 21 42'
        mock_popen.assert_called_once_with(cmd, shell=True, stderr=PIPE, stdout=PIPE)
예제 #3
0
    def test_unmount_tape_zero_returncode_should_return_output(self, mock_popen):
        attrs = {'communicate.return_value': ('All good', ''), 'returncode': 0}
        mock_popen.return_value.configure_mock(**attrs)

        self.assertEqual(unmount_tape("device_to_unmount", 21, 42), "All good")

        cmd = 'mtx -f device_to_unmount unload 21 42'
        mock_popen.assert_called_once_with(cmd, shell=True, stderr=PIPE, stdout=PIPE)
예제 #4
0
def unmount_tape_from_drive(drive):
    """
    Unmounts tape from drive into slot

    Args:
        drive: Which drive to unmount from
    """
    tape_drive = TapeDrive.objects.get(pk=drive)

    # Check if reverse one to one relation exists
    if not hasattr(tape_drive, 'storage_medium'):
        raise ValueError("No tape in tape drive to unmount")

    slot = tape_drive.storage_medium.tape_slot
    robot = tape_drive.robot

    if tape_drive.locked:
        raise TapeDriveLockedError()

    tape_drive.locked = True
    tape_drive.save(update_fields=['locked'])

    try:
        res = unmount_tape(robot.device, slot.slot_id, tape_drive.drive_id)
    except BaseException:
        StorageMedium.objects.filter(pk=tape_drive.storage_medium.pk).update(
            status=100,
            last_changed_local=timezone.now(),
        )
        TapeDrive.objects.filter(pk=drive).update(locked=False, status=100)
        TapeSlot.objects.filter(pk=slot.pk).update(status=100)
        raise

    StorageMedium.objects.filter(pk=tape_drive.storage_medium.pk).update(
        tape_drive=None,
        last_changed_local=timezone.now(),
    )

    tape_drive.last_change = timezone.now()
    tape_drive.locked = False
    tape_drive.save(update_fields=['last_change', 'locked'])

    return res
예제 #5
0
    def run(self, drive=None):
        """
        Unmounts tape from drive into slot

        Args:
            drive: Which drive to unmount from
        """

        tape_drive = TapeDrive.objects.get(pk=drive)

        if not hasattr(tape_drive, 'storage_medium'):
            raise ValueError("No tape in tape drive to unmount")

        slot = tape_drive.storage_medium.tape_slot
        robot = tape_drive.robot

        res = unmount_tape(robot.device, slot.slot_id, tape_drive.pk)

        StorageMedium.objects.filter(pk=tape_drive.storage_medium.pk).update(
            tape_drive=None)

        return res