-
Notifications
You must be signed in to change notification settings - Fork 2
Expand file tree
/
Copy pathwait_cloud_init.rs
More file actions
89 lines (77 loc) · 2.62 KB
/
Copy pathwait_cloud_init.rs
File metadata and controls
89 lines (77 loc) · 2.62 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
//! Cloud-init completion waiting step
//!
//! This module provides the `WaitForCloudInitStep` which ensures that cloud-init
//! has completed on remote instances before proceeding with further configuration.
//! This is crucial for ensuring instances are fully initialized before deployment.
//!
//! ## Key Features
//!
//! - Waits for cloud-init completion via Ansible playbook execution
//! - Provides timeout handling for cloud-init processes
//! - Integration with the deployment step system
//! - Comprehensive error handling and logging
//!
//! ## Usage Context
//!
//! This step is typically used early in the deployment workflow after
//! infrastructure provisioning to ensure instances are ready for configuration.
use std::sync::Arc;
use tracing::{info, instrument};
use crate::adapters::ansible::AnsibleClient;
use crate::shared::command::CommandError;
/// Step that waits for cloud-init completion on a remote host
pub struct WaitForCloudInitStep {
ansible_client: Arc<AnsibleClient>,
}
impl WaitForCloudInitStep {
#[must_use]
pub fn new(ansible_client: Arc<AnsibleClient>) -> Self {
Self { ansible_client }
}
/// Execute the cloud-init wait step
///
/// This will run the "wait-cloud-init" Ansible playbook to ensure
/// cloud-init has completed on the remote host before proceeding.
///
/// # Errors
///
/// Returns an error if:
/// * The Ansible client fails to execute the playbook
/// * Cloud-init has not completed within the timeout period
/// * The playbook execution fails for any other reason
#[instrument(
name = "wait_cloud_init",
skip_all,
fields(step_type = "system", component = "cloud_init")
)]
pub fn execute(&self) -> Result<(), CommandError> {
info!(
step = "wait_cloud_init",
action = "wait_cloud_init",
"Waiting for cloud-init completion"
);
self.ansible_client.run_playbook("wait-cloud-init", &[])?;
info!(
step = "wait_cloud_init",
status = "success",
"Cloud-init completion confirmed"
);
Ok(())
}
}
#[cfg(test)]
mod tests {
use std::path::PathBuf;
use std::sync::Arc;
use super::*;
#[test]
fn it_should_create_wait_for_cloud_init_step() {
let ansible_client = Arc::new(AnsibleClient::new(PathBuf::from("test_inventory.yml")));
let step = WaitForCloudInitStep::new(ansible_client);
// Test that the step can be created successfully
assert_eq!(
std::mem::size_of_val(&step),
std::mem::size_of::<Arc<AnsibleClient>>()
);
}
}