From ec764d19a573696c8dcf3c077de6e43ceb3d4c03 Mon Sep 17 00:00:00 2001 From: Colin Walters Date: Sat, 21 Oct 2023 16:17:09 -0400 Subject: [PATCH 1/2] spec: Make status always required This avoids unnecessary digging through an `Option`, particularly some `unwrap()` usage. Signed-off-by: Colin Walters --- lib/src/cli.rs | 28 ++++++++++++++++------------ lib/src/privtests.rs | 3 +-- lib/src/spec.rs | 5 +++-- lib/src/status.rs | 15 ++++++++++++--- 4 files changed, 32 insertions(+), 19 deletions(-) diff --git a/lib/src/cli.rs b/lib/src/cli.rs index 56c6b5f10..44f688b5c 100644 --- a/lib/src/cli.rs +++ b/lib/src/cli.rs @@ -284,26 +284,31 @@ async fn upgrade(opts: UpgradeOpts) -> Result<()> { prepare_for_write().await?; let sysroot = &get_locked_sysroot().await?; let repo = &sysroot.repo(); - let booted_deployment = &sysroot.require_booted_deployment()?; - let (_deployments, host) = crate::status::get_status(sysroot, Some(booted_deployment))?; - // SAFETY: There must be a status if we have a booted deployment - let status = host.status.unwrap(); + let (booted_deployment, _deployments, host) = + crate::status::get_status_require_booted(sysroot)?; let imgref = host.spec.image.as_ref(); // If there's no specified image, let's be nice and check if the booted system is using rpm-ostree - if imgref.is_none() && status.booted.as_ref().map_or(false, |b| b.incompatible) { + if imgref.is_none() + && host + .status + .booted + .as_ref() + .map_or(false, |b| b.incompatible) + { return Err(anyhow::anyhow!( "Booted deployment contains local rpm-ostree modifications; cannot upgrade via bootc" )); } let spec = RequiredHostSpec::from_spec(&host.spec)?; - let booted_image = status + let booted_image = host + .status .booted .map(|b| b.query_image(repo)) .transpose()? .flatten(); let imgref = imgref.ok_or_else(|| anyhow::anyhow!("No image source specified"))?; // Find the currently queued digest, if any before we pull - let staged = status.staged.as_ref(); + let staged = host.status.staged.as_ref(); let staged_image = staged.as_ref().and_then(|s| s.image.as_ref()); let mut changed = false; if opts.check { @@ -365,8 +370,8 @@ async fn switch(opts: SwitchOpts) -> Result<()> { let sysroot = &get_locked_sysroot().await?; let repo = &sysroot.repo(); - let booted_deployment = &sysroot.require_booted_deployment()?; - let (_deployments, host) = crate::status::get_status(sysroot, Some(booted_deployment))?; + let (booted_deployment, _deployments, host) = + crate::status::get_status_require_booted(sysroot)?; let transport = ostree_container::Transport::try_from(opts.transport.as_str())?; let imgref = ostree_container::ImageReference { @@ -419,9 +424,8 @@ async fn edit(opts: EditOpts) -> Result<()> { prepare_for_write().await?; let sysroot = &get_locked_sysroot().await?; let repo = &sysroot.repo(); - let booted_deployment = &sysroot.require_booted_deployment()?; - let (_deployments, host) = crate::status::get_status(sysroot, Some(booted_deployment))?; - + let (booted_deployment, _deployments, host) = + crate::status::get_status_require_booted(sysroot)?; let new_host: Host = if opts.filename == "-" { let tmpf = tempfile::NamedTempFile::new()?; serde_yaml::to_writer(std::io::BufWriter::new(tmpf.as_file()), &host)?; diff --git a/lib/src/privtests.rs b/lib/src/privtests.rs index ea541d2ea..97c07a046 100644 --- a/lib/src/privtests.rs +++ b/lib/src/privtests.rs @@ -103,8 +103,7 @@ pub(crate) fn impl_run_container() -> Result<()> { assert!(ostree_ext::container_utils::is_ostree_container()?); let sh = Shell::new()?; let host: Host = serde_yaml::from_str(&cmd!(sh, "bootc status").read()?)?; - let status = host.status.unwrap(); - assert!(status.is_container); + assert!(host.status.is_container); for c in ["upgrade", "update"] { let o = Command::new("bootc").arg(c).output()?; let st = o.status; diff --git a/lib/src/spec.rs b/lib/src/spec.rs index 577924e40..2e7e53dc2 100644 --- a/lib/src/spec.rs +++ b/lib/src/spec.rs @@ -19,7 +19,8 @@ pub struct Host { #[serde(default)] pub spec: HostSpec, /// The status - pub status: Option, + #[serde(default)] + pub status: HostStatus, } #[derive(Serialize, Deserialize, Default, Debug, Clone, PartialEq, Eq)] @@ -121,7 +122,7 @@ impl Host { metadata, }, spec, - status: None, + status: Default::default(), } } } diff --git a/lib/src/status.rs b/lib/src/status.rs index 4442a4666..29079bf7e 100644 --- a/lib/src/status.rs +++ b/lib/src/status.rs @@ -172,6 +172,15 @@ impl BootEntry { } } +/// A variant of [`get_status`] that requires a booted deployment. +pub(crate) fn get_status_require_booted( + sysroot: &SysrootLock, +) -> Result<(ostree::Deployment, Deployments, Host)> { + let booted_deployment = sysroot.require_booted_deployment()?; + let (deployments, host) = get_status(sysroot, Some(&booted_deployment))?; + Ok((booted_deployment, deployments, host)) +} + /// Gather the ostree deployment objects, but also extract metadata from them into /// a more native Rust structure. pub(crate) fn get_status( @@ -227,12 +236,12 @@ pub(crate) fn get_status( }) .unwrap_or_default(); let mut host = Host::new(OBJECT_NAME, spec); - host.status = Some(HostStatus { + host.status = HostStatus { staged, booted, rollback, is_container, - }); + }; Ok((deployments, host)) } @@ -244,7 +253,7 @@ pub(crate) async fn status(opts: super::cli::StatusOpts) -> Result<()> { ..Default::default() }; let mut r = Host::new(OBJECT_NAME, HostSpec { image: None }); - r.status = Some(status); + r.status = status; r } else { let sysroot = super::cli::get_locked_sysroot().await?; From 68419c6ffaa7b07201af0a2566aaec5673b32bca Mon Sep 17 00:00:00 2001 From: Colin Walters Date: Sun, 22 Oct 2023 13:02:35 -0400 Subject: [PATCH 2/2] ci: Disable zincati Signed-off-by: Colin Walters --- ci/run-kola.sh | 9 +++++++++ 1 file changed, 9 insertions(+) diff --git a/ci/run-kola.sh b/ci/run-kola.sh index 460a04b07..66df2bf5d 100755 --- a/ci/run-kola.sh +++ b/ci/run-kola.sh @@ -25,6 +25,15 @@ storage: - path: /etc/ostree/auth.json contents: local: auth.json +systemd: + units: + - name: zincati.service + dropins: + - name: disabled.conf + contents: | + [Unit] + ConditionPathExists=/enoent + EOF butane -d . < pull-secret.bu > pull-secret.ign kola_args+=("--append-ignition" "pull-secret.ign")