Ejemplo n.º 1
0
def pytest_runtest_teardown():
    """
    This method is executed always in the end of each test, even if it fails or raises exception in
    prepare stage.
    """
    TestRun.LOGGER.end_all_groups()

    with TestRun.LOGGER.step("Cleanup after test"):
        try:
            if TestRun.executor:
                if not TestRun.executor.is_active():
                    TestRun.executor.wait_for_connection()
                Udev.enable()
                kill_all_io()
                unmount_cas_devices()
                if installer.check_if_installed():
                    casadm.remove_all_detached_cores()
                    casadm.stop_all_caches()
                    from api.cas.init_config import InitConfig
                    InitConfig.create_default_init_config()
                DeviceMapper.remove_all()
        except Exception as ex:
            TestRun.LOGGER.warning(f"Exception occurred during platform cleanup.\n"
                                   f"{str(ex)}\n{traceback.format_exc()}")

    TestRun.LOGGER.end()
    for dut in TestRun.duts:
        with TestRun.use_dut(dut):
            if TestRun.executor:
                os.makedirs(os.path.join(TestRun.LOGGER.base_dir, "dut_info", dut.ip),
                            exist_ok=True)
                TestRun.LOGGER.get_additional_logs()
    Log.destroy()
    TestRun.teardown()
Ejemplo n.º 2
0
def base_prepare(item):
    with TestRun.LOGGER.step("Cleanup before test"):
        Udev.enable()
        kill_all_io()
        DeviceMapper.remove_all()

        if installer.check_if_installed():
            try:
                from api.cas.init_config import InitConfig
                InitConfig.create_default_init_config()
                unmount_cas_devices()
                casadm.stop_all_caches()
                casadm.remove_all_detached_cores()
            except Exception:
                pass  # TODO: Reboot DUT if test is executed remotely

        for disk in TestRun.dut.disks:
            disk.umount_all_partitions()
            if not create_partition_table(disk, PartitionTable.gpt):
                raise Exception(f"Failed to remove partitions from {disk}")

        if get_force_param(item) and not TestRun.usr.already_updated:
            installer.reinstall_opencas()
        elif not installer.check_if_installed():
            installer.install_opencas()
        TestRun.usr.already_updated = True
        TestRun.LOGGER.add_build_info(f'Commit hash:')
        TestRun.LOGGER.add_build_info(f"{git.get_current_commit_hash()}")
        TestRun.LOGGER.add_build_info(f'Commit message:')
        TestRun.LOGGER.add_build_info(f'{git.get_current_commit_message()}')
Ejemplo n.º 3
0
def test_core_pool_exclusive_open():
    """
    title: Exclusive open of core pool.
    description: |
      Check that CAS exclusively opens core devices from core device pool so that the core device
      cannot be used in any other way.
    pass_criteria:
      - No system crash while reloading CAS modules.
      - Core device was added successfully to core pool.
      - Core device is exclusively open in the core pool and cannot be used otherwise.
    """
    with TestRun.step("Prepare core device and create filesystem on it."):
        core_disk = TestRun.disks["core"]
        core_disk.create_partitions([Size(1, Unit.GibiByte)])
        core_dev = core_disk.partitions[0]
        core_dev.create_filesystem(Filesystem.ext4)
    with TestRun.step("Add core device to core device pool using --try-add flag."):
        core = casadm.try_add(core_dev, 1)
    with TestRun.step("Check if core status of added core in core pool is detached."):
        status = core.get_status()
        if status is not CoreStatus.detached:
            TestRun.fail(f"Core status should be detached but is {status}.")
    with TestRun.step("Check if it is impossible to add core device from core pool to "
                      "running cache."):
        TestRun.disks["cache"].create_partitions([Size(2, Unit.GibiByte)])
        cache_dev = TestRun.disks["cache"].partitions[0]
        cache = casadm.start_cache(cache_dev, force=True)
        try:
            cache.add_core(core_dev)
            TestRun.fail("Core from core pool added to cache, this is unexpected behaviour.")
        except CmdException:
            TestRun.LOGGER.info("Adding core from core pool to cache is blocked as expected.")
        cache.stop()
    with TestRun.step("Check if it is impossible to start cache with casadm start command on the "
                      "core device from core pool."):
        try:
            cache = casadm.start_cache(core_dev)
            cache.stop()
            TestRun.fail("Cache started successfully on core device from core pool, "
                         "this is unexpected behaviour.")
        except CmdException:
            TestRun.LOGGER.info("Using core device from core pool as cache is blocked as expected.")
    with TestRun.step("Check if it is impossible to make filesystem on the core device "
                      "from core pool."):
        try:
            core_dev.create_filesystem(Filesystem.ext4, force=False)
            TestRun.fail("Successfully created filesystem on core from core pool, "
                         "this is unexpected behaviour.")
        except Exception:
            TestRun.LOGGER.info("Creating filesystem on core device from core pool is "
                                "blocked as expected.")
    with TestRun.step("Check if it is impossible to mount the core device from core pool."):
        try:
            core_dev.mount("/mnt")
            TestRun.fail("Successfully mounted core pool device, this is unexpected behaviour.")
        except Exception:
            TestRun.LOGGER.info("Mounting core device form core pool is blocked as expected.")
    with TestRun.step("Remove core from core pool."):
        casadm.remove_all_detached_cores()
def test_remove_detached_cores():
    """
        title: Validate removing core devices from core pool.
        description: Validate that it is possible to remove core devices from core pool.
        pass_criteria:
          - No kernel error
          - All core devices are correctly added after plugging core disk.
          - All cores are successfully removed.
    """
    with TestRun.step("Prepare devices."):
        devices = prepare_devices([("cache", 1), ("core", 4)])
        cache_dev = devices["cache"].partitions[0]
        core_devs = devices["core"].partitions
        plug_device = devices["core"]
    with TestRun.step("Start cache and add four cores."):
        cache = casadm.start_cache(cache_dev,
                                   cache_mode=CacheMode.WB,
                                   force=True)
        cores = []
        for d in core_devs:
            cores.append(cache.add_core(d))
    with TestRun.step(
            "Create init config file using current CAS configuration."):
        InitConfig.create_init_config_from_running_configuration()
    with TestRun.step("Run random writes to all CAS devices."):
        run_fio([c.system_path for c in cores])
    with TestRun.step(
            "Flush dirty data from two CAS devices and verify than other two contain "
            "dirty data."):
        for core in cores:
            if core.core_id % 2 == 0:
                core.flush_core()
                if core.get_dirty_blocks() != Size.zero():
                    TestRun.fail("Failed to flush CAS device.")
            elif core.get_dirty_blocks() == Size.zero():
                TestRun.fail("There should be dirty data on CAS device.")
    with TestRun.step("Stop cache without flushing dirty data."):
        cache.stop(no_data_flush=True)
    with TestRun.step("Unplug core device from system and plug it back."):
        plug_device.unplug()
        time.sleep(2)
        plug_device.plug()
    with TestRun.step(
            "Verify that all cores from plugged core device are listed with "
            "proper status."):
        for core in cores:
            if core.get_status() != CoreStatus.detached:
                TestRun.fail(f"Each core should be in detached state. "
                             f"Actual states: {casadm.list_caches().stdout}")
    with TestRun.step("Remove CAS devices from core pool."):
        casadm.remove_all_detached_cores()
    with TestRun.step("Verify that cores are no longer listed."):
        output = casadm.list_caches().stdout
        for dev in core_devs:
            if dev.system_path in output:
                TestRun.fail(
                    f"CAS device is still listed in casadm list output:\n{output}"
                )
Ejemplo n.º 5
0
def test_attach_core_pool():
    """
    title: Attaching from core pool on cache load.
    description: |
      Check that CAS has the ability on cache load to attach core devices that were added to
      core device pool if those devices were previously used by cache instance being loaded.
      Prevent attaching core device if they were not previously used.
    pass_criteria:
      - No system crash while reloading CAS modules.
      - Core device was added successfully to core pool.
      - Core device has been successfully attached to cache on cache load.
      - Second core device was not attached to the cache instance.
    """
    with TestRun.step("Prepare devices."):
        cache_disk = TestRun.disks["cache"]
        cache_disk.create_partitions([Size(1, Unit.GibiByte)])
        cache_dev = cache_disk.partitions[0]
        core_disk = TestRun.disks["core"]
        core_disk.create_partitions(
            [Size(2, Unit.GibiByte),
             Size(2, Unit.GibiByte)])
        core_dev = core_disk.partitions[0]
        second_core_dev = core_disk.partitions[1]

    with TestRun.step("Start cache."):
        cache = casadm.start_cache(cache_dev, force=True)

    with TestRun.step("Add core device."):
        cache.add_core(core_dev)

    with TestRun.step("Stop cache."):
        cache.stop()

    with TestRun.step(
            "Add previously used core device to core pool using --try-add flag."
    ):
        first_core = casadm.try_add(core_dev, cache.cache_id)

    with TestRun.step(
            "Add different core device to core pool using --try-add flag."):
        second_core = casadm.try_add(second_core_dev, cache.cache_id)

    with TestRun.step("Load cache."):
        cache = casadm.load_cache(cache_dev)

    with TestRun.step("Check each core status."):
        if first_core.get_status() is not CoreStatus.active:
            TestRun.fail(
                f"First core status should be active but is {first_core.get_status()}."
            )
        if second_core.get_status() is not CoreStatus.detached:
            TestRun.fail(
                f"Second core status should be detached but is {second_core.get_status()}."
            )

    with TestRun.step("Stop cache and remove core from core pool."):
        casadm.remove_all_detached_cores()
        cache.stop()
Ejemplo n.º 6
0
def base_prepare(item):
    with TestRun.LOGGER.step("Cleanup before test"):
        TestRun.executor.run("pkill --signal=SIGKILL fsck")
        Udev.enable()
        kill_all_io()
        DeviceMapper.remove_all()

        if installer.check_if_installed():
            try:
                from api.cas.init_config import InitConfig
                InitConfig.create_default_init_config()
                unmount_cas_devices()
                casadm.stop_all_caches()
                casadm.remove_all_detached_cores()
            except Exception:
                pass  # TODO: Reboot DUT if test is executed remotely

        raids = Raid.discover()
        for raid in raids:
            # stop only those RAIDs, which are comprised of test disks
            if all(map(lambda device:
                       any(map(lambda disk_path:
                               disk_path in device.get_device_id(),
                               [bd.get_device_id() for bd in TestRun.dut.disks])),
                       raid.array_devices)):
                raid.umount_all_partitions()
                raid.remove_partitions()
                raid.stop()
                for device in raid.array_devices:
                    Mdadm.zero_superblock(os.path.join('/dev', device.get_device_id()))
                    Udev.settle()

        for disk in TestRun.dut.disks:
            disk_serial = get_disk_serial_number(disk.path)
            if disk.serial_number != disk_serial:
                raise Exception(
                    f"Serial for {disk.path} doesn't match the one from the config."
                    f"Serial from config {disk.serial_number}, actual serial {disk_serial}"
                )

            disk.umount_all_partitions()
            Mdadm.zero_superblock(os.path.join('/dev', disk.get_device_id()))
            TestRun.executor.run_expect_success("udevadm settle")
            disk.remove_partitions()
            create_partition_table(disk, PartitionTable.gpt)

        if get_force_param(item) and not TestRun.usr.already_updated:
            installer.rsync_opencas_sources()
            installer.reinstall_opencas()
        elif not installer.check_if_installed():
            installer.rsync_opencas_sources()
            installer.set_up_opencas()
        TestRun.usr.already_updated = True
        TestRun.LOGGER.add_build_info(f'Commit hash:')
        TestRun.LOGGER.add_build_info(f"{git.get_current_commit_hash()}")
        TestRun.LOGGER.add_build_info(f'Commit message:')
        TestRun.LOGGER.add_build_info(f'{git.get_current_commit_message()}')
Ejemplo n.º 7
0
def pytest_runtest_teardown():
    """
    This method is executed always in the end of each test, even if it fails or raises exception in
    prepare stage.
    """
    if TestRun.outcome == "skipped":
        return

    TestRun.LOGGER.end_all_groups()

    with TestRun.LOGGER.step("Cleanup after test"):
        try:
            if TestRun.executor:
                if TestRun.executor.is_active():
                    TestRun.executor.wait_for_connection()
                Udev.enable()
                unmount_cas_devices()
                casadm.remove_all_detached_cores()
                casadm.stop_all_caches()
                from api.cas import init_config
                init_config.create_default_init_config()
        except Exception as ex:
            TestRun.LOGGER.warning(
                f"Exception occured during platform cleanup.\n"
                f"{str(ex)}\n{traceback.format_exc()}")

        if 'test_wrapper' in sys.modules:
            try:
                test_wrapper.cleanup()
            except Exception as ex:
                TestRun.LOGGER.warning(
                    f"Exception occured during test wrapper cleanup.\n{str(ex)}"
                    f"\n{traceback.format_exc()}")

    TestRun.LOGGER.end()
    if TestRun.executor:
        TestRun.LOGGER.get_additional_logs()
    Log.destroy()