-
Notifications
You must be signed in to change notification settings - Fork 263
feat: return agent state as enum #521
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Conversation
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Pull Request Overview
This PR introduces a GuestAgentState enum to replace error-based parsing for agent states, providing a cleaner API for downstream consumers to determine guest agent status without parsing error strings.
Key Changes:
- Introduces a
GuestAgentStateenum with four states: Unknown, Running, NotRunning, and VmNotRunning - Updates function signatures across the codebase to return the state enum alongside data and errors
- Modifies the deprecated
GetVmAgentNetworkInterfacesfunction to use the new state enum for backward compatibility
Reviewed Changes
Copilot reviewed 6 out of 6 changed files in this pull request and generated 3 comments.
Show a summary per file
| File | Description |
|---|---|
| proxmox/data__qemu__agent.go | Defines the GuestAgentState enum and implements state-aware logic in getAgentInformation() |
| proxmox/client__api.go | Updates API layer to set state based on specific error messages from Proxmox |
| proxmox/client__api__mock.go | Updates mock implementation signatures to match new state parameter |
| proxmox/client__new.go | Updates interface definition to include state in return signature |
| proxmox/client__new__mock.go | Updates mock client signatures to match new state parameter |
| proxmox/client.go | Modifies deprecated function to use state enum and convert to appropriate errors |
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
proxmox/data__qemu__agent.go
Outdated
| return nil, nil | ||
| var state GuestAgentState | ||
| params, err := c.api.getGuestQemuAgent(ctx, vmr, &state) | ||
| if state == GuestAgentRunning || state == GuestAgentVmNotRunning { |
Copilot
AI
Nov 17, 2025
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Logic error: This condition returns early with nil data when state == GuestAgentRunning, but the agent being running means data should be available and fetched. Only GuestAgentNotRunning and GuestAgentVmNotRunning should trigger an early return. This condition should be:
if state == GuestAgentNotRunning || state == GuestAgentVmNotRunning {| if state == GuestAgentRunning || state == GuestAgentVmNotRunning { | |
| if state == GuestAgentNotRunning || state == GuestAgentVmNotRunning { |
proxmox/client__api.go
Outdated
| getGuestConfig(ctx context.Context, vmr *VmRef) (map[string]any, error) | ||
| getGuestPendingChanges(ctx context.Context, vmr *VmRef) ([]any, error) | ||
| getGuestQemuAgent(ctx context.Context, vmr *VmRef, isRunning *bool) (map[string]any, error) | ||
| getGuestQemuAgent(ctx context.Context, vmr *VmRef, isRunning *GuestAgentState) (map[string]any, error) |
Copilot
AI
Nov 17, 2025
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Parameter name isRunning is inconsistent with the actual type *GuestAgentState. It should be renamed to state to match the implementation and other files (e.g., client__api__mock.go already uses state).
proxmox/data__qemu__agent.go
Outdated
| func (vmr *VmRef) getAgentInformation(ctx context.Context, c *clientNew) (*rawAgentNetworkInterfaces, GuestAgentState, error) { | ||
| if err := c.oldClient.CheckVmRef(ctx, vmr); err != nil { | ||
| return nil, err | ||
| return nil, GuestAgentUnknown, err | ||
| } | ||
| var isRunning bool | ||
| params, err := c.api.getGuestQemuAgent(ctx, vmr, &isRunning) | ||
| if !isRunning { | ||
| return nil, nil | ||
| var state GuestAgentState | ||
| params, err := c.api.getGuestQemuAgent(ctx, vmr, &state) | ||
| if state == GuestAgentRunning || state == GuestAgentVmNotRunning { | ||
| return nil, state, nil | ||
| } | ||
| if err != nil { | ||
| return nil, err | ||
| return nil, GuestAgentUnknown, err | ||
| } | ||
| return &rawAgentNetworkInterfaces{a: params}, nil | ||
| return &rawAgentNetworkInterfaces{a: params}, GuestAgentRunning, nil |
Copilot
AI
Nov 17, 2025
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The new state handling logic (particularly the state checks and conversions on lines 34-40) lacks test coverage. Consider adding tests that verify:
- When the agent is not running, the function returns
(nil, GuestAgentNotRunning, nil) - When the VM is not running, the function returns
(nil, GuestAgentVmNotRunning, nil) - When the agent is running and returns data successfully, the function returns
(data, GuestAgentRunning, nil) - When an unexpected error occurs, the function returns
(nil, GuestAgentUnknown, error)
Before we returned the agent state as errors downstream projects would have to parse.
Now we return an enum, removing the need for downstream error parsing for agent related errors.