Exemplo n.º 1
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)
Exemplo n.º 2
0
def test_cli_start_stop_custom_id(shortcut):
    """
        title: Test for starting a cache with a custom ID - short and long command
        description: |
          Start a new cache with a random ID (from allowed pool) and then stop this cache.
        pass_criteria:
          - The cache has successfully started with a custom ID
          - The cache has successfully stopped
    """
    with TestRun.step("Prepare the device for the cache."):
        cache_device = TestRun.disks['cache']
        cache_device.create_partitions([Size(500, Unit.MebiByte)])
        cache_device = cache_device.partitions[0]

    with TestRun.step("Start the cache with a random ID."):
        cache_id = randint(*CACHE_ID_RANGE)
        cache = casadm.start_cache(cache_device,
                                   cache_id=cache_id,
                                   shortcut=shortcut,
                                   force=True)
        TestRun.LOGGER.info(f"Cache ID: {cache_id}")

    with TestRun.step("Check if the cache has started successfully."):
        caches = casadm_parser.get_caches()
        if len(caches) != 1:
            TestRun.fail(
                f"There is a wrong number of caches found in the OS: {len(caches)}. "
                f"Should be only 1.")
        if cache.cache_device.path != cache_device.path:
            TestRun.fail(f"The cache has started using a wrong device:"
                         f" {cache.cache_device.path}."
                         f"\nShould use {cache_device.path}.")

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

    with TestRun.step("Check if the cache has stopped properly."):
        caches = casadm_parser.get_caches()
        if len(caches) != 0:
            TestRun.fail(
                f"There is a wrong number of caches found in the OS: {len(caches)}."
                f"\nNo 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)
Exemplo n.º 3
0
def check_log(last_read_line, expected_message):
    """Read recent lines in log, look for given, expected message."""
    cmd = f"tail -qn +{last_read_line} {log_path}"
    log = TestRun.executor.run(cmd)

    if cli_messages.check_stdout_msg(log, expected_message):
        TestRun.LOGGER.info(
            f"Found expected message in log: {expected_message}")
        return True
    else:
        TestRun.LOGGER.warning(
            f"Haven't found expected message in log: {expected_message}")
        return False
Exemplo n.º 4
0
def test_cli_help(shortcut):
    """
    title: Test for 'help' command.
    description: Test if help for commands displays.
    pass_criteria:
      - Proper help displays for every command.
    """
    TestRun.LOGGER.info("Run 'help' for every 'casadm' command.")
    output = casadm.help(shortcut)
    check_stdout_msg(output, casadm_help)

    output = TestRun.executor.run("casadm" +
                                  (" -S" if shortcut else " --start-cache") +
                                  (" -H" if shortcut else " --help"))
    check_stdout_msg(output, start_cache_help)

    output = TestRun.executor.run("casadm" +
                                  (" -T" if shortcut else " --stop-cache") +
                                  (" -H" if shortcut else " --help"))
    check_stdout_msg(output, stop_cache_help)

    output = TestRun.executor.run("casadm" +
                                  (" -X" if shortcut else " --set-param") +
                                  (" -H" if shortcut else " --help"))
    check_stdout_msg(output, set_params_help)

    output = TestRun.executor.run("casadm" +
                                  (" -G" if shortcut else " --get-param") +
                                  (" -H" if shortcut else " --help"))
    check_stdout_msg(output, get_params_help)

    output = TestRun.executor.run(
        "casadm" + (" -Q" if shortcut else " --set-cache-mode") +
        (" -H" if shortcut else " --help"))
    check_stdout_msg(output, set_cache_mode_help)

    output = TestRun.executor.run("casadm" +
                                  (" -A" if shortcut else " --add-core") +
                                  (" -H" if shortcut else " --help"))
    check_stdout_msg(output, add_core_help)

    output = TestRun.executor.run("casadm" +
                                  (" -R" if shortcut else " --remove-core") +
                                  (" -H" if shortcut else " --help"))
    check_stdout_msg(output, remove_core_help)

    output = TestRun.executor.run("casadm" + " --remove-detached" +
                                  (" -H" if shortcut else " --help"))
    check_stdout_msg(output, remove_detached_help)

    output = TestRun.executor.run("casadm" +
                                  (" -L" if shortcut else " --list-caches") +
                                  (" -H" if shortcut else " --help"))
    check_stdout_msg(output, list_help)

    output = TestRun.executor.run("casadm" +
                                  (" -P" if shortcut else " --stats") +
                                  (" -H" if shortcut else " --help"))
    check_stdout_msg(output, stats_help)

    output = TestRun.executor.run(
        "casadm" + (" -Z" if shortcut else " --reset-counters") +
        (" -H" if shortcut else " --help"))
    check_stdout_msg(output, reset_counters_help)

    output = TestRun.executor.run("casadm" +
                                  (" -F" if shortcut else " --flush-cache") +
                                  (" -H" if shortcut else " --help"))
    check_stdout_msg(output, flush_cache_help)

    output = TestRun.executor.run("casadm" +
                                  (" -E" if shortcut else " --flush-core") +
                                  (" -H" if shortcut else " --help"))
    check_stdout_msg(output, flush_core_help)

    output = TestRun.executor.run("casadm" +
                                  (" -C" if shortcut else " --io-class") +
                                  (" -H" if shortcut else " --help"))
    check_stdout_msg(output, ioclass_help)

    output = TestRun.executor.run("casadm" +
                                  (" -V" if shortcut else " --version") +
                                  (" -H" if shortcut else " --help"))
    check_stdout_msg(output, version_help)

    output = TestRun.executor.run("casadm" +
                                  (" -H" if shortcut else " --help") +
                                  (" -H" if shortcut else " --help"))
    check_stdout_msg(output, help_help)

    output = TestRun.executor.run("casadm" + " --zero-metadata" +
                                  (" -H" if shortcut else " --help"))
    check_stdout_msg(output, zero_metadata_help)

    output = TestRun.executor.run("casadm" +
                                  (" -Y" if shortcut else " --yell") +
                                  (" -H" if shortcut else " --help"))
    check_stderr_msg(output, unrecognized_stderr)
    check_stdout_msg(output, unrecognized_stdout)