@@ -83,12 +83,7 @@ impl TestEnvironment {
83
83
} )
84
84
}
85
85
86
- async fn run_command (
87
- & self ,
88
- cmd : & str ,
89
- args : & [ & str ] ,
90
- working_dir : Option < & Path > ,
91
- ) -> Result < String > {
86
+ fn run_command ( & self , cmd : & str , args : & [ & str ] , working_dir : Option < & Path > ) -> Result < String > {
92
87
let mut command = Command :: new ( cmd) ;
93
88
command. args ( args) ;
94
89
@@ -124,7 +119,7 @@ impl TestEnvironment {
124
119
Ok ( String :: from_utf8_lossy ( & output. stdout ) . to_string ( ) )
125
120
}
126
121
127
- async fn provision_infrastructure ( & self ) -> Result < String > {
122
+ fn provision_infrastructure ( & self ) -> Result < String > {
128
123
println ! ( "🚀 Provisioning test infrastructure..." ) ;
129
124
130
125
// First, we need to update the container name in the OpenTofu config
@@ -136,32 +131,28 @@ impl TestEnvironment {
136
131
// Initialize OpenTofu
137
132
println ! ( " Initializing OpenTofu..." ) ;
138
133
self . run_command ( "tofu" , & [ "init" ] , Some ( & tofu_dir) )
139
- . await
140
134
. context ( "Failed to initialize OpenTofu" ) ?;
141
135
142
136
// Apply infrastructure
143
137
println ! ( " Applying infrastructure..." ) ;
144
138
self . run_command ( "tofu" , & [ "apply" , "-auto-approve" ] , Some ( & tofu_dir) )
145
- . await
146
139
. context ( "Failed to apply OpenTofu configuration" ) ?;
147
140
148
141
// Get the container IP
149
142
let container_ip = self
150
143
. get_container_ip ( )
151
- . await
152
144
. context ( "Failed to get container IP after provisioning" ) ?;
153
145
154
146
println ! ( "✅ Infrastructure provisioned successfully" ) ;
155
- println ! ( " Container IP: {}" , container_ip ) ;
147
+ println ! ( " Container IP: {container_ip}" ) ;
156
148
157
149
Ok ( container_ip)
158
150
}
159
151
160
- async fn get_container_ip ( & self ) -> Result < String > {
152
+ fn get_container_ip ( & self ) -> Result < String > {
161
153
// Get container information
162
154
let output = self
163
155
. run_command ( "lxc" , & [ "list" , "torrust-vm" , "--format=json" ] , None )
164
- . await
165
156
. context ( "Failed to list LXC containers" ) ?;
166
157
167
158
let containers: Value =
@@ -193,7 +184,7 @@ impl TestEnvironment {
193
184
194
185
while attempt < max_attempts {
195
186
let result = Command :: new ( "ssh" )
196
- . args ( & [
187
+ . args ( [
197
188
"-i" ,
198
189
self . ssh_key_path . to_str ( ) . unwrap ( ) ,
199
190
"-o" ,
@@ -202,7 +193,7 @@ impl TestEnvironment {
202
193
"UserKnownHostsFile=/dev/null" ,
203
194
"-o" ,
204
195
"ConnectTimeout=5" ,
205
- & format ! ( "torrust@{}" , ip ) ,
196
+ & format ! ( "torrust@{ip}" ) ,
206
197
"echo 'SSH connected'" ,
207
198
] )
208
199
. stdout ( Stdio :: null ( ) )
@@ -246,10 +237,8 @@ impl TestEnvironment {
246
237
let ip_regex =
247
238
Regex :: new ( r"ansible_host: \d+\.\d+\.\d+\.\d+" ) . context ( "Failed to create IP regex" ) ?;
248
239
249
- let updated_content = ip_regex. replace (
250
- & inventory_content,
251
- & format ! ( "ansible_host: {}" , container_ip) ,
252
- ) ;
240
+ let updated_content =
241
+ ip_regex. replace ( & inventory_content, & format ! ( "ansible_host: {container_ip}" ) ) ;
253
242
254
243
// Replace the SSH key path to use our temporary key
255
244
let ssh_key_regex = Regex :: new ( r"ansible_ssh_private_key_file: [^\n]+" )
@@ -267,46 +256,45 @@ impl TestEnvironment {
267
256
. await
268
257
. context ( "Failed to write updated inventory file" ) ?;
269
258
270
- println ! ( "✅ Ansible inventory updated with IP: {}" , container_ip ) ;
259
+ println ! ( "✅ Ansible inventory updated with IP: {container_ip}" ) ;
271
260
println ! (
272
261
"✅ Ansible inventory updated with SSH key: {}" ,
273
262
self . ssh_key_path. display( )
274
263
) ;
275
264
Ok ( ( ) )
276
265
}
277
266
278
- async fn run_ansible_playbook ( & self , playbook : & str ) -> Result < ( ) > {
279
- println ! ( "🎭 Running Ansible playbook: {}" , playbook ) ;
267
+ fn run_ansible_playbook ( & self , playbook : & str ) -> Result < ( ) > {
268
+ println ! ( "🎭 Running Ansible playbook: {playbook}" ) ;
280
269
281
270
let ansible_dir = self . project_root . join ( "config/ansible" ) ;
282
- let playbook_path = format ! ( "{}.yml" , playbook ) ;
271
+ let playbook_path = format ! ( "{playbook }.yml" ) ;
283
272
284
273
let mut args = vec ! [ "ansible-playbook" , & playbook_path] ;
285
274
if self . verbose {
286
275
args. push ( "-vvv" ) ;
287
276
}
288
277
289
278
self . run_command ( "ansible-playbook" , & [ & playbook_path] , Some ( & ansible_dir) )
290
- . await
291
- . context ( format ! ( "Failed to run Ansible playbook: {}" , playbook) ) ?;
279
+ . context ( format ! ( "Failed to run Ansible playbook: {playbook}" ) ) ?;
292
280
293
281
println ! ( "✅ Ansible playbook executed successfully" ) ;
294
282
Ok ( ( ) )
295
283
}
296
284
297
- async fn validate_cloud_init_completion ( & self , container_ip : & str ) -> Result < ( ) > {
285
+ fn validate_cloud_init_completion ( & self , container_ip : & str ) -> Result < ( ) > {
298
286
println ! ( "🔍 Validating cloud-init completion..." ) ;
299
287
300
288
// Check cloud-init status
301
289
let output = Command :: new ( "ssh" )
302
- . args ( & [
290
+ . args ( [
303
291
"-i" ,
304
292
self . ssh_key_path . to_str ( ) . unwrap ( ) ,
305
293
"-o" ,
306
294
"StrictHostKeyChecking=no" ,
307
295
"-o" ,
308
296
"UserKnownHostsFile=/dev/null" ,
309
- & format ! ( "torrust@{}" , container_ip ) ,
297
+ & format ! ( "torrust@{container_ip}" ) ,
310
298
"cloud-init status" ,
311
299
] )
312
300
. output ( )
@@ -326,14 +314,14 @@ impl TestEnvironment {
326
314
327
315
// Check for completion marker file
328
316
let marker_check = Command :: new ( "ssh" )
329
- . args ( & [
317
+ . args ( [
330
318
"-i" ,
331
319
self . ssh_key_path . to_str ( ) . unwrap ( ) ,
332
320
"-o" ,
333
321
"StrictHostKeyChecking=no" ,
334
322
"-o" ,
335
323
"UserKnownHostsFile=/dev/null" ,
336
- & format ! ( "torrust@{}" , container_ip ) ,
324
+ & format ! ( "torrust@{container_ip}" ) ,
337
325
"test -f /var/lib/cloud/instance/boot-finished" ,
338
326
] )
339
327
. status ( )
@@ -349,29 +337,25 @@ impl TestEnvironment {
349
337
Ok ( ( ) )
350
338
}
351
339
352
- async fn cleanup ( & self ) -> Result < ( ) > {
340
+ fn cleanup ( & self ) {
353
341
if self . keep_env {
354
342
println ! ( "🔒 Keeping test environment as requested" ) ;
355
343
println ! ( " Container: torrust-vm" ) ;
356
344
println ! ( " Connect with: lxc exec torrust-vm -- /bin/bash" ) ;
357
- return Ok ( ( ) ) ;
345
+ return ;
358
346
}
359
347
360
348
println ! ( "🧹 Cleaning up test environment..." ) ;
361
349
362
350
let tofu_dir = self . project_root . join ( "config/tofu/lxd" ) ;
363
351
364
352
// Destroy infrastructure
365
- let result = self
366
- . run_command ( "tofu" , & [ "destroy" , "-auto-approve" ] , Some ( & tofu_dir) )
367
- . await ;
353
+ let result = self . run_command ( "tofu" , & [ "destroy" , "-auto-approve" ] , Some ( & tofu_dir) ) ;
368
354
369
355
match result {
370
356
Ok ( _) => println ! ( "✅ Test environment cleaned up successfully" ) ,
371
- Err ( e) => println ! ( "⚠️ Warning: Cleanup failed: {}" , e ) ,
357
+ Err ( e) => println ! ( "⚠️ Warning: Cleanup failed: {e}" ) ,
372
358
}
373
-
374
- Ok ( ( ) )
375
359
}
376
360
}
377
361
@@ -381,7 +365,7 @@ impl Drop for TestEnvironment {
381
365
// Try basic cleanup in case async cleanup failed
382
366
let tofu_dir = self . project_root . join ( "config/tofu/lxd" ) ;
383
367
let _ = Command :: new ( "tofu" )
384
- . args ( & [ "destroy" , "-auto-approve" ] )
368
+ . args ( [ "destroy" , "-auto-approve" ] )
385
369
. current_dir ( & tofu_dir)
386
370
. output ( ) ;
387
371
}
@@ -392,7 +376,7 @@ async fn test_wait_cloud_init(env: &TestEnvironment) -> Result<()> {
392
376
println ! ( "🧪 Starting wait-cloud-init E2E test" ) ;
393
377
394
378
// 1. Provision infrastructure
395
- let container_ip = env. provision_infrastructure ( ) . await ?;
379
+ let container_ip = env. provision_infrastructure ( ) ?;
396
380
397
381
// 2. Wait for SSH connectivity
398
382
env. wait_for_ssh_connectivity ( & container_ip) . await ?;
@@ -401,10 +385,10 @@ async fn test_wait_cloud_init(env: &TestEnvironment) -> Result<()> {
401
385
env. update_ansible_inventory ( & container_ip) . await ?;
402
386
403
387
// 4. Run the wait-cloud-init playbook
404
- env. run_ansible_playbook ( "wait-cloud-init" ) . await ?;
388
+ env. run_ansible_playbook ( "wait-cloud-init" ) ?;
405
389
406
390
// 5. Validate cloud-init completion
407
- env. validate_cloud_init_completion ( & container_ip) . await ?;
391
+ env. validate_cloud_init_completion ( & container_ip) ?;
408
392
409
393
println ! ( "🎉 wait-cloud-init E2E test completed successfully!" ) ;
410
394
Ok ( ( ) )
@@ -425,23 +409,19 @@ async fn main() -> Result<()> {
425
409
TestType :: WaitCloudInit => test_wait_cloud_init ( & env) . await ,
426
410
} ;
427
411
428
- let cleanup_result = env. cleanup ( ) . await ;
412
+ env. cleanup ( ) ;
429
413
430
414
let test_duration = test_start. elapsed ( ) ;
431
- println ! ( "\n 📊 Test execution time: {:?}" , test_duration ) ;
415
+ println ! ( "\n 📊 Test execution time: {test_duration :?}" ) ;
432
416
433
417
// Handle results
434
- match ( result, cleanup_result ) {
435
- ( Ok ( ( ) ) , Ok ( ( ) ) ) => {
418
+ match result {
419
+ Ok ( ( ) ) => {
436
420
println ! ( "✅ All tests passed and cleanup completed successfully" ) ;
437
421
Ok ( ( ) )
438
422
}
439
- ( Ok ( ( ) ) , Err ( cleanup_err) ) => {
440
- println ! ( "✅ Tests passed but cleanup failed: {}" , cleanup_err) ;
441
- Ok ( ( ) ) // Don't fail the test due to cleanup issues
442
- }
443
- ( Err ( test_err) , _) => {
444
- println ! ( "❌ Test failed: {}" , test_err) ;
423
+ Err ( test_err) => {
424
+ println ! ( "❌ Test failed: {test_err}" ) ;
445
425
Err ( test_err)
446
426
}
447
427
}
0 commit comments