Skip to content

Commit

Permalink
Merge pull request #989 from cgwalters/rhsm-atomic
Browse files Browse the repository at this point in the history
two minor rhsm followups
  • Loading branch information
jeckersb authored Dec 20, 2024
2 parents c88fcfd + e6223aa commit 95fb311
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 8 deletions.
16 changes: 8 additions & 8 deletions lib/src/rhsm.rs
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
//! Integration with Red Hat Subscription Manager
use anyhow::Result;
use cap_std::fs::{Dir, OpenOptions};
use cap_std_ext::cap_std;
use anyhow::{Context, Result};
use cap_std::fs::Dir;
use cap_std_ext::{cap_std, dirext::CapStdExtDirExt};
use fn_error_context::context;
use serde::Serialize;

Expand Down Expand Up @@ -96,11 +96,11 @@ pub(crate) async fn publish_facts(root: &Dir) -> Result<()> {
let (_deployments, host) = crate::status::get_status(&sysroot, booted_deployment.as_ref())?;

let facts = RhsmFacts::from(host.status);
let mut bootc_facts_file = root.open_with(
FACTS_PATH,
OpenOptions::new().write(true).create(true).truncate(true),
)?;
serde_json::to_writer_pretty(&mut bootc_facts_file, &facts)?;
root.atomic_replace_with(FACTS_PATH, |w| {
serde_json::to_writer_pretty(w, &facts)?;
anyhow::Ok(())
})
.with_context(|| format!("Writing {FACTS_PATH}"))?;
Ok(())
}

Expand Down
8 changes: 8 additions & 0 deletions tests/booted/test-image-pushpull-upgrade.nu
Original file line number Diff line number Diff line change
Expand Up @@ -46,8 +46,16 @@ RUN echo test content > /usr/share/blah.txt
# Just sanity check it
let v = podman run --rm localhost/bootc-derived cat /usr/share/blah.txt | str trim
assert equal $v "test content"

let orig_root_mtime = ls -Dl /ostree/bootc | get modified

# Now, fetch it back into the bootc storage!
bootc switch --transport containers-storage localhost/bootc-derived

# Also test that the mtime changes on modification
let new_root_mtime = ls -Dl /ostree/bootc | get modified
assert ($new_root_mtime > $orig_root_mtime)

# And reboot into it
tmt-reboot
}
Expand Down

0 comments on commit 95fb311

Please sign in to comment.