From a9c98be2091012281744eb7f7f726bfe040d0f41 Mon Sep 17 00:00:00 2001 From: Luca Bruno Date: Wed, 3 Jul 2019 16:59:00 +0000 Subject: [PATCH] identity: introspect basearch This introspects node basearch from rpm-ostree, instead of using build-time configuration and the internal mapping table. --- src/identity/basearch.rs | 38 ------------------------------------ src/identity/mod.rs | 3 +-- src/rpm_ostree/cli_status.rs | 17 +++++++++++++++- src/rpm_ostree/mod.rs | 2 +- 4 files changed, 18 insertions(+), 42 deletions(-) delete mode 100644 src/identity/basearch.rs diff --git a/src/identity/basearch.rs b/src/identity/basearch.rs deleted file mode 100644 index e79fa5db..00000000 --- a/src/identity/basearch.rs +++ /dev/null @@ -1,38 +0,0 @@ -//! Fedora CoreOS base architecture. - -use cfg_if::cfg_if; -use failure::Fallible; - -// TODO(lucab): consider sourcing this directly from somewhere in OS rootfs. - -// Map Rust target to Fedora basearch. -cfg_if! { - if #[cfg(target_arch = "aarch64")] { - static BASEARCH: &str = "aarch64"; - } else if #[cfg(target_arch = "powerpc64le")] { - static BASEARCH: &str = "ppc64le"; - } else if #[cfg(target_arch = "x86_64")] { - static BASEARCH: &str = "x86_64"; - } else { - static BASEARCH: &str = "unsupported"; - } -} - -/// Fetch base architecture value. -pub(crate) fn read_basearch() -> Fallible { - if BASEARCH == "unsupported" { - // For forward compatibility, we log a message but keep going. - log::error!("unsupported base architecture"); - } - - Ok(BASEARCH.to_string()) -} - -#[cfg(test)] -mod tests { - #[test] - fn basic_basearch() { - let label = super::read_basearch().unwrap(); - assert!(!label.is_empty()); - } -} diff --git a/src/identity/mod.rs b/src/identity/mod.rs index 9f5e6ddf..338f6114 100644 --- a/src/identity/mod.rs +++ b/src/identity/mod.rs @@ -1,4 +1,3 @@ -mod basearch; mod platform; use crate::config::inputs; @@ -58,7 +57,7 @@ impl Identity { /// Try to build default agent identity. pub fn try_default() -> Fallible { - let basearch = basearch::read_basearch()?; + let basearch = rpm_ostree::basearch()?; let current_os = rpm_ostree::booted().context("failed to introspect booted OS image")?; let node_uuid = { let app_id = id128::Id128::try_from_slice(APP_ID) diff --git a/src/rpm_ostree/cli_status.rs b/src/rpm_ostree/cli_status.rs index 822a8b2c..673c8489 100644 --- a/src/rpm_ostree/cli_status.rs +++ b/src/rpm_ostree/cli_status.rs @@ -18,6 +18,8 @@ pub struct DeploymentJSON { booted: bool, #[serde(rename = "base-checksum")] base_checksum: Option, + #[serde(rename = "coreos-assembler.basearch")] + basearch: String, checksum: String, version: String, } @@ -39,8 +41,20 @@ impl DeploymentJSON { } } +/// Return base architecture for booted deployment. +pub fn basearch() -> Fallible { + let json = booted_json()?; + Ok(json.basearch) +} + /// Find the booted deployment. pub fn booted() -> Fallible { + let json = booted_json()?; + Ok(json.into_release()) +} + +/// Return JSON object for booted deployment. +fn booted_json() -> Fallible { let cmd = std::process::Command::new("rpm-ostree") .arg("status") .arg("--json") @@ -64,5 +78,6 @@ pub fn booted() -> Fallible { ensure!(!booted.base_revision().is_empty(), "empty base revision"); ensure!(!booted.version.is_empty(), "empty version"); - Ok(booted.into_release()) + ensure!(!booted.basearch.is_empty(), "empty basearch"); + Ok(booted) } diff --git a/src/rpm_ostree/mod.rs b/src/rpm_ostree/mod.rs index 601ebb23..392dfb80 100644 --- a/src/rpm_ostree/mod.rs +++ b/src/rpm_ostree/mod.rs @@ -1,7 +1,7 @@ mod cli_deploy; mod cli_finalize; mod cli_status; -pub use cli_status::booted; +pub use cli_status::{basearch, booted}; mod actor; pub use actor::{FinalizeDeployment, RpmOstreeClient, StageDeployment};