Skip to content

Commit

Permalink
fix(paloalto): add check if VirtualDeviceContext is nil
Browse files Browse the repository at this point in the history
  • Loading branch information
bl4ko committed Mar 21, 2024
1 parent 67bbd8d commit d9d25ac
Showing 1 changed file with 10 additions and 2 deletions.
12 changes: 10 additions & 2 deletions internal/source/paloalto/paloalto_sync.go
Original file line number Diff line number Diff line change
Expand Up @@ -121,6 +121,10 @@ func (pas *PaloAltoSource) SyncInterfaces(nbi *inventory.NetboxInventory) error
}
}

var ifaceVdcs []*objects.VirtualDeviceContext
if vdc := pas.getVirtualDeviceContext(nbi, iface.Name); vdc != nil {
ifaceVdcs = []*objects.VirtualDeviceContext{vdc}

Check warning on line 126 in internal/source/paloalto/paloalto_sync.go

View check run for this annotation

Codecov / codecov/patch

internal/source/paloalto/paloalto_sync.go#L124-L126

Added lines #L124 - L126 were not covered by tests
}
nbIface, err := nbi.AddInterface(pas.Ctx, &objects.Interface{
NetboxObject: objects.NetboxObject{
Tags: pas.SourceTags,
Expand All @@ -132,7 +136,7 @@ func (pas *PaloAltoSource) SyncInterfaces(nbi *inventory.NetboxInventory) error
Device: pas.NBFirewall,
MTU: iface.Mtu,
Speed: ifaceLinkSpeed,
Vdcs: []*objects.VirtualDeviceContext{pas.getVirtualDeviceContext(nbi, iface.Name)},
Vdcs: ifaceVdcs,

Check warning on line 139 in internal/source/paloalto/paloalto_sync.go

View check run for this annotation

Codecov / codecov/patch

internal/source/paloalto/paloalto_sync.go#L139

Added line #L139 was not covered by tests
})
if err != nil {
return fmt.Errorf("add interface %s", err)
Expand Down Expand Up @@ -173,6 +177,10 @@ func (pas *PaloAltoSource) SyncInterfaces(nbi *inventory.NetboxInventory) error
subIfaceVlans = append(subIfaceVlans, subIfaceVlan)
subifaceMode = &objects.InterfaceModeTagged
}
var vdcs []*objects.VirtualDeviceContext
if vdc := pas.getVirtualDeviceContext(nbi, subIfaceName); vdc != nil {
vdcs = []*objects.VirtualDeviceContext{vdc}

Check warning on line 182 in internal/source/paloalto/paloalto_sync.go

View check run for this annotation

Codecov / codecov/patch

internal/source/paloalto/paloalto_sync.go#L180-L182

Added lines #L180 - L182 were not covered by tests
}
nbSubIface, err := nbi.AddInterface(pas.Ctx, &objects.Interface{
NetboxObject: objects.NetboxObject{
Tags: pas.SourceTags,
Expand All @@ -185,7 +193,7 @@ func (pas *PaloAltoSource) SyncInterfaces(nbi *inventory.NetboxInventory) error
TaggedVlans: subIfaceVlans,
ParentInterface: nbIface,
MTU: subIface.Mtu,
Vdcs: []*objects.VirtualDeviceContext{pas.getVirtualDeviceContext(nbi, subIfaceName)},
Vdcs: vdcs,

Check warning on line 196 in internal/source/paloalto/paloalto_sync.go

View check run for this annotation

Codecov / codecov/patch

internal/source/paloalto/paloalto_sync.go#L196

Added line #L196 was not covered by tests
})
if err != nil {
return fmt.Errorf("add subinterface: %s", err)
Expand Down

0 comments on commit d9d25ac

Please sign in to comment.