Skip to content

Commit 92153e0

Browse files
committed
test: add tmt test to verify posttrans working
1 parent 112d5f0 commit 92153e0

5 files changed

Lines changed: 162 additions & 43 deletions

File tree

.packit.yaml

Lines changed: 23 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -10,43 +10,40 @@ downstream_package_name: rust-bootupd
1010

1111
specfile_path: contrib/packaging/bootupd.spec
1212

13+
srpm_build_deps:
14+
- cargo
15+
- git
16+
- libzstd-devel
17+
- openssl-devel
18+
- zstd
19+
20+
actions:
21+
# The last setp here is required by Packit to return the archive name
22+
# https://packit.dev/docs/configuration/actions#create-archive
23+
create-archive:
24+
- bash -c "cargo install cargo-vendor-filterer"
25+
- bash -c "cargo xtask spec"
26+
- bash -c "cat target/bootupd.spec"
27+
- bash -c "cp target/bootupd* contrib/packaging/"
28+
- bash -c "ls -1 target/bootupd*.tar.zstd | grep -v 'vendor'"
29+
# Do nothing with spec file. Two steps here are for debugging
30+
fix-spec-file:
31+
- bash -c "cat contrib/packaging/bootupd.spec"
32+
- bash -c "ls -al contrib/packaging/"
33+
1334
jobs:
1435
- job: copr_build
1536
trigger: pull_request
1637
targets:
17-
- centos-stream-9-x86_64
18-
- centos-stream-9-aarch64
19-
- centos-stream-9-s390x
20-
- centos-stream-10-x86_64
21-
- centos-stream-10-aarch64
22-
- centos-stream-10-s390x
23-
- centos-stream-10-ppc64le
24-
- fedora-43-x86_64
25-
- fedora-43-aarch64
26-
- fedora-43-s390x
27-
- fedora-43-ppc64le
28-
- fedora-rawhide-x86_64
2938
- fedora-rawhide-aarch64
30-
- fedora-rawhide-s390x
31-
- fedora-rawhide-ppc64le
39+
- fedora-rawhide-x86_64
3240

3341
- job: tests
3442
trigger: pull_request
3543
targets:
36-
- centos-stream-9-x86_64
37-
- centos-stream-9-aarch64
38-
- centos-stream-10-x86_64
39-
- centos-stream-10-aarch64
40-
- fedora-43-x86_64
41-
- fedora-43-aarch64
42-
- fedora-rawhide-x86_64
4344
- fedora-rawhide-aarch64
45+
- fedora-rawhide-x86_64
4446
tmt_plan: /tmt/plans/package
45-
tf_extra_params:
46-
environments:
47-
- tmt:
48-
context:
49-
running_env: "packit"
5047

5148
- job: propose_downstream
5249
trigger: release

tmt/plans/package.fmf

Lines changed: 28 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -1,22 +1,38 @@
1-
# Common settings for all plans
1+
discover:
2+
how: fmf
3+
execute:
4+
how: tmt
25
provision:
36
how: virtual
4-
image: $@{test_disk_image}
7+
hardware:
8+
boot:
9+
method: uefi
10+
image: $@{test_image}
11+
user: root
512
prepare:
6-
# Run on package mode VM running on Packit and Gating
13+
# Run on package mode VM especially on Fedora
714
- how: shell
8-
order: 98
9-
script:
10-
- mkdir -p bootc && cp /var/share/test-artifacts/*.src.rpm bootc
11-
- cd bootc && rpm2cpio *.src.rpm | cpio -idmv && rm -f *-vendor.tar.zstd && zstd -d *.tar.zstd && tar -xvf *.tar -C . --strip-components=1 && ls -al
12-
- pwd && ls -al && cd bootc/hack && ./provision-packit.sh
13-
when: running_env != image_mode
14-
execute:
15-
how: tmt
15+
order: 10
16+
adjust:
17+
- when: distro == fedora
18+
script:
19+
- |
20+
set -eux
21+
if [ -d /boot/efi/EFI/fedora ]; then
22+
for f in /boot/efi/EFI/fedora/grub*.efi; do
23+
echo "Corrupting $f"
24+
echo "test" > "$f"
25+
done
26+
fi
27+
- how: install
28+
order: 20
29+
package:
30+
- bootupd
31+
1632

1733
/plan-post-install:
1834
summary: Execute post install tests
1935
discover:
2036
how: fmf
2137
test:
22-
- /tmt/tests/tests/test-post-install
38+
- /tmt/tests/tests/test-post-install
Lines changed: 66 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,66 @@
1+
# number: 10
2+
# tmt:
3+
# summary: Test posttrans on package mode
4+
# duration: 10m
5+
#
6+
#!/bin/bash
7+
set -eux
8+
9+
echo "Testing posttrans on package mode"
10+
11+
bootupctl --version
12+
13+
source /etc/os-release
14+
if [ "$ID" == "fedora" ] && [ "$VERSION_ID" -lt 44 ]; then
15+
echo "Skip testing on F43 and older"
16+
exit 0
17+
fi
18+
19+
suffix=""
20+
get_grub_suffix() {
21+
case "$(uname -m)" in
22+
x86_64)
23+
suffix="x64"
24+
;;
25+
aarch64)
26+
suffix="aa64"
27+
;;
28+
*)
29+
echo "Unsupported arch"
30+
exit 1
31+
;;
32+
esac
33+
}
34+
35+
if [ "$TMT_REBOOT_COUNT" -eq 0 ]; then
36+
echo 'Before first reboot'
37+
# assume ESP is already mounted at /boot/efi
38+
mountpoint /boot/efi
39+
get_grub_suffix
40+
grubefi="grub${suffix}.efi"
41+
42+
grub_source_path=$(find /usr/lib/efi/ -name "${grubefi}")
43+
if [ -z "${grub_source_path}" ]; then
44+
echo "Error: Source GRUB binary ${grub_source_path} not found."
45+
exit 1
46+
fi
47+
48+
grub_target_path=/boot/efi/EFI/fedora/${grubefi}
49+
if [ ! -f "${grub_target_path}" ]; then
50+
echo "Error: Could not find target GRUB binary ${grub_target_path}."
51+
exit 1
52+
fi
53+
# get checksum from /usr/lib/efi/grub2/xx/EFI/fedora/grub.efi
54+
source_checksum=$(sha256sum "${grub_source_path}" | cut -d' ' -f1)
55+
# get checksum from target /boot/efi
56+
target_checksum=$(sha256sum "${grub_target_path}" | cut -d' ' -f1)
57+
# confirm that the target grub.efi is updated
58+
[ "${source_checksum}" == "${target_checksum}" ]
59+
tmt-reboot
60+
elif [ "$TMT_REBOOT_COUNT" -eq 1 ]; then
61+
echo 'After the reboot'
62+
# just confirm the reboot is successful
63+
whoami
64+
fi
65+
66+
echo "Run posttrans test successfully"

tmt/tests/tests.fmf

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,8 @@
11
/test-post-install:
22
summary: Execute installation on package mode
33
duration: 10m
4-
test: bash package/post-install.sh
4+
adjust:
5+
- when: distro != fedora
6+
enabled: false
7+
test: bash package/test-post-install.sh
8+

xtask/src/main.rs

Lines changed: 40 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -32,6 +32,7 @@ fn try_main() -> Result<()> {
3232
"vendor" => vendor,
3333
"package" => package,
3434
"package-srpm" => package_srpm,
35+
"spec" => spec,
3536
_ => print_help,
3637
};
3738
f(&sh)?;
@@ -155,10 +156,9 @@ fn impl_package(sh: &Shell) -> Result<Package> {
155156
)
156157
.run()?;
157158
}
158-
// Compress with gzip and write to crate
159-
let srcpath: Utf8PathBuf = Utf8Path::new("target").join(format!("{namev}.crate"));
160-
cmd!(sh, "gzip --force --best {p}").run()?;
161-
std::fs::rename(format!("{p}.gz"), &srcpath)?;
159+
// Compress with zstd
160+
let srcpath: Utf8PathBuf = format!("{p}.zstd").into();
161+
cmd!(sh, "zstd --rm -f {p} -o {srcpath}").run()?;
162162

163163
Ok(Package {
164164
version: v,
@@ -243,6 +243,42 @@ fn package_srpm(sh: &Shell) -> Result<()> {
243243
Ok(())
244244
}
245245

246+
fn update_spec(sh: &Shell) -> Result<Utf8PathBuf> {
247+
let _targetdir = get_target_dir()?;
248+
let p = Utf8Path::new("target");
249+
let pkg = impl_package(sh)?;
250+
let srcpath = pkg.srcpath.file_name().unwrap();
251+
let v = pkg.version;
252+
let src_vendorpath = pkg.vendorpath.file_name().unwrap();
253+
{
254+
let specin = File::open(format!("contrib/packaging/{NAME}.spec"))
255+
.map(BufReader::new)
256+
.context("Opening spec")?;
257+
let mut o = File::create(p.join(format!("{NAME}.spec"))).map(BufWriter::new)?;
258+
for line in specin.lines() {
259+
let line = line?;
260+
if line.starts_with("Version:") {
261+
writeln!(o, "# Replaced by cargo xtask spec")?;
262+
writeln!(o, "Version: {v}")?;
263+
} else if line.starts_with("Source0") {
264+
writeln!(o, "Source0: {srcpath}")?;
265+
} else if line.starts_with("Source1") {
266+
writeln!(o, "Source1: {src_vendorpath}")?;
267+
} else {
268+
writeln!(o, "{line}")?;
269+
}
270+
}
271+
}
272+
let spec_path = p.join(format!("{NAME}.spec"));
273+
Ok(spec_path)
274+
}
275+
276+
fn spec(sh: &Shell) -> Result<()> {
277+
let s = update_spec(sh)?;
278+
println!("Generated: {s}");
279+
Ok(())
280+
}
281+
246282
fn print_help(_sh: &Shell) -> Result<()> {
247283
eprintln!(
248284
"Tasks:

0 commit comments

Comments
 (0)