mirror of
https://github.com/ostreedev/ostree.git
synced 2025-01-09 01:18:35 +03:00
Merge pull request #2181 from cgwalters/port-sh-inline
tests/inst: Port to new sh-inline repo
This commit is contained in:
commit
27413afbff
@ -14,7 +14,8 @@ structopt = "0.3"
|
||||
serde = "1.0.111"
|
||||
serde_derive = "1.0.111"
|
||||
serde_json = "1.0"
|
||||
commandspec = "0.12.2"
|
||||
# To be published on crates.io soon
|
||||
sh-inline = { git = "https://github.com/cgwalters/rust-sh-inline" }
|
||||
anyhow = "1.0"
|
||||
tempfile = "3.1.0"
|
||||
glib = "0.10"
|
||||
@ -43,8 +44,3 @@ with-procspawn-tempdir = { git = "https://github.com/cgwalters/with-procspawn-te
|
||||
|
||||
# Internal crate for the test macro
|
||||
itest-macro = { path = "itest-macro" }
|
||||
|
||||
[patch.crates-io]
|
||||
# See https://github.com/tcr/commandspec/pulls?q=is%3Apr+author%3Acgwalters+
|
||||
# If patches don't get reviewed I'll probably fork it.
|
||||
commandspec = { git = "https://github.com/cgwalters/commandspec", branch = 'walters-master' }
|
||||
|
@ -20,7 +20,7 @@
|
||||
//! AUTOPKGTEST_REBOOT_MARK.
|
||||
|
||||
use anyhow::{Context, Result};
|
||||
use commandspec::sh_execute;
|
||||
use sh_inline::bash;
|
||||
use rand::seq::SliceRandom;
|
||||
use rand::Rng;
|
||||
use serde::{Deserialize, Serialize};
|
||||
@ -133,7 +133,7 @@ impl InterruptStrategy {
|
||||
/// TODO add readonly sysroot handling into base ostree
|
||||
fn testinit() -> Result<()> {
|
||||
assert!(std::path::Path::new("/run/ostree-booted").exists());
|
||||
sh_execute!(
|
||||
bash!(
|
||||
r"if ! test -w /sysroot; then
|
||||
mount -o remount,rw /sysroot
|
||||
fi"
|
||||
@ -152,7 +152,7 @@ fn generate_update(commit: &str) -> Result<()> {
|
||||
// Amortize the prune across multiple runs; we don't want to leak space,
|
||||
// but traversing all the objects is expensive. So here we only prune 1/5 of the time.
|
||||
if rand::thread_rng().gen_ratio(1, 5) {
|
||||
sh_execute!(
|
||||
bash!(
|
||||
"ostree --repo={srvrepo} prune --refs-only --depth=1",
|
||||
srvrepo = SRVREPO
|
||||
)?;
|
||||
@ -165,7 +165,7 @@ fn generate_update(commit: &str) -> Result<()> {
|
||||
/// and then teach our webserver to redirect to the system for objects it doesn't
|
||||
/// have.
|
||||
fn generate_srv_repo(commit: &str) -> Result<()> {
|
||||
sh_execute!(
|
||||
bash!(
|
||||
r#"
|
||||
ostree --repo={srvrepo} init --mode=archive
|
||||
ostree --repo={srvrepo} config set archive.zlib-level 1
|
||||
@ -200,7 +200,7 @@ struct RebootStats {
|
||||
}
|
||||
|
||||
fn upgrade_and_finalize() -> Result<()> {
|
||||
sh_execute!(
|
||||
bash!(
|
||||
"rpm-ostree upgrade
|
||||
systemctl start ostree-finalize-staged
|
||||
systemctl stop ostree-finalize-staged"
|
||||
@ -304,8 +304,8 @@ fn parse_and_validate_reboot_mark<M: AsRef<str>>(
|
||||
|
||||
fn validate_pending_commit(pending_commit: &str, commitstates: &CommitStates) -> Result<()> {
|
||||
if pending_commit != commitstates.target {
|
||||
sh_execute!("rpm-ostree status -v")?;
|
||||
sh_execute!(
|
||||
bash!("rpm-ostree status -v")?;
|
||||
bash!(
|
||||
"ostree show {pending_commit}",
|
||||
pending_commit = pending_commit
|
||||
)?;
|
||||
@ -418,7 +418,7 @@ fn impl_transaction_test<M: AsRef<str>>(
|
||||
// If we've reached our target iterations, exit the test successfully
|
||||
if mark.iter == ITERATIONS {
|
||||
// TODO also add ostree admin fsck to check the deployment directories
|
||||
sh_execute!(
|
||||
bash!(
|
||||
"echo Performing final validation...
|
||||
ostree fsck"
|
||||
)?;
|
||||
@ -455,7 +455,7 @@ fn impl_transaction_test<M: AsRef<str>>(
|
||||
);
|
||||
// Reset the target ref to booted, and perform a cleanup
|
||||
// to ensure we're re-downloading objects each time
|
||||
sh_execute!(
|
||||
bash!(
|
||||
"
|
||||
systemctl stop rpm-ostreed
|
||||
systemctl stop ostree-finalize-staged
|
||||
@ -498,7 +498,7 @@ fn impl_transaction_test<M: AsRef<str>>(
|
||||
// the interrupt strategy.
|
||||
match strategy {
|
||||
InterruptStrategy::Force(ForceInterruptStrategy::Kill9) => {
|
||||
sh_execute!(
|
||||
bash!(
|
||||
"systemctl kill -s KILL rpm-ostreed || true
|
||||
systemctl kill -s KILL ostree-finalize-staged || true"
|
||||
)?;
|
||||
@ -508,7 +508,7 @@ fn impl_transaction_test<M: AsRef<str>>(
|
||||
mark.reboot_strategy = Some(strategy.clone());
|
||||
prepare_reboot(serde_json::to_string(&mark)?)?;
|
||||
// This is a forced reboot - no syncing of the filesystem.
|
||||
sh_execute!("reboot -ff")?;
|
||||
bash!("reboot -ff")?;
|
||||
std::thread::sleep(time::Duration::from_secs(60));
|
||||
// Shouldn't happen
|
||||
anyhow::bail!("failed to reboot");
|
||||
@ -522,7 +522,7 @@ fn impl_transaction_test<M: AsRef<str>>(
|
||||
// We either rebooted, or failed to reboot
|
||||
}
|
||||
InterruptStrategy::Polite(PoliteInterruptStrategy::Stop) => {
|
||||
sh_execute!(
|
||||
bash!(
|
||||
"systemctl stop rpm-ostreed || true
|
||||
systemctl stop ostree-finalize-staged || true"
|
||||
)?;
|
||||
@ -566,7 +566,7 @@ fn transactionality() -> Result<()> {
|
||||
};
|
||||
with_webserver_in(&srvrepo, &webserver_opts, move |addr| {
|
||||
let url = format!("http://{}", addr);
|
||||
sh_execute!(
|
||||
bash!(
|
||||
"ostree remote delete --if-exists testrepo
|
||||
ostree remote add --set=gpg-verify=false testrepo {url}",
|
||||
url = url
|
||||
@ -576,13 +576,13 @@ fn transactionality() -> Result<()> {
|
||||
// Also disable some services (like zincati) because we don't want automatic updates
|
||||
// in our reboots, and it currently fails to start. The less
|
||||
// we have in each reboot, the faster reboots are.
|
||||
sh_execute!("systemctl disable --now zincati fedora-coreos-pinger")?;
|
||||
bash!("systemctl disable --now zincati fedora-coreos-pinger")?;
|
||||
// And prepare for updates
|
||||
sh_execute!("rpm-ostree cleanup -pr")?;
|
||||
bash!("rpm-ostree cleanup -pr")?;
|
||||
generate_update(&commit)?;
|
||||
// Directly set the origin, so that we're not dependent on the pending deployment.
|
||||
// FIXME: make this saner
|
||||
sh_execute!(
|
||||
bash!(
|
||||
"
|
||||
ostree admin set-origin testrepo {url} {testref}
|
||||
ostree refs --create testrepo:{testref} {commit}
|
||||
@ -608,7 +608,7 @@ fn transactionality() -> Result<()> {
|
||||
let mut f = std::io::BufWriter::new(std::fs::File::create(&TDATAPATH)?);
|
||||
serde_json::to_writer(&mut f, &tdata)?;
|
||||
f.flush()?;
|
||||
sh_execute!("rpm-ostree status")?;
|
||||
bash!("rpm-ostree status")?;
|
||||
}
|
||||
|
||||
let tdata = {
|
||||
|
@ -5,12 +5,12 @@ use std::path::Path;
|
||||
|
||||
use crate::test::*;
|
||||
use anyhow::{Context, Result};
|
||||
use commandspec::{sh_command, sh_execute};
|
||||
use sh_inline::{bash_command, bash};
|
||||
use with_procspawn_tempdir::with_procspawn_tempdir;
|
||||
|
||||
#[itest]
|
||||
fn test_basic() -> Result<()> {
|
||||
sh_execute!(r"ostree --help >/dev/null")?;
|
||||
bash!(r"ostree --help >/dev/null")?;
|
||||
Ok(())
|
||||
}
|
||||
|
||||
@ -18,14 +18,14 @@ fn test_basic() -> Result<()> {
|
||||
#[with_procspawn_tempdir]
|
||||
fn test_nofifo() -> Result<()> {
|
||||
assert!(std::path::Path::new(".procspawn-tmpdir").exists());
|
||||
sh_execute!(
|
||||
bash!(
|
||||
r"ostree --repo=repo init --mode=archive
|
||||
mkdir tmproot
|
||||
mkfifo tmproot/afile
|
||||
"
|
||||
)?;
|
||||
cmd_fails_with(
|
||||
sh_command!(
|
||||
bash_command!(
|
||||
r#"ostree --repo=repo commit -b fifotest -s "commit fifo" --tree=dir=./tmproot"#
|
||||
)
|
||||
.unwrap(),
|
||||
@ -37,7 +37,7 @@ fn test_nofifo() -> Result<()> {
|
||||
#[itest]
|
||||
#[with_procspawn_tempdir]
|
||||
fn test_mtime() -> Result<()> {
|
||||
sh_execute!(
|
||||
bash!(
|
||||
r"ostree --repo=repo init --mode=archive
|
||||
mkdir tmproot
|
||||
echo afile > tmproot/afile
|
||||
@ -45,7 +45,7 @@ fn test_mtime() -> Result<()> {
|
||||
"
|
||||
)?;
|
||||
let ts = Path::new("repo").metadata()?.modified().unwrap();
|
||||
sh_execute!(
|
||||
bash!(
|
||||
r#"ostree --repo=repo commit -b test -s "bump mtime" --tree=dir=tmproot >/dev/null"#
|
||||
)?;
|
||||
assert_ne!(ts, Path::new("repo").metadata()?.modified().unwrap());
|
||||
@ -55,7 +55,7 @@ fn test_mtime() -> Result<()> {
|
||||
#[itest]
|
||||
#[with_procspawn_tempdir]
|
||||
fn test_extensions() -> Result<()> {
|
||||
sh_execute!(r"ostree --repo=repo init --mode=bare")?;
|
||||
bash!(r"ostree --repo=repo init --mode=bare")?;
|
||||
assert!(Path::new("repo/extensions").exists());
|
||||
Ok(())
|
||||
}
|
||||
@ -78,7 +78,7 @@ fn test_pull_basicauth() -> Result<()> {
|
||||
)?;
|
||||
let osroot = Path::new("osroot");
|
||||
crate::treegen::mkroot(&osroot)?;
|
||||
sh_execute!(
|
||||
bash!(
|
||||
r#"ostree --repo={serverrepo} init --mode=archive
|
||||
ostree --repo={serverrepo} commit -b os --tree=dir={osroot} >/dev/null
|
||||
mkdir client
|
||||
@ -96,7 +96,7 @@ fn test_pull_basicauth() -> Result<()> {
|
||||
)?;
|
||||
for rem in &["unauth", "badauth"] {
|
||||
cmd_fails_with(
|
||||
sh_command!(
|
||||
bash_command!(
|
||||
r#"ostree --repo=client/repo pull origin-{rem} os >/dev/null"#,
|
||||
rem = *rem
|
||||
)
|
||||
@ -105,7 +105,7 @@ fn test_pull_basicauth() -> Result<()> {
|
||||
)
|
||||
.context(rem)?;
|
||||
}
|
||||
sh_execute!(r#"ostree --repo=client/repo pull origin-goodauth os >/dev/null"#,)?;
|
||||
bash!(r#"ostree --repo=client/repo pull origin-goodauth os >/dev/null"#,)?;
|
||||
Ok(())
|
||||
})?;
|
||||
Ok(())
|
||||
|
@ -35,6 +35,6 @@ fn test_sysroot_ro() -> Result<()> {
|
||||
#[itest]
|
||||
fn test_immutable_bit() -> Result<()> {
|
||||
// https://bugzilla.redhat.com/show_bug.cgi?id=1867601
|
||||
cmd_has_output(commandspec::sh_command!("lsattr -d /").unwrap(), "-i-")?;
|
||||
cmd_has_output(sh_inline::bash_command!("lsattr -d /").unwrap(), "-i-")?;
|
||||
Ok(())
|
||||
}
|
||||
|
@ -237,8 +237,8 @@ mod tests {
|
||||
fn test_output() -> Result<()> {
|
||||
cmd_has_output(Command::new("true"), "")?;
|
||||
assert!(cmd_has_output(Command::new("true"), "foo").is_err());
|
||||
cmd_has_output(commandspec::sh_command!("echo foobarbaz; echo fooblahbaz").unwrap(), "blah")?;
|
||||
assert!(cmd_has_output(commandspec::sh_command!("echo foobarbaz").unwrap(), "blah").is_err());
|
||||
cmd_has_output(sh_inline::bash_command!("echo foobarbaz; echo fooblahbaz").unwrap(), "blah")?;
|
||||
assert!(cmd_has_output(sh_inline::bash_command!("echo foobarbaz").unwrap(), "blah").is_err());
|
||||
Ok(())
|
||||
}
|
||||
|
||||
|
@ -1,5 +1,5 @@
|
||||
use anyhow::{Context, Result};
|
||||
use commandspec::sh_execute;
|
||||
use sh_inline::bash;
|
||||
use openat_ext::{FileExt, OpenatDirExt};
|
||||
use rand::Rng;
|
||||
use std::fs::File;
|
||||
@ -140,7 +140,7 @@ pub(crate) fn update_os_tree<P: AsRef<Path>>(
|
||||
}
|
||||
assert!(mutated > 0);
|
||||
println!("Mutated ELF files: {}", mutated);
|
||||
sh_execute!("ostree --repo={repo} commit --consume -b {ostref} --base={ostref} --tree=dir={tempdir} --owner-uid 0 --owner-gid 0 --selinux-policy-from-base --link-checkout-speedup --no-bindings --no-xattrs",
|
||||
bash!("ostree --repo={repo} commit --consume -b {ostref} --base={ostref} --tree=dir={tempdir} --owner-uid 0 --owner-gid 0 --selinux-policy-from-base --link-checkout-speedup --no-bindings --no-xattrs",
|
||||
repo = repo_path.to_str().unwrap(),
|
||||
ostref = ostref,
|
||||
tempdir = tempdir.path().to_str().unwrap()).context("Failed to commit updated content")?;
|
||||
|
Loading…
Reference in New Issue
Block a user