コード例 #1
0
def test_cli_add_remove_default_value(prepare_and_cleanup, shortcut):
    prepare()
    cache_device = next(disk for disk in TestProperties.dut.disks
                        if disk.disk_type == DiskType.optane)
    casadm.start_cache(cache_device, shortcut=shortcut, force=True)

    core_device = next(disk for disk in TestProperties.dut.disks
                       if disk.disk_type != DiskType.optane)
    casadm.add_core(1, core_device, shortcut=shortcut)

    caches = casadm.parse_list_caches()
    assert len(caches["1"]["cores"]) == 1
    assert caches["1"]["cores"]["1"]["path"] == core_device.system_path

    casadm.remove_core(1, 1, shortcut=shortcut)
    caches = casadm.parse_list_caches()
    assert len(caches) == 1
    assert len(caches["1"]["cores"]) == 0

    casadm.stop_cache(cache_id=1, shortcut=shortcut)

    output = casadm.list_caches(shortcut=shortcut)
    caches = casadm.parse_list_caches()
    assert len(caches) == 0
    assert output.stdout == "No caches running"
コード例 #2
0
def test_cli_add_remove_default_value(shortcut):
    cache_device = TestRun.disks['cache']
    cache_device.create_partitions([Size(50, Unit.MebiByte)])
    cache_device = cache_device.partitions[0]
    cache = casadm.start_cache(cache_device, shortcut=shortcut, force=True)

    core_device = TestRun.disks['core']

    casadm.add_core(cache, core_device, shortcut=shortcut)

    caches = casadm_parser.get_caches()
    if len(caches[0].get_core_devices()) != 1:
        TestRun.fail("One core should be present in cache")
    if caches[0].get_core_devices(
    )[0].core_device.system_path != core_device.system_path:
        TestRun.fail("Core path should equal to path of core added")

    casadm.remove_core(cache.cache_id, 1, shortcut=shortcut)
    caches = casadm_parser.get_caches()
    if len(caches) != 1:
        TestRun.fail("One cache should be present still after removing core")
    if len(caches[0].get_core_devices()) != 0:
        TestRun.fail("No core devices should be present after removing core")

    casadm.stop_cache(cache_id=cache.cache_id, shortcut=shortcut)

    output = casadm.list_caches(shortcut=shortcut)
    caches = casadm_parser.get_caches()
    if len(caches) != 0:
        TestRun.fail("No cache should be present after stopping the cache")
    if output.stdout != "No caches running":
        TestRun.fail(
            f"Invalid message, expected 'No caches running', got {output.stdout}"
        )
コード例 #3
0
def test_cli_add_remove_default_value(prepare_and_cleanup, shortcut):
    prepare()
    cache_device = next(disk for disk in TestRun.dut.disks
                        if disk.disk_type == DiskType.optane)
    cache_device.create_partitions([Size(500, Unit.MebiByte)])
    cache_device = cache_device.partitions[0]
    cache = casadm.start_cache(cache_device, shortcut=shortcut, force=True)

    core_device = next(disk for disk in TestRun.dut.disks
                       if disk.disk_type != DiskType.optane)
    casadm.add_core(cache, core_device, shortcut=shortcut)

    caches = casadm_parser.get_caches()
    assert len(caches[0].get_core_devices()) == 1
    assert caches[0].get_core_devices(
    )[0].core_device.system_path == core_device.system_path

    casadm.remove_core(cache.cache_id, 1, shortcut=shortcut)
    caches = casadm_parser.get_caches()
    assert len(caches) == 1
    assert len(caches[0].get_core_devices()) == 0

    casadm.stop_cache(cache_id=cache.cache_id, shortcut=shortcut)

    output = casadm.list_caches(shortcut=shortcut)
    caches = casadm_parser.get_caches()
    assert len(caches) == 0
    assert output.stdout == "No caches running"
コード例 #4
0
def test_cli_add_remove_default_value(shortcut):
    cache_device = TestRun.disks['cache']
    cache_device.create_partitions([Size(500, Unit.MebiByte)])
    cache_device = cache_device.partitions[0]
    cache = casadm.start_cache(cache_device, shortcut=shortcut, force=True)

    core_device = TestRun.disks['core']
    casadm.add_core(cache, core_device, shortcut=shortcut)

    caches = casadm_parser.get_caches()
    assert len(caches[0].get_core_devices()) == 1
    assert caches[0].get_core_devices(
    )[0].core_device.system_path == core_device.system_path

    casadm.remove_core(cache.cache_id, 1, shortcut=shortcut)
    caches = casadm_parser.get_caches()
    assert len(caches) == 1
    assert len(caches[0].get_core_devices()) == 0

    casadm.stop_cache(cache_id=cache.cache_id, shortcut=shortcut)

    output = casadm.list_caches(shortcut=shortcut)
    caches = casadm_parser.get_caches()
    assert len(caches) == 0
    assert output.stdout == "No caches running"
コード例 #5
0
def test_cli_add_remove_custom_id(shortcut):
    """
        title: Test for adding and removing a core with a custom ID - short and long command
        description: |
          Start a new cache and add a core to it with passing a random core ID
          (from allowed pool) as an argument and then remove this core from the cache.
        pass_criteria:
          - The core is added to the cache with a default ID
          - The core is successfully removed from the cache
    """
    with TestRun.step("Prepare the devices."):
        cache_disk = TestRun.disks['cache']
        cache_disk.create_partitions([Size(50, Unit.MebiByte)])
        cache_device = cache_disk.partitions[0]
        core_device = TestRun.disks['core']

    with TestRun.step("Start the cache and add the core with a random ID."):
        core_id = randint(*CORE_ID_RANGE)
        cache = casadm.start_cache(cache_device, shortcut=shortcut, force=True)
        core = casadm.add_core(cache,
                               core_device,
                               core_id=core_id,
                               shortcut=shortcut)
        TestRun.LOGGER.info(f"Core ID: {core_id}")

    with TestRun.step("Check if the core is added to the cache."):
        caches = casadm_parser.get_caches()
        if len(caches[0].get_core_devices()) != 1:
            TestRun.fail("One core should be present in the cache.")
        if caches[0].get_core_devices()[0].path != core.path:
            TestRun.fail(
                "The core path should be equal to the path of the core added.")

    with TestRun.step("Remove the core from the cache."):
        casadm.remove_core(cache.cache_id, core.core_id, shortcut=shortcut)

    with TestRun.step(
            "Check if the core is successfully removed from still running cache."
    ):
        caches = casadm_parser.get_caches()
        if len(caches) != 1:
            TestRun.fail(
                "One cache should be still present after removing the core.")
        if len(caches[0].get_core_devices()) != 0:
            TestRun.fail(
                "No core device should be present after removing the core.")

    with TestRun.step("Stop the cache."):
        casadm.stop_cache(cache_id=cache.cache_id, shortcut=shortcut)

    with TestRun.step("Check if the cache has successfully stopped."):
        caches = casadm_parser.get_caches()
        if len(caches) != 0:
            TestRun.fail(
                "No cache should be present after stopping the cache.")
        output = casadm.list_caches(shortcut=shortcut)
        cli_messages.check_stdout_msg(output, cli_messages.no_caches_running)
コード例 #6
0
def test_ioclass_file_extension_preexisting_filesystem(prepare_and_cleanup):
    """Create files on filesystem, add device with filesystem as a core,
        write data to files and check if they are cached properly"""
    cache, core = prepare()
    ioclass_id = 1
    extensions = ["tmp", "tm", "out", "txt", "log", "123"]
    dd_size = Size(4, Unit.KibiByte)
    dd_count = 10

    TestProperties.LOGGER.info(f"Preparing files on raw block device")
    casadm.remove_core(cache.cache_id, core_id=core.core_id)
    core.core_device.create_filesystem(Filesystem.ext3)
    core.core_device.mount(mountpoint)

    # Prepare files
    for ext in extensions:
        dd = (Dd().input("/dev/zero").output(f"{mountpoint}/test_file.{ext}").
              count(dd_count).block_size(dd_size))
        dd.run()
    core.core_device.unmount()

    # Prepare ioclass config
    rule = "|".join([f"extension:{ext}" for ext in extensions])
    ioclass_config.add_ioclass(
        ioclass_id=ioclass_id,
        eviction_priority=1,
        allocation=True,
        rule=f"{rule}&done",
        ioclass_config_path=ioclass_config_path,
    )

    # Prepare cache for test
    TestProperties.LOGGER.info(
        f"Adding device with preexisting data as a core")
    core = casadm.add_core(cache, core_dev=core.core_device)
    casadm.load_io_classes(cache_id=cache.cache_id, file=ioclass_config_path)

    core.mount(mountpoint)
    cache.flush_cache()

    # Check if files with proper extensions are cached
    TestProperties.LOGGER.info(f"Writing to file with cached extension.")
    for ext in extensions:
        dd = (Dd().input("/dev/zero").output(f"{mountpoint}/test_file.{ext}").
              count(dd_count).block_size(dd_size))
        dd.run()
        sync()
        stats = cache.get_cache_statistics(per_io_class=True,
                                           io_class_id=ioclass_id)
        assert (stats["dirty"].get_value(
            Unit.Blocks4096) == (extensions.index(ext) + 1) * dd_count)
コード例 #7
0
def test_ioclass_file_extension_preexisting_filesystem():
    """
        title: Test IO classification by file extension with preexisting filesystem on core device.
        description: |
          Test if file extension classification works properly when there is an existing
          filesystem on core device.
        pass_criteria:
          - No kernel bug.
          - IO is classified properly based on IO class rule with file extension
            after mounting core device.
    """
    ioclass_id = 1
    extensions = ["tmp", "tm", "out", "txt", "log", "123"]
    dd_size = Size(4, Unit.KibiByte)
    dd_count = 10

    with TestRun.step("Prepare cache and core devices."):
        cache, core = prepare()

    with TestRun.step(f"Prepare files on raw block device."):
        casadm.remove_core(cache.cache_id, core_id=core.core_id)
        core.core_device.create_filesystem(Filesystem.ext3)
        core.core_device.mount(mountpoint)

        for ext in extensions:
            dd = (
                Dd().input("/dev/zero").output(f"{mountpoint}/test_file.{ext}")
                .count(dd_count).block_size(dd_size))
            dd.run()
        core.core_device.unmount()

    with TestRun.step("Create IO class config."):
        rule = "|".join([f"extension:{ext}" for ext in extensions])
        ioclass_config.add_ioclass(
            ioclass_id=ioclass_id,
            eviction_priority=1,
            allocation="1.00",
            rule=f"{rule}&done",
            ioclass_config_path=ioclass_config_path,
        )

    with TestRun.step(f"Add device with preexisting data as a core."):
        core = casadm.add_core(cache, core_dev=core.core_device)

    with TestRun.step("Load IO class config."):
        casadm.load_io_classes(cache_id=cache.cache_id,
                               file=ioclass_config_path)

    with TestRun.step("Mount core and flush cache."):
        core.mount(mountpoint)
        cache.flush_cache()

    with TestRun.step(
            f"Write to file with cached extension and check if they are cached."
    ):
        for ext in extensions:
            dd = (
                Dd().input("/dev/zero").output(f"{mountpoint}/test_file.{ext}")
                .count(dd_count).block_size(dd_size))
            dd.run()
            sync()
            dirty = cache.get_io_class_statistics(
                io_class_id=ioclass_id).usage_stats.dirty
            if dirty.get_value(
                    Unit.Blocks4096) != (extensions.index(ext) + 1) * dd_count:
                TestRun.LOGGER.error(f"Wrong amount of dirty data ({dirty}).")
コード例 #8
0
ファイル: core.py プロジェクト: lausaa/open-cas-linux
 def remove_core(self, force: bool = False):
     return casadm.remove_core(self.cache_id, self.core_id, force)