def read_files_with_reclassification_check(cache, target_ioclass_id: int, source_ioclass_id: int, directory: Directory, with_delay: bool): start_time = datetime.now() target_occupancy_after = cache.get_io_class_statistics( io_class_id=target_ioclass_id).usage_stats.occupancy source_occupancy_after = cache.get_io_class_statistics( io_class_id=source_ioclass_id).usage_stats.occupancy files_to_reclassify = [] target_ioclass_is_enabled = ioclass_is_enabled(cache, target_ioclass_id) for file in [item for item in directory.ls() if isinstance(item, File)]: target_occupancy_before = target_occupancy_after source_occupancy_before = source_occupancy_after time_from_start = datetime.now() - start_time dd = Dd().input(file.full_path).output("/dev/null").block_size( Size(1, Unit.Blocks4096)) dd.run() target_occupancy_after = cache.get_io_class_statistics( io_class_id=target_ioclass_id).usage_stats.occupancy source_occupancy_after = cache.get_io_class_statistics( io_class_id=source_ioclass_id).usage_stats.occupancy if target_ioclass_is_enabled: if target_occupancy_after < target_occupancy_before: TestRun.LOGGER.error("Target IO class occupancy lowered!") elif target_occupancy_after - target_occupancy_before < file.size: files_to_reclassify.append(file) if with_delay and time_from_start <= ioclass_config.MAX_CLASSIFICATION_DELAY: continue TestRun.LOGGER.error( "Target IO class occupancy not changed properly!\n" f"Expected: {file.size + target_occupancy_before}\n" f"Actual: {target_occupancy_after}") elif target_occupancy_after > target_occupancy_before and with_delay: files_to_reclassify.append(file) if source_occupancy_after >= source_occupancy_before: if file not in files_to_reclassify: files_to_reclassify.append(file) if with_delay and time_from_start <= ioclass_config.MAX_CLASSIFICATION_DELAY: continue TestRun.LOGGER.error( "Source IO class occupancy not changed properly!\n" f"Before: {source_occupancy_before}\n" f"After: {source_occupancy_after}") if len(files_to_reclassify): TestRun.LOGGER.info("Rereading unclassified test files...") sync() drop_caches(DropCachesMode.ALL) for file in files_to_reclassify: (Dd().input(file.full_path).output("/dev/null").block_size( Size(1, Unit.Blocks4096)).run())
def read_files_with_reclassification_check(target_ioclass_id: int, source_ioclass_id: int, directory: Directory, with_delay: bool): start_time = datetime.now() target_occupancy_after = cache.get_statistics_deprecated( io_class_id=target_ioclass_id)["occupancy"] source_occupancy_after = cache.get_statistics_deprecated( io_class_id=source_ioclass_id)["occupancy"] unclassified_files = [] for file in [ item for item in directory.ls() if isinstance(item, File) ]: target_occupancy_before = target_occupancy_after source_occupancy_before = source_occupancy_after time_from_start = datetime.now() - start_time (Dd().input(file.full_path).output("/dev/null").block_size( Size(1, Unit.Blocks4096)).run()) target_occupancy_after = cache.get_statistics_deprecated( io_class_id=target_ioclass_id)["occupancy"] source_occupancy_after = cache.get_statistics_deprecated( io_class_id=source_ioclass_id)["occupancy"] if target_occupancy_after < target_occupancy_before: pytest.xfail("Target IO class occupancy lowered!") elif target_occupancy_after - target_occupancy_before < file.size: unclassified_files.append(file) if with_delay and time_from_start <= ioclass_config.MAX_CLASSIFICATION_DELAY: continue pytest.xfail("Target IO class occupancy not changed properly!") if source_occupancy_after >= source_occupancy_before: if file not in unclassified_files: unclassified_files.append(file) if with_delay and time_from_start <= ioclass_config.MAX_CLASSIFICATION_DELAY: continue pytest.xfail("Source IO class occupancy not changed properly!") if len(unclassified_files): TestRun.LOGGER.info("Rereading unclassified test files...") sync() drop_caches(DropCachesMode.ALL) for file in unclassified_files: (Dd().input(file.full_path).output("/dev/null").block_size( Size(1, Unit.Blocks4096)).run())
def test_create_example_files(): """ title: Example test manipulating on filesystem. description: Perform various operations on filesystem. pass_criteria: - System does not crash. - All operations complete successfully. - Data consistency is being preserved. """ with TestRun.step("Create file with content"): file1 = File.create_file("example_file") file1.write("Test file\ncontent line\ncontent") with TestRun.step("Read file content"): content_before_change = file1.read() TestRun.LOGGER.info(f"File content: {content_before_change}") with TestRun.step("Replace single line in file"): fs_utils.replace_in_lines(file1, 'content line', 'replaced line') with TestRun.step("Read file content and check if it changed"): content_after_change = file1.read() if content_before_change == content_after_change: TestRun.fail("Content didn't changed as expected") with TestRun.step("Make copy of the file and check if md5 sum matches"): file2 = file1.copy('/tmp', force=True) if file1.md5sum() != file2.md5sum(): TestRun.fail("md5 sum doesn't match!") with TestRun.step("Change permissions of second file"): file2.chmod_numerical(123) with TestRun.step("Remove second file"): fs_utils.remove(file2.full_path, True) with TestRun.step("List contents of home directory"): dir1 = Directory("~") dir_content = dir1.ls() with TestRun.step("Change permissions of file"): file1.chmod(fs_utils.Permissions['r'] | fs_utils.Permissions['w'], fs_utils.PermissionsUsers(7)) with TestRun.step("Log home directory content"): for item in dir_content: TestRun.LOGGER.info(f"Item {str(item)} - {type(item).__name__}") with TestRun.step("Remove file"): fs_utils.remove(file1.full_path, True)
def test_create_example_files(prepare_and_cleanup): prepare() TestProperties.LOGGER.info("Test run") file1 = File.create_file("example_file") file1.write("Test file\ncontent line\ncontent") content_before_change = file1.read() TestProperties.LOGGER.info(f"File content: {content_before_change}") fs_utils.replace_in_lines(file1, 'content line', 'replaced line') content_after_change = file1.read() assert content_before_change != content_after_change file2 = file1.copy('/tmp', force=True) assert file1.md5sum() == file2.md5sum() file2.chmod_numerical(123) fs_utils.remove(file2.full_path, True) dir1 = Directory("~") dir_content = dir1.ls() file1.chmod(fs_utils.Permissions['r'] | fs_utils.Permissions['w'], fs_utils.PermissionsUsers(7)) for item in dir_content: TestProperties.LOGGER.info(f"Item {str(item)} - {type(item).__name__}") fs_utils.remove(file1.full_path, True)