Skip to content

Commit 6ba4fdb

Browse files
committed
check version before adding sag configuration
1 parent 62e57b3 commit 6ba4fdb

File tree

2 files changed

+73
-4
lines changed

2 files changed

+73
-4
lines changed

configdb/configdb.go

Lines changed: 13 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -66,6 +66,11 @@ func GenerateConfigDB(input *values.Values, platform *p.Platform, environment *p
6666
rules, tables := getACLRulesAndTables(input.SSHSourceranges)
6767
vxlanevpn, vxlanTunnel, vxlanTunnelMap := getVXLAN(input.VTEP, input.LoopbackAddress)
6868

69+
sag, err := getSAG(input.SAG, version)
70+
if err != nil {
71+
return nil, err
72+
}
73+
6974
configdb := ConfigDB{
7075
ACLRules: rules,
7176
ACLTables: tables,
@@ -98,7 +103,7 @@ func GenerateConfigDB(input *values.Values, platform *p.Platform, environment *p
98103
Ports: ports,
99104
PortChannels: getPortChannels(input.PortChannels),
100105
PortChannelMembers: getPortChannelMembers(input.PortChannels.List),
101-
SAG: getSAG(input.SAG),
106+
SAG: sag,
102107
VLANs: getVLANs(input.VLANs),
103108
VLANInterfaces: getVLANInterfaces(input.VLANs),
104109
VLANMembers: getVLANMembers(input.VLANs),
@@ -487,16 +492,20 @@ func getPortsAndBreakouts(ports values.Ports, breakouts map[string]string, platf
487492
return configPorts, configBreakouts, nil
488493
}
489494

490-
func getSAG(sag values.SAG) *SAG {
495+
func getSAG(sag values.SAG, version *v.Version) (*SAG, error) {
496+
if version.Branch != string(v.Branch202211) {
497+
return nil, fmt.Errorf("sag configuration only works with sonic versions from the ec202211 branch")
498+
}
499+
491500
if sag.MAC == "" {
492-
return nil
501+
return nil, nil
493502
}
494503

495504
return &SAG{
496505
SAGGlobal: SAGGlobal{
497506
GatewayMAC: sag.MAC,
498507
},
499-
}
508+
}, nil
500509
}
501510

502511
func getVLANs(vlans []values.VLAN) map[string]VLAN {

configdb/configdb_test.go

Lines changed: 60 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@ import (
88
"github.com/metal-stack/metal-lib/pkg/testcommon"
99
p "github.com/metal-stack/sonic-configdb-utils/platform"
1010
"github.com/metal-stack/sonic-configdb-utils/values"
11+
v "github.com/metal-stack/sonic-configdb-utils/version"
1112
)
1213

1314
func Test_getInterfaces(t *testing.T) {
@@ -551,3 +552,62 @@ func Test_getVRFs(t *testing.T) {
551552
})
552553
}
553554
}
555+
556+
func Test_getSAG(t *testing.T) {
557+
tests := []struct {
558+
name string
559+
sag values.SAG
560+
version *v.Version
561+
want *SAG
562+
wantErr bool
563+
}{
564+
{
565+
name: "wrong version",
566+
sag: values.SAG{
567+
MAC: "11:11:11:11:11:11",
568+
},
569+
version: &v.Version{
570+
Branch: string(v.Branch202111),
571+
},
572+
want: nil,
573+
wantErr: true,
574+
},
575+
{
576+
name: "empty mac",
577+
sag: values.SAG{},
578+
version: &v.Version{
579+
Branch: string(v.Branch202211),
580+
},
581+
want: nil,
582+
wantErr: false,
583+
},
584+
{
585+
name: "valid",
586+
sag: values.SAG{
587+
MAC: "11:11:11:11:11:11",
588+
},
589+
version: &v.Version{
590+
Branch: string(v.Branch202211),
591+
},
592+
want: &SAG{
593+
SAGGlobal: SAGGlobal{
594+
GatewayMAC: "11:11:11:11:11:11",
595+
},
596+
},
597+
wantErr: false,
598+
},
599+
}
600+
601+
for _, tt := range tests {
602+
t.Run(tt.name, func(t *testing.T) {
603+
got, err := getSAG(tt.sag, tt.version)
604+
if (err != nil) != tt.wantErr {
605+
t.Errorf("getSAG() error = %v, wantErr %v", err, tt.wantErr)
606+
return
607+
}
608+
if diff := cmp.Diff(tt.want, got); diff != "" {
609+
t.Errorf("getSAG() diff = %s", diff)
610+
}
611+
})
612+
}
613+
}

0 commit comments

Comments
 (0)