예제 #1
0
def test_cas_config_from_file_to_file(
    mock_validate_core,
    mock_validate_cache,
    mock_file,
    caches_config,
    cores_config,
):
    """
    1. Read config from mocked file with parametrized caches and cores section
    2. Serialize config back to mocked file
    3. Check if serialized file is proper config file and the same content-wise
       as the initial file. Specifically check:
           * Version tag is present in first line
           * There is only one of each [caches] and [cores] sections marking
           * [cores] section comes after [caches]
           * sets of caches and cores are equal before and after test
    """

    mock_file.set_contents(
        dedent(
            """
            version=3.8.0
            [caches]
            {0}
            [cores]
            {1}
            """
        ).format("\n".join(caches_config), "\n".join(cores_config))
    )

    config = opencas.cas_config.from_file("/dummy/file.conf")

    config.write("/dummy/file.conf")

    f = mock_file("/dummy/file.conf", "r")
    contents_hashed = h.get_hashed_config_list(f)

    assert contents_hashed[0] == "version=3.8.0"
    assert contents_hashed.count("[caches]") == 1
    assert contents_hashed.count("[cores]") == 1

    caches_index = contents_hashed.index("[caches]")
    cores_index = contents_hashed.index("[cores]")

    assert cores_index > caches_index

    caches_hashed = h.get_hashed_config_list(caches_config)
    cores_hashed = h.get_hashed_config_list(cores_config)

    assert set(caches_hashed) == set(
        contents_hashed[caches_index + 1 : cores_index]
    )
    assert set(cores_hashed) == set(contents_hashed[cores_index + 1 :])
예제 #2
0
def test_cas_config_from_file_insert_cache_insert_core_to_file(
    mock_validate_core,
    mock_validate_cache,
    mock_file,
    caches_config,
    cores_config,
):
    """
    1. Read config from mocked file with parametrized caches and cores section
    2. Add one core and one cache to config
    3. Serialize config back to mocked file
    4. Compare that config file after serialization is same content-wise with
       initial + added core and cache
    """

    mock_file.set_contents(
        dedent(
            """
            version=3.8.0
            [caches]
            {0}
            [cores]
            {1}
            """
        ).format("\n".join(caches_config), "\n".join(cores_config))
    )

    config = opencas.cas_config.from_file("/dummy/file.conf")

    config.insert_cache(opencas.cas_config.cache_config(5, "/dev/mango", "WT"))
    config.insert_core(opencas.cas_config.core_config(5, 1, "/dev/mango_core"))

    config.write("/dummy/file.conf")

    f = mock_file("/dummy/file.conf", "r")
    contents_hashed = h.get_hashed_config_list(f)

    caches_index = contents_hashed.index("[caches]")
    cores_index = contents_hashed.index("[cores]")

    caches_hashed = h.get_hashed_config_list(caches_config)
    cores_hashed = h.get_hashed_config_list(cores_config)

    assert set(contents_hashed[caches_index + 1 : cores_index]) - set(
        caches_hashed
    ) == set(["5/dev/mangowt"])
    assert set(contents_hashed[cores_index + 1 :]) - set(cores_hashed) == set(
        ["51/dev/mango_core"]
    )