25
25
26
26
use anyhow:: { Context , Result } ;
27
27
use clap:: Parser ;
28
+ use std:: net:: SocketAddr ;
28
29
use std:: sync:: Arc ;
29
30
use std:: time:: { Duration , Instant } ;
30
31
use tokio:: runtime:: Runtime ;
@@ -147,10 +148,10 @@ fn run_configuration_tests() -> Result<()> {
147
148
. context ( "Failed to start provisioned instance container" ) ?;
148
149
149
150
// 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 ( ) ;
151
152
let ssh_wait_action = SshWaitAction :: new ( Duration :: from_secs ( 30 ) , 10 ) ;
152
153
ssh_wait_action
153
- . execute ( & ssh_host , ssh_port )
154
+ . execute ( socket_addr )
154
155
. context ( "SSH server failed to start" ) ?;
155
156
156
157
// Get SSH credentials from test environment and setup keys
@@ -161,8 +162,7 @@ fn run_configuration_tests() -> Result<()> {
161
162
. context ( "Failed to setup SSH authentication" ) ?;
162
163
163
164
info ! (
164
- ssh_host = %ssh_host,
165
- ssh_port = ssh_port,
165
+ socket_addr = %socket_addr,
166
166
ssh_user = %ssh_credentials. ssh_username,
167
167
container_id = %running_container. container_id( ) ,
168
168
"Container ready for Ansible configuration"
@@ -194,11 +194,10 @@ fn run_configuration_tests() -> Result<()> {
194
194
async fn run_provision_simulation (
195
195
running_container : & torrust_tracker_deploy:: e2e:: containers:: RunningProvisionedContainer ,
196
196
) -> Result < ( ) > {
197
- let ( ssh_host , ssh_port ) = running_container. ssh_details ( ) ;
197
+ let socket_addr = running_container. ssh_details ( ) ;
198
198
199
199
info ! (
200
- ssh_host = %ssh_host,
201
- ssh_port = ssh_port,
200
+ socket_addr = %socket_addr,
202
201
"Running provision simulation for container"
203
202
) ;
204
203
@@ -211,8 +210,7 @@ async fn run_provision_simulation(
211
210
provision_docker_infrastructure (
212
211
Arc :: clone ( & services. ansible_template_renderer ) ,
213
212
ssh_credentials,
214
- ssh_host. parse ( ) ?,
215
- ssh_port,
213
+ socket_addr,
216
214
)
217
215
. await
218
216
. context ( "Failed to complete Docker infrastructure provision simulation" ) ?;
@@ -229,11 +227,10 @@ async fn run_provision_simulation(
229
227
fn run_ansible_configuration (
230
228
running_container : & torrust_tracker_deploy:: e2e:: containers:: RunningProvisionedContainer ,
231
229
) -> Result < ( ) > {
232
- let ( ssh_host , ssh_port ) = running_container. ssh_details ( ) ;
230
+ let socket_addr = running_container. ssh_details ( ) ;
233
231
234
232
info ! (
235
- ssh_host = %ssh_host,
236
- ssh_port = ssh_port,
233
+ socket_addr = %socket_addr,
237
234
"Running Ansible configuration on container"
238
235
) ;
239
236
@@ -291,11 +288,10 @@ fn run_ansible_configuration(
291
288
async fn run_deployment_validation (
292
289
running_container : & torrust_tracker_deploy:: e2e:: containers:: RunningProvisionedContainer ,
293
290
) -> Result < ( ) > {
294
- let ( ssh_host , ssh_port ) = running_container. ssh_details ( ) ;
291
+ let socket_addr = running_container. ssh_details ( ) ;
295
292
296
293
info ! (
297
- ssh_host = %ssh_host,
298
- ssh_port = ssh_port,
294
+ socket_addr = %socket_addr,
299
295
"Running deployment validation on container"
300
296
) ;
301
297
@@ -304,10 +300,7 @@ async fn run_deployment_validation(
304
300
match credentials_result {
305
301
Ok ( ssh_credentials) => {
306
302
// 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 {
311
304
Ok ( ( ) ) => {
312
305
info ! ( status = "success" , "All deployment validations passed" ) ;
313
306
}
@@ -378,29 +371,30 @@ fn create_container_ssh_credentials() -> Result<SshCredentials> {
378
371
/// Validate container deployment using SSH infrastructure with custom port
379
372
async fn validate_container_deployment_with_port (
380
373
ssh_credentials : & SshCredentials ,
381
- host_ip : std:: net:: IpAddr ,
382
- ssh_port : u16 ,
374
+ socket_addr : SocketAddr ,
383
375
) -> Result < ( ) > {
384
376
use torrust_tracker_deploy:: infrastructure:: remote_actions:: {
385
377
DockerComposeValidator , DockerValidator , RemoteAction ,
386
378
} ;
387
379
380
+ let ip_addr = socket_addr. ip ( ) ;
381
+
388
382
// Create SSH connection with the container's dynamic port using the new port support
389
383
let ssh_connection = ssh_credentials
390
384
. clone ( )
391
- . with_host_and_port ( host_ip , ssh_port ) ;
385
+ . with_host_and_port ( ip_addr , socket_addr . port ( ) ) ;
392
386
393
387
// Validate Docker installation
394
388
let docker_validator = DockerValidator :: new ( ssh_connection. clone ( ) ) ;
395
389
docker_validator
396
- . execute ( & host_ip )
390
+ . execute ( & ip_addr )
397
391
. await
398
392
. context ( "Docker validation failed" ) ?;
399
393
400
394
// Validate Docker Compose installation
401
395
let compose_validator = DockerComposeValidator :: new ( ssh_connection) ;
402
396
compose_validator
403
- . execute ( & host_ip )
397
+ . execute ( & ip_addr )
404
398
. await
405
399
. context ( "Docker Compose validation failed" ) ?;
406
400
0 commit comments