Skip to content

Commit 46fc035

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 5397026 commit 46fc035

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;
@@ -426,20 +427,35 @@ impl Storage {
426427
///
427428
/// This lazily opens the composefs repository, creating the directory if needed
428429
/// and bootstrapping verity settings from the ostree configuration.
429-
pub(crate) fn get_ensure_composefs(&self) -> Result<Arc<ComposefsRepository>> {
430+
pub(crate) fn get_ensure_composefs(
431+
&self,
432+
opt_path: Option<Utf8PathBuf>,
433+
) -> Result<Arc<ComposefsRepository>> {
430434
if let Some(composefs) = self.composefs.get() {
431435
return Ok(Arc::clone(composefs));
432436
}
433437

434-
ensure_composefs_dir(&self.physical_root)?;
438+
let cfs_root = match opt_path {
439+
Some(path) => {
440+
let dir = Dir::open_ambient_dir(&path, ambient_authority())
441+
.with_context(|| format!("Opening {path:?}"))?;
442+
443+
ensure_composefs_dir(&dir)?;
444+
445+
dir
446+
}
447+
None => {
448+
ensure_composefs_dir(&self.physical_root)?;
449+
self.physical_root.try_clone()?
450+
}
451+
};
435452

436453
// Bootstrap verity off of the ostree state. In practice this means disabled by
437454
// default right now.
438455
let ostree = self.get_ostree()?;
439456
let ostree_repo = &ostree.repo();
440457
let ostree_verity = ostree_ext::fsverity::is_verity_enabled(ostree_repo)?;
441-
let mut composefs =
442-
ComposefsRepository::open_path(self.physical_root.open_dir(COMPOSEFS)?, ".")?;
458+
let mut composefs = ComposefsRepository::open_path(cfs_root.open_dir(COMPOSEFS)?, ".")?;
443459
if !ostree_verity.enabled {
444460
tracing::debug!("Setting insecure mode for composefs repo");
445461
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)