diff --git a/.fmf/version b/.fmf/version new file mode 100644 index 0000000..d00491f --- /dev/null +++ b/.fmf/version @@ -0,0 +1 @@ +1 diff --git a/gating.yaml b/gating.yaml index d71584a..4ca9235 100644 --- a/gating.yaml +++ b/gating.yaml @@ -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} diff --git a/plans/run-tests.fmf b/plans/run-tests.fmf new file mode 100644 index 0000000..cf8a582 --- /dev/null +++ b/plans/run-tests.fmf @@ -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 diff --git a/tests/scripts/pyparted-tests b/tests/scripts/pyparted-tests new file mode 100755 index 0000000..8edcca1 --- /dev/null +++ b/tests/scripts/pyparted-tests @@ -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 " % sys.argv[0], file=sys.stderr) + sys.exit(1) + + main(sys.argv[1]) diff --git a/tests/scripts/run_tests.sh b/tests/scripts/run_tests.sh deleted file mode 100755 index 21804db..0000000 --- a/tests/scripts/run_tests.sh +++ /dev/null @@ -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} diff --git a/tests/tests.yml b/tests/tests.yml deleted file mode 100644 index 171d4d0..0000000 --- a/tests/tests.yml +++ /dev/null @@ -1,15 +0,0 @@ ---- - -- hosts: localhost - roles: - - role: standard-test-basic - tags: - - classic - - required_packages: - - fedpkg - - tests: - - simple: - dir: scripts/ - run: ./run_tests.sh