2525
2626use anyhow:: { Context , Result } ;
2727use clap:: Parser ;
28+ use std:: net:: SocketAddr ;
2829use std:: sync:: Arc ;
2930use std:: time:: { Duration , Instant } ;
3031use tokio:: runtime:: Runtime ;
@@ -147,10 +148,10 @@ fn run_configuration_tests() -> Result<()> {
147148 . context ( "Failed to start provisioned instance container" ) ?;
148149
149150 // Step 2: Wait for SSH server and setup connectivity (only available when running)
150- let ( ssh_host , ssh_port ) = running_container. ssh_details ( ) ;
151+ let socket_addr = running_container. ssh_details ( ) ;
151152 let ssh_wait_action = SshWaitAction :: new ( Duration :: from_secs ( 30 ) , 10 ) ;
152153 ssh_wait_action
153- . execute ( & ssh_host , ssh_port )
154+ . execute ( socket_addr )
154155 . context ( "SSH server failed to start" ) ?;
155156
156157 // Get SSH credentials from test environment and setup keys
@@ -161,8 +162,7 @@ fn run_configuration_tests() -> Result<()> {
161162 . context ( "Failed to setup SSH authentication" ) ?;
162163
163164 info ! (
164- ssh_host = %ssh_host,
165- ssh_port = ssh_port,
165+ socket_addr = %socket_addr,
166166 ssh_user = %ssh_credentials. ssh_username,
167167 container_id = %running_container. container_id( ) ,
168168 "Container ready for Ansible configuration"
@@ -194,11 +194,10 @@ fn run_configuration_tests() -> Result<()> {
194194async fn run_provision_simulation (
195195 running_container : & torrust_tracker_deploy:: e2e:: containers:: RunningProvisionedContainer ,
196196) -> Result < ( ) > {
197- let ( ssh_host , ssh_port ) = running_container. ssh_details ( ) ;
197+ let socket_addr = running_container. ssh_details ( ) ;
198198
199199 info ! (
200- ssh_host = %ssh_host,
201- ssh_port = ssh_port,
200+ socket_addr = %socket_addr,
202201 "Running provision simulation for container"
203202 ) ;
204203
@@ -211,8 +210,7 @@ async fn run_provision_simulation(
211210 provision_docker_infrastructure (
212211 Arc :: clone ( & services. ansible_template_renderer ) ,
213212 ssh_credentials,
214- ssh_host. parse ( ) ?,
215- ssh_port,
213+ socket_addr,
216214 )
217215 . await
218216 . context ( "Failed to complete Docker infrastructure provision simulation" ) ?;
@@ -229,11 +227,10 @@ async fn run_provision_simulation(
229227fn run_ansible_configuration (
230228 running_container : & torrust_tracker_deploy:: e2e:: containers:: RunningProvisionedContainer ,
231229) -> Result < ( ) > {
232- let ( ssh_host , ssh_port ) = running_container. ssh_details ( ) ;
230+ let socket_addr = running_container. ssh_details ( ) ;
233231
234232 info ! (
235- ssh_host = %ssh_host,
236- ssh_port = ssh_port,
233+ socket_addr = %socket_addr,
237234 "Running Ansible configuration on container"
238235 ) ;
239236
@@ -291,11 +288,10 @@ fn run_ansible_configuration(
291288async fn run_deployment_validation (
292289 running_container : & torrust_tracker_deploy:: e2e:: containers:: RunningProvisionedContainer ,
293290) -> Result < ( ) > {
294- let ( ssh_host , ssh_port ) = running_container. ssh_details ( ) ;
291+ let socket_addr = running_container. ssh_details ( ) ;
295292
296293 info ! (
297- ssh_host = %ssh_host,
298- ssh_port = ssh_port,
294+ socket_addr = %socket_addr,
299295 "Running deployment validation on container"
300296 ) ;
301297
@@ -304,10 +300,7 @@ async fn run_deployment_validation(
304300 match credentials_result {
305301 Ok ( ssh_credentials) => {
306302 // Create SSH connection with the container's dynamic port
307- let host_ip = ssh_host. parse ( ) . context ( "Failed to parse SSH host as IP" ) ?;
308-
309- match validate_container_deployment_with_port ( & ssh_credentials, host_ip, ssh_port) . await
310- {
303+ match validate_container_deployment_with_port ( & ssh_credentials, socket_addr) . await {
311304 Ok ( ( ) ) => {
312305 info ! ( status = "success" , "All deployment validations passed" ) ;
313306 }
@@ -378,29 +371,30 @@ fn create_container_ssh_credentials() -> Result<SshCredentials> {
378371/// Validate container deployment using SSH infrastructure with custom port
379372async fn validate_container_deployment_with_port (
380373 ssh_credentials : & SshCredentials ,
381- host_ip : std:: net:: IpAddr ,
382- ssh_port : u16 ,
374+ socket_addr : SocketAddr ,
383375) -> Result < ( ) > {
384376 use torrust_tracker_deploy:: infrastructure:: remote_actions:: {
385377 DockerComposeValidator , DockerValidator , RemoteAction ,
386378 } ;
387379
380+ let ip_addr = socket_addr. ip ( ) ;
381+
388382 // Create SSH connection with the container's dynamic port using the new port support
389383 let ssh_connection = ssh_credentials
390384 . clone ( )
391- . with_host_and_port ( host_ip , ssh_port ) ;
385+ . with_host_and_port ( ip_addr , socket_addr . port ( ) ) ;
392386
393387 // Validate Docker installation
394388 let docker_validator = DockerValidator :: new ( ssh_connection. clone ( ) ) ;
395389 docker_validator
396- . execute ( & host_ip )
390+ . execute ( & ip_addr )
397391 . await
398392 . context ( "Docker validation failed" ) ?;
399393
400394 // Validate Docker Compose installation
401395 let compose_validator = DockerComposeValidator :: new ( ssh_connection) ;
402396 compose_validator
403- . execute ( & host_ip )
397+ . execute ( & ip_addr )
404398 . await
405399 . context ( "Docker Compose validation failed" ) ?;
406400
0 commit comments