diff --git a/crates/lib/src/cli.rs b/crates/lib/src/cli.rs index efb3df316..23bae71d9 100644 --- a/crates/lib/src/cli.rs +++ b/crates/lib/src/cli.rs @@ -1336,10 +1336,12 @@ async fn run_from_opt(opt: Opt) -> Result<()> { } Opt::Edit(opts) => edit(opts).await, Opt::UsrOverlay => { - let storage = &get_storage().await?; - match storage.kind()? { - BootedStorageKind::Ostree(_) => usroverlay().await, - BootedStorageKind::Composefs(_) => composefs_usr_overlay(), + use crate::store::Environment; + let env = Environment::detect()?; + match env { + Environment::OstreeBooted => usroverlay().await, + Environment::ComposefsBooted(_) => composefs_usr_overlay(), + _ => anyhow::bail!("usroverlay only applies on booted hosts"), } } Opt::Container(opts) => match opts { diff --git a/tmt/plans/integration.fmf b/tmt/plans/integration.fmf index fe74cc737..104f90feb 100644 --- a/tmt/plans/integration.fmf +++ b/tmt/plans/integration.fmf @@ -106,6 +106,13 @@ execute: enabled: false because: tmt-reboot does not work with systemd reboot in testing farm environment (see bug-soft-reboot.md) +/test-23-usroverlay: + summary: Usroverlay + discover: + how: fmf + test: + - /tmt/tests/test-23-usroverlay + /test-28-factory-reset: summary: Factory reset discover: diff --git a/tmt/tests/booted/bootc_testlib.nu b/tmt/tests/booted/bootc_testlib.nu new file mode 100644 index 000000000..45089a358 --- /dev/null +++ b/tmt/tests/booted/bootc_testlib.nu @@ -0,0 +1,14 @@ +# A simple nushell "library" for the + +# This is a workaround for what must be a systemd bug +# that seems to have appeared in C10S +# TODO diagnose and fill in here +export def reboot [] { + # Sometimes systemd daemons are still running old binaries and response "Access denied" when send reboot request + # Force a full sync before reboot + sync + # Allow more delay for bootc to settle + sleep 30sec + + tmt-reboot +} diff --git a/tmt/tests/booted/test-factory-reset.nu b/tmt/tests/booted/test-factory-reset.nu index 32e5928da..a89b10027 100644 --- a/tmt/tests/booted/test-factory-reset.nu +++ b/tmt/tests/booted/test-factory-reset.nu @@ -1,5 +1,6 @@ use std assert use tap.nu +use bootc_testlib.nu def initial_build [] { tap begin "factory reset test" @@ -41,16 +42,7 @@ def initial_build [] { # nu's cp doesn't have -T /usr/bin/cp -r -T $workdir_root $"($new_stateroot_path)/($workdir_root)" - # Check reset status before reboot - RUST_LOG=trace bootc status - - # Sometimes systemd daemons are still running old binaries and response "Access denied" when send reboot request - # Force a full sync before reboot - sync - # Allow more delay for bootc to settle - sleep 30sec - - tmt-reboot + bootc_testlib reboot } # The second boot; verify we're in the factory reset deployment diff --git a/tmt/tests/booted/test-usroverlay.nu b/tmt/tests/booted/test-usroverlay.nu new file mode 100644 index 000000000..6fb93346a --- /dev/null +++ b/tmt/tests/booted/test-usroverlay.nu @@ -0,0 +1,32 @@ +# Verify that bootc usroverlay works +use std assert +use tap.nu +use bootc_testlib.nu + +bootc status + +# We should start out in a non-writable state on each boot +let is_writable = (do -i { /bin/test -w /usr } | complete | get exit_code) == 0 +assert (not $is_writable) + +def initial_run [] { + bootc usroverlay + let is_writable = (do -i { /bin/test -w /usr } | complete | get exit_code) == 0 + assert ($is_writable) + + bootc_testlib reboot +} + +# The second boot; verify we're in the derived image +def second_boot [] { + # Nothing, we already verified non-writability above +} + +def main [] { + # See https://tmt.readthedocs.io/en/stable/stories/features.html#reboot-during-test + match $env.TMT_REBOOT_COUNT? { + null | "0" => initial_run, + "1" => second_boot, + $o => { error make { msg: $"Invalid TMT_REBOOT_COUNT ($o)" } }, + } +} diff --git a/tmt/tests/test-23-usroverlay.fmf b/tmt/tests/test-23-usroverlay.fmf new file mode 100644 index 000000000..fe273d36c --- /dev/null +++ b/tmt/tests/test-23-usroverlay.fmf @@ -0,0 +1,3 @@ +summary: Execute tests for bootc usrover +test: nu booted/test-usroverlay.nu +duration: 30m