(vmid string, action string)
| 480 | } |
| 481 | |
| 482 | func (s *MockState) UpdateVMStatus(vmid string, action string) (string, error) { |
| 483 | s.mu.Lock() |
| 484 | // Check if VM exists |
| 485 | vm, ok := s.VMs[vmid] |
| 486 | s.mu.Unlock() |
| 487 | |
| 488 | if !ok { |
| 489 | return "", fmt.Errorf("vm not found") |
| 490 | } |
| 491 | |
| 492 | // Queue task |
| 493 | // NOTE: We queue the task first, but the state update (running -> stopped) happens when the task completes. |
| 494 | // OR for simplicity in testing, we might update it immediately or inside the goroutine. |
| 495 | // To test "Waiting", we should update it in the goroutine. |
| 496 | |
| 497 | upid := s.createTaskWithCompletion(vm.Node, "qm"+action, vmid, "root@pam", func() { |
| 498 | s.mu.Lock() |
| 499 | defer s.mu.Unlock() |
| 500 | |
| 501 | if vm, ok := s.VMs[vmid]; ok { |
| 502 | switch action { |
| 503 | case "start": |
| 504 | vm.Status = guestStatusRunning |
| 505 | vm.Uptime = 1 |
| 506 | case "stop", "shutdown": |
| 507 | vm.Status = guestStatusStopped |
| 508 | vm.Uptime = 0 |
| 509 | case "reboot": |
| 510 | vm.Status = guestStatusRunning |
| 511 | vm.Uptime = 1 |
| 512 | } |
| 513 | } |
| 514 | }) |
| 515 | |
| 516 | return upid, nil |
| 517 | } |
| 518 | |
| 519 | func (s *MockState) DeleteVM(vmid string) error { |
| 520 | s.mu.Lock() |
no test coverage detected