Skip to content

Commit 4a99257

Browse files
committed
test: add tmt test to verify posttrans working
1 parent 0e05926 commit 4a99257

File tree

7 files changed

+215
-5
lines changed

7 files changed

+215
-5
lines changed

.fmf/version

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
1

.packit.yaml

Lines changed: 62 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,62 @@
1+
---
2+
# See the documentation for more information:
3+
# https://packit.dev/docs/configuration/
4+
5+
# name in upstream package repository or registry
6+
upstream_package_name: bootupd
7+
upstream_tag_template: v{version}
8+
9+
downstream_package_name: rust-bootupd
10+
11+
specfile_path: contrib/packaging/bootupd.spec
12+
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+
34+
jobs:
35+
- job: copr_build
36+
trigger: pull_request
37+
targets:
38+
- fedora-rawhide-aarch64
39+
- fedora-rawhide-x86_64
40+
41+
- job: tests
42+
trigger: pull_request
43+
targets:
44+
- fedora-rawhide-aarch64
45+
- fedora-rawhide-x86_64
46+
tmt_plan: /tmt/plans/package
47+
48+
- job: propose_downstream
49+
trigger: release
50+
dist_git_branches:
51+
fedora-rawhide:
52+
fast_forward_merge_into: [fedora-latest-stable]
53+
54+
- job: koji_build
55+
trigger: commit
56+
dist_git_branches:
57+
- fedora-all
58+
59+
- job: bodhi_update
60+
trigger: commit
61+
dist_git_branches:
62+
- fedora-all

contrib/packaging/bootupd.spec

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@ Summary: Bootloader updater
99

1010
License: Apache-2.0
1111
URL: https://github.com/coreos/bootupd
12-
Source0: %{crates_source}
12+
Source0: %{url}/releases/download/v%{version}/bootupd-%{version}.tar.zstd
1313
Source1: %{url}/releases/download/v%{version}/bootupd-%{version}-vendor.tar.zstd
1414
%if 0%{?fedora} || 0%{?rhel} >= 10
1515
ExcludeArch: %{ix86}

tmt/plans/package.fmf

Lines changed: 38 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,38 @@
1+
discover:
2+
how: fmf
3+
execute:
4+
how: tmt
5+
provision:
6+
how: virtual
7+
hardware:
8+
boot:
9+
method: uefi
10+
image: $@{test_image}
11+
user: root
12+
prepare:
13+
# Run on package mode VM especially on Fedora
14+
- how: shell
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+
32+
33+
/plan-post-install:
34+
summary: Execute post install tests
35+
discover:
36+
how: fmf
37+
test:
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: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
/test-post-install:
2+
summary: Execute installation on package mode
3+
duration: 10m
4+
adjust:
5+
- when: distro != fedora
6+
enabled: false
7+
test: bash package/test-post-install.sh

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)