def test_cache_config_from_line_parameter_validation_02(
    mock_check_block, mock_device_empty, mock_path_exists, params
):
    mock_path_exists.side_effect = h.get_mock_os_exists(
        ["/dev/sda", "ioclass.csv"]
    )

    line = "1   /dev/sda    WT  {0}".format(params)

    opencas.cas_config.cache_config.from_line(line)
def test_cache_config_from_line_cache_id_validation_01(mock_check_block,
                                                       mock_device_empty,
                                                       mock_path_exists,
                                                       cache_id):
    mock_path_exists.side_effect = h.get_mock_os_exists(
        ["/dev/sda", "ioclass.csv"])

    line = "{0}   /dev/sda    WT".format(cache_id)

    with pytest.raises(ValueError):
        opencas.cas_config.cache_config.from_line(line)
def test_cache_config_validate_force_device_with_partitions(
        mock_run, mock_stat, mock_path_exists):
    mock_path_exists.side_effect = h.get_mock_os_exists(["/dev/sda"])
    mock_stat.return_value = mock.Mock(st_mode=stat.S_IFBLK)
    mock_run.return_value = h.get_process_mock(0, "sda\nsda1\nsda2", "")

    cache = opencas.cas_config.cache_config(cache_id="1",
                                            device="/dev/sda",
                                            cache_mode="WT")

    cache.validate_config(True)
def test_cache_config_from_line_parameter_validation_01(
    mock_check_block, mock_device_empty, mock_path_exists, params
):
    mock_path_exists.side_effect = h.get_mock_os_exists(
        ["/dev/sda", "ioclass.csv"]
    )

    line = "1   /dev/sda    WT  {0}".format(params)

    with pytest.raises(ValueError, match="[Ii]nvalid"):
        opencas.cas_config.cache_config.from_line(line)
def test_core_config_from_line_cache_id_validation_01(mock_stat,
                                                      mock_path_exists,
                                                      cache_id, core_id):
    mock_path_exists.side_effect = h.get_mock_os_exists(
        ["/dev/not_a_real_device"])
    mock_stat.return_value = mock.Mock(st_mode=stat.S_IFBLK)

    line = "{0}   {1}   /dev/not_a_real_device".format(cache_id, core_id)

    with pytest.raises(ValueError):
        opencas.cas_config.core_config.from_line(line)
def test_cache_config_from_line_missing_ioclass_file(
    mock_check_block, mock_path_exists
):
    mock_path_exists.side_effect = h.get_mock_os_exists(["/dev/nvme0n1"])

    with pytest.raises(ValueError):
        opencas.cas_config.cache_config.from_line(
            (
                "11 /dev/nvme0n1 WT   ioclass_file=ioclass.csv,"
                "cleaning_policy=nop,cache_line_size=4"
            )
        )
def test_cache_config_validate_device_with_partitions(mock_popen, mock_stat,
                                                      mock_path_exists):
    mock_path_exists.side_effect = h.get_mock_os_exists(["/dev/sda"])
    mock_stat.return_value = mock.Mock(st_mode=stat.S_IFBLK)
    mock_popen.return_value = h.get_process_mock(0, "sda\nsda1\nsda2", "")

    cache = opencas.cas_config.cache_config(cache_id="1",
                                            device="/dev/sda",
                                            cache_mode="WT",
                                            params=dict())

    with pytest.raises(ValueError):
        cache.validate_config(False)
예제 #8
0
def test_core_config_from_line_cache_id_validation(
    mock_stat, mock_path_exists, cache_id, core_id, device
):
    mock_path_exists.side_effect = h.get_mock_os_exists([device])
    mock_stat.return_value = mock.Mock(st_mode=stat.S_IFBLK)

    core_reference = opencas.cas_config.core_config(
        cache_id=cache_id, core_id=core_id, path=device
    )

    core_reference.validate_config()

    core_after = opencas.cas_config.core_config.from_line(core_reference.to_line())
    assert core_after.cache_id == core_reference.cache_id
    assert core_after.core_id == core_reference.core_id
    assert core_after.device == core_reference.device
def test_cache_config_to_line_from_line(mock_check_block, mock_device_empty,
                                        mock_path_exists, params):
    mock_path_exists.side_effect = h.get_mock_os_exists(
        [params["device"], "ioclass.csv"])

    cache_reference = opencas.cas_config.cache_config(**params)

    cache_reference.validate_config(False)

    cache_after = opencas.cas_config.cache_config.from_line(
        cache_reference.to_line())

    assert cache_after.cache_id == cache_reference.cache_id
    assert cache_after.device == cache_reference.device
    assert str.lower(cache_after.cache_mode) == str.lower(
        cache_reference.cache_mode)
    assert cache_after.params == cache_reference.params
def test_cache_config_from_line_multilevel(mock_stat, mock_path_exists):
    mock_path_exists.side_effect = h.get_mock_os_exists([])
    mock_stat.raises = OSError()

    opencas.cas_config.cache_config.from_line("2    /dev/cas1-1    WT")
def test_cache_config_from_line_device_not_present(mock_stat, mock_path_exists):
    mock_path_exists.side_effect = h.get_mock_os_exists([])
    mock_stat.side_effect = OSError()

    with pytest.raises(ValueError, match="not found"):
        opencas.cas_config.cache_config.from_line("1    /dev/nvme0n1    WT")
예제 #12
0
def test_core_config_from_line_device_not_present(mock_stat, mock_path_exists):
    mock_path_exists.side_effect = h.get_mock_os_exists([])
    mock_stat.side_effect = ValueError()

    with pytest.raises(ValueError):
        opencas.cas_config.core_config.from_line("1    1   /dev/not_a_real_device")
예제 #13
0
def test_core_config_from_line_device_is_directory(mock_stat, mock_path_exists):
    mock_path_exists.side_effect = h.get_mock_os_exists(["/home/user/stuff"])
    mock_stat.return_value = mock.Mock(st_mode=stat.S_IFDIR)

    with pytest.raises(ValueError):
        opencas.cas_config.core_config.from_line("1    1   /home/user/stuff")