Skip to content

Commit 8608d6d

Browse files
committed
Address PR review feedback
- Make --ssh and --ssh-wait mutually exclusive using conflicts_with - Change error handling in wait_for_ssh_ready to return Ok(false) on error instead of propagating, to avoid noisy debug logging during polling - Extract hardcoded 180 second timeout into SSH_WAIT_TIMEOUT_SECONDS constant - Move debug logs outside suppress_output check so they're always logged Assisted-by: Claude Code (Sonnet 4.5)
1 parent 2c05e9e commit 8608d6d

3 files changed

Lines changed: 17 additions & 11 deletions

File tree

crates/integration-tests/src/tests/libvirt_verb.rs

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1440,5 +1440,3 @@ fn test_libvirt_run_bind_mounts() -> Result<()> {
14401440
Ok(())
14411441
}
14421442
integration_test!(test_libvirt_run_bind_mounts);
1443-
1444-
/// Test --ssh-wait flag waits for SSH without entering shell

crates/kit/src/libvirt/run.rs

Lines changed: 10 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,9 @@ use crate::libvirt::domain::VirtiofsFilesystem;
1919
use crate::utils::parse_memory_to_mb;
2020
use crate::xml_utils;
2121

22+
/// SSH wait timeout in seconds
23+
const SSH_WAIT_TIMEOUT_SECONDS: u64 = 180;
24+
2225
/// Create a virsh command with optional connection URI
2326
pub(super) fn virsh_command(connect_uri: Option<&str>) -> Result<std::process::Command> {
2427
let mut cmd = std::process::Command::new("virsh");
@@ -254,7 +257,7 @@ pub struct LibvirtRunOpts {
254257
pub ssh: bool,
255258

256259
/// Wait for SSH to become available and verify connectivity (for testing)
257-
#[clap(long)]
260+
#[clap(long, conflicts_with = "ssh")]
258261
pub ssh_wait: bool,
259262

260263
/// Mount host container storage (RO) at /run/host-container-storage
@@ -364,7 +367,10 @@ fn wait_for_ssh_ready(
364367
};
365368

366369
// Try to connect
367-
crate::libvirt::ssh::run_ssh_impl(&global_opts_clone, ssh_opts).map(|_| true)
370+
match crate::libvirt::ssh::run_ssh_impl(&global_opts_clone, ssh_opts) {
371+
Ok(_) => Ok(true),
372+
Err(_) => Ok(false),
373+
}
368374
},
369375
Duration::from_secs(timeout_secs),
370376
Duration::from_secs(2), // Poll every 2 seconds
@@ -502,12 +508,12 @@ pub fn run(global_opts: &crate::libvirt::LibvirtOptions, opts: LibvirtRunOpts) -
502508

503509
if opts.ssh_wait {
504510
// Wait for SSH to be ready and verify connectivity
505-
wait_for_ssh_ready(global_opts, &vm_name, 180)?;
511+
wait_for_ssh_ready(global_opts, &vm_name, SSH_WAIT_TIMEOUT_SECONDS)?;
506512
println!("Ready; use bcvk libvirt ssh to connect");
507513
Ok(())
508514
} else if opts.ssh {
509515
// Wait for SSH then enter interactive shell
510-
wait_for_ssh_ready(global_opts, &vm_name, 180)?;
516+
wait_for_ssh_ready(global_opts, &vm_name, SSH_WAIT_TIMEOUT_SECONDS)?;
511517

512518
// Use the libvirt SSH functionality directly
513519
let ssh_opts = crate::libvirt::ssh::LibvirtSshOpts {

crates/kit/src/libvirt/ssh.rs

Lines changed: 7 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -319,17 +319,19 @@ impl LibvirtSshOpts {
319319
.output()
320320
.map_err(|e| eyre!("Failed to execute SSH command: {}", e))?;
321321

322-
if !self.suppress_output {
323-
if !output.stdout.is_empty() {
322+
if !output.stdout.is_empty() {
323+
if !self.suppress_output {
324324
// Forward stdout to parent process
325325
print!("{}", String::from_utf8_lossy(&output.stdout));
326-
debug!("SSH stdout: {}", String::from_utf8_lossy(&output.stdout));
327326
}
328-
if !output.stderr.is_empty() {
327+
debug!("SSH stdout: {}", String::from_utf8_lossy(&output.stdout));
328+
}
329+
if !output.stderr.is_empty() {
330+
if !self.suppress_output {
329331
// Forward stderr to parent process
330332
eprint!("{}", String::from_utf8_lossy(&output.stderr));
331-
debug!("SSH stderr: {}", String::from_utf8_lossy(&output.stderr));
332333
}
334+
debug!("SSH stderr: {}", String::from_utf8_lossy(&output.stderr));
333335
}
334336

335337
if !output.status.success() {

0 commit comments

Comments
 (0)