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

Commit 374d763

Browse files
committed
feat: [#10] enhance development workflow and SSH debugging
- Add auto-approve flags to Makefile commands (apply, apply-minimal, destroy) - Add new VM management commands: 'make vm-ip' and 'make vm-info' - Update integration testing guide with manual volume cleanup section (1.4.1) - Enhance minimal cloud-init configuration with SSH debugging features: - Add password authentication support - Add explicit SSH daemon configuration - Add cloud-init completion tracking files - Add SSH service restart commands - Improve test script error message for libvirtd service This improves the development experience by eliminating manual confirmation prompts and providing better debugging tools for SSH connectivity issues.
1 parent b9e6606 commit 374d763

File tree

4 files changed

+80
-5
lines changed

4 files changed

+80
-5
lines changed

Makefile

Lines changed: 25 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -51,7 +51,7 @@ apply-minimal: ## Deploy VM with minimal cloud-init configuration
5151
@echo "Ensuring libvirt permissions are correct..."
5252
@$(MAKE) fix-libvirt
5353
@echo "Deploying VM with minimal configuration..."
54-
cd $(TERRAFORM_DIR) && tofu apply -var-file="local.tfvars" -var="use_minimal_config=true" -parallelism=1
54+
cd $(TERRAFORM_DIR) && tofu apply -var-file="local.tfvars" -var="use_minimal_config=true" -parallelism=1 -auto-approve
5555
@echo "Fixing permissions after deployment..."
5656
@$(MAKE) fix-libvirt
5757

@@ -61,7 +61,7 @@ apply: ## Deploy the VM
6161
@echo "Deploying VM..."
6262
@if [ -f $(TERRAFORM_DIR)/local.tfvars ]; then \
6363
echo "Using local SSH key configuration..."; \
64-
cd $(TERRAFORM_DIR) && tofu apply -var-file="local.tfvars" -parallelism=1; \
64+
cd $(TERRAFORM_DIR) && tofu apply -var-file="local.tfvars" -parallelism=1 -auto-approve; \
6565
else \
6666
echo "WARNING: No local.tfvars found. Creating with placeholder..."; \
6767
echo 'ssh_public_key = "REPLACE_WITH_YOUR_SSH_PUBLIC_KEY"' > $(TERRAFORM_DIR)/local.tfvars; \
@@ -73,7 +73,7 @@ apply: ## Deploy the VM
7373

7474
destroy: ## Destroy the VM
7575
@echo "Destroying VM..."
76-
cd $(TERRAFORM_DIR) && tofu destroy
76+
cd $(TERRAFORM_DIR) && tofu destroy -auto-approve
7777

7878
status: ## Show current infrastructure status
7979
@echo "Infrastructure status:"
@@ -284,3 +284,25 @@ ci-test-syntax: ## Test syntax for CI (with dummy values)
284284
else \
285285
echo "yamllint not available, skipping additional YAML validation"; \
286286
fi
287+
288+
vm-ip: ## Show VM IP address
289+
@echo "Getting VM IP address..."
290+
@VM_IP=$$(virsh domifaddr $(VM_NAME) | grep ipv4 | awk '{print $$4}' | cut -d'/' -f1); \
291+
if [ -n "$$VM_IP" ]; then \
292+
echo "VM IP: $$VM_IP"; \
293+
else \
294+
echo "VM IP not assigned yet or VM not running"; \
295+
echo "VM status:"; \
296+
virsh list --all | grep $(VM_NAME) || echo "VM not found"; \
297+
fi
298+
299+
vm-info: ## Show detailed VM network information
300+
@echo "VM Network Information:"
301+
@echo "======================"
302+
@virsh list --all | grep $(VM_NAME) | head -1 || echo "VM not found"
303+
@echo ""
304+
@echo "Network interfaces:"
305+
@virsh domifaddr $(VM_NAME) 2>/dev/null || echo "No network information available"
306+
@echo ""
307+
@echo "DHCP leases:"
308+
@virsh net-dhcp-leases default 2>/dev/null | grep $(VM_NAME) || echo "No DHCP lease found"

docs/guides/integration-testing-guide.md

Lines changed: 25 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -35,8 +35,10 @@ make test-prereq
3535

3636
### 1.1 Navigate to Project Directory
3737

38+
For example:
39+
3840
```bash
39-
cd /home/josecelano/Documents/git/committer/me/github/torrust/torrust-tracker-demo
41+
cd /home/yourname/Documents/git/committer/me/github/torrust/torrust-tracker-demo
4042
```
4143

4244
**⚠️ Important**: All commands in this guide assume you are running from the
@@ -104,6 +106,28 @@ ls infrastructure/terraform/terraform.tfstate* 2>/dev/null && \
104106

105107
**Expected Output**: All checks should show "✅" (no conflicts).
106108

109+
110+
### 1.4.1 Manual Cleanup (if needed)
111+
112+
If the verification step shows "❌ Volumes still exist!" then manually clean them:
113+
114+
```bash
115+
# List conflicting volumes
116+
virsh vol-list user-default 2>/dev/null | grep torrust-tracker-demo
117+
118+
# Delete each volume manually
119+
virsh vol-delete torrust-tracker-demo-cloudinit.iso user-default
120+
virsh vol-delete torrust-tracker-demo.qcow2 user-default
121+
122+
# Verify cleanup
123+
virsh vol-list user-default 2>/dev/null | grep torrust-tracker-demo && \
124+
echo "❌ Volumes still exist!" || echo "✅ No volume conflicts"
125+
```
126+
127+
**Expected Output**: Should show "✅ No volume conflicts" after manual cleanup.
128+
129+
**What This Fixes**: Removes leftover volumes that `make clean-and-fix` sometimes misses.
130+
107131
### 1.5 Set Up SSH Key Configuration
108132

109133
⚠️ **CRITICAL STEP**: This step was **missing** from our initial testing and

infrastructure/cloud-init/user-data-minimal.yaml.tpl

Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -15,13 +15,42 @@ users:
1515
ssh_authorized_keys:
1616
- ${ssh_public_key}
1717

18+
# Set password using chpasswd (most reliable method)
19+
chpasswd:
20+
list: |
21+
torrust:torrust123
22+
expire: false
23+
24+
# Enable SSH password authentication for debugging
25+
ssh_pwauth: true
26+
27+
# Write SSH configuration to explicitly enable password auth
28+
write_files:
29+
- path: /etc/ssh/sshd_config.d/99-cloud-init-debug.conf
30+
content: |
31+
PasswordAuthentication yes
32+
PubkeyAuthentication yes
33+
AuthenticationMethods publickey password
34+
permissions: '0644'
35+
owner: root:root
36+
- path: /tmp/cloud-init-completed
37+
content: |
38+
Cloud-init configuration applied successfully
39+
Timestamp: $(date)
40+
permissions: '0644'
41+
1842
# Package updates (minimal)
1943
package_update: true
2044

2145
packages:
2246
- curl
2347
- vim
2448

49+
# Commands to run after package installation
50+
runcmd:
51+
- systemctl restart ssh
52+
- echo "SSH service restarted at $(date)" >> /tmp/cloud-init-completed
53+
2554
# Minimal final message
2655
final_message: |
2756
Minimal VM setup completed!

infrastructure/tests/test-local-setup.sh

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -54,7 +54,7 @@ test_prerequisites() {
5454
if systemctl is-active --quiet libvirtd; then
5555
log_success "libvirtd service is running"
5656
else
57-
log_error "libvirtd service is not running"
57+
log_error "libvirtd service is not running. Run: sudo systemctl start libvirtd"
5858
return 1
5959
fi
6060

0 commit comments

Comments
 (0)