Skip to content
This repository was archived by the owner on Oct 10, 2025. It is now read-only.

Commit 37cb207

Browse files
committed
refactor: move completion messages to main execution flow
- Move final completion message from Ansible verification back to main execute() method - Ensure proper message flow and output flushing - Improve E2E test error reporting with output on failure - Switch Ansible to JSON output to prevent TAP conflicts This completes the refactoring that removed 109 lines of redundant verification code and replaces custom SSH verification with Ansible-based post-provision verification.
1 parent f10cf52 commit 37cb207

File tree

3 files changed

+21
-10
lines changed

3 files changed

+21
-10
lines changed

lib/TorrustDeploy/App/Command/Provision.pm

Lines changed: 8 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -55,6 +55,7 @@ sub execute {
5555

5656
# Get VM IP address
5757
my $vm_ip = $tofu->get_vm_ip($tofu_dir);
58+
STDOUT->flush();
5859

5960
# Create SSH connection
6061
my $ssh_connection = TorrustDeploy::Infrastructure::SSH::Connection->new(host => $vm_ip);
@@ -64,6 +65,13 @@ sub execute {
6465

6566
# Run Ansible post-provision verification
6667
$self->_run_ansible_verification($vm_ip, $work_dir);
68+
69+
# Final completion message
70+
say "";
71+
say "✅ Provisioning completed successfully!";
72+
say "VM is ready at IP: " . $vm_ip;
73+
say "You can connect using: ssh -i ~/.ssh/testing_rsa torrust@" . $vm_ip;
74+
STDOUT->flush();
6775
}
6876

6977
sub _copy_templates {
@@ -278,13 +286,6 @@ sub _run_ansible_verification {
278286

279287
# Run verification playbook
280288
$ansible->run_verification($ansible_dir);
281-
282-
# Final completion message
283-
say "";
284-
say "✅ Provisioning completed successfully!";
285-
say "VM is ready at IP: $vm_ip";
286-
say "You can connect using: ssh -i ~/.ssh/testing_rsa torrust@$vm_ip";
287-
STDOUT->flush();
288289
}
289290

290291
1;

t/e2e/provision.t

Lines changed: 12 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -127,8 +127,8 @@ subtest 'provision command executes successfully' => sub {
127127

128128
note "Provision command completed in ${duration} seconds";
129129

130-
# Show output summary in verbose mode
131-
if ($ENV{TEST_VERBOSE} || $ENV{HARNESS_IS_VERBOSE}) {
130+
# Show output summary in verbose mode or on failure
131+
if ($ENV{TEST_VERBOSE} || $ENV{HARNESS_IS_VERBOSE} || $exit_code != 0) {
132132
note "Command output (last 50 lines):";
133133
my @output_lines = split /\n/, $output;
134134
my $start_line = @output_lines > 50 ? @output_lines - 50 : 0;
@@ -140,6 +140,16 @@ subtest 'provision command executes successfully' => sub {
140140
# Command should complete successfully
141141
is($exit_code, 0, 'provision command exits with status 0');
142142

143+
# Show helpful message on failure
144+
if ($exit_code != 0) {
145+
note "Provision command failed with exit code: $exit_code";
146+
note "Check the output above for details. Common issues:";
147+
note " - SSH connectivity problems";
148+
note " - Ansible execution failures";
149+
note " - VM creation timeouts";
150+
note " - Cloud-init completion issues";
151+
}
152+
143153
# Basic checks - we can't easily check output without complexity
144154
pass('provision command executed (use prove -v to see output)');
145155
pass('provision completed within timeout');

templates/ansible/ansible.cfg

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@ remote_user = torrust
55
private_key_file = ~/.ssh/testing_rsa
66
host_key_checking = False
77
retry_files_enabled = False
8-
stdout_callback = yaml
8+
stdout_callback = json
99
gathering = smart
1010
fact_caching = memory
1111

0 commit comments

Comments
 (0)