From 4da68f426dd2250eac8e911fb056fe2e3ea0a41e Mon Sep 17 00:00:00 2001 From: Robert Baldyga Date: Wed, 6 Nov 2019 09:21:36 +0100 Subject: [PATCH] tests: Update example using new utils Signed-off-by: Robert Baldyga --- test/functional/test-framework | 2 +- test/functional/tests/example/example_test.py | 88 +++++++++++++------ 2 files changed, 61 insertions(+), 29 deletions(-) diff --git a/test/functional/test-framework b/test/functional/test-framework index b3f62cb..731227c 160000 --- a/test/functional/test-framework +++ b/test/functional/test-framework @@ -1 +1 @@ -Subproject commit b3f62cb3d65ea42c05f297340ca5a1e9ef70fab0 +Subproject commit 731227cfb6dad0916a4761da26042b45801bece3 diff --git a/test/functional/tests/example/example_test.py b/test/functional/tests/example/example_test.py index 5708d19..3c5dc1d 100644 --- a/test/functional/tests/example/example_test.py +++ b/test/functional/tests/example/example_test.py @@ -19,37 +19,69 @@ def setup_module(): @pytest.mark.require_disk("cache", DiskTypeSet([DiskType.optane, DiskType.nand])) def test_create_example_partitions(): - TestRun.LOGGER.info("Test run") - TestRun.LOGGER.info(f"DUT info: {TestRun.dut}") - test_disk = TestRun.disks['cache'] - part_sizes = [] - for i in range(1, 6): - part_sizes.append(Size(10 * i + 100, Unit.MebiByte)) - test_disk.create_partitions(part_sizes) - TestRun.LOGGER.info(f"DUT info: {TestRun.dut}") - test_disk.partitions[0].create_filesystem(Filesystem.ext3) + """ + title: Example test creating partitions and filesystems. + description: Create 6 partitions and create filesystem on each of them. + pass_criteria: + - Partitions are created with no error. + - Filesystems are created successfully. + """ + with TestRun.step("Prepare"): + test_disk = TestRun.disks['cache'] + + with TestRun.group("Repartition disk"): + with TestRun.step("Genetare partitions table"): + part_sizes = [] + for i in range(1, 6): + part_sizes.append(Size(10 * i + 100, Unit.MebiByte)) + with TestRun.step("Create partitions"): + test_disk.create_partitions(part_sizes) + for i in TestRun.iteration(range(0, 5)): + with TestRun.step(f"Create filesystem on partition {i}"): + test_disk.partitions[i].create_filesystem(Filesystem.ext3) + def test_create_example_files(): - TestRun.LOGGER.info("Test run") - file1 = File.create_file("example_file") - file1.write("Test file\ncontent line\ncontent") - content_before_change = file1.read() - TestRun.LOGGER.info(f"File content: {content_before_change}") - fs_utils.replace_in_lines(file1, 'content line', 'replaced line') + """ + title: Example test manipulating on filesystem. + description: Perform various operaations 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") - content_after_change = file1.read() - assert content_before_change != content_after_change + 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) - 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: - TestRun.LOGGER.info(f"Item {str(item)} - {type(item).__name__}") - fs_utils.remove(file1.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)