Skip to content

Commit 0d796a6

Browse files
committed
feat: enable cloud-init validation for both VM and container environments
- Refactor CloudInitValidator.execute() to detect cloud-init installation - Only check cloud-init status when cloud-init is actually installed - Always check completion marker file for both VM and container environments - Uncomment cloud-init validation step in TestCommand.execute() - Remove TODO comments as the issue is now resolved This allows the cloud-init validation to work seamlessly across: - VM environments: Checks cloud-init status + completion marker - Container environments: Only checks completion marker (cloud-init not installed)
1 parent f97b0ad commit 0d796a6

File tree

2 files changed

+47
-30
lines changed

2 files changed

+47
-30
lines changed

src/application/commands/test.rs

Lines changed: 4 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -16,8 +16,7 @@ use std::net::IpAddr;
1616
use tracing::{info, instrument};
1717

1818
use crate::application::steps::{
19-
// ValidateCloudInitCompletionStep, // Disabled for container testing - see execute() method
20-
ValidateDockerComposeInstallationStep,
19+
ValidateCloudInitCompletionStep, ValidateDockerComposeInstallationStep,
2120
ValidateDockerInstallationStep,
2221
};
2322
use crate::infrastructure::remote_actions::RemoteActionError;
@@ -76,16 +75,9 @@ impl TestCommand {
7675
let ssh_connection =
7776
SshConnection::with_default_port(self.ssh_credentials.clone(), self.instance_ip);
7877

79-
// TODO: Cloud-init validation disabled for container testing
80-
// This step fails when testing with Docker containers since they don't have cloud-init installed.
81-
// In the future, we can:
82-
// - Add a flag to enable this only when the provisioned instance supports it
83-
// - Check for the cloud-init completion file (which is simulated in the Docker container)
84-
// instead of calling the cloud-init service directly
85-
//
86-
// ValidateCloudInitCompletionStep::new(ssh_connection.clone())
87-
// .execute()
88-
// .await?;
78+
ValidateCloudInitCompletionStep::new(ssh_connection.clone())
79+
.execute()
80+
.await?;
8981

9082
ValidateDockerInstallationStep::new(ssh_connection.clone())
9183
.execute()

src/infrastructure/remote_actions/cloud_init.rs

Lines changed: 43 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -61,23 +61,52 @@ impl RemoteAction for CloudInitValidator {
6161
"Validating cloud-init completion"
6262
);
6363

64-
// Check cloud-init status
65-
let status_output = self
64+
// Check if cloud-init is installed
65+
let cloud_init_installed = self
6666
.ssh_client
67-
.execute("cloud-init status")
67+
.check_command("command -v cloud-init")
6868
.map_err(|source| RemoteActionError::SshCommandFailed {
6969
action_name: self.name().to_string(),
7070
source,
7171
})?;
7272

73-
if !status_output.contains("status: done") {
74-
return Err(RemoteActionError::ValidationFailed {
75-
action_name: self.name().to_string(),
76-
message: format!("Cloud-init status is not 'done': {status_output}"),
77-
});
73+
if cloud_init_installed {
74+
info!(
75+
action = "cloud_init_validation",
76+
check = "installation",
77+
"Cloud-init is installed, checking status"
78+
);
79+
80+
// Check cloud-init status only if cloud-init is installed
81+
let status_output = self
82+
.ssh_client
83+
.execute("cloud-init status")
84+
.map_err(|source| RemoteActionError::SshCommandFailed {
85+
action_name: self.name().to_string(),
86+
source,
87+
})?;
88+
89+
if !status_output.contains("status: done") {
90+
return Err(RemoteActionError::ValidationFailed {
91+
action_name: self.name().to_string(),
92+
message: format!("Cloud-init status is not 'done': {status_output}"),
93+
});
94+
}
95+
96+
info!(
97+
action = "cloud_init_validation",
98+
check = "status_done",
99+
"Cloud-init status is 'done'"
100+
);
101+
} else {
102+
info!(
103+
action = "cloud_init_validation",
104+
check = "installation",
105+
"Cloud-init is not installed, skipping status check (container environment)"
106+
);
78107
}
79108

80-
// Check for completion marker file
109+
// Check for completion marker file (applies to both VM and container environments)
81110
let marker_exists = self
82111
.ssh_client
83112
.check_command("test -f /var/lib/cloud/instance/boot-finished")
@@ -95,18 +124,14 @@ impl RemoteAction for CloudInitValidator {
95124

96125
info!(
97126
action = "cloud_init_validation",
98-
status = "success",
99-
"Cloud-init validation passed"
100-
);
101-
info!(
102-
action = "cloud_init_validation",
103-
check = "status_done",
104-
"Cloud-init status is 'done'"
127+
check = "completion_marker",
128+
"Completion marker file exists"
105129
);
130+
106131
info!(
107132
action = "cloud_init_validation",
108-
check = "completion_marker",
109-
"Completion marker file exists"
133+
status = "success",
134+
"Cloud-init validation passed"
110135
);
111136

112137
Ok(())

0 commit comments

Comments
 (0)