Skip to content

Commit

Permalink
bios.rs: add adopt-and-update
Browse files Browse the repository at this point in the history
  • Loading branch information
HuijingHei committed Sep 12, 2024
1 parent b74840b commit e66f5ec
Show file tree
Hide file tree
Showing 2 changed files with 48 additions and 2 deletions.
43 changes: 41 additions & 2 deletions src/bios.rs
Original file line number Diff line number Diff line change
Expand Up @@ -122,16 +122,55 @@ impl Component for Bios {
}

fn query_adopt(&self) -> Result<Option<Adoptable>> {
// This would be extended with support for other operating systems later
if let Some(coreos_aleph) = crate::coreos::get_aleph_version(Path::new("/"))? {
let meta = ContentMetadata {
timestamp: coreos_aleph.ts,
version: coreos_aleph.aleph.version,
};
log::trace!("BIOS adoptable: {:?}", &meta);
return Ok(Some(Adoptable {
version: meta,
confident: true,
}));
} else {
log::trace!("No CoreOS aleph detected");
}
let ostree_deploy_dir = Path::new("/ostree/deploy");
if ostree_deploy_dir.exists() {
let btime = ostree_deploy_dir.metadata()?.created()?;
let timestamp = chrono::DateTime::from(btime);
let meta = ContentMetadata {
timestamp,
version: "unknown".to_string(),
};
return Ok(Some(Adoptable {
version: meta,
confident: true,
}));
}
Ok(None)
}

#[allow(unused_variables)]
fn adopt_update(
&self,
sysroot: &openat::Dir,
update: &ContentMetadata,
) -> Result<InstalledContent> {
todo!();
let meta = if let Some(meta) = self.query_adopt()? {
meta
} else {
anyhow::bail!("Failed to find adoptable system");
};

let device = self.get_device()?;
let device = device.trim();
self.run_grub_install("/", device)?;
Ok(InstalledContent {
meta: update.clone(),
filetree: None,
adopted_from: Some(meta.version),
})
}

fn query_update(&self, sysroot: &openat::Dir) -> Result<Option<ContentMetadata>> {
Expand Down
7 changes: 7 additions & 0 deletions tests/e2e-update/e2e-update-in-vm.sh
Original file line number Diff line number Diff line change
Expand Up @@ -84,6 +84,13 @@ if test -s out.txt; then
fi
ok update not avail

mount -o remount,rw /boot
rm -f /boot/bootupd-state.json
bootupctl adopt-and-update | tee out.txt
assert_file_has_content out.txt "Adopted and updated: BIOS: .*"
assert_file_has_content out.txt "Adopted and updated: EFI: .*"
ok adopt-and-update

tap_finish
touch /run/testtmp/success
sync
Expand Down

0 comments on commit e66f5ec

Please sign in to comment.