| 47 |
rodolico |
1 |
# havirt Test Suite
|
|
|
2 |
|
|
|
3 |
This directory (tests/) contains comprehensive test scripts for exercising the havirt system.
|
|
|
4 |
|
|
|
5 |
All test scripts are located in the `tests/` directory and are designed to run from there.
|
|
|
6 |
|
|
|
7 |
## Test Scripts
|
|
|
8 |
|
|
|
9 |
### 1. test_havirt_safe.sh (Bash Safe Tests - Recommended)
|
|
|
10 |
|
|
|
11 |
A safe bash script that tests havirt in read-only mode without requiring SSH connections.
|
|
|
12 |
|
|
|
13 |
**Usage:**
|
|
|
14 |
```bash
|
|
|
15 |
./test_havirt_safe.sh [--verbose|-v]
|
|
|
16 |
```
|
|
|
17 |
|
|
|
18 |
**Features:**
|
|
|
19 |
- Tests all read-only havirt commands
|
|
|
20 |
- No SSH connections required
|
|
|
21 |
- Safe to run in any environment
|
|
|
22 |
- Tests command syntax and help functions
|
|
|
23 |
- Validates configuration files and modules
|
|
|
24 |
- Colored output with pass/fail indicators
|
|
|
25 |
|
|
|
26 |
**Example:**
|
|
|
27 |
```bash
|
|
|
28 |
# Run safe tests
|
|
|
29 |
./test_havirt_safe.sh
|
|
|
30 |
|
|
|
31 |
# Run with verbose output
|
|
|
32 |
./test_havirt_safe.sh --verbose
|
|
|
33 |
```
|
|
|
34 |
|
|
|
35 |
### 2. test_havirt.sh (Bash Full Tests - Requires Live Environment)
|
|
|
36 |
|
|
|
37 |
A comprehensive bash script that tests havirt commands including operations that require SSH connections.
|
|
|
38 |
|
|
|
39 |
**Usage:**
|
|
|
40 |
```bash
|
|
|
41 |
./test_havirt.sh [--verbose|-v]
|
|
|
42 |
```
|
|
|
43 |
|
|
|
44 |
**Features:**
|
|
|
45 |
- Tests all major havirt commands (domain, node, cluster)
|
|
|
46 |
- Runs in dry-run mode by default (safe to run)
|
|
|
47 |
- Tests command shortcuts (start, shutdown, migrate, destroy)
|
|
|
48 |
- Tests various flag combinations
|
|
|
49 |
- Validates configuration files and directory structure
|
|
|
50 |
- Error handling tests
|
|
|
51 |
- Colored output with pass/fail indicators
|
|
|
52 |
|
|
|
53 |
**Test Sections:**
|
|
|
54 |
1. Basic Commands (version, help)
|
|
|
55 |
2. Domain Module (list, update, start, shutdown)
|
|
|
56 |
3. Node Module (list, update, scan)
|
|
|
57 |
4. Cluster Module (status, balance, iscsi)
|
|
|
58 |
5. Flag Combinations (verbose, debug, quiet, testing)
|
|
|
59 |
6. Configuration (config files, directories)
|
|
|
60 |
7. Error Handling (invalid commands)
|
|
|
61 |
|
|
|
62 |
**Example:**
|
|
|
63 |
```bash
|
|
|
64 |
# Run all tests with minimal output
|
|
|
65 |
./test_havirt.sh
|
|
|
66 |
|
|
|
67 |
# Run with verbose output
|
|
|
68 |
./test_havirt.sh --verbose
|
|
|
69 |
```
|
|
|
70 |
|
|
|
71 |
**WARNING:** This script performs actual operations including SSH connections to configured nodes. Use with caution in production environments.
|
|
|
72 |
|
|
|
73 |
### 3. test_integration.pl (Perl Integration Tests)
|
|
|
74 |
|
|
|
75 |
A Perl script that tests havirt modules and functions directly at the code level.
|
|
|
76 |
|
|
|
77 |
**Usage:**
|
|
|
78 |
```bash
|
|
|
79 |
./test_integration.pl [--verbose|-v] [--dryrun|-n]
|
|
|
80 |
```
|
|
|
81 |
|
|
|
82 |
**Features:**
|
|
|
83 |
- Tests havirt.pm core functions directly
|
|
|
84 |
- Tests domain.pm, node.pm, and cluster.pm modules
|
|
|
85 |
- Validates data structures in status database
|
|
|
86 |
- Tests utility functions (MAC generation, VNC port finding)
|
|
|
87 |
- Checks for data integrity issues (orphaned domains)
|
|
|
88 |
- Runs in dry-run mode by default for safety
|
|
|
89 |
- Colored output with detailed results
|
|
|
90 |
|
|
|
91 |
**Test Sections:**
|
|
|
92 |
1. Configuration Tests
|
|
|
93 |
2. havirt.pm Core Functions
|
|
|
94 |
3. node.pm Module Tests
|
|
|
95 |
4. domain.pm Module Tests
|
|
|
96 |
5. cluster.pm Module Tests
|
|
|
97 |
6. Data Structure Validation
|
|
|
98 |
|
|
|
99 |
**Example:**
|
|
|
100 |
```bash
|
|
|
101 |
# Run integration tests in dry-run mode
|
|
|
102 |
./test_integration.pl
|
|
|
103 |
|
|
|
104 |
# Run with verbose output
|
|
|
105 |
./test_integration.pl -v
|
|
|
106 |
|
|
|
107 |
# Run with extra verbose output
|
|
|
108 |
./test_integration.pl -vv
|
|
|
109 |
|
|
|
110 |
# Run in live mode (actually executes operations)
|
|
|
111 |
./test_integration.pl --nodryrun # Use with caution!
|
|
|
112 |
```
|
|
|
113 |
|
|
|
114 |
## Prerequisites
|
|
|
115 |
|
|
|
116 |
Both test scripts require:
|
|
|
117 |
- havirt to be properly installed and configured
|
|
|
118 |
- Required Perl modules (see [INSTALL.md](INSTALL.md))
|
|
|
119 |
- Bash shell (for test_havirt.sh)
|
|
|
120 |
- Perl 5.x (for test_integration.pl)
|
|
|
121 |
|
|
|
122 |
## Running the Tests
|
|
|
123 |
|
|
|
124 |
All commands should be run from the `tests/` directory:
|
|
|
125 |
|
|
|
126 |
```bash
|
|
|
127 |
cd tests/
|
|
|
128 |
```
|
|
|
129 |
|
|
|
130 |
### Quick Test (Safe)
|
|
|
131 |
```bash
|
|
|
132 |
# Run safe read-only tests (recommended for first test)
|
|
|
133 |
./test_havirt_safe.sh
|
|
|
134 |
```
|
|
|
135 |
|
|
|
136 |
### Full Test Suite
|
|
|
137 |
```bash
|
|
|
138 |
# Run all test suites
|
|
|
139 |
./test_havirt_safe.sh --verbose
|
|
|
140 |
./test_integration.pl --verbose
|
|
|
141 |
# Only run test_havirt.sh if you have a live cluster configured
|
|
|
142 |
./test_havirt.sh --verbose
|
|
|
143 |
```
|
|
|
144 |
|
|
|
145 |
### Using the Test Runner
|
|
|
146 |
```bash
|
|
|
147 |
# Interactive test runner
|
|
|
148 |
./run_tests.sh
|
|
|
149 |
```
|
|
|
150 |
|
|
|
151 |
### Continuous Integration
|
|
|
152 |
```bash
|
|
|
153 |
# Exit with non-zero status if any tests fail
|
|
|
154 |
cd tests/
|
|
|
155 |
./test_havirt_safe.sh && ./test_integration.pl
|
|
|
156 |
```
|
|
|
157 |
|
|
|
158 |
## Test Output
|
|
|
159 |
|
|
|
160 |
Both scripts provide:
|
|
|
161 |
- **Colored output**: Green for pass, red for fail, yellow for test names
|
|
|
162 |
- **Test counters**: Total tests run, passed, and failed
|
|
|
163 |
- **Summary report**: Final results with counts
|
|
|
164 |
- **Verbose mode**: Detailed output for debugging
|
|
|
165 |
|
|
|
166 |
### Example Output
|
|
|
167 |
```
|
|
|
168 |
==========================================
|
|
|
169 |
havirt Test Suite
|
|
|
170 |
==========================================
|
|
|
171 |
|
|
|
172 |
[TEST] Version flag
|
|
|
173 |
[PASS] Version flag
|
|
|
174 |
[TEST] Help flag
|
|
|
175 |
[PASS] Help flag
|
|
|
176 |
...
|
|
|
177 |
|
|
|
178 |
==========================================
|
|
|
179 |
Test Summary
|
|
|
180 |
==========================================
|
|
|
181 |
|
|
|
182 |
Total tests run: 45
|
|
|
183 |
Tests passed: 43
|
|
|
184 |
Tests failed: 2
|
|
|
185 |
```
|
|
|
186 |
|
|
|
187 |
## Safety Features
|
|
|
188 |
|
|
|
189 |
- **Dry-run by default**: Both scripts default to dry-run mode to prevent accidental changes
|
|
|
190 |
- **No destructive operations**: Tests don't create, delete, or modify actual VMs
|
|
|
191 |
- **Configuration validation**: Tests verify configuration before running
|
|
|
192 |
- **Error handling**: Graceful failure with informative error messages
|
|
|
193 |
|
|
|
194 |
## Adding New Tests
|
|
|
195 |
|
|
|
196 |
### Adding to test_havirt.sh
|
|
|
197 |
|
|
|
198 |
Add new test sections following the pattern:
|
|
|
199 |
|
|
|
200 |
```bash
|
|
|
201 |
echo "=========================================="
|
|
|
202 |
echo "Section N: Your Test Section"
|
|
|
203 |
echo "=========================================="
|
|
|
204 |
echo ""
|
|
|
205 |
|
|
|
206 |
run_test "Test description" "$HAVIRT command --dryrun"
|
|
|
207 |
run_test_with_output "Test that needs output" "$HAVIRT other-command --dryrun"
|
|
|
208 |
```
|
|
|
209 |
|
|
|
210 |
### Adding to test_integration.pl
|
|
|
211 |
|
|
|
212 |
Add new tests using the test framework:
|
|
|
213 |
|
|
|
214 |
```perl
|
|
|
215 |
run_test("Test description", sub {
|
|
|
216 |
my $result = your_function();
|
|
|
217 |
return $result ? "Success message" : undef;
|
|
|
218 |
});
|
|
|
219 |
|
|
|
220 |
test_returns_defined("Test that must return value", sub {
|
|
|
221 |
return your_function_that_must_return_something();
|
|
|
222 |
});
|
|
|
223 |
```
|
|
|
224 |
|
|
|
225 |
## Troubleshooting
|
|
|
226 |
|
|
|
227 |
### Tests Fail to Run
|
|
|
228 |
- Ensure havirt executable exists and is executable
|
|
|
229 |
- Check that config.yaml exists (will be auto-generated if missing)
|
|
|
230 |
- Verify Perl modules are installed: `perl -c havirt`
|
|
|
231 |
|
|
|
232 |
### All Tests Fail
|
|
|
233 |
- Check that you're in the correct directory
|
|
|
234 |
- Verify file permissions: `ls -l test_*.sh test_*.pl`
|
|
|
235 |
- Run with --verbose to see detailed error messages
|
|
|
236 |
|
|
|
237 |
### Specific Tests Fail
|
|
|
238 |
- Review the error output
|
|
|
239 |
- Check if the required nodes/domains exist
|
|
|
240 |
- Verify configuration in config.yaml
|
|
|
241 |
- Some tests may fail if there are no domains or nodes configured
|
|
|
242 |
|
|
|
243 |
## Notes
|
|
|
244 |
|
|
|
245 |
- Tests are designed to be **idempotent** - safe to run multiple times
|
|
|
246 |
- Tests use the existing configuration and status files
|
|
|
247 |
- No external dependencies beyond standard Perl modules and bash
|
|
|
248 |
- Compatible with havirt version 1.2.2 and later
|
|
|
249 |
|
|
|
250 |
## License
|
|
|
251 |
|
|
|
252 |
Copyright 2026 Daily Data, Inc.
|
|
|
253 |
|
|
|
254 |
See main havirt license for details.
|