コード例 #1
0
def new_cleaning_parameters_random_values(cleaning_policy):
    if cleaning_policy == CleaningPolicy.alru:
        alru_params_range = FlushParametersAlru().alru_params_range()
        wake_up_time_random_value = Time(seconds=random.randint(
            *alru_params_range.wake_up_time))
        staleness_time_random_value = Time(seconds=random.randint(
            *alru_params_range.staleness_time))
        flush_max_buffers_random_value = random.randint(
            *alru_params_range.flush_max_buffers)
        activity_threshold_random_value = Time(milliseconds=random.randint(
            *alru_params_range.activity_threshold))
        cleaning_params = FlushParametersAlru()
        cleaning_params.wake_up_time = wake_up_time_random_value
        cleaning_params.staleness_time = staleness_time_random_value
        cleaning_params.flush_max_buffers = flush_max_buffers_random_value
        cleaning_params.activity_threshold = activity_threshold_random_value

    if cleaning_policy == CleaningPolicy.acp:
        acp_params_range = FlushParametersAcp().acp_params_range()
        wake_up_time_random_value = Time(milliseconds=random.randint(
            *acp_params_range.wake_up_time))
        flush_max_buffers_random_value = random.randint(
            *acp_params_range.flush_max_buffers)
        cleaning_params = FlushParametersAcp()
        cleaning_params.wake_up_time = wake_up_time_random_value
        cleaning_params.flush_max_buffers = flush_max_buffers_random_value

    return cleaning_params
コード例 #2
0
def set_cleaning_policy_and_params(cache, cleaning_policy):
    if cleaning_policy != CleaningPolicy.DEFAULT:
        cache.set_cleaning_policy(cleaning_policy)
    current_cleaning_policy = cache.get_cleaning_policy()
    if current_cleaning_policy != cleaning_policy:
        TestRun.LOGGER.error(f"Cleaning policy is {current_cleaning_policy}, "
                             f"should be {cleaning_policy}")

    if cleaning_policy == CleaningPolicy.alru:
        alru_params = FlushParametersAlru()
        alru_params.wake_up_time = Time(seconds=10)
        alru_params.staleness_time = Time(seconds=2)
        alru_params.flush_max_buffers = 100
        alru_params.activity_threshold = Time(milliseconds=1000)
        cache.set_params_alru(alru_params)
        current_alru_params = cache.get_flush_parameters_alru()
        if current_alru_params != alru_params:
            failed_params = ""
            if current_alru_params.wake_up_time != alru_params.wake_up_time:
                failed_params += (
                    f"Wake Up time is {current_alru_params.wake_up_time}, "
                    f"should be {alru_params.wake_up_time}\n")
            if current_alru_params.staleness_time != alru_params.staleness_time:
                failed_params += (
                    f"Staleness Time is {current_alru_params.staleness_time}, "
                    f"should be {alru_params.staleness_time}\n")
            if current_alru_params.flush_max_buffers != alru_params.flush_max_buffers:
                failed_params += (
                    f"Flush Max Buffers is {current_alru_params.flush_max_buffers}, "
                    f"should be {alru_params.flush_max_buffers}\n")
            if current_alru_params.activity_threshold != alru_params.activity_threshold:
                failed_params += (
                    f"Activity Threshold is {current_alru_params.activity_threshold}, "
                    f"should be {alru_params.activity_threshold}\n")
            TestRun.LOGGER.error(
                f"ALRU parameters did not switch properly:\n{failed_params}")

    if cleaning_policy == CleaningPolicy.acp:
        acp_params = FlushParametersAcp()
        acp_params.wake_up_time = Time(milliseconds=100)
        acp_params.flush_max_buffers = 64
        cache.set_params_acp(acp_params)
        current_acp_params = cache.get_flush_parameters_acp()
        if current_acp_params != acp_params:
            failed_params = ""
            if current_acp_params.wake_up_time != acp_params.wake_up_time:
                failed_params += (
                    f"Wake Up time is {current_acp_params.wake_up_time}, "
                    f"should be {acp_params.wake_up_time}\n")
            if current_acp_params.flush_max_buffers != acp_params.flush_max_buffers:
                failed_params += (
                    f"Flush Max Buffers is {current_acp_params.flush_max_buffers}, "
                    f"should be {acp_params.flush_max_buffers}\n")
            TestRun.LOGGER.error(
                f"ACP parameters did not switch properly:\n{failed_params}")
コード例 #3
0
def test_load_x_to_one_diff_params(cache_mode, cleaning_policy,
                                   cache_line_size, cores_amount):
    """
        title: Test for loading CAS with 1 cache and 1 or 4 cores with different params.
        description: |
          Verify that loading cache configurations works properly in every mode
          with 1 cache and 1 or 4 cores. Use different parameters with load command.
        pass_criteria:
          - OpenCAS should load successfully but with saved configuration.
          - No errors in cache are found.
    """
    with TestRun.step(f"Prepare 1 cache and {cores_amount} core devices"):
        cache_dev = TestRun.disks['cache']
        cache_dev.create_partitions([Size(512, Unit.MebiByte)])
        cache_dev = cache_dev.partitions[0]
        core_dev = TestRun.disks['core']
        core_size = []
        for i in range(cores_amount):
            core_size.append(Size(1, Unit.GibiByte))
        core_dev.create_partitions(core_size)

    with TestRun.step(f"Start cache with {cores_amount} cores."):
        cache = casadm.start_cache(cache_dev,
                                   cache_mode[0],
                                   cache_line_size[0],
                                   force=True)
        id_cache = cache.cache_id
        cores = []
        for i in range(cores_amount):
            cores.append(cache.add_core(core_dev.partitions[i]))
        caches_count = len(casadm_parser.get_caches())
        if caches_count != 1:
            TestRun.fail(
                f"Expected caches count: 1; Actual caches count: {caches_count}."
            )
        cores_count = len(casadm_parser.get_cores(cache.cache_id))
        if cores_count != cores_amount:
            TestRun.fail(
                f"Expected cores count: {cores_amount}; Actual cores count: {cores_count}."
            )

    with TestRun.step("Configure cleaning policy."):
        cache.set_cleaning_policy(cleaning_policy)
        if cleaning_policy == CleaningPolicy.alru:
            alru = FlushParametersAlru()
            alru.activity_threshold = Time(milliseconds=1000)
            alru.flush_max_buffers = 10
            alru.staleness_time = Time(seconds=60)
            alru.wake_up_time = Time(seconds=5)
            cache.set_params_alru(alru)
        if cleaning_policy == CleaningPolicy.acp:
            acp = FlushParametersAcp()
            acp.flush_max_buffers = 100
            acp.wake_up_time = Time(seconds=5)
            cache.set_params_acp(acp)

    with TestRun.step("Run FIO on exported object"):
        fio = (Fio().create_command().io_engine(
            IoEngine.libaio).io_depth(64).direct().read_write(
                ReadWrite.randrw).size(Size(1, Unit.GibiByte)).block_size(
                    cache_line_size[0]).read_write(ReadWrite.randrw).num_jobs(
                        cores_amount).cpus_allowed_policy(
                            CpusAllowedPolicy.split))
        for core in cores:
            fio.add_job(f"job_{core.core_id}").target(core.path)
        fio.run()

    with TestRun.step("Stop cache."):
        cache.stop()
        caches_count = len(casadm_parser.get_caches())
        if caches_count != 0:
            TestRun.fail(
                f"There are still {caches_count} caches running after stopping service."
            )
        cores_count = len(casadm_parser.get_cores(cache.cache_id))
        if cores_count != 0:
            TestRun.fail(
                f"There are still {cores_count} cores running after stopping service."
            )

    with TestRun.step("Load cache."):
        try:
            cache = casadm.start_cache(cache_dev,
                                       cache_mode[1],
                                       cache_line_size[1],
                                       id_cache + 1,
                                       load=True)
        except Exception:
            TestRun.LOGGER.error("Cannot pass other cache ID to cache load.")
            TestRun.LOGGER.info(
                "Load cache without passing cache ID to command.")
            cache = casadm.start_cache(cache_dev,
                                       cache_mode[1],
                                       cache_line_size[1],
                                       load=True)
        caches_count = len(casadm_parser.get_caches())
        if caches_count != 1:
            TestRun.fail(
                f"Expected caches count: 1; Actual caches count: {caches_count}."
            )
        cores_count = len(casadm_parser.get_cores(cache.cache_id))
        if cores_count != cores_amount:
            TestRun.fail(
                f"Expected cores count: {cores_amount}; Actual cores count: {cores_count}."
            )

    with TestRun.step("Compare cache configuration before and after load."):
        if cache_mode[0] != cache.get_cache_mode():
            TestRun.fail("Cache modes are different. Should be the same.")
        if cache_line_size[0] != cache.get_cache_line_size():
            TestRun.fail("Cache line sizes are different. Should be the same.")
        if id_cache != cache.cache_id:
            TestRun.fail("Cache IDs are different. Should be the same.")
        if cleaning_policy != cache.get_cleaning_policy():
            TestRun.fail("Cleaning policies are different.")
        if cleaning_policy == CleaningPolicy.alru:
            if alru != cache.get_flush_parameters_alru():
                TestRun.fail("Cleaning policy parameters are different.")
        if cleaning_policy == CleaningPolicy.acp:
            if acp != cache.get_flush_parameters_acp():
                TestRun.fail("Cleaning policy parameters are different.")

    with TestRun.step("Run FIO again on exported object"):
        fio = (Fio().create_command().io_engine(
            IoEngine.libaio).io_depth(64).direct().read_write(
                ReadWrite.randrw).size(Size(1, Unit.GibiByte)).block_size(
                    cache_line_size[1]).read_write(ReadWrite.randrw).num_jobs(
                        cores_amount).cpus_allowed_policy(
                            CpusAllowedPolicy.split))
        for core in cores:
            fio.add_job(f"job_{core.core_id}").target(core.path)
        fio.run()

    with TestRun.step("Check if there are no error statistics."):
        if cache.get_statistics().error_stats.total_errors != 0:
            TestRun.fail("There are errors in the cache.")

    with TestRun.step("Stop caches."):
        casadm.stop_all_caches()