Skip to content

Commit d3c5fdd

Browse files
committed
test(kubevirt): Add gevals-based integration tests for VM toolset
Introduce a comprehensive gevals testing framework to validate VM lifecycle operations including creation with various configurations (basic, Ubuntu, instancetypes, performance, sizing) and troubleshooting scenarios. This enables automated verification of the KubeVirt toolset's functionality and regression prevention. Assisted-By: Claude <noreply@anthropic.com> Signed-off-by: Lee Yarwood <lyarwood@redhat.com>
1 parent cc31fd7 commit d3c5fdd

File tree

11 files changed

+654
-0
lines changed

11 files changed

+654
-0
lines changed

.gitignore

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -27,3 +27,6 @@ python/build/
2727
python/dist/
2828
python/kubernetes_mcp_server.egg-info/
2929
!python/kubernetes-mcp-server
30+
31+
.gevals-step*
32+
gevals-kubevirt-vm-operations-out.json
Lines changed: 214 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,214 @@
1+
# KubeVirt VM Toolset Tests
2+
3+
This directory contains gevals-based tests for the KubeVirt VM toolset in the Kubernetes MCP Server.
4+
5+
## Overview
6+
7+
These tests validate the VM creation and troubleshooting tools (`vm_create` and `vm_troubleshoot`) by having AI agents complete real tasks using the MCP server.
8+
9+
## Test Structure
10+
11+
```
12+
tests/
13+
├── README.md # This file
14+
├── mcp-config.yaml # MCP server configuration
15+
├── claude-code/ # Claude Code agent configuration
16+
│ ├── agent.yaml
17+
│ └── eval.yaml
18+
└── tasks/ # Test tasks
19+
├── create-vm-basic/ # Basic VM creation test
20+
├── create-vm-with-instancetype/ # VM with specific instancetype
21+
├── create-vm-with-size/ # VM with size parameter
22+
├── create-vm-ubuntu/ # Ubuntu VM creation
23+
├── create-vm-with-performance/ # VM with performance family
24+
└── troubleshoot-vm/ # VM troubleshooting test
25+
```
26+
27+
## Prerequisites
28+
29+
1. **Kubernetes cluster** with KubeVirt installed
30+
- The cluster must have KubeVirt CRDs installed
31+
- For testing, you can use a Kind cluster with KubeVirt
32+
33+
2. **Kubernetes MCP Server** running at `http://localhost:8888/mcp`
34+
35+
```bash
36+
# Build and run the server
37+
cd /path/to/kubernetes-mcp-server
38+
make build
39+
./kubernetes-mcp-server --port 8888
40+
```
41+
42+
3. **gevals binary** built from the gevals project
43+
44+
```bash
45+
cd /path/to/gevals
46+
go build -o gevals ./cmd/gevals
47+
```
48+
49+
4. **Claude Code** installed and in PATH
50+
51+
```bash
52+
# Install Claude Code (if not already installed)
53+
npm install -g @anthropicsdk/claude-code
54+
```
55+
56+
5. **kubectl** configured to access your cluster
57+
58+
## Running the Tests
59+
60+
### Run All Tests
61+
62+
```bash
63+
# From the gevals directory
64+
./gevals eval /path/to/kubernetes-mcp-server/pkg/toolsets/kubevirt/vm/tests/claude-code/eval.yaml
65+
```
66+
67+
### Run a Specific Test
68+
69+
```bash
70+
# Run just the basic VM creation test
71+
./gevals eval /path/to/kubernetes-mcp-server/pkg/toolsets/kubevirt/vm/tests/tasks/create-vm-basic/create-vm-basic.yaml \
72+
--agent-file /path/to/kubernetes-mcp-server/pkg/toolsets/kubevirt/vm/tests/claude-code/agent.yaml \
73+
--mcp-config-file /path/to/kubernetes-mcp-server/pkg/toolsets/kubevirt/vm/tests/mcp-config.yaml
74+
```
75+
76+
## Test Descriptions
77+
78+
### create-vm-basic
79+
80+
**Difficulty:** Easy
81+
**Description:** Tests basic VM creation with default Fedora workload.
82+
**Key Tool:** `vm_create`
83+
**Expected Behavior:** Agent should use `vm_create` to generate a plan and then create the VM using `resources_create_or_update`.
84+
85+
### create-vm-with-instancetype
86+
87+
**Difficulty:** Medium
88+
**Description:** Tests VM creation with a specific instancetype (u1.medium).
89+
**Key Tool:** `vm_create`
90+
**Expected Behavior:** Agent should pass the instancetype parameter to `vm_create` and create a VM with the correct instancetype reference.
91+
92+
### create-vm-with-size
93+
94+
**Difficulty:** Medium
95+
**Description:** Tests VM creation using a size hint ('large').
96+
**Key Tool:** `vm_create`
97+
**Expected Behavior:** Agent should use the size parameter which should map to an appropriate instancetype.
98+
99+
### create-vm-ubuntu
100+
101+
**Difficulty:** Easy
102+
**Description:** Tests VM creation with Ubuntu workload.
103+
**Key Tool:** `vm_create`
104+
**Expected Behavior:** Agent should create a VM using the Ubuntu container disk image.
105+
106+
### create-vm-with-performance
107+
108+
**Difficulty:** Medium
109+
**Description:** Tests VM creation with performance family ('compute-optimized') and size.
110+
**Key Tool:** `vm_create`
111+
**Expected Behavior:** Agent should combine performance and size to select an appropriate instancetype (e.g., c1.medium).
112+
113+
### troubleshoot-vm
114+
115+
**Difficulty:** Easy
116+
**Description:** Tests VM troubleshooting guide generation.
117+
**Key Tool:** `vm_troubleshoot`
118+
**Expected Behavior:** Agent should use `vm_troubleshoot` to generate a troubleshooting guide for the VM.
119+
120+
## Assertions
121+
122+
The tests validate:
123+
124+
- **Tool Usage:** Agents must call `vm_create`, `vm_troubleshoot`, or `resources_*` tools
125+
- **Call Limits:** Between 1 and 30 tool calls (allows for exploration and creation)
126+
- **Task Success:** Verification scripts confirm VMs are created correctly
127+
128+
## Expected Results
129+
130+
**✅ Pass** means:
131+
132+
- The VM tools are well-designed and discoverable
133+
- Tool descriptions are clear to AI agents
134+
- Schemas are properly structured
135+
- Implementation works correctly
136+
137+
**❌ Fail** indicates:
138+
139+
- Tool descriptions may need improvement
140+
- Schema complexity issues
141+
- Missing functionality
142+
- Implementation bugs
143+
144+
## Output
145+
146+
Results are saved to `gevals-kubevirt-vm-operations-out.json` with:
147+
148+
- Task pass/fail status
149+
- Assertion results
150+
- Tool call history
151+
- Agent interactions
152+
153+
## Customization
154+
155+
### Using Different AI Agents
156+
157+
You can create additional agent configurations (similar to the `claude-code/` directory) for testing with different AI models:
158+
159+
```yaml
160+
# Example: openai-agent/agent.yaml
161+
kind: Agent
162+
metadata:
163+
name: "openai-agent"
164+
commands:
165+
argTemplateMcpServer: "{{ .File }}"
166+
runPrompt: |-
167+
agent-wrapper.sh {{ .McpServerFileArgs }} "{{ .Prompt }}"
168+
```
169+
170+
### Adding New Tests
171+
172+
To add a new test task:
173+
174+
1. Create a new directory under `tasks/`
175+
2. Add task YAML file with prompt
176+
3. Add setup, verify, and cleanup scripts
177+
4. The test will be automatically discovered by the glob pattern in `eval.yaml`
178+
179+
## Troubleshooting
180+
181+
### Tests Fail to Connect to MCP Server
182+
183+
Ensure the Kubernetes MCP Server is running:
184+
185+
```bash
186+
curl http://localhost:8888/mcp/health
187+
```
188+
189+
### VirtualMachine Not Created
190+
191+
Check if KubeVirt is installed:
192+
193+
```bash
194+
kubectl get crds | grep kubevirt
195+
kubectl get pods -n kubevirt
196+
```
197+
198+
### Permission Issues
199+
200+
Ensure your kubeconfig has permissions to:
201+
202+
- Create namespaces
203+
- Create VirtualMachine resources
204+
- List instancetypes and preferences
205+
206+
## Contributing
207+
208+
When adding new tests:
209+
210+
- Keep tasks focused on a single capability
211+
- Make verification scripts robust
212+
- Document expected behavior
213+
- Set appropriate difficulty levels
214+
- Ensure cleanup scripts remove all resources
Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
kind: Agent
2+
metadata:
3+
name: "claude-code"
4+
commands:
5+
useVirtualHome: false
6+
argTemplateMcpServer: "--mcp-config {{ .File }}"
7+
argTemplateAllowedTools: "mcp__{{ .ServerName }}__{{ .ToolName }}"
8+
allowedToolsJoinSeparator: ","
9+
runPrompt: |-
10+
claude {{ .McpServerFileArgs }} --strict-mcp-config --allowedTools "{{ .AllowedToolArgs }}" --print "{{ .Prompt }}"
Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
kind: Eval
2+
metadata:
3+
name: "kubevirt-vm-operations"
4+
config:
5+
agentFile: agent.yaml
6+
mcpConfigFile: ../mcp-config.yaml
7+
taskSets:
8+
- glob: ../tasks/*/*.yaml
9+
assertions:
10+
toolsUsed:
11+
- server: kubernetes
12+
toolPattern: "(vm_create|vm_troubleshoot|resources_.*)"
13+
minToolCalls: 1
14+
maxToolCalls: 30
Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
mcpServers:
2+
kubernetes:
3+
type: http
4+
url: http://localhost:8888/mcp
5+
enableAllTools: true
Lines changed: 55 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,55 @@
1+
kind: Task
2+
metadata:
3+
name: "create-basic-vm"
4+
difficulty: easy
5+
steps:
6+
setup:
7+
inline: |-
8+
#!/usr/bin/env bash
9+
kubectl delete namespace vm-test --ignore-not-found
10+
kubectl create namespace vm-test
11+
verify:
12+
inline: |-
13+
#!/usr/bin/env bash
14+
# Wait for VirtualMachine to be created
15+
if ! kubectl wait --for=jsonpath='{.metadata.name}'=test-vm virtualmachine/test-vm -n vm-test --timeout=30s 2>/dev/null; then
16+
echo "VirtualMachine test-vm not found"
17+
kubectl get virtualmachines -n vm-test
18+
exit 1
19+
fi
20+
21+
echo "VirtualMachine test-vm created successfully"
22+
23+
# Verify container disk is Fedora (check all volumes)
24+
CONTAINER_DISKS=$(kubectl get virtualmachine test-vm -n vm-test -o jsonpath='{.spec.template.spec.volumes[*].containerDisk.image}')
25+
if [[ "$CONTAINER_DISKS" =~ fedora ]]; then
26+
echo "✓ VirtualMachine uses Fedora container disk"
27+
else
28+
echo "✗ Expected Fedora container disk, found volumes with images: $CONTAINER_DISKS"
29+
kubectl get virtualmachine test-vm -n vm-test -o yaml
30+
exit 1
31+
fi
32+
33+
# Verify runStrategy is set (check both spec and status)
34+
SPEC_RUN_STRATEGY=$(kubectl get virtualmachine test-vm -n vm-test -o jsonpath='{.spec.runStrategy}')
35+
STATUS_RUN_STRATEGY=$(kubectl get virtualmachine test-vm -n vm-test -o jsonpath='{.status.runStrategy}')
36+
37+
if [[ -n "$SPEC_RUN_STRATEGY" ]]; then
38+
echo "✓ VirtualMachine uses runStrategy in spec: $SPEC_RUN_STRATEGY"
39+
elif [[ -n "$STATUS_RUN_STRATEGY" ]]; then
40+
echo "✓ VirtualMachine has runStrategy in status: $STATUS_RUN_STRATEGY"
41+
echo " Note: VM may have been created with deprecated 'running' field, but runStrategy is set in status"
42+
else
43+
echo "✗ VirtualMachine missing runStrategy field in both spec and status"
44+
exit 1
45+
fi
46+
47+
echo "All validations passed"
48+
exit 0
49+
cleanup:
50+
inline: |-
51+
#!/usr/bin/env bash
52+
kubectl delete virtualmachine test-vm -n vm-test --ignore-not-found
53+
kubectl delete namespace vm-test --ignore-not-found
54+
prompt:
55+
inline: Please create a Fedora virtual machine named test-vm in the vm-test namespace.
Lines changed: 60 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,60 @@
1+
kind: Task
2+
metadata:
3+
name: "create-ubuntu-vm"
4+
difficulty: easy
5+
steps:
6+
setup:
7+
inline: |-
8+
#!/usr/bin/env bash
9+
kubectl delete namespace vm-test --ignore-not-found
10+
kubectl create namespace vm-test
11+
verify:
12+
inline: |-
13+
#!/usr/bin/env bash
14+
# Wait for VirtualMachine to be created
15+
if ! kubectl wait --for=jsonpath='{.metadata.name}'=ubuntu-vm virtualmachine/ubuntu-vm -n vm-test --timeout=30s 2>/dev/null; then
16+
echo "VirtualMachine ubuntu-vm not found"
17+
kubectl get virtualmachines -n vm-test
18+
exit 1
19+
fi
20+
21+
echo "VirtualMachine ubuntu-vm created successfully"
22+
23+
# Verify container disk is Ubuntu (should be quay.io/containerdisks/ubuntu:24.04)
24+
CONTAINER_DISKS=$(kubectl get virtualmachine ubuntu-vm -n vm-test -o jsonpath='{.spec.template.spec.volumes[*].containerDisk.image}')
25+
if [[ "$CONTAINER_DISKS" =~ ubuntu ]]; then
26+
echo "✓ VirtualMachine uses Ubuntu container disk"
27+
28+
# Verify it's using the specific Ubuntu 24.04 image
29+
if [[ "$CONTAINER_DISKS" =~ containerdisks/ubuntu ]]; then
30+
echo "✓ Using containerdisks Ubuntu image"
31+
fi
32+
else
33+
echo "✗ Expected Ubuntu container disk, found volumes with images: $CONTAINER_DISKS"
34+
kubectl get virtualmachine ubuntu-vm -n vm-test -o yaml
35+
exit 1
36+
fi
37+
38+
# Verify runStrategy is set (check both spec and status)
39+
SPEC_RUN_STRATEGY=$(kubectl get virtualmachine ubuntu-vm -n vm-test -o jsonpath='{.spec.runStrategy}')
40+
STATUS_RUN_STRATEGY=$(kubectl get virtualmachine ubuntu-vm -n vm-test -o jsonpath='{.status.runStrategy}')
41+
42+
if [[ -n "$SPEC_RUN_STRATEGY" ]]; then
43+
echo "✓ VirtualMachine uses runStrategy in spec: $SPEC_RUN_STRATEGY"
44+
elif [[ -n "$STATUS_RUN_STRATEGY" ]]; then
45+
echo "✓ VirtualMachine has runStrategy in status: $STATUS_RUN_STRATEGY"
46+
echo " Note: VM may have been created with deprecated 'running' field, but runStrategy is set in status"
47+
else
48+
echo "✗ VirtualMachine missing runStrategy field in both spec and status"
49+
exit 1
50+
fi
51+
52+
echo "All validations passed"
53+
exit 0
54+
cleanup:
55+
inline: |-
56+
#!/usr/bin/env bash
57+
kubectl delete virtualmachine ubuntu-vm -n vm-test --ignore-not-found
58+
kubectl delete namespace vm-test --ignore-not-found
59+
prompt:
60+
inline: Create an Ubuntu virtual machine named ubuntu-vm in the vm-test namespace.

0 commit comments

Comments
 (0)