Skip to content

Conversation

@Tinyblargon
Copy link
Collaborator

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.

@Tinyblargon Tinyblargon requested a review from Copilot November 17, 2025 23:21
@Tinyblargon Tinyblargon self-assigned this Nov 17, 2025
@Tinyblargon Tinyblargon added type/enhancement An improvement of existing functionality modifies/go Pull requests that update Go code size/M Denotes a PR that changes 30-99 lines, ignoring generated files test/needen This PR has to be tested labels Nov 17, 2025
Copy link
Contributor

Copilot AI left a 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 GuestAgentState enum 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 GetVmAgentNetworkInterfaces function 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.

return nil, nil
var state GuestAgentState
params, err := c.api.getGuestQemuAgent(ctx, vmr, &state)
if state == GuestAgentRunning || state == GuestAgentVmNotRunning {
Copy link

Copilot AI Nov 17, 2025

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 {
Suggested change
if state == GuestAgentRunning || state == GuestAgentVmNotRunning {
if state == GuestAgentNotRunning || state == GuestAgentVmNotRunning {

Copilot uses AI. Check for mistakes.
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)
Copy link

Copilot AI Nov 17, 2025

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).

Copilot uses AI. Check for mistakes.
Comment on lines 28 to 40
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
Copy link

Copilot AI Nov 17, 2025

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:

  1. When the agent is not running, the function returns (nil, GuestAgentNotRunning, nil)
  2. When the VM is not running, the function returns (nil, GuestAgentVmNotRunning, nil)
  3. When the agent is running and returns data successfully, the function returns (data, GuestAgentRunning, nil)
  4. When an unexpected error occurs, the function returns (nil, GuestAgentUnknown, error)

Copilot uses AI. Check for mistakes.
@Tinyblargon Tinyblargon merged commit 57c2a42 into Telmate:master Nov 23, 2025
5 checks passed
@Tinyblargon Tinyblargon added test/done This PR has been tested and the result was succesfull and removed test/needen This PR has to be tested labels Nov 23, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

modifies/go Pull requests that update Go code size/M Denotes a PR that changes 30-99 lines, ignoring generated files test/done This PR has been tested and the result was succesfull type/enhancement An improvement of existing functionality

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant