Skip to content

Commit

Permalink
wip: tweaking tests, and getting understanding of cmd
Browse files Browse the repository at this point in the history
  • Loading branch information
prestist committed May 7, 2024
1 parent d5943f9 commit f63ebe8
Show file tree
Hide file tree
Showing 2 changed files with 26 additions and 7 deletions.
3 changes: 2 additions & 1 deletion lib/src/cli.rs
Original file line number Diff line number Diff line change
Expand Up @@ -627,7 +627,8 @@ fn lint() -> Result<()> {
}

let root = cap_std::fs::Dir::open_ambient_dir("/", cap_std::ambient_authority())?;
ostree_ext::bootabletree::find_kernel_dir_fs(&root)?;
let result = ostree_ext::bootabletree::find_kernel_dir_fs(&root)?;
tracing::debug!("Found kernel: {:?}", result);
return Ok(());
}

Expand Down
30 changes: 24 additions & 6 deletions lib/src/privtests.rs
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,6 @@ use cap_std_ext::cap_std::fs::Dir;
use fn_error_context::context;
use rustix::fd::AsFd;
use xshell::{cmd, Shell};

use crate::blockdev::LoopbackDevice;
use crate::install::config::InstallConfiguration;

Expand Down Expand Up @@ -198,14 +197,33 @@ fn verify_selinux_recurse(root: &Dir, path: &mut PathBuf, warn: bool) -> Result<

#[context("Container tests")]
fn test_build_lint(image: &str) -> Result<()> {
let sh = Shell::new()?;

cmd!(sh, "podman run --rm --privileged --pid=host --env=RUST_LOG -v /usr/bin/bootc:/usr/bin/bootc {image} bootc build-lint").run()?;
let copy_kernel = "bootc build-lint";
cmd!(sh, "podman run --rm --privileged --pid=host --env=RUST_LOG -v /usr/bin/bootc:/usr/bin/bootc {image} {copy_kernel}").run()?;
let sh = Shell::new()?;

// Smoke test of build_lint
let _test_1_result = cmd!(sh, "podman run --rm --privileged --pid=host --env=RUST_LOG -v /usr/bin/bootc:/usr/bin/bootc {image} bootc build-lint").run();

// Setup for multiple kernels lint test
cmd!(sh, "podman run -dt --name test --privileged --pid=host --env=RUST_LOG -v /usr/bin/bootc:/usr/bin/bootc {image} bash").run()?;
let kernel_name = cmd!(sh, "podman exec test bash -c 'ls /usr/lib/modules | tail -n -1'" ).read()?;
Command::new("podman")
.arg("exec")
.arg("test")
.arg("bash")
.arg("-c")
.arg(format!("sudo cp -r /usr/lib/modules/{} /usr/lib/modules/delete-me", kernel_name))
.output()?;
let more_then_one_kernel_result = cmd!(sh, "podman exec test bash -c 'bootc build-lint'").read_stderr();
// Container Cleanup
cmd!(sh, "podman rm -f test").run()?;

_test_1_result?;
if let Err(e) = more_then_one_kernel_result {
assert!(e.to_string().contains("bootc build-lint"));
} else {
assert!(false, "Expected error, got none");
}
Ok(())

}

pub(crate) async fn run(opts: TestingOpts) -> Result<()> {
Expand Down

0 comments on commit f63ebe8

Please sign in to comment.