Skip to content

Commit 455bc9c

Browse files
committed
docs: update run_configure_command module comments
- Remove outdated notes about container inventory limitations - Add E2E Config Tests Integration section explaining provision simulation - Update function documentation to reflect simplified role after removing run_ansible_configuration - Clarify that provision simulation ensures correct Ansible config generation
1 parent 4995ff0 commit 455bc9c

File tree

1 file changed

+12
-108
lines changed

1 file changed

+12
-108
lines changed

src/e2e/tasks/run_configure_command.rs

Lines changed: 12 additions & 108 deletions
Original file line numberDiff line numberDiff line change
@@ -17,130 +17,34 @@
1717
//! - Works with both container and VM-based infrastructure
1818
//! - Integrates with the existing `ConfigureCommand` workflow
1919
//!
20-
//! ## Notes
20+
//! ## E2E Config Tests Integration
2121
//!
22-
//! Currently, this task has limitations when used with containers due to
23-
//! inventory addressing differences. Container-specific inventory templates
24-
//! may be needed for full container support.
22+
//! In E2E config tests, this module works seamlessly with provision simulation.
23+
//! The provision simulation ensures that Ansible config files are generated with
24+
//! the correct configuration even without executing the actual provision phase,
25+
//! allowing the configuration command to run successfully on simulated infrastructure.
2526
26-
use std::net::SocketAddr;
2727
use std::sync::Arc;
2828

2929
use anyhow::{Context, Result};
30-
use tracing::{info, warn};
30+
use tracing::info;
3131

3232
use crate::application::commands::ConfigureCommand;
33-
use crate::container::Services;
34-
use crate::e2e::environment::TestEnvironment;
3533

36-
/// Run Ansible configuration on a target instance
37-
///
38-
/// This function executes Ansible playbooks to configure services and applications
39-
/// on the target instance. It uses the existing `ConfigureCommand` workflow and
40-
/// handles both successful configurations and expected failures.
41-
///
42-
/// # Arguments
43-
///
44-
/// * `socket_addr` - Socket address where the target instance can be reached
45-
/// * `test_env` - Test environment containing configuration and services
46-
/// * `expect_success` - Whether to expect configuration to succeed (for testing purposes)
47-
///
48-
/// # Returns
49-
///
50-
/// Returns `Ok(())` when:
51-
/// - Configuration succeeds (if `expect_success` is true)
52-
/// - Expected failure occurs (if `expect_success` is false)
53-
///
54-
/// # Errors
55-
///
56-
/// Returns an error if:
57-
/// - Configuration fails unexpectedly (when `expect_success` is true)
58-
/// - Services cannot be initialized
59-
/// - `ConfigureCommand` execution encounters unexpected errors
60-
///
61-
/// # Example
62-
///
63-
/// ```rust,no_run
64-
/// use torrust_tracker_deploy::e2e::tasks::run_configure_command::run_ansible_configuration;
65-
/// use torrust_tracker_deploy::e2e::environment::TestEnvironment;
66-
/// use torrust_tracker_deploy::config::InstanceName;
67-
/// use std::net::{IpAddr, Ipv4Addr, SocketAddr};
68-
///
69-
/// fn main() -> anyhow::Result<()> {
70-
/// let socket_addr = SocketAddr::new(IpAddr::V4(Ipv4Addr::new(127, 0, 0, 1)), 2222);
71-
/// let instance_name = InstanceName::new("test-instance".to_string())?;
72-
/// let test_env = TestEnvironment::new(false, "./templates".to_string(), instance_name)?;
73-
///
74-
/// run_ansible_configuration(socket_addr, &test_env, true)?;
75-
/// println!("Ansible configuration completed successfully");
76-
/// Ok(())
77-
/// }
78-
/// ```
79-
pub fn run_ansible_configuration(
80-
socket_addr: SocketAddr,
81-
test_env: &TestEnvironment,
82-
expect_success: bool,
83-
) -> Result<()> {
84-
info!(
85-
socket_addr = %socket_addr,
86-
expect_success = expect_success,
87-
"Running Ansible configuration on instance"
88-
);
89-
90-
// Initialize services from test environment configuration
91-
let services = Services::new(&test_env.config);
92-
let configure_command = ConfigureCommand::new(Arc::clone(&services.ansible_client));
93-
94-
// Execute configuration command
95-
match configure_command.execute().map_err(anyhow::Error::from) {
96-
Ok(()) => {
97-
if expect_success {
98-
info!(
99-
socket_addr = %socket_addr,
100-
status = "success",
101-
"Configuration completed successfully"
102-
);
103-
} else {
104-
warn!(
105-
socket_addr = %socket_addr,
106-
status = "unexpected_success",
107-
"Configuration succeeded when failure was expected"
108-
);
109-
}
110-
}
111-
Err(e) => {
112-
if expect_success {
113-
return Err(e.context("Ansible configuration failed unexpectedly"));
114-
}
115-
info!(
116-
socket_addr = %socket_addr,
117-
status = "expected_failure",
118-
error = %e,
119-
"Configuration failed as expected"
120-
);
121-
}
122-
}
123-
124-
info!(
125-
socket_addr = %socket_addr,
126-
status = "complete",
127-
"Ansible configuration workflow completed"
128-
);
129-
130-
Ok(())
131-
}
34+
use crate::e2e::environment::TestEnvironment;
13235

133-
/// Configure infrastructure using Ansible playbooks (compatibility wrapper)
36+
/// Configure infrastructure using Ansible playbooks
13437
///
135-
/// This is a simplified wrapper around the `ConfigureCommand` for use in full E2E tests.
136-
/// For more advanced configuration with success/failure handling, use `run_ansible_configuration`.
38+
/// This function executes Ansible configuration using the `ConfigureCommand` for E2E tests.
39+
/// It works with both VM and container-based infrastructure, utilizing rendered Ansible
40+
/// inventories and configuration files generated during the provision simulation phase.
13741
///
13842
/// # Errors
13943
///
14044
/// Returns an error if:
14145
/// - `ConfigureCommand` execution fails
14246
/// - Infrastructure configuration fails
143-
pub fn configure_infrastructure(env: &TestEnvironment) -> Result<()> {
47+
pub fn run_configure_command(env: &TestEnvironment) -> Result<()> {
14448
info!("Configuring test infrastructure");
14549

14650
// Use the new ConfigureCommand to handle all infrastructure configuration steps

0 commit comments

Comments
 (0)