Skip to content

Commit

Permalink
Merge pull request #1136 from cgwalters/cfs-lint-opt
Browse files Browse the repository at this point in the history
lint: Split composefs into separate warning lint
  • Loading branch information
cgwalters authored Feb 21, 2025
2 parents 5309d5b + 406bfe3 commit a9979e9
Show file tree
Hide file tree
Showing 2 changed files with 57 additions and 7 deletions.
61 changes: 55 additions & 6 deletions lib/src/lints.rs
Original file line number Diff line number Diff line change
Expand Up @@ -360,6 +360,40 @@ fn check_utf8(dir: &Dir) -> LintResult {
lint_ok()
}

fn check_prepareroot_composefs_norecurse(dir: &Dir) -> LintResult {
let path = ostree_ext::ostree_prepareroot::CONF_PATH;
let Some(config) = ostree_prepareroot::load_config_from_root(dir)? else {
return lint_err(format!("{path} is not present to enable composefs"));
};
if !ostree_prepareroot::overlayfs_enabled_in_config(&config)? {
return lint_err(format!("{path} does not have composefs enabled"));
}
lint_ok()
}

#[distributed_slice(LINTS)]
static LINT_COMPOSEFS: Lint = Lint::new_warning(
"baseimage-composefs",
indoc! { r#"
Check that composefs is enabled for ostree. More in
<https://ostreedev.github.io/ostree/composefs/>.
"#},
check_composefs,
);
fn check_composefs(dir: &Dir) -> LintResult {
if let Err(e) = check_prepareroot_composefs_norecurse(dir)? {
return Ok(Err(e));
}
// If we have our own documentation with the expected root contents
// embedded, then check that too! Mostly just because recursion is fun.
if let Some(dir) = dir.open_dir_optional(BASEIMAGE_REF)? {
if let Err(e) = check_prepareroot_composefs_norecurse(&dir)? {
return Ok(Err(e));
}
}
lint_ok()
}

/// Check for a few files and directories we expect in the base image.
fn check_baseimage_root_norecurse(dir: &Dir) -> LintResult {
// Check /sysroot
Expand All @@ -380,12 +414,7 @@ fn check_baseimage_root_norecurse(dir: &Dir) -> LintResult {
let link = dir.read_link_contents("ostree")?;
let expected = "sysroot/ostree";
if link.as_os_str().as_bytes() != expected.as_bytes() {
return lint_err("Expected /ostree -> {expected}, not {link:?}");
}

let config = ostree_prepareroot::require_config_from_root(dir)?;
if !ostree_prepareroot::overlayfs_enabled_in_config(&config)? {
return lint_err("{prepareroot_path} does not have composefs enabled");
return lint_err(format!("Expected /ostree -> {expected}, not {link:?}"));
}

lint_ok()
Expand Down Expand Up @@ -860,6 +889,26 @@ mod tests {
Ok(())
}

#[test]
fn test_composefs() -> Result<()> {
let td = fixture()?;

// An empty root should fail our test
assert!(check_composefs(&td).unwrap().is_err());

drop(td);
let td = passing_fixture()?;
check_baseimage_root(&td).unwrap().unwrap();

td.write(
"usr/lib/ostree/prepare-root.conf",
b"[composefs]\nenabled = false",
)?;
assert!(check_composefs(&td).unwrap().is_err());

Ok(())
}

#[test]
fn test_buildah_injected() -> Result<()> {
let td = fixture()?;
Expand Down
3 changes: 2 additions & 1 deletion ostree-ext/src/ostree_prepareroot.rs
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,8 @@ use crate::keyfileext::KeyFileExt;
use crate::ostree_manual;
use crate::utils::ResultExt;

pub(crate) const CONF_PATH: &str = "ostree/prepare-root.conf";
/// The relative path to ostree-prepare-root's config.
pub const CONF_PATH: &str = "ostree/prepare-root.conf";

pub(crate) fn load_config(root: &ostree::RepoFile) -> Result<Option<glib::KeyFile>> {
let cancellable = gio::Cancellable::NONE;
Expand Down

0 comments on commit a9979e9

Please sign in to comment.