Skip to content

Commit

Permalink
Merge pull request #274 from cgwalters/switch-idempotent
Browse files Browse the repository at this point in the history
switch: Be idempotent
  • Loading branch information
cgwalters authored Jan 22, 2024
2 parents f8f3af1 + d2eebb9 commit 1e9c282
Show file tree
Hide file tree
Showing 3 changed files with 12 additions and 4 deletions.
4 changes: 2 additions & 2 deletions docs/usage.md
Original file line number Diff line number Diff line change
Expand Up @@ -22,8 +22,8 @@ on the target, use
bootc switch --transport oci /var/mnt/usb/myos.oci
```

The above command can only be invoked once currently; thereafter, use `bootc upgrade`
as normal to fetch updates from the USB device.
The above command is only necessary once, and thereafter will be idempotent.
Then, use `bootc upgrade --apply` to fetch and apply the update from the USB device.

This process can all be automated by creating systemd
units that look for a USB device with a specific label, mount (optionally with LUKS
Expand Down
3 changes: 2 additions & 1 deletion lib/src/cli.rs
Original file line number Diff line number Diff line change
Expand Up @@ -442,7 +442,8 @@ async fn switch(opts: SwitchOpts) -> Result<()> {
};

if new_spec == host.spec {
anyhow::bail!("No changes in current host spec");
println!("Image specification is unchanged.");
return Ok(());
}
let new_spec = RequiredHostSpec::from_spec(&new_spec)?;

Expand Down
9 changes: 8 additions & 1 deletion tests/kolainst/basic
Original file line number Diff line number Diff line change
Expand Up @@ -15,10 +15,17 @@ case "${AUTOPKGTEST_REBOOT_MARK:-}" in
bootc status > status.txt
grep 'Version:' status.txt
bootc status --json > status.json
image=$(jq -r '.status.booted.image.image' < status.json)
image=$(jq '.status.booted.image.image' < status.json)
echo "booted into $image"
echo "ok status test"

# Switch should be idempotent
# (also TODO, get rid of the crazy .image.image.image nesting)
name=$(echo "${image}" | jq -r '.image')
bootc switch $name
staged=$(bootc status --json | jq .status.staged)
test "$staged" = "null"

host_ty=$(jq -r '.status.type' < status.json)
test "${host_ty}" = "bootcHost"
# Now fake things out with an empty /run
Expand Down

0 comments on commit 1e9c282

Please sign in to comment.