|
2 | 2 | //! |
3 | 3 | //! This module handles the TOML configuration file for `bootc install`. |
4 | 4 |
|
| 5 | +use crate::spec::Bootloader; |
5 | 6 | use anyhow::{Context, Result}; |
6 | 7 | use clap::ValueEnum; |
7 | 8 | use fn_error_context::context; |
@@ -97,6 +98,8 @@ pub(crate) struct InstallConfiguration { |
97 | 98 | pub(crate) boot_mount_spec: Option<String>, |
98 | 99 | /// Bootupd configuration |
99 | 100 | pub(crate) bootupd: Option<Bootupd>, |
| 101 | + /// Bootloader to use (grub, systemd, none) |
| 102 | + pub(crate) bootloader: Option<Bootloader>, |
100 | 103 | } |
101 | 104 |
|
102 | 105 | fn merge_basic<T>(s: &mut Option<T>, o: Option<T>, _env: &EnvProperties) { |
@@ -180,6 +183,7 @@ impl Mergeable for InstallConfiguration { |
180 | 183 | merge_basic(&mut self.root_mount_spec, other.root_mount_spec, env); |
181 | 184 | merge_basic(&mut self.boot_mount_spec, other.boot_mount_spec, env); |
182 | 185 | self.bootupd.merge(other.bootupd, env); |
| 186 | + merge_basic(&mut self.bootloader, other.bootloader, env); |
183 | 187 | if let Some(other_kargs) = other.kargs { |
184 | 188 | self.kargs |
185 | 189 | .get_or_insert_with(Default::default) |
@@ -810,3 +814,46 @@ skip-boot-uuid = false |
810 | 814 | assert_eq!(install.bootupd.unwrap().skip_boot_uuid.unwrap(), true); |
811 | 815 | } |
812 | 816 | } |
| 817 | + |
| 818 | +#[test] |
| 819 | +fn test_parse_bootloader() { |
| 820 | + let env = EnvProperties { |
| 821 | + sys_arch: "x86_64".to_string(), |
| 822 | + }; |
| 823 | + |
| 824 | + // 1. Test parsing "none" |
| 825 | + let c: InstallConfigurationToplevel = toml::from_str( |
| 826 | + r##"[install] |
| 827 | +bootloader = "none" |
| 828 | +"##, |
| 829 | + ) |
| 830 | + .unwrap(); |
| 831 | + assert_eq!(c.install.unwrap().bootloader, Some(Bootloader::None)); |
| 832 | + |
| 833 | + // 2. Test parsing "grub" |
| 834 | + let c: InstallConfigurationToplevel = toml::from_str( |
| 835 | + r##"[install] |
| 836 | +bootloader = "grub" |
| 837 | +"##, |
| 838 | + ) |
| 839 | + .unwrap(); |
| 840 | + assert_eq!(c.install.unwrap().bootloader, Some(Bootloader::Grub)); |
| 841 | + |
| 842 | + // 3. Test merging |
| 843 | + // Initial config has "systemd" |
| 844 | + let mut install: InstallConfiguration = toml::from_str( |
| 845 | + r#"bootloader = "systemd" |
| 846 | +"#, |
| 847 | + ) |
| 848 | + .unwrap(); |
| 849 | + |
| 850 | + // Incoming config has "none" |
| 851 | + let other = InstallConfiguration { |
| 852 | + bootloader: Some(Bootloader::None), |
| 853 | + ..Default::default() |
| 854 | + }; |
| 855 | + |
| 856 | + // Merge should overwrite systemd with none |
| 857 | + install.merge(other, &env); |
| 858 | + assert_eq!(install.bootloader, Some(Bootloader::None)); |
| 859 | +} |
0 commit comments