Skip to content

Commit d9c00b2

Browse files
committed
tests/inst: convert more sh-inline to xshell
Part of #2857
1 parent 78c45e8 commit d9c00b2

3 files changed

Lines changed: 57 additions & 23 deletions

File tree

tests/inst/src/destructive.rs

Lines changed: 25 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,6 @@ use ostree_ext::ostree;
2525
use rand::seq::SliceRandom;
2626
use rand::Rng;
2727
use serde::{Deserialize, Serialize};
28-
use sh_inline::bash;
2928
use std::collections::BTreeMap;
3029
use std::io::Write;
3130
use std::path::Path;
@@ -132,12 +131,15 @@ impl InterruptStrategy {
132131

133132
/// TODO add readonly sysroot handling into base ostree
134133
fn testinit() -> Result<()> {
134+
let sh = xshell::Shell::new()?;
135135
assert!(std::path::Path::new("/run/ostree-booted").exists());
136-
bash!(
136+
cmd!(
137+
sh,
137138
r"if ! test -w /sysroot; then
138139
mount -o remount,rw /sysroot
139140
fi"
140-
)?;
141+
)
142+
.run()?;
141143
Ok(())
142144
}
143145

@@ -146,16 +148,19 @@ fi"
146148
/// reworked the tree mutation to operate on an ostree repo
147149
/// rather than a filesystem.
148150
fn generate_update(commit: &str) -> Result<()> {
151+
let sh = xshell::Shell::new()?;
149152
println!("Generating update from {}", commit);
150153
crate::treegen::update_os_tree(SRVREPO, TESTREF, TREEGEN_PERCENTAGE)
151154
.context("Failed to generate new content")?;
152155
// Amortize the prune across multiple runs; we don't want to leak space,
153156
// but traversing all the objects is expensive. So here we only prune 1/5 of the time.
154157
if rand::thread_rng().gen_ratio(1, 5) {
155-
bash!(
158+
cmd!(
159+
sh,
156160
"ostree --repo=${srvrepo} prune --refs-only --depth=1",
157161
srvrepo = SRVREPO
158-
)?;
162+
)
163+
.run()?;
159164
}
160165
Ok(())
161166
}
@@ -165,7 +170,9 @@ fn generate_update(commit: &str) -> Result<()> {
165170
/// and then teach our webserver to redirect to the system for objects it doesn't
166171
/// have.
167172
fn generate_srv_repo(commit: &str) -> Result<()> {
168-
bash!(
173+
let sh = xshell::Shell::new()?;
174+
cmd!(
175+
sh,
169176
r#"
170177
ostree --repo=${srvrepo} init --mode=archive
171178
ostree --repo=${srvrepo} config set archive.zlib-level 1
@@ -176,6 +183,7 @@ fn generate_srv_repo(commit: &str) -> Result<()> {
176183
commit = commit,
177184
testref = TESTREF
178185
)
186+
.run()
179187
.context("Failed to generate srv repo")?;
180188
generate_update(commit)?;
181189
Ok(())
@@ -200,11 +208,14 @@ struct RebootStats {
200208
}
201209

202210
fn upgrade_and_finalize() -> Result<()> {
203-
bash!(
211+
let sh = xshell::Shell::new()?;
212+
cmd!(
213+
sh,
204214
"rpm-ostree upgrade
205215
systemctl start ostree-finalize-staged
206216
systemctl stop ostree-finalize-staged"
207217
)
218+
.run()
208219
.context("Upgrade and finalize failed")?;
209220
Ok(())
210221
}
@@ -309,9 +320,10 @@ fn parse_and_validate_reboot_mark<M: AsRef<str>>(
309320
}
310321

311322
fn validate_pending_commit(pending_commit: &str, commitstates: &CommitStates) -> Result<()> {
323+
let sh = xshell::Shell::new()?;
312324
if pending_commit != commitstates.target {
313-
bash!("rpm-ostree status -v")?;
314-
bash!("ostree show ${pending_commit}", pending_commit)?;
325+
cmd!(sh, "rpm-ostree status -v").run()?;
326+
cmd!(sh, "ostree show ${pending_commit}", pending_commit).run()?;
315327
anyhow::bail!(
316328
"Expected target commit={} but pending={} ({:?})",
317329
commitstates.target,
@@ -622,7 +634,8 @@ pub(crate) fn itest_transactionality() -> Result<()> {
622634
// FIXME: make this saner
623635
let origref = ORIGREF;
624636
let testref = TESTREF;
625-
bash!(
637+
cmd!(
638+
sh,
626639
"
627640
ostree admin set-origin testrepo ${url} ${testref}
628641
ostree refs --create testrepo:${testref} ${commit}
@@ -632,7 +645,8 @@ pub(crate) fn itest_transactionality() -> Result<()> {
632645
origref,
633646
testref,
634647
commit
635-
)?;
648+
)
649+
.run()?;
636650
// We gather a single "cycle time" at start as a way of gauging how
637651
// long an upgrade should take, so we know when to interrupt. This
638652
// obviously has some pitfalls, mainly when there are e.g. other competing

tests/inst/src/repobin.rs

Lines changed: 31 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -5,23 +5,28 @@ use std::path::Path;
55

66
use crate::test::*;
77
use anyhow::{Context, Result};
8-
use sh_inline::{bash, bash_command};
8+
use sh_inline::bash_command;
99
use with_procspawn_tempdir::with_procspawn_tempdir;
10+
use xshell::cmd;
1011

1112
pub(crate) fn itest_basic() -> Result<()> {
12-
bash!(r"ostree --help >/dev/null")?;
13+
let sh = xshell::Shell::new()?;
14+
cmd!(sh, r"ostree --help >/dev/null").run()?;
1315
Ok(())
1416
}
1517

1618
#[with_procspawn_tempdir]
1719
pub(crate) fn itest_nofifo() -> Result<()> {
20+
let sh = xshell::Shell::new()?;
1821
assert!(std::path::Path::new(".procspawn-tmpdir").exists());
19-
bash!(
22+
cmd!(
23+
sh,
2024
r"ostree --repo=repo init --mode=archive
2125
mkdir tmproot
2226
mkfifo tmproot/afile
2327
"
24-
)?;
28+
)
29+
.run()?;
2530
cmd_fails_with(
2631
bash_command!(
2732
r#"ostree --repo=repo commit -b fifotest -s "commit fifo" --tree=dir=./tmproot"#
@@ -34,29 +39,38 @@ pub(crate) fn itest_nofifo() -> Result<()> {
3439

3540
#[with_procspawn_tempdir]
3641
pub(crate) fn itest_mtime() -> Result<()> {
37-
bash!(
42+
let sh = xshell::Shell::new()?;
43+
cmd!(
44+
sh,
3845
r"ostree --repo=repo init --mode=archive
3946
mkdir tmproot
4047
echo afile > tmproot/afile
4148
ostree --repo=repo commit -b test --tree=dir=tmproot >/dev/null
4249
"
43-
)?;
50+
)
51+
.run()?;
4452
let ts = Path::new("repo").metadata()?.modified().unwrap();
4553
std::thread::sleep(std::time::Duration::from_secs(1));
46-
bash!(r#"ostree --repo=repo commit -b test -s "bump mtime" --tree=dir=tmproot >/dev/null"#)?;
54+
cmd!(
55+
sh,
56+
r#"ostree --repo=repo commit -b test -s "bump mtime" --tree=dir=tmproot >/dev/null"#
57+
)
58+
.run()?;
4759
assert_ne!(ts, Path::new("repo").metadata()?.modified().unwrap());
4860
Ok(())
4961
}
5062

5163
#[with_procspawn_tempdir]
5264
pub(crate) fn itest_extensions() -> Result<()> {
53-
bash!(r"ostree --repo=repo init --mode=bare")?;
65+
let sh = xshell::Shell::new()?;
66+
cmd!(sh, r"ostree --repo=repo init --mode=bare").run()?;
5467
assert!(Path::new("repo/extensions").exists());
5568
Ok(())
5669
}
5770

5871
#[with_procspawn_tempdir]
5972
pub(crate) fn itest_pull_basicauth() -> Result<()> {
73+
let sh = xshell::Shell::new()?;
6074
let opts = TestHttpServerOpts {
6175
basicauth: true,
6276
..Default::default()
@@ -72,7 +86,8 @@ pub(crate) fn itest_pull_basicauth() -> Result<()> {
7286
)?;
7387
let osroot = Path::new("osroot");
7488
crate::treegen::mkroot(&osroot)?;
75-
bash!(
89+
cmd!(
90+
sh,
7691
r#"ostree --repo=${serverrepo} init --mode=archive
7792
ostree --repo=${serverrepo} commit -b os --tree=dir=${osroot} >/dev/null
7893
mkdir client
@@ -87,7 +102,8 @@ pub(crate) fn itest_pull_basicauth() -> Result<()> {
87102
baseuri = baseuri.to_string(),
88103
unauthuri = unauthuri.to_string(),
89104
authuri = authuri.to_string()
90-
)?;
105+
)
106+
.run()?;
91107
for rem in &["unauth", "badauth"] {
92108
cmd_fails_with(
93109
bash_command!(
@@ -99,7 +115,11 @@ pub(crate) fn itest_pull_basicauth() -> Result<()> {
99115
)
100116
.context(rem)?;
101117
}
102-
bash!(r#"ostree --repo=client/repo pull origin-goodauth os >/dev/null"#,)?;
118+
cmd!(
119+
sh,
120+
r#"ostree --repo=client/repo pull origin-goodauth os >/dev/null"#,
121+
)
122+
.run()?;
103123
Ok(())
104124
})?;
105125
Ok(())

tests/inst/src/treegen.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -151,5 +151,5 @@ pub(crate) fn update_os_tree<P: AsRef<Path>>(
151151
assert!(mutated > 0);
152152
println!("Mutated ELF files: {}", mutated);
153153
let tempdir = tempdir.path();
154-
cmd!(sh, "ostree --repo={repo_path} 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").run().context("Failed to commit updated content")
154+
cmd!(sh, "ostree --repo={repo_path} 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").run().context("Failed to commit updated content")?
155155
}

0 commit comments

Comments
 (0)