Beispiel #1
0
def test_optimize_readahead_should_not_apply(mocker):
    mock_subprocess_call = _mock_subprocess_call(mocker)
    mock_config = _get_new_mock_config(True)
    _mock_should_revise_readahead(mocker, False)
    mount_efs.optimize_readahead_window(MOUNT_POINT, DEFAULT_OPTIONS,
                                        mock_config)
    utils.assert_not_called(mock_subprocess_call)
def test_optimize_readahead_should_apply_failed_with_exception(mocker):
    mock_subprocess_call = _mock_subprocess_call(mocker, True)
    mock_config = _get_new_mock_config(True)
    mock_log_warning = mocker.patch("logging.warning")
    _mock_should_revise_readahead(mocker, True)

    mocker.patch(
        "subprocess.check_output",
        return_value='"' + str(EXPECTED_MOUNT_POINT_DEV_NUMBER) + '"\n',
    )

    mount_efs.optimize_readahead_window(MOUNT_POINT, DEFAULT_OPTIONS,
                                        mock_config)

    utils.assert_called_once(mock_subprocess_call)

    args, _ = mock_subprocess_call.call_args

    readahead_kb_value = int(mount_efs.DEFAULT_NFS_MAX_READAHEAD_MULTIPLIER *
                             int(DEFAULT_OPTIONS["rsize"]) / 1024)
    expected_subprocess_call = EXPECTED_CALL_FORMAT % (
        readahead_kb_value,
        EXPECTED_READAHEAD_KB_PATH,
    )
    assert expected_subprocess_call == args[0]

    assert "failed to modify read_ahead_kb" in mock_log_warning.call_args[0][0]
Beispiel #3
0
def test_optimize_readahead_should_apply(mocker):
    mock_subprocess_call = _mock_subprocess_call(mocker)
    mock_config = _get_new_mock_config(True)
    _mock_should_revise_readahead(mocker, True)

    mocker.patch('subprocess.check_output',
                 return_value='"' + str(EXPECTED_MOUNT_POINT_DEV_NUMBER) +
                 '"\n')

    mount_efs.optimize_readahead_window(MOUNT_POINT, DEFAULT_OPTIONS,
                                        mock_config)

    utils.assert_called_once(mock_subprocess_call)

    args, _ = mock_subprocess_call.call_args

    readahead_kb_value = int(mount_efs.DEFAULT_NFS_MAX_READAHEAD_MULTIPLIER *
                             int(DEFAULT_OPTIONS['rsize']) / 1024)
    expected_subprocess_call = EXPECTED_CALL_FORMAT % (
        readahead_kb_value, EXPECTED_READAHEAD_KB_PATH)
    assert expected_subprocess_call == args[0]