-
Notifications
You must be signed in to change notification settings - Fork 28
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Parse and print CoreOS aleph version
This is prep for work on "adoption": #38 In order to (as safely as possible) take over management of a system *not installed via bootupd* we want to gather as much information as we can. For example, we can use the imgid as the "version" of the current bootloader data.
- Loading branch information
1 parent
8dea817
commit 536aca6
Showing
5 changed files
with
86 additions
and
1 deletion.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,59 @@ | ||
//! Bits specific to Fedora CoreOS (and derivatives). | ||
/* | ||
* Copyright (C) 2020 Red Hat, Inc. | ||
* | ||
* SPDX-License-Identifier: Apache-2.0 | ||
*/ | ||
|
||
use anyhow::Result; | ||
use openat_ext::OpenatDirExt; | ||
use serde::{Deserialize, Serialize}; | ||
|
||
#[derive(Serialize, Deserialize, Clone, Debug, Hash, Ord, PartialOrd, PartialEq, Eq)] | ||
#[serde(rename_all = "kebab-case")] | ||
/// See https://github.com/coreos/fedora-coreos-tracker/blob/66d7d00bedd9d5eabc7287b9577f443dcefb7c04/internals/README-internals.md#aleph-version | ||
pub(crate) struct Aleph { | ||
pub(crate) build: String, | ||
#[serde(rename = "ref")] | ||
pub(crate) ostree_ref: String, | ||
pub(crate) ostree_commit: String, | ||
pub(crate) imgid: String, | ||
} | ||
|
||
/// Path to the file, see above | ||
const ALEPH_PATH: &str = "/sysroot/.coreos-aleph-version.json"; | ||
|
||
pub(crate) fn get_aleph_version() -> Result<Option<Aleph>> { | ||
let sysroot = openat::Dir::open("/")?; | ||
if let Some(statusf) = sysroot.open_file_optional(ALEPH_PATH)? { | ||
let bufr = std::io::BufReader::new(statusf); | ||
let aleph: Aleph = serde_json::from_reader(bufr)?; | ||
Ok(Some(aleph)) | ||
} else { | ||
Ok(None) | ||
} | ||
} | ||
|
||
#[cfg(test)] | ||
mod test { | ||
use super::*; | ||
use anyhow::Result; | ||
|
||
#[test] | ||
fn test_parse_aleph() -> Result<()> { | ||
let alephdata = r##" | ||
{ | ||
"build": "32.20201002.dev.2", | ||
"ref": "fedora/x86_64/coreos/testing-devel", | ||
"ostree-commit": "b2ea6159d6274e1bbbb49aa0ef093eda5d53a75c8a793dbe184f760ed64dc862", | ||
"imgid": "fedora-coreos-32.20201002.dev.2-qemu.x86_64.qcow2" | ||
}"##; | ||
let aleph: Aleph = serde_json::from_str(alephdata)?; | ||
assert_eq!( | ||
aleph.imgid, | ||
"fedora-coreos-32.20201002.dev.2-qemu.x86_64.qcow2" | ||
); | ||
Ok(()) | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters