-
Notifications
You must be signed in to change notification settings - Fork 2
Expand file tree
/
Copy pathcloud_init.rs
More file actions
97 lines (83 loc) · 3.2 KB
/
Copy pathcloud_init.rs
File metadata and controls
97 lines (83 loc) · 3.2 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
90
91
92
93
94
95
96
97
//! Cloud-init completion validation step
//!
//! This module provides the `ValidateCloudInitCompletionStep` which validates
//! that cloud-init has completed successfully on remote instances. This step
//! ensures instances are fully initialized before proceeding with deployment.
//!
//! ## Key Features
//!
//! - Cloud-init completion status verification via remote validation
//! - System initialization readiness checking
//! - Integration with SSH-based remote actions
//! - Comprehensive error handling for initialization failures
//!
//! ## Validation Process
//!
//! The step uses the `CloudInitValidator` remote action to check cloud-init
//! status and ensure all system initialization tasks have completed successfully,
//! providing confidence that the instance is ready for configuration and
//! software installation.
use tracing::{info, instrument};
use crate::adapters::ssh::SshConfig;
use crate::infrastructure::remote_actions::{CloudInitValidator, RemoteAction, RemoteActionError};
/// Step that validates cloud-init completion on a remote host
pub struct ValidateCloudInitCompletionStep {
ssh_config: SshConfig,
}
impl ValidateCloudInitCompletionStep {
#[must_use]
pub fn new(ssh_config: SshConfig) -> Self {
Self { ssh_config }
}
/// Execute the cloud-init completion validation step
///
/// This will validate that cloud-init has finished running on the remote host
/// by checking cloud-init status and ensuring all initialization is complete.
///
/// # Errors
///
/// Returns an error if:
/// * SSH connection to the remote host fails
/// * Cloud-init validation fails
/// * The remote action execution fails for any other reason
///
/// # Notes
///
/// - This validation ensures that all cloud-init modules have completed
/// - Critical for ensuring the system is ready for further configuration
/// - Checks both cloud-init status and completion markers
#[instrument(
name = "validate_cloud_init",
skip_all,
fields(step_type = "validation", component = "cloud_init")
)]
pub async fn execute(&self) -> Result<(), RemoteActionError> {
info!(component = "cloud_init", "Validating cloud-init completion");
let cloud_init_validator = CloudInitValidator::new(self.ssh_config.clone());
cloud_init_validator
.execute(&self.ssh_config.host_ip())
.await?;
Ok(())
}
}
#[cfg(test)]
mod tests {
use std::net::{IpAddr, Ipv4Addr};
use std::path::PathBuf;
use crate::adapters::ssh::SshCredentials;
use crate::shared::Username;
use super::*;
#[test]
fn it_should_create_validate_cloud_init_completion_step() {
let ssh_credentials = SshCredentials::new(
PathBuf::from("test_key"),
PathBuf::from("test_key.pub"),
Username::new("test_user").unwrap(),
);
let host_ip = IpAddr::V4(Ipv4Addr::new(192, 168, 1, 1));
let ssh_config = SshConfig::with_default_port(ssh_credentials, host_ip);
let step = ValidateCloudInitCompletionStep::new(ssh_config);
// Test that the step can be created successfully
assert_eq!(step.ssh_config.host_ip(), host_ip);
}
}