mirror of
https://github.com/containers/bootc.git
synced 2026-02-05 06:45:13 +01:00
parser/bls: Add tests for bls parser
Signed-off-by: Johan-Liebert1 <pragyanpoudyal41999@gmail.com>
This commit is contained in:
@@ -66,6 +66,7 @@ where
|
||||
}
|
||||
}
|
||||
|
||||
#[allow(dead_code)]
|
||||
pub(crate) fn parse_bls_config(input: &str) -> Result<BLSConfig> {
|
||||
let mut map = HashMap::new();
|
||||
|
||||
|
||||
@@ -25,11 +25,11 @@ use ostree_ext::sysroot::SysrootLock;
|
||||
use ostree_ext::tokio_util::spawn_blocking_cancellable_flatten;
|
||||
use rustix::fs::{fsync, renameat_with, AtFlags, RenameFlags};
|
||||
|
||||
use crate::bls_config::{parse_bls_config, BLSConfig};
|
||||
use crate::composefs_consts::{
|
||||
BOOT_LOADER_ENTRIES, ROLLBACK_BOOT_LOADER_ENTRIES, USER_CFG, USER_CFG_ROLLBACK,
|
||||
};
|
||||
use crate::install::{get_efi_uuid_source, BootType};
|
||||
use crate::parsers::bls_config::{parse_bls_config, BLSConfig};
|
||||
use crate::parsers::grub_menuconfig::{parse_grub_menuentry_file, MenuEntry};
|
||||
use crate::progress_jsonl::{Event, ProgressWriter, SubTaskBytes, SubTaskStep};
|
||||
use crate::spec::ImageReference;
|
||||
@@ -854,7 +854,7 @@ pub(crate) fn rollback_composefs_bls() -> Result<()> {
|
||||
|
||||
// Update the indicies so that they're swapped
|
||||
for (idx, cfg) in all_configs.iter_mut().enumerate() {
|
||||
cfg.version = idx as u32;
|
||||
cfg.sort_key = Some(idx.to_string());
|
||||
}
|
||||
|
||||
// TODO(Johan-Liebert): Currently assuming there are only two deployments
|
||||
@@ -872,7 +872,8 @@ pub(crate) fn rollback_composefs_bls() -> Result<()> {
|
||||
|
||||
// Write the BLS configs in there
|
||||
for cfg in all_configs {
|
||||
let file_name = format!("bootc-composefs-{}.conf", cfg.version);
|
||||
// SAFETY: We set sort_key above
|
||||
let file_name = format!("bootc-composefs-{}.conf", cfg.sort_key.as_ref().unwrap());
|
||||
|
||||
rollback_entries_dir
|
||||
.atomic_write(&file_name, cfg.to_string())
|
||||
|
||||
@@ -74,7 +74,6 @@ use serde::{Deserialize, Serialize};
|
||||
|
||||
#[cfg(feature = "install-to-disk")]
|
||||
use self::baseline::InstallBlockDeviceOpts;
|
||||
use crate::bls_config::{parse_bls_config, BLSConfig};
|
||||
use crate::boundimage::{BoundImage, ResolvedBoundImage};
|
||||
use crate::composefs_consts::{
|
||||
BOOT_LOADER_ENTRIES, COMPOSEFS_CMDLINE, COMPOSEFS_STAGED_DEPLOYMENT_FNAME,
|
||||
@@ -88,6 +87,7 @@ use crate::deploy::{
|
||||
PreparedPullResult,
|
||||
};
|
||||
use crate::lsm;
|
||||
use crate::parsers::bls_config::{parse_bls_config, BLSConfig};
|
||||
use crate::parsers::grub_menuconfig::MenuEntry;
|
||||
use crate::progress_jsonl::ProgressWriter;
|
||||
use crate::spec::ImageReference;
|
||||
@@ -1559,8 +1559,11 @@ fn get_booted_bls() -> Result<BLSConfig> {
|
||||
|
||||
let bls = parse_bls_config(&std::fs::read_to_string(&entry.path())?)?;
|
||||
|
||||
// TODO clean this up
|
||||
if bls.options.contains(booted.as_ref()) {
|
||||
let Some(opts) = &bls.options else {
|
||||
anyhow::bail!("options not found in bls config")
|
||||
};
|
||||
|
||||
if opts.contains(booted.as_ref()) {
|
||||
return Ok(bls);
|
||||
}
|
||||
}
|
||||
@@ -1770,18 +1773,18 @@ pub(crate) fn setup_composefs_bls_boot(
|
||||
let boot_digest = compute_boot_digest(usr_lib_modules_vmlinuz, &repo)
|
||||
.context("Computing boot digest")?;
|
||||
|
||||
let mut bls_config = BLSConfig {
|
||||
title: Some(id_hex.clone()),
|
||||
version: 1,
|
||||
linux: format!("/boot/{id_hex}/vmlinuz"),
|
||||
initrd: format!("/boot/{id_hex}/initrd"),
|
||||
options: cmdline_refs,
|
||||
extra: HashMap::new(),
|
||||
};
|
||||
let mut bls_config = BLSConfig::default();
|
||||
bls_config.title = Some(id_hex.clone());
|
||||
bls_config.sort_key = Some("1".into());
|
||||
bls_config.machine_id = None;
|
||||
bls_config.linux = format!("/boot/{id_hex}/vmlinuz");
|
||||
bls_config.initrd = vec![format!("/boot/{id_hex}/initrd")];
|
||||
bls_config.options = Some(cmdline_refs);
|
||||
bls_config.extra = HashMap::new();
|
||||
|
||||
if let Some(symlink_to) = find_vmlinuz_initrd_duplicates(&boot_digest)? {
|
||||
bls_config.linux = format!("/boot/{symlink_to}/vmlinuz");
|
||||
bls_config.initrd = format!("/boot/{symlink_to}/initrd");
|
||||
bls_config.initrd = vec![format!("/boot/{symlink_to}/initrd")];
|
||||
} else {
|
||||
write_bls_boot_entries_to_disk(&boot_dir, id, usr_lib_modules_vmlinuz, &repo)?;
|
||||
}
|
||||
@@ -1792,7 +1795,7 @@ pub(crate) fn setup_composefs_bls_boot(
|
||||
|
||||
let (entries_path, booted_bls) = if is_upgrade {
|
||||
let mut booted_bls = get_booted_bls()?;
|
||||
booted_bls.version = 0; // entries are sorted by their filename in reverse order
|
||||
booted_bls.sort_key = Some("0".into()); // entries are sorted by their filename in reverse order
|
||||
|
||||
// This will be atomically renamed to 'loader/entries' on shutdown/reboot
|
||||
(
|
||||
@@ -1810,13 +1813,15 @@ pub(crate) fn setup_composefs_bls_boot(
|
||||
.with_context(|| format!("Opening {entries_path}"))?;
|
||||
|
||||
loader_entries_dir.atomic_write(
|
||||
format!("bootc-composefs-{}.conf", bls_config.version),
|
||||
// SAFETY: We set sort_key above
|
||||
format!("bootc-composefs-{}.conf", bls_config.sort_key.as_ref().unwrap()),
|
||||
bls_config.to_string().as_bytes(),
|
||||
)?;
|
||||
|
||||
if let Some(booted_bls) = booted_bls {
|
||||
loader_entries_dir.atomic_write(
|
||||
format!("bootc-composefs-{}.conf", booted_bls.version),
|
||||
// SAFETY: We set sort_key above
|
||||
format!("bootc-composefs-{}.conf", booted_bls.sort_key.as_ref().unwrap()),
|
||||
booted_bls.to_string().as_bytes(),
|
||||
)?;
|
||||
}
|
||||
|
||||
@@ -4,7 +4,6 @@
|
||||
//! to provide a fully "container native" tool for using
|
||||
//! bootable container images.
|
||||
|
||||
mod bls_config;
|
||||
pub(crate) mod bootc_kargs;
|
||||
mod boundimage;
|
||||
mod cfsctl;
|
||||
@@ -43,5 +42,7 @@ pub(crate) mod parsers;
|
||||
#[cfg(feature = "rhsm")]
|
||||
mod rhsm;
|
||||
|
||||
mod parsers;
|
||||
|
||||
// Re-export blockdev crate for internal use
|
||||
pub(crate) use bootc_blockdev as blockdev;
|
||||
|
||||
@@ -12,7 +12,7 @@ use uapi_version::Version;
|
||||
/// The boot loader should present the available boot menu entries to the user in a sorted list.
|
||||
/// The list should be sorted by the `sort-key` field, if it exists, otherwise by the `machine-id` field.
|
||||
/// If multiple entries have the same `sort-key` (or `machine-id`), they should be sorted by the `version` field in descending order.
|
||||
#[derive(Debug, Eq, PartialEq)]
|
||||
#[derive(Debug, Eq, PartialEq, Default)]
|
||||
#[non_exhaustive]
|
||||
pub(crate) struct BLSConfig {
|
||||
/// The title of the boot entry, to be displayed in the boot menu.
|
||||
|
||||
@@ -559,6 +559,8 @@ pub(crate) async fn composefs_deployment_status() -> Result<Host> {
|
||||
.first()
|
||||
.ok_or(anyhow::anyhow!("First boot entry not found"))?
|
||||
.options
|
||||
.as_ref()
|
||||
.ok_or(anyhow::anyhow!("options key not found in bls config"))?
|
||||
.contains(composefs_arg.as_ref());
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user