Skip to content

Commit 26c3f6a

Browse files
committed
refactor: reorganize E2E tasks module by deployment target
- Create container/ and virtual_machine/ submodules for better architecture separation - Move provision_docker_infrastructure to container/provision_docker_infrastructure - Move provision_infrastructure and cleanup_infrastructure to virtual_machine/ - Extract preflight_cleanup into modular structure: - Common directory cleanup functions in preflight_cleanup_common - Container-specific preflight cleanup in container/preflight_cleanup - VM-specific preflight cleanup in virtual_machine/preflight_cleanup - Maintain backward compatibility through re-exports in preflight_cleanup - Update all imports across E2E test binaries to use new module structure
1 parent b59bb34 commit 26c3f6a

13 files changed

+489
-422
lines changed

src/bin/e2e_config_tests.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -63,8 +63,8 @@ use torrust_tracker_deploy::e2e::containers::{
6363
RunningProvisionedContainer, StoppedProvisionedContainer,
6464
};
6565
use torrust_tracker_deploy::e2e::environment::TestEnvironment;
66+
use torrust_tracker_deploy::e2e::tasks::container::provision_docker_infrastructure::provision_docker_infrastructure;
6667
use torrust_tracker_deploy::e2e::tasks::preflight_cleanup;
67-
use torrust_tracker_deploy::e2e::tasks::provision_docker_infrastructure::provision_docker_infrastructure;
6868
use torrust_tracker_deploy::logging::{self, LogFormat};
6969

7070
#[derive(Parser)]

src/bin/e2e_provision_tests.rs

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -25,8 +25,11 @@ use tracing::{error, info};
2525
use torrust_tracker_deploy::config::InstanceName;
2626
use torrust_tracker_deploy::e2e::environment::TestEnvironment;
2727
use torrust_tracker_deploy::e2e::tasks::{
28-
cleanup_infrastructure::cleanup_infrastructure, preflight_cleanup::cleanup_lingering_resources,
29-
provision_infrastructure::provision_infrastructure,
28+
preflight_cleanup::cleanup_lingering_resources,
29+
virtual_machine::{
30+
cleanup_infrastructure::cleanup_infrastructure,
31+
provision_infrastructure::provision_infrastructure,
32+
},
3033
};
3134
use torrust_tracker_deploy::logging::{self, LogFormat};
3235

src/bin/e2e_tests_full.rs

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -30,10 +30,13 @@ use tracing::{error, info};
3030
use torrust_tracker_deploy::config::InstanceName;
3131
use torrust_tracker_deploy::e2e::environment::TestEnvironment;
3232
use torrust_tracker_deploy::e2e::tasks::{
33-
cleanup_infrastructure::cleanup_infrastructure,
3433
configure_infrastructure::configure_infrastructure,
3534
preflight_cleanup::cleanup_lingering_resources,
36-
provision_infrastructure::provision_infrastructure, validate_deployment::validate_deployment,
35+
validate_deployment::validate_deployment,
36+
virtual_machine::{
37+
cleanup_infrastructure::cleanup_infrastructure,
38+
provision_infrastructure::provision_infrastructure,
39+
},
3740
};
3841
use torrust_tracker_deploy::logging::{self, LogFormat};
3942

src/e2e/tasks/container/mod.rs

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
//! Container-specific E2E tasks
2+
//!
3+
//! This module contains tasks that are specifically designed for container-based
4+
//! E2E testing using Docker containers instead of VMs. These tasks handle the
5+
//! unique requirements and workflows when using testcontainers for testing
6+
//! infrastructure deployment.
7+
8+
pub mod preflight_cleanup;
9+
pub mod provision_docker_infrastructure;
Lines changed: 56 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,56 @@
1+
//! Container-specific preflight cleanup functionality
2+
//!
3+
//! This module provides preflight cleanup functionality specifically designed
4+
//! for Docker container-based E2E testing. Since containers are managed by
5+
//! testcontainers and automatically cleaned up, this module only handles
6+
//! directory cleanup operations.
7+
8+
use crate::e2e::environment::TestEnvironment;
9+
use crate::e2e::tasks::preflight_cleanup::PreflightCleanupError;
10+
use crate::e2e::tasks::preflight_cleanup_common::{
11+
cleanup_build_directory, cleanup_templates_directory,
12+
};
13+
use tracing::info;
14+
15+
/// Performs pre-flight cleanup for Docker-based E2E tests
16+
///
17+
/// This function is specifically designed for Docker-based E2E tests that use
18+
/// testcontainers for container lifecycle management. It only cleans directories
19+
/// since Docker containers are automatically cleaned up when testcontainer objects
20+
/// are dropped.
21+
///
22+
/// # Arguments
23+
///
24+
/// * `env` - The test environment containing configuration and services
25+
///
26+
/// # Returns
27+
///
28+
/// Returns `Ok(())` if cleanup succeeds or if there were no resources to clean up.
29+
///
30+
/// # Errors
31+
///
32+
/// Returns an error if directory cleanup fails and would prevent new test runs.
33+
pub fn cleanup_lingering_resources_docker(
34+
env: &TestEnvironment,
35+
) -> Result<(), PreflightCleanupError> {
36+
info!(
37+
operation = "preflight_cleanup_docker",
38+
"Starting pre-flight cleanup for Docker-based E2E tests"
39+
);
40+
41+
// Clean the build directory to ensure fresh template state for E2E tests
42+
cleanup_build_directory(env)?;
43+
44+
// Clean the templates directory to ensure fresh embedded template extraction for E2E tests
45+
cleanup_templates_directory(env)?;
46+
47+
// Note: Docker containers are automatically cleaned up by testcontainers when objects are dropped
48+
// No need for explicit container cleanup like with LXD/OpenTofu
49+
50+
info!(
51+
operation = "preflight_cleanup_docker",
52+
status = "success",
53+
"Pre-flight cleanup for Docker-based E2E tests completed successfully"
54+
);
55+
Ok(())
56+
}
File renamed without changes.

src/e2e/tasks/mod.rs

Lines changed: 22 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -4,25 +4,37 @@
44
//! workflow. Each task represents a significant phase in the deployment testing process
55
//! and can be executed independently or as part of a complete test sequence.
66
//!
7-
//! ## Available Tasks
7+
//! ## Module Organization
88
//!
9+
//! The tasks are organized by deployment target:
10+
//!
11+
//! ### Infrastructure-agnostic tasks (can be used with both containers and VMs):
912
//! - `clean_and_prepare_templates` - Template cleanup and preparation
10-
//! - `cleanup_infrastructure` - Infrastructure resource cleanup
11-
//! - `configure_infrastructure` - Infrastructure configuration via Ansible
12-
//! - `preflight_cleanup` - Pre-test cleanup of lingering resources
13-
//! - `provision_infrastructure` - Infrastructure provisioning via `OpenTofu`
14-
//! - `provision_docker_infrastructure` - Docker container provisioning simulation
13+
//! - `configure_infrastructure` - Infrastructure configuration via Ansible
1514
//! - `setup_ssh_key` - SSH key generation and setup
1615
//! - `validate_deployment` - Deployment validation and testing
1716
//!
18-
//! These tasks are orchestrated by the E2E test binary to provide comprehensive
17+
//! ### Container-specific tasks (`container` submodule):
18+
//! - `provision_docker_infrastructure` - Docker container provisioning simulation
19+
//! - `preflight_cleanup` - Container-specific preflight cleanup
20+
//!
21+
//! ### Virtual machine-specific tasks (`virtual_machine` submodule):
22+
//! - `provision_infrastructure` - Infrastructure provisioning via `OpenTofu`
23+
//! - `cleanup_infrastructure` - Infrastructure resource cleanup
24+
//! - `preflight_cleanup` - VM-specific preflight cleanup (`OpenTofu` + LXD)
25+
//!
26+
//! ### Common functionality:
27+
//! - `preflight_cleanup_common` - Shared directory cleanup functions
28+
//! - `preflight_cleanup` - Legacy module with common error types and functions
29+
//!
30+
//! These tasks are orchestrated by the E2E test binaries to provide comprehensive
1931
//! testing coverage of the entire deployment system.
2032
2133
pub mod clean_and_prepare_templates;
22-
pub mod cleanup_infrastructure;
2334
pub mod configure_infrastructure;
35+
pub mod container;
2436
pub mod preflight_cleanup;
25-
pub mod provision_docker_infrastructure;
26-
pub mod provision_infrastructure;
37+
pub mod preflight_cleanup_common;
2738
pub mod setup_ssh_key;
2839
pub mod validate_deployment;
40+
pub mod virtual_machine;

0 commit comments

Comments
 (0)