tests: Update example using new utils
Signed-off-by: Robert Baldyga <robert.baldyga@intel.com>
This commit is contained in:
parent
07d8fdbf01
commit
4da68f426d
@ -1 +1 @@
|
|||||||
Subproject commit b3f62cb3d65ea42c05f297340ca5a1e9ef70fab0
|
Subproject commit 731227cfb6dad0916a4761da26042b45801bece3
|
@ -19,37 +19,69 @@ def setup_module():
|
|||||||
|
|
||||||
@pytest.mark.require_disk("cache", DiskTypeSet([DiskType.optane, DiskType.nand]))
|
@pytest.mark.require_disk("cache", DiskTypeSet([DiskType.optane, DiskType.nand]))
|
||||||
def test_create_example_partitions():
|
def test_create_example_partitions():
|
||||||
TestRun.LOGGER.info("Test run")
|
"""
|
||||||
TestRun.LOGGER.info(f"DUT info: {TestRun.dut}")
|
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']
|
test_disk = TestRun.disks['cache']
|
||||||
|
|
||||||
|
with TestRun.group("Repartition disk"):
|
||||||
|
with TestRun.step("Genetare partitions table"):
|
||||||
part_sizes = []
|
part_sizes = []
|
||||||
for i in range(1, 6):
|
for i in range(1, 6):
|
||||||
part_sizes.append(Size(10 * i + 100, Unit.MebiByte))
|
part_sizes.append(Size(10 * i + 100, Unit.MebiByte))
|
||||||
|
with TestRun.step("Create partitions"):
|
||||||
test_disk.create_partitions(part_sizes)
|
test_disk.create_partitions(part_sizes)
|
||||||
TestRun.LOGGER.info(f"DUT info: {TestRun.dut}")
|
for i in TestRun.iteration(range(0, 5)):
|
||||||
test_disk.partitions[0].create_filesystem(Filesystem.ext3)
|
with TestRun.step(f"Create filesystem on partition {i}"):
|
||||||
|
test_disk.partitions[i].create_filesystem(Filesystem.ext3)
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
def test_create_example_files():
|
def test_create_example_files():
|
||||||
TestRun.LOGGER.info("Test run")
|
"""
|
||||||
|
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 = File.create_file("example_file")
|
||||||
file1.write("Test file\ncontent line\ncontent")
|
file1.write("Test file\ncontent line\ncontent")
|
||||||
|
with TestRun.step("Read file content"):
|
||||||
content_before_change = file1.read()
|
content_before_change = file1.read()
|
||||||
TestRun.LOGGER.info(f"File content: {content_before_change}")
|
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')
|
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()
|
content_after_change = file1.read()
|
||||||
assert content_before_change != content_after_change
|
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)
|
file2 = file1.copy('/tmp', force=True)
|
||||||
assert file1.md5sum() == file2.md5sum()
|
if file1.md5sum() != file2.md5sum():
|
||||||
|
TestRun.fail("md5 sum doesn't match!")
|
||||||
|
with TestRun.step("Change permissions of second file"):
|
||||||
file2.chmod_numerical(123)
|
file2.chmod_numerical(123)
|
||||||
|
with TestRun.step("Remove second file"):
|
||||||
fs_utils.remove(file2.full_path, True)
|
fs_utils.remove(file2.full_path, True)
|
||||||
|
|
||||||
|
with TestRun.step("List contents of home directory"):
|
||||||
dir1 = Directory("~")
|
dir1 = Directory("~")
|
||||||
dir_content = dir1.ls()
|
dir_content = dir1.ls()
|
||||||
file1.chmod(fs_utils.Permissions['r'] | fs_utils.Permissions['w'], fs_utils.PermissionsUsers(7))
|
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:
|
for item in dir_content:
|
||||||
TestRun.LOGGER.info(f"Item {str(item)} - {type(item).__name__}")
|
TestRun.LOGGER.info(f"Item {str(item)} - {type(item).__name__}")
|
||||||
|
with TestRun.step("Remove file"):
|
||||||
fs_utils.remove(file1.full_path, True)
|
fs_utils.remove(file1.full_path, True)
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user