Skip to content

Commit c69e132

Browse files
authored
Merge pull request #548 from cgwalters/test-improvements
Move install tests shell script into Rust
2 parents 11473f7 + 65136e0 commit c69e132

File tree

9 files changed

+327
-88
lines changed

9 files changed

+327
-88
lines changed

.github/workflows/ci.yml

Lines changed: 12 additions & 86 deletions
Original file line numberDiff line numberDiff line change
@@ -68,26 +68,6 @@ jobs:
6868
with:
6969
name: bootc.tar.zst
7070
path: target/bootc.tar.zst
71-
build-c9s:
72-
if: ${{ !contains(github.event.pull_request.labels.*.name, 'control/skip-ci') }}
73-
runs-on: ubuntu-latest
74-
container: quay.io/centos/centos:stream9
75-
steps:
76-
- run: dnf -y install git-core
77-
- uses: actions/checkout@v4
78-
- name: Install deps
79-
run: ./ci/installdeps.sh
80-
- name: Cache Dependencies
81-
uses: Swatinem/rust-cache@v2
82-
with:
83-
key: "build-c9s"
84-
- name: Build
85-
run: make test-bin-archive
86-
- name: Upload binary
87-
uses: actions/upload-artifact@v4
88-
with:
89-
name: bootc-c9s.tar.zst
90-
path: target/bootc.tar.zst
9171
cargo-deny:
9272
runs-on: ubuntu-latest
9373
steps:
@@ -127,78 +107,24 @@ jobs:
127107
run: sudo tar -C / -xvf bootc.tar.zst
128108
- name: Integration tests
129109
run: bootc internal-tests run-container-integration
130-
privtest-alongside:
110+
install-tests:
131111
if: ${{ !contains(github.event.pull_request.labels.*.name, 'control/skip-ci') }}
132-
name: "Test install-alongside"
133-
needs: [build-c9s]
134-
runs-on: ubuntu-latest
112+
name: "Test install"
113+
# For a not-ancient podman
114+
runs-on: ubuntu-24.04
135115
steps:
116+
- name: Checkout repository
117+
uses: actions/checkout@v4
136118
- name: Ensure host skopeo is disabled
137119
run: sudo rm -f /bin/skopeo /usr/bin/skopeo
138-
- name: Download
139-
uses: actions/download-artifact@v4
140-
with:
141-
name: bootc-c9s.tar.zst
142-
- name: Install
143-
run: tar -xvf bootc.tar.zst
144-
- name: Integration tests
145-
run: |
146-
set -xeuo pipefail
147-
image=quay.io/centos-bootc/centos-bootc-dev:stream9
148-
echo 'ssh-ed25519 ABC0123 testcase@example.com' > test_authorized_keys
149-
sudo podman run --rm --privileged -v ./test_authorized_keys:/test_authorized_keys --env RUST_LOG=debug -v /:/target -v /var/lib/containers:/var/lib/containers -v ./usr/bin/bootc:/usr/bin/bootc --pid=host --security-opt label=disable \
150-
${image} bootc install to-filesystem --acknowledge-destructive \
151-
--karg=foo=bar --disable-selinux --replace=alongside --root-ssh-authorized-keys=/test_authorized_keys /target
152-
ls -al /boot/loader/
153-
sudo grep foo=bar /boot/loader/entries/*.conf
154-
grep authorized_keys /ostree/deploy/default/deploy/*/etc/tmpfiles.d/bootc-root-ssh.conf
155-
# TODO fix https://github.com/containers/bootc/pull/137
156-
sudo chattr -i /ostree/deploy/default/deploy/*
157-
sudo rm /ostree/deploy/default -rf
158-
sudo podman run --rm --privileged --env RUST_LOG=debug -v /:/target -v /var/lib/containers:/var/lib/containers -v ./usr/bin/bootc:/usr/bin/bootc --pid=host --security-opt label=disable \
159-
${image} bootc install to-existing-root --acknowledge-destructive
160-
sudo podman run --rm --privileged -v /:/target -v ./usr/bin/bootc:/usr/bin/bootc --pid=host --security-opt label=disable ${image} bootc internal-tests verify-selinux /target/ostree --warn
161-
install-to-existing-root:
162-
if: ${{ !contains(github.event.pull_request.labels.*.name, 'control/skip-ci') }}
163-
name: "Test install-to-existing-root"
164-
needs: [build-c9s]
165-
runs-on: ubuntu-latest
166-
steps:
167-
- name: Download
168-
uses: actions/download-artifact@v4
169-
with:
170-
name: bootc-c9s.tar.zst
171-
- name: Install
172-
run: tar -xvf bootc.tar.zst
173-
- name: Integration tests
174-
run: |
175-
set -xeuo pipefail
176-
# We should be able to install to-existing-root with no install config,
177-
# so we bind mount an empty directory over /usr/lib/bootc/install.
178-
empty=$(mktemp -d)
179-
image=quay.io/centos-bootc/centos-bootc-dev:stream9
180-
sudo podman run --rm --privileged --env RUST_LOG=debug -v /:/target -v /var/lib/containers:/var/lib/containers -v ./usr/bin/bootc:/usr/bin/bootc -v ${empty}:/usr/lib/bootc/install --pid=host --security-opt label=disable \
181-
${image} bootc install to-existing-root
182-
install-to-loopback:
183-
if: ${{ !contains(github.event.pull_request.labels.*.name, 'control/skip-ci') }}
184-
name: "Test install to-disk --via-loopback"
185-
needs: [build-c9s]
186-
runs-on: ubuntu-latest
187-
steps:
188-
- name: Download
189-
uses: actions/download-artifact@v4
190-
with:
191-
name: bootc-c9s.tar.zst
192-
- name: Install
193-
run: tar -xvf bootc.tar.zst
194120
- name: Integration tests
195121
run: |
196-
set -xeuo pipefail
197-
image=quay.io/centos-bootc/centos-bootc-dev:stream9
198-
tmpdisk=$(mktemp -p /var/tmp)
199-
truncate -s 20G ${tmpdisk}
200-
sudo podman run --rm --privileged --env RUST_LOG=debug -v /dev:/dev -v /:/target -v /var/lib/containers:/var/lib/containers -v ./usr/bin/bootc:/usr/bin/bootc --pid=host --security-opt label=disable \
201-
-v ${tmpdisk}:/disk ${image} bootc install to-disk --via-loopback /disk
122+
set -xeu
123+
sudo podman build -t localhost/bootc -f hack/Containerfile .
124+
# Nondestructive but privileged tests
125+
cargo run -p tests-integration host-privileged localhost/bootc
126+
# Finally the install-alongside suite
127+
cargo run -p tests-integration install-alongside localhost/bootc
202128
docs:
203129
if: ${{ contains(github.event.pull_request.labels.*.name, 'documentation') }}
204130
runs-on: ubuntu-latest

Cargo.lock

Lines changed: 84 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

Cargo.toml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
[workspace]
2-
members = ["cli", "lib", "xtask"]
2+
members = ["cli", "lib", "xtask", "tests-integration"]
33
resolver = "2"
44

55
[profile.dev]

hack/Containerfile

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@ WORKDIR /build
1010
RUN mkdir -p /build/target/dev-rootfs # This can hold arbitrary extra content
1111
# See https://www.reddit.com/r/rust/comments/126xeyx/exploring_the_problem_of_faster_cargo_docker/
1212
# We aren't using the full recommendations there, just the simple bits.
13-
RUN --mount=type=cache,target=/build/target --mount=type=cache,target=/var/roothome make bin-archive && mkdir -p /out && cp target/bootc.tar.zst /out
13+
RUN --mount=type=cache,target=/build/target --mount=type=cache,target=/var/roothome make test-bin-archive && mkdir -p /out && cp target/bootc.tar.zst /out
1414

1515
FROM $base
1616
COPY --from=build /out/bootc.tar.zst /tmp

tests-integration/Cargo.toml

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
# Our integration tests
2+
[package]
3+
name = "tests-integration"
4+
version = "0.1.0"
5+
license = "MIT OR Apache-2.0"
6+
edition = "2021"
7+
publish = false
8+
9+
[[bin]]
10+
name = "tests-integration"
11+
path = "src/tests-integration.rs"
12+
13+
[dependencies]
14+
anyhow = "1.0.82"
15+
camino = "1.1.6"
16+
cap-std-ext = "4"
17+
clap = { version= "4.5.4", features = ["derive","cargo"] }
18+
fn-error-context = "0.2.1"
19+
libtest-mimic = "0.7.3"
20+
tempfile = "3.10.1"
21+
xshell = { version = "0.2.6" }

tests-integration/README.md

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,24 @@
1+
# Integration tests crate
2+
3+
This crate holds integration tests (as distinct from the regular
4+
Rust unit tests run as part of `cargo test`).
5+
6+
## Building and running
7+
8+
`cargo run -p tests-integration`
9+
will work. Note that at the current time all test suites target
10+
an externally built bootc-compatible container image. See
11+
how things are set up in e.g. Github Actions, where we first
12+
run a `podman build` with the bootc git sources.
13+
14+
## Available suites
15+
16+
### `host-privileged`
17+
18+
This suite will run the target container image in a way that expects
19+
full privileges, but is *not* destructive.
20+
21+
### `install-alongside`
22+
23+
This suite is *DESTRUCTIVE*, executing the bootc `install to-existing-root`
24+
style flow using the host root. Run it in a transient virtual machine.

tests-integration/src/hostpriv.rs

Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,27 @@
1+
use anyhow::Result;
2+
use fn_error_context::context;
3+
use libtest_mimic::Trial;
4+
use xshell::cmd;
5+
6+
/// Tests that require real root (e.g. CAP_SYS_ADMIN) to do things like
7+
/// create loopback devices, but are *not* destructive. At the current time
8+
/// these tests are defined to reference a bootc container image.
9+
#[context("Hostpriv tests")]
10+
pub(crate) fn run_hostpriv(image: &str, testargs: libtest_mimic::Arguments) -> Result<()> {
11+
// Just leak the image name so we get a static reference as required by the test framework
12+
let image: &'static str = String::from(image).leak();
13+
let base_args = super::install::BASE_ARGS;
14+
15+
let tests = [Trial::test("loopback install", move || {
16+
let sh = &xshell::Shell::new()?;
17+
let size = 10 * 1000 * 1000 * 1000;
18+
let mut tmpdisk = tempfile::NamedTempFile::new_in("/var/tmp")?;
19+
tmpdisk.as_file_mut().set_len(size)?;
20+
let tmpdisk = tmpdisk.into_temp_path();
21+
let tmpdisk = tmpdisk.to_str().unwrap();
22+
cmd!(sh, "sudo {base_args...} -v {tmpdisk}:/disk {image} bootc install to-disk --via-loopback --skip-fetch-check /disk").run()?;
23+
Ok(())
24+
})];
25+
26+
libtest_mimic::run(&testargs, tests.into()).exit()
27+
}

0 commit comments

Comments
 (0)