Skip to content

Commit 9493f2c

Browse files
authored
Merge pull request #1355 from ckyrouac/system-reinstall-pull-fix
reinstall: Only pull the image if it's not already present
2 parents 726041f + e0301cd commit 9493f2c

File tree

4 files changed

+55
-10
lines changed

4 files changed

+55
-10
lines changed

.github/workflows/ci.yml

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -115,8 +115,8 @@ jobs:
115115
sudo mkdir -p /run/sshd
116116
117117
sudo install -m 0755 target/release/system-reinstall-bootc /usr/bin/system-reinstall-bootc
118-
sudo podman pull quay.io/fedora/fedora-bootc:42
119-
sudo bootc-integration-tests system-reinstall quay.io/fedora/fedora-bootc:42 --test-threads=1
118+
# These tests may mutate the system live so we can't run in parallel
119+
sudo bootc-integration-tests system-reinstall localhost/bootc --test-threads=1
120120
121121
# And the fsverity case
122122
sudo podman run --privileged --pid=host localhost/bootc-fsverity bootc install to-existing-root --stateroot=other \

system-reinstall-bootc/src/main.rs

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -25,10 +25,7 @@ fn run() -> Result<()> {
2525
podman::ensure_podman_installed()?;
2626

2727
//pull image early so it can be inspected, e.g. to check for cloud-init
28-
let mut pull_image_command = podman::pull_image_command(&config.bootc_image);
29-
pull_image_command
30-
.run_with_cmd_context()
31-
.context(format!("pulling image {}", &config.bootc_image))?;
28+
podman::pull_if_not_present(&config.bootc_image)?;
3229

3330
println!();
3431

system-reinstall-bootc/src/podman.rs

Lines changed: 24 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -96,12 +96,35 @@ pub(crate) fn reinstall_command(image: &str, ssh_key_file: &str) -> Result<Comma
9696
Ok(command)
9797
}
9898

99-
pub(crate) fn pull_image_command(image: &str) -> Command {
99+
fn pull_image_command(image: &str) -> Command {
100100
let mut command = Command::new("podman");
101101
command.args(["pull", image]);
102102
command
103103
}
104104

105+
fn image_exists_command(image: &str) -> Command {
106+
let mut command = Command::new("podman");
107+
command.args(["image", "exists", image]);
108+
command
109+
}
110+
111+
pub(crate) fn pull_if_not_present(image: &str) -> Result<()> {
112+
let result = image_exists_command(image).status()?;
113+
114+
if result.success() {
115+
println!("Image {} is already present locally, skipping pull.", image);
116+
return Ok(());
117+
} else {
118+
println!("Image {} is not present locally, pulling it now.", image);
119+
println!();
120+
pull_image_command(image)
121+
.run_with_cmd_context()
122+
.context(format!("pulling image {}", image))?;
123+
}
124+
125+
Ok(())
126+
}
127+
105128
/// Path to the podman installation script. Can be influenced by the build
106129
/// SYSTEM_REINSTALL_BOOTC_INSTALL_PODMAN_PATH parameter to override. Defaults
107130
/// to /usr/lib/system-reinstall-bootc/install-podman

tests-integration/src/system_reinstall.rs

Lines changed: 28 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@ use std::{
1010

1111
use crate::install;
1212

13-
const TIMEOUT: u64 = 120000;
13+
const TIMEOUT: u64 = 60000;
1414

1515
fn get_deployment_dir() -> Result<std::path::PathBuf> {
1616
let base_path = Path::new("/ostree/deploy/default/deploy");
@@ -62,11 +62,14 @@ pub(crate) fn run(image: &str, testargs: libtest_mimic::Arguments) -> Result<()>
6262
)?;
6363

6464
// Basic flow stdout verification
65+
p.exp_string(
66+
format!("Image {image} is already present locally, skipping pull.").as_str(),
67+
)?;
6568
p.exp_regex("Found only one user ([^:]+) with ([\\d]+) SSH authorized keys.")?;
6669
p.exp_string("Would you like to import its SSH authorized keys")?;
6770
p.exp_string("into the root user on the new bootc system?")?;
6871
p.exp_string("Then you can login as root@ using those keys. [Y/n]")?;
69-
p.send_line("a")?;
72+
p.send_line("y")?;
7073

7174
p.exp_string("Going to run command:")?;
7275

@@ -133,13 +136,35 @@ pub(crate) fn run(image: &str, testargs: libtest_mimic::Arguments) -> Result<()>
133136
)?;
134137

135138
p.exp_regex("Found only one user ([^:]+) with ([\\d]+) SSH authorized keys.")?;
136-
p.send_line("a")?;
139+
p.exp_string("[Y/n]")?;
140+
p.send_line("y")?;
137141
p.exp_string("NOTICE: This will replace the installed operating system and reboot. Are you sure you want to continue? [y/N]")?;
138142
p.send_line("y")?;
139143
p.exp_string("Insufficient free space")?;
140144
p.exp_eof()?;
141145
Ok(())
142146
}),
147+
Trial::test("image pull check", move || {
148+
let sh = &xshell::Shell::new()?;
149+
install::reset_root(sh, image)?;
150+
151+
// Run system-reinstall-bootc
152+
let mut p: PtySession = rexpect::spawn(
153+
"/usr/bin/system-reinstall-bootc quay.io/centos-bootc/centos-bootc:stream10",
154+
Some(600000), // Increase timeout for pulling the image
155+
)?;
156+
157+
p.exp_string("Image quay.io/centos-bootc/centos-bootc:stream10 is not present locally, pulling it now.")?;
158+
p.exp_regex("Found only one user ([^:]+) with ([\\d]+) SSH authorized keys.")?;
159+
p.exp_string("[Y/n]")?;
160+
p.send_line("y")?;
161+
p.exp_string("NOTICE: This will replace the installed operating system and reboot. Are you sure you want to continue? [y/N]")?;
162+
p.send_line("y")?;
163+
p.exp_string("Operation complete, rebooting in 10 seconds. Press Ctrl-C to cancel reboot, or press enter to continue immediately.")?;
164+
p.send_control('c')?;
165+
p.exp_eof()?;
166+
Ok(())
167+
}),
143168
];
144169

145170
libtest_mimic::run(&testargs, tests.into()).exit()

0 commit comments

Comments
 (0)