@@ -283,7 +283,50 @@ impl Drop for TestEnvironment {
283283 }
284284}
285285
286- async fn run_full_deployment_test ( env : & TestEnvironment ) -> Result < ( ) > {
286+ async fn validate_deployment ( env : & TestEnvironment , instance_ip : & str ) -> Result < ( ) > {
287+ println ! ( "🔍 Starting deployment validation..." ) ;
288+
289+ // Validate cloud-init completion
290+ println ! ( " Validating cloud-init completion..." ) ;
291+ let cloud_init_validator = CloudInitValidator :: new (
292+ & env. config . ssh_key_path ,
293+ & env. config . ssh_username ,
294+ env. config . verbose ,
295+ ) ;
296+ cloud_init_validator
297+ . execute ( instance_ip)
298+ . await
299+ . map_err ( |e| anyhow:: anyhow!( e) ) ?;
300+
301+ // Validate Docker installation
302+ println ! ( " Validating Docker installation..." ) ;
303+ let docker_validator = DockerValidator :: new (
304+ & env. config . ssh_key_path ,
305+ & env. config . ssh_username ,
306+ env. config . verbose ,
307+ ) ;
308+ docker_validator
309+ . execute ( instance_ip)
310+ . await
311+ . map_err ( |e| anyhow:: anyhow!( e) ) ?;
312+
313+ // Validate Docker Compose installation
314+ println ! ( " Validating Docker Compose installation..." ) ;
315+ let docker_compose_validator = DockerComposeValidator :: new (
316+ & env. config . ssh_key_path ,
317+ & env. config . ssh_username ,
318+ env. config . verbose ,
319+ ) ;
320+ docker_compose_validator
321+ . execute ( instance_ip)
322+ . await
323+ . map_err ( |e| anyhow:: anyhow!( e) ) ?;
324+
325+ println ! ( "✅ All deployment validations passed!" ) ;
326+ Ok ( ( ) )
327+ }
328+
329+ async fn run_full_deployment_test ( env : & TestEnvironment ) -> Result < String > {
287330 println ! ( "🧪 Starting full deployment E2E test with template-based workflow" ) ;
288331 println ! ( " This will test the complete 4-stage template system:" ) ;
289332 println ! ( " Stage 1: Render provision templates to build/" ) ;
@@ -312,56 +355,28 @@ async fn run_full_deployment_test(env: &TestEnvironment) -> Result<()> {
312355 println ! ( "📋 Step 1: Waiting for cloud-init completion..." ) ;
313356 env. run_ansible_playbook ( "wait-cloud-init" ) ?;
314357
315- // Validate cloud-init completion
316- let cloud_init_validator = CloudInitValidator :: new (
317- & env. config . ssh_key_path ,
318- & env. config . ssh_username ,
319- env. config . verbose ,
320- ) ;
321- cloud_init_validator
322- . execute ( & instance_ip)
323- . await
324- . map_err ( |e| anyhow:: anyhow!( e) ) ?;
325-
326358 // Run the install-docker playbook
327359 // NOTE: We skip the update-apt-cache playbook in E2E tests to avoid CI network issues
328360 // The install-docker playbook now assumes the cache is already updated or will handle stale cache gracefully
329361 println ! ( "📋 Step 2: Installing Docker..." ) ;
330362 env. run_ansible_playbook ( "install-docker" ) ?;
331363
332- // 7. Validate Docker installation
333- let docker_validator = DockerValidator :: new (
334- & env. config . ssh_key_path ,
335- & env. config . ssh_username ,
336- env. config . verbose ,
337- ) ;
338- docker_validator
339- . execute ( & instance_ip)
340- . await
341- . map_err ( |e| anyhow:: anyhow!( e) ) ?;
342-
343- // 8. Run the install-docker-compose playbook
364+ // Run the install-docker-compose playbook
344365 println ! ( "📋 Step 3: Installing Docker Compose..." ) ;
345366 env. run_ansible_playbook ( "install-docker-compose" ) ?;
346367
347- // 9. Validate Docker Compose installation
348- let docker_compose_validator = DockerComposeValidator :: new (
349- & env. config . ssh_key_path ,
350- & env. config . ssh_username ,
351- env. config . verbose ,
352- ) ;
353- docker_compose_validator
354- . execute ( & instance_ip)
355- . await
356- . map_err ( |e| anyhow:: anyhow!( e) ) ?;
368+ println ! ( "✅ Deployment stages completed successfully!" ) ;
369+ println ! ( " ✅ Infrastructure provisioned with OpenTofu" ) ;
370+ println ! ( " ✅ Configuration rendered with Ansible templates" ) ;
371+ println ! ( " ✅ Ansible playbooks executed successfully" ) ;
357372
358373 println ! ( "🎉 Full deployment E2E test completed successfully!" ) ;
359- println ! ( " ✅ Cloud-init setup completed" ) ;
360- println ! ( " ✅ Ansible playbooks executed successfully" ) ;
361374 println ! (
362375 " ℹ️ Docker/Docker Compose installation status varies based on network connectivity"
363376 ) ;
364- Ok ( ( ) )
377+
378+ // Return the instance IP for validation in main
379+ Ok ( instance_ip)
365380}
366381
367382#[ tokio:: main]
@@ -380,13 +395,25 @@ async fn main() -> Result<()> {
380395
381396 let result = run_full_deployment_test ( & env) . await ;
382397
398+ // Handle deployment results and run validation if deployment succeeded
399+ let validation_result = match result {
400+ Ok ( instance_ip) => {
401+ println ! ( ) ;
402+ validate_deployment ( & env, & instance_ip) . await
403+ }
404+ Err ( deployment_err) => {
405+ println ! ( "❌ Deployment failed: {deployment_err}" ) ;
406+ Err ( deployment_err)
407+ }
408+ } ;
409+
383410 env. cleanup ( ) ;
384411
385412 let test_duration = test_start. elapsed ( ) ;
386413 println ! ( "\n 📊 Test execution time: {test_duration:?}" ) ;
387414
388- // Handle results
389- match result {
415+ // Handle final results
416+ match validation_result {
390417 Ok ( ( ) ) => {
391418 println ! ( "✅ All tests passed and cleanup completed successfully" ) ;
392419 Ok ( ( ) )
0 commit comments