コード例 #1
0
def test_cache_config_from_line_device_without_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\n", "")

    opencas.cas_config.cache_config.from_line("1    /dev/sda    WT")
コード例 #2
0
def test_cache_config_from_line_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", "")

    with pytest.raises(ValueError, match="Partitions"):
        opencas.cas_config.cache_config.from_line("1    /dev/sda    WT")
コード例 #3
0
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)
コード例 #4
0
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)
コード例 #5
0
def test_get_version_01(mock_run):
    mock_run.return_value = get_process_mock(0, "0.0.1", "errors")
    result = casadm.get_version()

    assert result.exit_code == 0
    assert result.stdout == "0.0.1"
    assert result.stderr == "errors"
    mock_run.assert_called_once_with(
        [casadm.casadm_path, "--version", "--output-format", "csv"],
        stdout=subprocess.PIPE,
        stderr=subprocess.PIPE,
        universal_newlines=mock.ANY,
    )
コード例 #6
0
def test_run_cmd_01(mock_run):
    mock_run.return_value = get_process_mock(0, "successes", "errors")
    result = casadm.run_cmd(["casadm", "-L"])

    assert result.exit_code == 0
    assert result.stdout == "successes"
    assert result.stderr == "errors"
    mock_run.assert_called_once_with(
        ["casadm", "-L"],
        stdout=subprocess.PIPE,
        stderr=subprocess.PIPE,
        universal_newlines=mock.ANY,
    )
コード例 #7
0
def test_get_version_02(mock_run):
    mock_run.return_value = get_process_mock(4, "successes", "errors")
    with pytest.raises(casadm.CasadmError):
        casadm.get_version()
コード例 #8
0
def test_run_cmd_02(mock_run):
    mock_run.return_value = get_process_mock(4, "successes", "errors")
    with pytest.raises(casadm.CasadmError):
        casadm.run_cmd(["casadm", "-L"])