Skip to content
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

fix(domain): restore error handling for network operations #1144

Open
wants to merge 1 commit into
base: main
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
16 changes: 12 additions & 4 deletions libvirt/domain.go
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,6 @@ import (
"strconv"
"strings"

"github.com/davecgh/go-spew/spew"
libvirt "github.com/digitalocean/go-libvirt"
"github.com/hashicorp/terraform-plugin-sdk/v2/helper/retry"
"github.com/hashicorp/terraform-plugin-sdk/v2/helper/schema"
Expand Down Expand Up @@ -194,10 +193,19 @@ func domainGetIfacesInfo(virConn *libvirt.Libvirt, domain libvirt.Domain, rd *sc
var interfaces []libvirt.DomainInterface
interfaces, err = virConn.DomainInterfaceAddresses(domain, addrsrc, 0)
if err != nil {
return interfaces, fmt.Errorf("error retrieving interface addresses: %w", err)
switch virErr := err.(type) {
case libvirt.Error:
// Agent can be unresponsive if being installed/setup
if addrsrc == uint32(libvirt.DomainInterfaceAddressesSrcLease) && virErr.Code != uint32(libvirt.ErrOperationInvalid) ||
addrsrc == uint32(libvirt.DomainInterfaceAddressesSrcAgent) && virErr.Code != uint32(libvirt.ErrAgentUnresponsive) {
return interfaces, fmt.Errorf("error retrieving interface addresses: %w", err)
}
// If it is ErrAgentUnresponsive, continue trying
return interfaces, nil
default:
return interfaces, fmt.Errorf("error retrieving interface addresses: %w", virErr)
}
}
log.Printf("[DEBUG] Interfaces info obtained with libvirt API:\n%s\n", spew.Sdump(interfaces))

return interfaces, nil
}

Expand Down