Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

identity: introspect updates stream #67

Merged
merged 1 commit into from
Jul 10, 2019
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
13 changes: 4 additions & 9 deletions src/identity/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -57,16 +57,17 @@ impl Identity {

/// Try to build default agent identity.
pub fn try_default() -> Fallible<Self> {
let basearch = rpm_ostree::basearch()?;
let basearch =
rpm_ostree::basearch().context("failed to introspect OS base architecture")?;
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)
.map_err(|e| format_err!("failed to parse application ID: {}", e))?;
compute_node_uuid(&app_id)?
};
let platform = platform::read_id("/proc/cmdline")?;
// TODO(lucab): populate this from node introspection.
let stream = read_stream()?;
let stream =
rpm_ostree::updates_stream().context("failed to introspect OS updates stream")?;

let id = Self {
basearch,
Expand Down Expand Up @@ -124,12 +125,6 @@ impl Identity {
}
}

fn read_stream() -> Fallible<String> {
// TODO(lucab): read this from os-release.
let ver = "testing".to_string();
Ok(ver)
}

fn compute_node_uuid(app_id: &id128::Id128) -> Fallible<id128::Id128> {
let id = id128::get_machine_app_specific(app_id)
.map_err(|e| format_err!("failed to get node ID: {}", e))?;
Expand Down
17 changes: 17 additions & 0 deletions src/rpm_ostree/cli_status.rs
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,8 @@ pub struct DeploymentJSON {
struct BaseCommitMetaJSON {
#[serde(rename = "coreos-assembler.basearch")]
basearch: String,
#[serde(rename = "fedora-coreos.stream")]
stream: String,
}

impl DeploymentJSON {
Expand Down Expand Up @@ -62,6 +64,14 @@ pub fn booted() -> Fallible<Release> {
Ok(json.into_release())
}

/// Return updates stream for booted deployment.
pub fn updates_stream() -> Fallible<String> {
let status = status_json(true)?;
let json = booted_json(status)?;
ensure!(!json.base_metadata.stream.is_empty(), "empty stream value");
Ok(json.base_metadata.stream)
}

/// Return JSON object for booted deployment.
fn booted_json(status: StatusJSON) -> Fallible<DeploymentJSON> {
let booted = status
Expand Down Expand Up @@ -118,4 +128,11 @@ mod tests {
let booted = booted_json(status).unwrap();
assert_eq!(booted.base_metadata.basearch, "x86_64");
}

#[test]
fn mock_booted_updates_stream() {
let status = mock_status().unwrap();
let booted = booted_json(status).unwrap();
assert_eq!(booted.base_metadata.stream, "testing-devel");
}
}
2 changes: 1 addition & 1 deletion src/rpm_ostree/mod.rs
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
mod cli_deploy;
mod cli_finalize;
mod cli_status;
pub use cli_status::{basearch, booted};
pub use cli_status::{basearch, booted, updates_stream};

mod actor;
pub use actor::{FinalizeDeployment, RpmOstreeClient, StageDeployment};
Expand Down
1 change: 1 addition & 0 deletions tests/fixtures/rpm-ostree-status.json
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@
"coreos-assembler.config-dirty" : "true",
"coreos-assembler.config-gitrev" : "e5ffda727170e124c7f7d8782e256b0462bf9869",
"coreos-assembler.basearch" : "x86_64",
"fedora-coreos.stream" : "testing-devel",
"rpmostree.inputhash" : "0e2ba98bac847c8a8cc5ffd42822a41d53ef6719ccaf6a0094559768aa24da33",
"version" : "30.1",
"rpmostree.rpmmd-repos" : [
Expand Down