tests: Add pyparted tmt tests

The previous tests weren't running (gating was from fedora and it would
have tried to use fedpkg to clone the fedora version...).

So this converts to using tmt style tests, and adds a test that actually
uses the installed pyparted library to manipulate a temporary disk
image.

Resolves: RHEL-53371
This commit is contained in:
Brian C. Lane 2024-08-20 16:53:47 -07:00
parent 8d8ddbee9c
commit 3896527ede
6 changed files with 101 additions and 47 deletions

1
.fmf/version Normal file
View File

@ -0,0 +1 @@
1

View File

@ -1,6 +1,6 @@
--- !Policy
product_versions:
- fedora-*
decision_context: bodhi_update_push_testing
- rhel-10
decision_context: osci_compose_gate
rules:
- !PassingTestCaseRule {test_case_name: dist.depcheck}
- !PassingTestCaseRule {test_case_name: osci.brew-build.tier0.functional}

9
plans/run-tests.fmf Normal file
View File

@ -0,0 +1,9 @@
summary: Run pyparted tests
prepare:
how: install
package:
- python3-pyparted
execute:
script: |
fallocate -l 1G $PWD/disk.img
./tests/scripts/pyparted-tests $PWD/disk.img

88
tests/scripts/pyparted-tests Executable file
View File

@ -0,0 +1,88 @@
#!/usr/bin/python3
import parted
import sys
def init_disk(disk_img):
# Make a disklabel (failures here will raise an error)
dev = parted.getDevice(disk_img)
disk = parted.freshDisk(dev, "gpt")
# Make a partition
geom = parted.Geometry(device=dev,
start=2048,
end=50*2048)
fs = parted.FileSystem(type="ext4", geometry=geom)
part = parted.Partition(disk=disk,
type=parted.PARTITION_NORMAL,
fs=fs,
geometry=geom)
disk.addPartition(partition=part,
constraint=dev.optimalAlignedConstraint)
part.setFlag(parted.PARTITION_BOOT)
disk.commit()
def read_disk(disk_img):
# Read the disk and check the partitions
dev = parted.getDevice(disk_img)
disk = parted.newDisk(dev)
if dev.length == 0:
print("ERROR: Disk has no length", file=sys.stderr)
sys.exit(1)
if len(disk.partitions) != 1:
print("ERROR: Wrong number of partitions", file=sys.stderr)
sys.exit(1)
part = disk.partitions[0]
if part.geometry.end != 50*2048:
print("ERROR: Partition is wrong length", file=sys.stderr)
sys.exit(1)
if part.geometry.start != 2048:
print("ERROR: Parition doesn't start at sector 2048", file=sys.stderr)
sys.exit(1)
def remove_partition(disk_img):
# Remove partition and check disk
dev = parted.getDevice(disk_img)
disk = parted.newDisk(dev)
if len(disk.partitions) != 1:
print("ERROR: Wrong number of partitions", file=sys.stderr)
sys.exit(1)
disk.removePartition(partition=disk.partitions[0])
disk.commit()
dev = parted.getDevice(disk_img)
disk = parted.newDisk(dev)
if len(disk.partitions) != 0:
print("ERROR: Failed to delete partition", file=sys.stderr)
sys.exit(1)
def main(disk_img):
print(f"Running tests on {disk_img}")
try:
init_disk(disk_img)
read_disk(disk_img)
remove_partition(disk_img)
except Exception as e:
print(f"ERROR: {str(e)}", file=sys.stderr)
sys.exit(1)
print("PASS", file=sys.stderr)
sys.exit(0)
if __name__ == '__main__':
if len(sys.argv) < 2:
print("Usage: %s <disk.img>" % sys.argv[0], file=sys.stderr)
sys.exit(1)
main(sys.argv[1])

View File

@ -1,29 +0,0 @@
#!/bin/sh
PATH=/usr/bin
TMPDIR="$(mktemp -d)"
CWD="$(pwd)"
PACKAGE=pyparted
BRANCH=
# clone the dist-git tree for this package
cd ${TMPDIR}
fedpkg co ${PACKAGE}
cd ${PACKAGE}
[ -z "${BRANCH}" ] || fedpkg switch-branch ${BRANCH}
fedpkg prep
# scramble together the extracted source tree name
SRCDIR="${PACKAGE}-$(grep Version: ${PACKAGE}.spec | cut -d ' ' -f 2)"
# run the tests
cd ${SRCDIR}
#make check # this runs pylint, which is sometimes wrong/noisy
make test
RET=$?
# clean up and exit
cd ${CWD}
rm -rf ${TMPDIR}
exit ${RET}

View File

@ -1,15 +0,0 @@
---
- hosts: localhost
roles:
- role: standard-test-basic
tags:
- classic
required_packages:
- fedpkg
tests:
- simple:
dir: scripts/
run: ./run_tests.sh