Skip to content

Commit 6fa01b1

Browse files
authored
F #8: Allow manage_vm to be performed on multiple VMs (#11)
* F #8: Add tests for terminating multiple VMs using comma-separated IDs, ranges, and mixed valid/invalid IDs. * F #8: Add promptfoo tests for terminating multiple VMs with various formats * F #8: Refactor VM management tool to enhance multi-VM handling and state validation. * F #8: Enhance VM management documentation and tests for multi-VM operations
1 parent 3907a91 commit 6fa01b1

File tree

4 files changed

+512
-67
lines changed

4 files changed

+512
-67
lines changed

src/static/mcp_server_prompt.md

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -37,7 +37,7 @@ This is a non-negotiable security and stability requirement.
3737
### Managing VM Lifecycle
3838
1. Call `list_vms()` to identify the target VM.
3939
2. Call `get_vm_status()` to check its state and resources.
40-
3. Call `manage_vm()` to perform actions (start, stop, reboot, terminate).
40+
3. Call `manage_vm()` to perform actions (start, stop, reboot, terminate). **CRITICAL**: For multiple VMs, use a single call with a comma-separated list ("1,2,3") or a range ("5..10") instead of multiple calls.
4141

4242
### Infrastructure Monitoring
4343
1. Call `list_clusters()`, `list_hosts()`, `list_datastores()`.
@@ -154,7 +154,7 @@ This policy ensures:
154154
1. **MANDATORY FIRST**: Call VM listing MCP tools to check current VM inventory and status
155155
2. **MANDATORY**: Use MCP monitoring tools to review resource usage and performance metrics
156156
3. Scale resources: Use MCP tools to adjust CPU, memory, or storage as needed
157-
4. Manage state: Use MCP tools to start, stop, restart, or suspend VMs based on requirements
157+
4. Manage state: Use `manage_vm()` to start, stop, restart, or suspend VMs based on requirements. **CRITICAL**: For multiple VMs, you MUST use a single call with a comma-separated list ("1,2,3") or a range ("5..10") instead of multiple individual calls.
158158
5. Troubleshoot issues: Use MCP tools to check logs, events, and system metrics for problems
159159
6. Clean up: Use MCP tools to remove VMs when no longer needed to free resources
160160

src/tests/promptfoo/tests/tools/vm/vm_manage.yaml

Lines changed: 158 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -152,3 +152,161 @@
152152
assert:
153153
- type: javascript
154154
value: output.length === 0
155+
156+
# 12. Terminate multiple VMs (comma-separated list)
157+
- vars:
158+
input: "Terminate VMs 3, 5, 7."
159+
options:
160+
transform: file://transforms/extract_function_call.js
161+
assert:
162+
- type: javascript
163+
value: output.length === 1 &&
164+
output[0].function === 'manage_vm' &&
165+
output[0].arguments.vm_id === '3,5,7' &&
166+
output[0].arguments.operation === 'terminate'
167+
168+
# 13. Terminate multiple VMs (range syntax)
169+
- vars:
170+
input: "Terminate VMs 5 through 10."
171+
options:
172+
transform: file://transforms/extract_function_call.js
173+
assert:
174+
- type: javascript
175+
value: output.length === 1 &&
176+
output[0].function === 'manage_vm' &&
177+
output[0].arguments.vm_id === '5..10' &&
178+
output[0].arguments.operation === 'terminate'
179+
180+
# 14. Force-terminate multiple VMs (hard flag)
181+
- vars:
182+
input: "Force-terminate VMs 12 and 13 now."
183+
options:
184+
transform: file://transforms/extract_function_call.js
185+
assert:
186+
- type: javascript
187+
value: output.length === 1 &&
188+
output[0].function === 'manage_vm' &&
189+
output[0].arguments.vm_id === '12,13' &&
190+
output[0].arguments.operation === 'terminate' &&
191+
output[0].arguments.hasOwnProperty('hard') && output[0].arguments.hard === true
192+
193+
# 15. Invalid multi-VM format (spaces instead of commas)
194+
- vars:
195+
input: "Terminate VMs id: 1 2 3."
196+
options:
197+
transform: file://transforms/extract_function_call.js
198+
assert:
199+
- type: javascript
200+
value: output[0].function == 'manage_vm' && (output[0].arguments.vm_id == '1,2,3' || output[0].arguments.vm_id == '1..3')
201+
202+
# 16. Stop multiple VMs (comma-list)
203+
- vars:
204+
input: "Power off VMs 3,4,5."
205+
options:
206+
transform: file://transforms/extract_function_call.js
207+
assert:
208+
- type: javascript
209+
value: output.length === 1 &&
210+
output[0].function === 'manage_vm' &&
211+
output[0].arguments.vm_id === '3,4,5' &&
212+
output[0].arguments.operation === 'stop'
213+
214+
# 17. Stop multiple VMs (range syntax)
215+
- vars:
216+
input: "Power off VMs 10 through 15."
217+
options:
218+
transform: file://transforms/extract_function_call.js
219+
assert:
220+
- type: javascript
221+
value: output.length === 1 &&
222+
output[0].function === 'manage_vm' &&
223+
output[0].arguments.vm_id === '10..15' &&
224+
output[0].arguments.operation === 'stop'
225+
226+
# 18. Hard-stop multiple VMs
227+
- vars:
228+
input: "Force power off VMs 7,8,9 immediately."
229+
options:
230+
transform: file://transforms/extract_function_call.js
231+
assert:
232+
- type: javascript
233+
value: output.length === 1 &&
234+
output[0].function === 'manage_vm' &&
235+
output[0].arguments.vm_id === '7,8,9' &&
236+
output[0].arguments.operation === 'stop' &&
237+
output[0].arguments.hasOwnProperty('hard') && output[0].arguments.hard === true
238+
239+
# 19. Start multiple VMs (comma-list)
240+
- vars:
241+
input: "Start VMs 20,21,22."
242+
options:
243+
transform: file://transforms/extract_function_call.js
244+
assert:
245+
- type: javascript
246+
value: output.length === 1 &&
247+
output[0].function === 'manage_vm' &&
248+
output[0].arguments.vm_id === '20,21,22' &&
249+
output[0].arguments.operation === 'start'
250+
251+
# 20. Start multiple VMs (range syntax)
252+
- vars:
253+
input: "Start VMs 25 through 30."
254+
options:
255+
transform: file://transforms/extract_function_call.js
256+
assert:
257+
- type: javascript
258+
value: output.length === 1 &&
259+
output[0].function === 'manage_vm' &&
260+
output[0].arguments.vm_id === '25..30' &&
261+
output[0].arguments.operation === 'start'
262+
263+
# 21. Reboot multiple VMs (comma-list)
264+
- vars:
265+
input: "Reboot VMs 31,32,33."
266+
options:
267+
transform: file://transforms/extract_function_call.js
268+
assert:
269+
- type: javascript
270+
value: output.length === 1 &&
271+
output[0].function === 'manage_vm' &&
272+
output[0].arguments.vm_id === '31,32,33' &&
273+
output[0].arguments.operation === 'reboot'
274+
275+
# 22. Hard-reboot multiple VMs (range)
276+
- vars:
277+
input: "Force reboot VMs 40 through 45 immediately."
278+
options:
279+
transform: file://transforms/extract_function_call.js
280+
assert:
281+
- type: javascript
282+
value: output.length === 1 &&
283+
output[0].function === 'manage_vm' &&
284+
output[0].arguments.vm_id === '40..45' &&
285+
output[0].arguments.operation === 'reboot' &&
286+
output[0].arguments.hasOwnProperty('hard') && output[0].arguments.hard === true
287+
288+
# 23. Mixed operations with multi-VM (should split into separate calls)
289+
- vars:
290+
input: "Start VMs 50,51 and terminate VMs 52 through 54."
291+
options:
292+
transform: file://transforms/extract_function_call.js
293+
assert:
294+
- type: javascript
295+
value: output.length === 2 &&
296+
output[0].function === 'manage_vm' &&
297+
output[0].arguments.vm_id === '50,51' &&
298+
output[0].arguments.operation === 'start' &&
299+
output[1].function === 'manage_vm' &&
300+
output[1].arguments.vm_id === '52..54' &&
301+
output[1].arguments.operation === 'terminate'
302+
303+
# 24. Invalid multi-VM format with mixed delimiters
304+
- vars:
305+
input: "Stop VMs 60..61,62."
306+
options:
307+
transform: file://transforms/extract_function_call.js
308+
assert:
309+
- type: javascript
310+
value: output.length === 0 ||
311+
(output[0].function === 'manage_vm' &&
312+
(output[0].arguments.vm_id === '60..62' || output[0].arguments.vm_id === '60,61,62'))

0 commit comments

Comments
 (0)