Skip to content

Commit

Permalink
fix(dnac,inventory): fixing wrong lock usage and empty mac addresses
Browse files Browse the repository at this point in the history
  • Loading branch information
bl4ko committed Jan 29, 2025
1 parent 8b00e9c commit 8f2ad7b
Show file tree
Hide file tree
Showing 3 changed files with 15 additions and 19 deletions.
6 changes: 0 additions & 6 deletions go.sum
Original file line number Diff line number Diff line change
@@ -1,9 +1,5 @@
github.com/PaloAltoNetworks/pango v0.10.2 h1:Tjn6vIzzAq6Dd7N0mDuiP8w8pz8k5W9zz/TTSUQCsQY=
github.com/PaloAltoNetworks/pango v0.10.2/go.mod h1:GztcRnVLur7G+VFG7Z5ZKNFgScLtsycwPMp1qVebE5g=
github.com/bl4ko/go-devicetype-library v0.1.35 h1:5zXFlkIx2w4b9DOLi3QetJj32TehiG3e23oxQAbxmlw=
github.com/bl4ko/go-devicetype-library v0.1.35/go.mod h1:Pzm1BlRyR4uECezsRINDA6ZieFPumdFL+6yySpXM6t8=
github.com/bl4ko/go-devicetype-library v0.1.36 h1:wpVVWy2p5TQGfMZF5KA8XSpqsvdu5ET0V6PsAr00VDY=
github.com/bl4ko/go-devicetype-library v0.1.36/go.mod h1:Pzm1BlRyR4uECezsRINDA6ZieFPumdFL+6yySpXM6t8=
github.com/bl4ko/go-devicetype-library v0.1.37 h1:uPtTWoAhUW9q/cx+mbn39lP91fpCqDIZm5lrDl/itIA=
github.com/bl4ko/go-devicetype-library v0.1.37/go.mod h1:Pzm1BlRyR4uECezsRINDA6ZieFPumdFL+6yySpXM6t8=
github.com/buger/goterm v1.0.4 h1:Z9YvGmOih81P0FbVtEYTFF6YsSgxSUKEhf/f9bTMXbY=
Expand Down Expand Up @@ -63,8 +59,6 @@ github.com/stretchr/testify v1.10.0 h1:Xv5erBjTwe/5IxqUQTdXv5kgmIvbHo3QQyRwhJsOf
github.com/stretchr/testify v1.10.0/go.mod h1:r2ic/lqez/lEtzL7wO/rwa5dbSLXVDPFyf8C91i36aY=
github.com/ulikunitz/xz v0.5.11 h1:kpFauv27b6ynzBNT/Xy+1k+fK4WswhN/6PN5WhFAGw8=
github.com/ulikunitz/xz v0.5.11/go.mod h1:nbz6k7qbPmH4IRqmfOplQw/tblSgqTqBwxkY0oWt/14=
github.com/vmware/govmomi v0.47.0 h1:yFDYALpyuyZfN9L0oZ2wP+Pk9e3++Ak57dW8xuuiJ44=
github.com/vmware/govmomi v0.47.0/go.mod h1:bYwUHpGpisE4AOlDl5eph90T+cjJMIcKx/kaa5v5rQM=
github.com/vmware/govmomi v0.48.0 h1:CP5bCvkDNGkmn29UlcJKTWMLwDg3iusP8anrZnedWrg=
github.com/vmware/govmomi v0.48.0/go.mod h1:bYwUHpGpisE4AOlDl5eph90T+cjJMIcKx/kaa5v5rQM=
golang.org/x/crypto v0.31.0 h1:ihbySMvVjLAeSH1IbfcRTkD/iNscyz8rGzjF/E5hV6U=
Expand Down
4 changes: 2 additions & 2 deletions internal/netbox/inventory/add_items.go
Original file line number Diff line number Diff line change
Expand Up @@ -860,8 +860,8 @@ func (nbi *NetboxInventory) AddVirtualDeviceContext(
newVDC.NetboxObject.AddTag(nbi.SsotTag)
addSourceNameCustomField(ctx, &newVDC.NetboxObject)
newVDC.SetCustomField(constants.CustomFieldOrphanLastSeenName, nil)
nbi.devicesLock.Lock()
defer nbi.devicesLock.Unlock()
nbi.virtualDeviceContextsLock.Lock()
defer nbi.virtualDeviceContextsLock.Unlock()

Check warning on line 864 in internal/netbox/inventory/add_items.go

View check run for this annotation

Codecov / codecov/patch

internal/netbox/inventory/add_items.go#L863-L864

Added lines #L863 - L864 were not covered by tests
if newVDC.Device == nil {
return nil, fmt.Errorf(
"VirtualDeviceContext %s is not assigned to a device, but it should be",
Expand Down
24 changes: 13 additions & 11 deletions internal/source/dnac/dnac_sync.go
Original file line number Diff line number Diff line change
Expand Up @@ -404,17 +404,19 @@ func (ds *DnacSource) syncDeviceInterface(
return fmt.Errorf("add device interface: %s", err)
}

nbMACAddress, err := common.CreateMACAddressForObjectType(
ds.Ctx,
nbi,
iface.MacAddress,
nbIface,
)
if err != nil {
return fmt.Errorf("creating MAC address: %s", err)
}
if err = common.SetPrimaryMACForInterface(ds.Ctx, nbi, nbIface, nbMACAddress); err != nil {
return fmt.Errorf("setting primary MAC for interface: %s", err)
if iface.MacAddress != "" {
nbMACAddress, err := common.CreateMACAddressForObjectType(
ds.Ctx,
nbi,
iface.MacAddress,
nbIface,
)
if err != nil {
return fmt.Errorf("creating MAC address: %s", err)
}
if err = common.SetPrimaryMACForInterface(ds.Ctx, nbi, nbIface, nbMACAddress); err != nil {
return fmt.Errorf("setting primary MAC for interface: %s", err)
}

Check warning on line 419 in internal/source/dnac/dnac_sync.go

View check run for this annotation

Codecov / codecov/patch

internal/source/dnac/dnac_sync.go#L407-L419

Added lines #L407 - L419 were not covered by tests
}

err = ds.addIPAddressToInterface(nbi, nbIface, iface, ifaceDevice)
Expand Down

0 comments on commit 8f2ad7b

Please sign in to comment.