-
Notifications
You must be signed in to change notification settings - Fork 192
system-reinstall-bootc: fallback image from /usr/lib/os-release #2135
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
base: main
Are you sure you want to change the base?
Changes from all commits
a095e34
fb71e1e
ee263a3
00c8669
a168777
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,118 @@ | ||
| use std::fs::File; | ||
| use std::io::{BufRead, BufReader}; | ||
| use std::path::Path; | ||
|
|
||
| use anyhow::{Context, Result}; | ||
|
|
||
| /// Searches for the BOOTC_IMAGE key in a given os-release file. | ||
| /// Follows standard os-release(5) quoting rules. | ||
| fn parse_bootc_image_from_reader<R: BufRead>(reader: R) -> Result<Option<String>> { | ||
| let mut last_found = None; | ||
|
|
||
| for line in reader.lines() { | ||
| let line = line?; | ||
| let line = line.trim(); | ||
|
|
||
| if line.is_empty() || line.starts_with('#') { | ||
| continue; | ||
| } | ||
|
|
||
| if let Some((key, value)) = line.split_once('=') { | ||
| if key.trim() == "BOOTC_IMAGE" { | ||
| let value = value.trim(); | ||
|
|
||
| if value.starts_with('"') && value.ends_with('"') && value.len() >= 2 { | ||
| let unquoted = &value[1..value.len() - 1]; | ||
| let processed = unquoted | ||
| .replace(r#"\""#, "\"") | ||
| .replace(r#"\\"#, "\\") | ||
| .replace(r#"\$"#, "$") | ||
| .replace(r#"\`"#, "`"); | ||
| last_found = Some(processed); | ||
| } else if value.starts_with('\'') && value.ends_with('\'') && value.len() >= 2 { | ||
| last_found = Some(value[1..value.len() - 1].to_string()); | ||
| } else { | ||
| last_found = Some(value.to_string()); | ||
| } | ||
| } | ||
| } | ||
| } | ||
|
|
||
| Ok(last_found) | ||
| } | ||
|
|
||
| /// Reads the provided os-release file and returns the BOOTC_IMAGE value if found. | ||
| pub(crate) fn get_bootc_image_from_file<P: AsRef<Path>>(path: P) -> Result<Option<String>> { | ||
| let file = File::open(path.as_ref()).with_context(|| format!("Opening {:?}", path.as_ref()))?; | ||
| let reader = BufReader::new(file); | ||
| parse_bootc_image_from_reader(reader) | ||
| } | ||
|
|
||
| #[cfg(test)] | ||
| mod tests { | ||
| use super::*; | ||
| use indoc::indoc; | ||
| use std::io::Cursor; | ||
|
|
||
| fn parse_str(content: &str) -> Option<String> { | ||
| let reader = Cursor::new(content); | ||
| parse_bootc_image_from_reader(reader).unwrap() | ||
| } | ||
|
|
||
| #[test] | ||
| fn test_parse_os_release_standard() { | ||
| let content = indoc! { " | ||
| NAME=Fedora | ||
| BOOTC_IMAGE=quay.io/example/image:latest | ||
| VERSION=39 | ||
| " }; | ||
| assert_eq!(parse_str(content).unwrap(), "quay.io/example/image:latest"); | ||
| } | ||
|
|
||
| #[test] | ||
| fn test_parse_os_release_double_quotes() { | ||
| let content = "BOOTC_IMAGE=\"quay.io/example/image:latest\""; | ||
| assert_eq!(parse_str(content).unwrap(), "quay.io/example/image:latest"); | ||
| } | ||
|
|
||
| #[test] | ||
| fn test_parse_os_release_single_quotes() { | ||
| let content = "BOOTC_IMAGE='quay.io/example/image:latest'"; | ||
| assert_eq!(parse_str(content).unwrap(), "quay.io/example/image:latest"); | ||
| } | ||
|
|
||
| #[test] | ||
| fn test_parse_os_release_escaped() { | ||
| let content = indoc! { r#" | ||
| BOOTC_IMAGE="quay.io/img/with\"quote" | ||
| "# }; | ||
| assert_eq!(parse_str(content).unwrap(), "quay.io/img/with\"quote"); | ||
| } | ||
|
|
||
| #[test] | ||
| fn test_parse_os_release_missing() { | ||
| let content = indoc! { " | ||
| NAME=Fedora | ||
| VERSION=39 | ||
| " }; | ||
| assert!(parse_str(content).is_none()); | ||
| } | ||
|
|
||
| #[test] | ||
| fn test_parse_os_release_comments_and_spaces() { | ||
| let content = indoc! { " | ||
| # comment | ||
| BOOTC_IMAGE= \"quay.io/img\" | ||
| " }; | ||
| assert_eq!(parse_str(content).unwrap(), "quay.io/img"); | ||
| } | ||
|
|
||
| #[test] | ||
| fn test_parse_os_release_last_wins() { | ||
| let content = indoc! { " | ||
| BOOTC_IMAGE=quay.io/old/image | ||
| BOOTC_IMAGE=quay.io/new/image | ||
| " }; | ||
| assert_eq!(parse_str(content).unwrap(), "quay.io/new/image"); | ||
| } | ||
| } |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -8,7 +8,7 @@ prepare: | |
| # Run on package mode VM running on Packit and Gating | ||
| # order 9x means run it at the last job of prepare | ||
| - how: install | ||
| order: 97 | ||
| order: 96 | ||
| package: | ||
| - podman | ||
| - skopeo | ||
|
|
@@ -25,12 +25,18 @@ prepare: | |
| - e2fsprogs | ||
| when: running_env != image_mode | ||
| - how: shell | ||
| order: 98 | ||
| order: 97 | ||
| script: | ||
| - mkdir -p bootc && cp /var/share/test-artifacts/*.src.rpm bootc | ||
| - cd bootc && rpm2cpio *.src.rpm | cpio -idmv && rm -f *-vendor.tar.zstd && zstd -d *.tar.zstd && tar -xvf *.tar -C . --strip-components=1 && ls -al | ||
| - pwd && ls -al && cd bootc/hack && ./provision-packit.sh | ||
| when: running_env != image_mode | ||
| - how: shell | ||
| order: 98 | ||
| script: | ||
| - echo 'BOOTC_IMAGE=localhost/bootc' | tee -a /usr/lib/os-release | ||
| - pwd && ls -al && cd bootc/hack && ./provision-packit.sh | ||
| when: running_env != image_mode | ||
|
Comment on lines
+28
to
+39
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. These two shell steps are redundant and inefficient. Both steps perform the same setup and run
Contributor
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I thought it was easier to just build the image twice than try to do a cleanup step for testing the BOOTC_IMAGE path on reinstall.
hone marked this conversation as resolved.
Show resolved
Hide resolved
|
||
| # tmt-reboot and reboot do not work in this case | ||
| # reboot in ansible is the only way to reboot in tmt prepare | ||
| - how: ansible | ||
|
|
||
Uh oh!
There was an error while loading. Please reload this page.