Skip to content

Commit

Permalink
Merge pull request #876 from cgwalters/parse-container
Browse files Browse the repository at this point in the history
Remove requirement for `coreos-assembler.basearch`
  • Loading branch information
Luca Bruno authored Nov 2, 2022
2 parents 1e54976 + 4bb6d5c commit 4848f9e
Show file tree
Hide file tree
Showing 4 changed files with 13 additions and 22 deletions.
1 change: 0 additions & 1 deletion docs/development/os-metadata.md
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,6 @@ Booted deployment must provide several mandatory metadata entries:
* `checksum`: OSTree commit revision
* `version`: OS version
* under `base-commit-meta`:
* `coreos-assembler.basearch`: base architecture
* `fedora-coreos.stream`: update stream

All those metadata entries must exist with a non-empty string value.
Expand Down
14 changes: 12 additions & 2 deletions src/identity/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -93,8 +93,7 @@ impl Identity {
pub fn try_default() -> Result<Self> {
// Invoke rpm-ostree to get the status of the currently booted deployment.
let status = rpm_ostree::invoke_cli_status(true)?;
let basearch = rpm_ostree::parse_basearch(&status)
.context("failed to introspect OS base architecture")?;
let basearch = crate::identity::current_architeture().to_string();
let current_os =
rpm_ostree::parse_booted(&status).context("failed to introspect booted OS image")?;
let node_uuid = {
Expand Down Expand Up @@ -190,6 +189,17 @@ fn compute_node_uuid(app_id: &id128::Id128) -> Result<id128::Id128> {
Ok(id)
}

// Translate the architecture we were compiled for to the
// output from the `arch` command that is used for RPM and
// coreos-assembler builds.
pub(crate) fn current_architeture() -> &'static str {
match std::env::consts::ARCH {
"powerpc64" if cfg!(target_endian = "big") => "ppc64",
"powerpc64" if cfg!(target_endian = "little") => "ppc64le",
o => o,
}
}

#[cfg(test)]
mod tests {
use super::*;
Expand Down
16 changes: 0 additions & 16 deletions src/rpm_ostree/cli_status.rs
Original file line number Diff line number Diff line change
Expand Up @@ -61,8 +61,6 @@ pub struct DeploymentJson {
/// Metadata from base commit (only fields relevant to zincati).
#[derive(Clone, Debug, Deserialize)]
struct BaseCommitMetaJson {
#[serde(rename = "coreos-assembler.basearch")]
basearch: String,
#[serde(rename = "fedora-coreos.stream")]
stream: String,
}
Expand All @@ -85,12 +83,6 @@ impl DeploymentJson {
}
}

/// Parse base architecture for booted deployment from status object.
pub fn parse_basearch(status: &StatusJson) -> Result<String> {
let json = booted_json(status)?;
Ok(json.base_metadata.basearch)
}

/// Parse the booted deployment from status object.
pub fn parse_booted(status: &StatusJson) -> Result<Release> {
let json = booted_json(status)?;
Expand Down Expand Up @@ -157,7 +149,6 @@ fn booted_json(status: &StatusJson) -> Result<DeploymentJson> {

ensure!(!booted.base_revision().is_empty(), "empty base revision");
ensure!(!booted.version.is_empty(), "empty version");
ensure!(!booted.base_metadata.basearch.is_empty(), "empty basearch");
Ok(booted)
}

Expand Down Expand Up @@ -244,13 +235,6 @@ mod tests {
}
}

#[test]
fn mock_booted_basearch() {
let status = mock_status("tests/fixtures/rpm-ostree-status.json").unwrap();
let booted = booted_json(&status).unwrap();
assert_eq!(booted.base_metadata.basearch, "x86_64");
}

#[test]
fn mock_booted_updates_stream() {
let status = mock_status("tests/fixtures/rpm-ostree-status.json").unwrap();
Expand Down
4 changes: 1 addition & 3 deletions src/rpm_ostree/mod.rs
Original file line number Diff line number Diff line change
@@ -1,9 +1,7 @@
mod cli_deploy;
mod cli_finalize;
mod cli_status;
pub use cli_status::{
invoke_cli_status, parse_basearch, parse_booted, parse_booted_updates_stream,
};
pub use cli_status::{invoke_cli_status, parse_booted, parse_booted_updates_stream};

mod actor;
pub use actor::{
Expand Down

0 comments on commit 4848f9e

Please sign in to comment.