Skip to content

Commit

Permalink
[agent] fix specPortChannelConfigEnforcer
Browse files Browse the repository at this point in the history
  • Loading branch information
Frostman committed Mar 1, 2024
1 parent 926e59d commit 7727162
Show file tree
Hide file tree
Showing 2 changed files with 23 additions and 14 deletions.
6 changes: 4 additions & 2 deletions pkg/agent/dozer/bcm/enforcer.go
Original file line number Diff line number Diff line change
Expand Up @@ -77,7 +77,8 @@ const (
ActionWeightInterfaceEthernetSwitchedTrunkUpdate
ActionWeightInterfaceVLANAnycastGatewayUpdate
ActionWeightInterfaceNATZoneUpdate
ActionWeightPortChannelConfigUpdate
ActionWeightPortChannelConfigMACUpdate
ActionWeightPortChannelConfigFallbackUpdate

ActionWeightInterfaceSubinterfaceIPsDelete
ActionWeightVRFInterfaceDelete
Expand Down Expand Up @@ -167,7 +168,8 @@ const (
ActionWeightMCLAGInterfaceDelete
ActionWeightMCLAGDomainDelete

ActionWeightPortChannelConfigDelete
ActionWeightPortChannelConfigMACDelete
ActionWeightPortChannelConfigFallbackDelete
ActionWeightInterfaceEthernetSwitchedAccessDelete
ActionWeightInterfaceEthernetSwitchedTrunkDelete
ActionWeightInterfaceEthernetBaseDelete
Expand Down
31 changes: 19 additions & 12 deletions pkg/agent/dozer/bcm/spec_pc_config.go
Original file line number Diff line number Diff line change
Expand Up @@ -18,10 +18,8 @@ var specPortChannelConfigsEnforcer = &DefaultMapEnforcer[string, *dozer.SpecPort
var specPortChannelConfigEnforcer = &DefaultValueEnforcer[string, *dozer.SpecPortChannelConfig]{
Summary: "PortChannel Config %s",
CustomHandler: func(basePath string, key string, actual, desired *dozer.SpecPortChannelConfig, actions *ActionQueue) error {
if desired.SystemMAC != nil {
if err := specPortChannelConfigSystemMACEnforcer.Handle(basePath, key, actual, desired, actions); err != nil {
return errors.Wrap(err, "failed to handle system mac")
}
if err := specPortChannelConfigSystemMACEnforcer.Handle(basePath, key, actual, desired, actions); err != nil {
return errors.Wrap(err, "failed to handle system mac")
}

if err := specPortChannelConfigFallbackEnforcer.Handle(basePath, key, actual, desired, actions); err != nil {
Expand All @@ -33,10 +31,13 @@ var specPortChannelConfigEnforcer = &DefaultValueEnforcer[string, *dozer.SpecPor
}

var specPortChannelConfigSystemMACEnforcer = &DefaultValueEnforcer[string, *dozer.SpecPortChannelConfig]{
Summary: "PortChannel System MAC %s",
Path: "/sonic-portchannel/PORTCHANNEL/PORTCHANNEL_LIST[name=%s]/system_mac",
UpdateWeight: ActionWeightPortChannelConfigUpdate,
DeleteWeight: ActionWeightPortChannelConfigDelete,
Summary: "PortChannel System MAC %s",
Path: "/sonic-portchannel/PORTCHANNEL/PORTCHANNEL_LIST[name=%s]/system_mac",
Getter: func(key string, value *dozer.SpecPortChannelConfig) any {
return value.SystemMAC
},
UpdateWeight: ActionWeightPortChannelConfigMACUpdate,
DeleteWeight: ActionWeightPortChannelConfigMACDelete,
Marshal: func(key string, value *dozer.SpecPortChannelConfig) (ygot.ValidatedGoStruct, error) {
return &oc.SonicPortchannel_SonicPortchannel_PORTCHANNEL_PORTCHANNEL_LIST{
SystemMac: value.SystemMAC,
Expand All @@ -45,10 +46,13 @@ var specPortChannelConfigSystemMACEnforcer = &DefaultValueEnforcer[string, *doze
}

var specPortChannelConfigFallbackEnforcer = &DefaultValueEnforcer[string, *dozer.SpecPortChannelConfig]{
Summary: "PortChannel Fallback %s",
Path: "/sonic-portchannel/PORTCHANNEL/PORTCHANNEL_LIST[name=%s]/fallback",
UpdateWeight: ActionWeightPortChannelConfigUpdate,
DeleteWeight: ActionWeightPortChannelConfigDelete,
Summary: "PortChannel Fallback %s",
Path: "/sonic-portchannel/PORTCHANNEL/PORTCHANNEL_LIST[name=%s]/fallback",
Getter: func(key string, value *dozer.SpecPortChannelConfig) any {
return value.Fallback
},
UpdateWeight: ActionWeightPortChannelConfigFallbackUpdate,
DeleteWeight: ActionWeightPortChannelConfigFallbackDelete,
Marshal: func(key string, value *dozer.SpecPortChannelConfig) (ygot.ValidatedGoStruct, error) {
return &oc.SonicPortchannel_SonicPortchannel_PORTCHANNEL_PORTCHANNEL_LIST{
Fallback: value.Fallback,
Expand Down Expand Up @@ -79,6 +83,9 @@ func unmarshalActualPortChannelConfigs(ocVal *oc.SonicPortchannel_SonicPortchann
}

for name, portChannel := range ocVal.PORTCHANNEL.PORTCHANNEL_LIST {
if portChannel == nil || portChannel.SystemMac == nil && portChannel.Fallback == nil {
continue
}

portChannelConfigs[name] = &dozer.SpecPortChannelConfig{
SystemMAC: portChannel.SystemMac,
Expand Down

0 comments on commit 7727162

Please sign in to comment.