Skip to content

Commit 8dd25ba

Browse files
cfs/test: Fix ro /sysroot problem
The `bootc internals cfs` test was running into an issue where pulling an image into a composefs repository at `/sysroot/composefs` was failing due to /sysroot being mounted ro. We did remount it rw in an earlier cmd, but that was in a separate mount ns which did not carry over to the next commands Instead of globally remounting /sysroot as rw, we now pass a path to the `test-composefs` command which initializes a composefs repository at said path. Also, pass in `--insecure` to `bootc internals cfs ...` as in the ostree case we're testing in xfs which does not support fs-verity Signed-off-by: Pragyan Poudyal <pragyanpoudyal41999@gmail.com>
1 parent bb9b581 commit 8dd25ba

3 files changed

Lines changed: 34 additions & 10 deletions

File tree

crates/lib/src/cli.rs

Lines changed: 8 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -602,7 +602,12 @@ pub(crate) enum InternalsOpts {
602602
args: Vec<OsString>,
603603
},
604604
/// Ensure that a composefs repository is initialized
605-
TestComposefs,
605+
TestComposefs {
606+
/// The path where to initialize composefs repository
607+
/// Will use `/sysroot` if not provided
608+
#[clap(long)]
609+
path: Option<Utf8PathBuf>,
610+
},
606611
/// Loopback device cleanup helper (internal use only)
607612
LoopbackCleanupHelper {
608613
/// Device path to clean up
@@ -1745,10 +1750,10 @@ async fn run_from_opt(opt: Opt) -> Result<()> {
17451750
)
17461751
.await
17471752
}
1748-
InternalsOpts::TestComposefs => {
1753+
InternalsOpts::TestComposefs { path } => {
17491754
// This is a stub to be replaced
17501755
let storage = get_storage().await?;
1751-
let cfs = storage.get_ensure_composefs()?;
1756+
let cfs = storage.get_ensure_composefs(path)?;
17521757
let testdata = b"some test data";
17531758
let testdata_digest = hex::encode(openssl::sha::sha256(testdata));
17541759
let mut w = SplitStreamWriter::new(&cfs, 0);

crates/lib/src/store/mod.rs

Lines changed: 20 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -30,6 +30,7 @@ use cap_std_ext::cap_std::fs::{
3030
use cap_std_ext::dirext::CapStdExtDirExt;
3131
use fn_error_context::context;
3232

33+
use ocidir::cap_std::ambient_authority;
3334
use ostree_ext::container_utils::ostree_booted;
3435
use ostree_ext::prelude::FileExt;
3536
use ostree_ext::sysroot::SysrootLock;
@@ -418,20 +419,35 @@ impl Storage {
418419
///
419420
/// This lazily opens the composefs repository, creating the directory if needed
420421
/// and bootstrapping verity settings from the ostree configuration.
421-
pub(crate) fn get_ensure_composefs(&self) -> Result<Arc<ComposefsRepository>> {
422+
pub(crate) fn get_ensure_composefs(
423+
&self,
424+
opt_path: Option<Utf8PathBuf>,
425+
) -> Result<Arc<ComposefsRepository>> {
422426
if let Some(composefs) = self.composefs.get() {
423427
return Ok(Arc::clone(composefs));
424428
}
425429

426-
ensure_composefs_dir(&self.physical_root)?;
430+
let cfs_root = match opt_path {
431+
Some(path) => {
432+
let dir = Dir::open_ambient_dir(&path, ambient_authority())
433+
.with_context(|| format!("Opening {path:?}"))?;
434+
435+
ensure_composefs_dir(&dir)?;
436+
437+
dir
438+
}
439+
None => {
440+
ensure_composefs_dir(&self.physical_root)?;
441+
self.physical_root.try_clone()?
442+
}
443+
};
427444

428445
// Bootstrap verity off of the ostree state. In practice this means disabled by
429446
// default right now.
430447
let ostree = self.get_ostree()?;
431448
let ostree_repo = &ostree.repo();
432449
let ostree_verity = ostree_ext::fsverity::is_verity_enabled(ostree_repo)?;
433-
let mut composefs =
434-
ComposefsRepository::open_path(self.physical_root.open_dir(COMPOSEFS)?, ".")?;
450+
let mut composefs = ComposefsRepository::open_path(cfs_root.open_dir(COMPOSEFS)?, ".")?;
435451
if !ostree_verity.enabled {
436452
tracing::debug!("Setting insecure mode for composefs repo");
437453
composefs.set_insecure(true);

tmt/tests/booted/readonly/030-test-composefs.nu

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -37,10 +37,13 @@ if $is_composefs {
3737
bootc internals cfs --help
3838
} else {
3939
# When not on composefs, run the full test including initialization
40-
bootc internals test-composefs
40+
# We use a separate `/sysroot` as we need rw access to the repo which
41+
# we can't get from `bootc internals cfs ...`
42+
mkdir /var/tmp/sysroot
43+
bootc internals test-composefs --path /var/tmp/sysroot
4144
bootc internals cfs --help
42-
bootc internals cfs oci pull docker://busybox busybox
43-
test -L /sysroot/composefs/streams/refs/busybox
45+
bootc internals cfs --insecure --repo /var/tmp/sysroot/composefs oci pull docker://busybox busybox
46+
test -L /var/tmp/sysroot/composefs/streams/refs/oci/busybox
4447
}
4548

4649
tap ok

0 commit comments

Comments
 (0)