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