mirror of
https://github.com/cloud-hypervisor/cloud-hypervisor.git
synced 2026-08-05 02:19:16 +00:00
test_infra: bound SSH session runtime in wait_for_ssh
Allow one-shot SSH commands to install a libssh2 session timeout and use that path from wait_for_ssh. This keeps SSH readiness probes from blocking far beyond their caller provided timeout when the guest network is slow or broken. On-behalf-of: SAP philipp.schuster@sap.com Signed-off-by: Philipp Schuster <philipp.schuster@cyberus-technology.de>
This commit is contained in:
committed by
Rob Bradford
parent
a3b4687caa
commit
b26488b1bf
@@ -771,11 +771,15 @@ pub fn ssh_command_ip_with_auth(
|
|||||||
command: &str,
|
command: &str,
|
||||||
auth: &PasswordAuth,
|
auth: &PasswordAuth,
|
||||||
ip: &str,
|
ip: &str,
|
||||||
|
timeout: Option<Duration>,
|
||||||
) -> Result<String, SshCommandError> {
|
) -> Result<String, SshCommandError> {
|
||||||
let mut s = String::new();
|
let mut s = String::new();
|
||||||
let tcp = TcpStream::connect(format!("{ip}:22")).map_err(SshCommandError::Connection)?;
|
let tcp = TcpStream::connect(format!("{ip}:22")).map_err(SshCommandError::Connection)?;
|
||||||
let mut sess = Session::new().unwrap();
|
let mut sess = Session::new().unwrap();
|
||||||
sess.set_tcp_stream(tcp);
|
sess.set_tcp_stream(tcp);
|
||||||
|
if let Some(timeout) = timeout {
|
||||||
|
sess.set_timeout(timeout.as_millis() as u32);
|
||||||
|
}
|
||||||
sess.handshake().map_err(SshCommandError::Handshake)?;
|
sess.handshake().map_err(SshCommandError::Handshake)?;
|
||||||
sess.userauth_password(&auth.username, &auth.password)
|
sess.userauth_password(&auth.username, &auth.password)
|
||||||
.map_err(SshCommandError::Authentication)?;
|
.map_err(SshCommandError::Authentication)?;
|
||||||
@@ -819,7 +823,7 @@ pub fn ssh_command_ip_with_auth_retry(
|
|||||||
) -> Result<String, SshCommandError> {
|
) -> Result<String, SshCommandError> {
|
||||||
let mut counter = 0;
|
let mut counter = 0;
|
||||||
loop {
|
loop {
|
||||||
match ssh_command_ip_with_auth(command, auth, ip) {
|
match ssh_command_ip_with_auth(command, auth, ip, None) {
|
||||||
Ok(s) => return Ok(s),
|
Ok(s) => return Ok(s),
|
||||||
Err(e) => {
|
Err(e) => {
|
||||||
counter += 1;
|
counter += 1;
|
||||||
@@ -870,7 +874,7 @@ pub fn wait_for_ssh(
|
|||||||
timeout: Duration,
|
timeout: Duration,
|
||||||
) -> Result<String, WaitForSshError> {
|
) -> Result<String, WaitForSshError> {
|
||||||
wait_until_succeeds(timeout, || {
|
wait_until_succeeds(timeout, || {
|
||||||
ssh_command_ip_with_auth_retry(command, auth, ip, 1, 1)
|
ssh_command_ip_with_auth(command, auth, ip, Some(timeout))
|
||||||
})
|
})
|
||||||
.map_err(|source| WaitForSshError::Timeout {
|
.map_err(|source| WaitForSshError::Timeout {
|
||||||
command: command.to_string(),
|
command: command.to_string(),
|
||||||
|
|||||||
Reference in New Issue
Block a user