[FTTH-59259] Ut coverage for vgc upto 50%
Change-Id: I0ae047de26ec913a34fd2f8001ec3cbe170155a9
diff --git a/internal/pkg/application/igmptasks_test.go b/internal/pkg/application/igmptasks_test.go
new file mode 100644
index 0000000..8a71b29
--- /dev/null
+++ b/internal/pkg/application/igmptasks_test.go
@@ -0,0 +1,167 @@
+/*
+* Copyright 2022-present Open Networking Foundation
+* Licensed under the Apache License, Version 2.0 (the "License");
+* you may not use this file except in compliance with the License.
+* You may obtain a copy of the License at
+*
+* http://www.apache.org/licenses/LICENSE-2.0
+*
+* Unless required by applicable law or agreed to in writing, software
+* distributed under the License is distributed on an "AS IS" BASIS,
+* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+* See the License for the specific language governing permissions and
+* limitations under the License.
+ */
+
+package application
+
+import (
+ "context"
+ "testing"
+ "voltha-go-controller/internal/pkg/of"
+
+ "github.com/google/gopacket"
+ "github.com/stretchr/testify/assert"
+)
+
+func TestTickTask_Name(t *testing.T) {
+ tt := &TickTask{}
+ got := tt.Name()
+ assert.NotNil(t, got)
+ got1 := tt.TaskID()
+ assert.NotNil(t, got1)
+ got2 := tt.Timestamp()
+ assert.NotNil(t, got2)
+ ipk := IgmpPacketTask{}
+ got3 := ipk.Name()
+ assert.NotNil(t, got3)
+ got4 := ipk.TaskID()
+ assert.NotNil(t, got4)
+ got5 := ipk.Timestamp()
+ assert.NotNil(t, got5)
+ mt := &UpdateMvlanTask{}
+ got6 := mt.Name()
+ assert.NotNil(t, got6)
+ got7 := mt.TaskID()
+ assert.NotNil(t, got7)
+ got8 := mt.Timestamp()
+ assert.NotNil(t, got8)
+ got9 := NewTickTask()
+ assert.NotNil(t, got9)
+}
+
+func TestTickTask_Start(t *testing.T) {
+ type args struct {
+ ctx context.Context
+ taskID uint8
+ }
+ tests := []struct {
+ name string
+ args args
+ wantErr bool
+ }{
+ {
+ name: "TickTask_Start",
+ args: args{
+ ctx: context.Background(),
+ },
+ wantErr: false,
+ },
+ }
+ for _, tt := range tests {
+ t.Run(tt.name, func(t *testing.T) {
+ tt1 := &TickTask{}
+ if err := tt1.Start(tt.args.ctx, tt.args.taskID); (err != nil) != tt.wantErr {
+ t.Errorf("TickTask.Start() error = %v, wantErr %v", err, tt.wantErr)
+ }
+ })
+ }
+}
+
+func TestNewIgmpPacketTask(t *testing.T) {
+ type args struct {
+ device string
+ port string
+ pkt gopacket.Packet
+ }
+ tests := []struct {
+ name string
+ args args
+ want *IgmpPacketTask
+ }{
+ {
+ name: "NewIgmpPacketTask",
+ args: args{
+ device: "SDX6320031",
+ port: "16777472",
+ },
+ want: &IgmpPacketTask{},
+ },
+ }
+ for _, tt := range tests {
+ t.Run(tt.name, func(t *testing.T) {
+ got := NewIgmpPacketTask(tt.args.device, tt.args.port, tt.args.pkt)
+ assert.NotNil(t, got)
+ })
+ }
+}
+
+func TestNewUpdateMvlanTask(t *testing.T) {
+ type args struct {
+ mvp *MvlanProfile
+ deviceID string
+ }
+ tests := []struct {
+ name string
+ args args
+ want *UpdateMvlanTask
+ }{
+ {
+ name: "NewUpdateMvlanTask",
+ args: args{
+ mvp: &MvlanProfile{},
+ deviceID: "SDX6320031",
+ },
+ want: &UpdateMvlanTask{},
+ },
+ }
+ for _, tt := range tests {
+ t.Run(tt.name, func(t *testing.T) {
+ got := NewUpdateMvlanTask(tt.args.mvp, tt.args.deviceID)
+ assert.NotNil(t, got)
+ })
+ }
+}
+
+func TestUpdateMvlanTask_Start(t *testing.T) {
+ type args struct {
+ ctx context.Context
+ taskID uint8
+ }
+ tests := []struct {
+ name string
+ args args
+ wantErr bool
+ }{
+ {
+ name: "UpdateMvlanTask_Start",
+ args: args{
+ ctx: context.Background(),
+ taskID: uint8(123),
+ },
+ },
+ }
+ for _, tt := range tests {
+ t.Run(tt.name, func(t *testing.T) {
+ mt := &UpdateMvlanTask{
+ DeviceID: "SDX6320031",
+ mvp: &MvlanProfile{
+ Mvlan: of.VlanAny,
+ },
+ }
+ if err := mt.Start(tt.args.ctx, tt.args.taskID); (err != nil) != tt.wantErr {
+ t.Errorf("UpdateMvlanTask.Start() error = %v, wantErr %v", err, tt.wantErr)
+ }
+ })
+ }
+}
diff --git a/internal/pkg/application/major_upgrade_test.go b/internal/pkg/application/major_upgrade_test.go
index 47e1f45..c0bb684 100644
--- a/internal/pkg/application/major_upgrade_test.go
+++ b/internal/pkg/application/major_upgrade_test.go
@@ -140,6 +140,9 @@
data []byte
}
vpvmap := make(map[string]interface{})
+ vpvmap["MacLearning"] = true
+ vpvmap["UsFlowsApplied"] = true
+ vpvmap["DsFlowsApplied"] = true
byteData, _ := json.Marshal(&vpvmap)
tests := []struct {
name string
diff --git a/internal/pkg/application/pppoeia_test.go b/internal/pkg/application/pppoeia_test.go
index fc07d1f..0b8ed04 100644
--- a/internal/pkg/application/pppoeia_test.go
+++ b/internal/pkg/application/pppoeia_test.go
@@ -296,3 +296,42 @@
})
}
}
+
+func TestNewPppoeIaPacketTask(t *testing.T) {
+ type args struct {
+ pkt gopacket.Packet
+ dev string
+ port string
+ }
+ pkt := mocks.NewMockPacket(gomock.NewController(t))
+ tests := []struct {
+ name string
+ args args
+ want *PppoeIaPacketTask
+ }{
+ {
+ name: "NewPppoeIaPacketTask",
+ args: args{
+ pkt: pkt,
+ dev: test_device,
+ port: "test_port",
+ },
+ },
+ }
+ for _, tt := range tests {
+ t.Run(tt.name, func(t *testing.T) {
+ got := NewPppoeIaPacketTask(tt.args.pkt, tt.args.dev, tt.args.port)
+ assert.NotNil(t, got)
+ })
+ }
+}
+
+func TestPppoeIaPacketTask_Name(t *testing.T) {
+ dpt := &PppoeIaPacketTask{}
+ got := dpt.Name()
+ assert.NotNil(t, got)
+ got1 := dpt.TaskID()
+ assert.NotNil(t, got1)
+ got2 := dpt.Timestamp()
+ assert.NotNil(t, got2)
+}
diff --git a/internal/pkg/application/service.go b/internal/pkg/application/service.go
index 6c44450..d93c8f4 100644
--- a/internal/pkg/application/service.go
+++ b/internal/pkg/application/service.go
@@ -2085,7 +2085,7 @@
} else if !vs.DsHSIAFlowsApplied && !vs.UsHSIAFlowsApplied {
flowProvisionStatus.FlowProvisionStatus = NO_FLOWS_PROVISIONED
return false
- } else if vs.LenOfPendingFlows() > 0 {
+ } else if vs.DsHSIAFlowsApplied && vs.UsHSIAFlowsApplied && vs.LenOfPendingFlows() > 0 {
flowProvisionStatus.FlowProvisionStatus = FLOWS_PROVISIONED_PARTIALLY
return false
}
diff --git a/internal/pkg/application/service_test.go b/internal/pkg/application/service_test.go
index 0f07347..83e39d7 100644
--- a/internal/pkg/application/service_test.go
+++ b/internal/pkg/application/service_test.go
@@ -3073,3 +3073,100 @@
})
}
}
+
+func TestVoltApplication_GetFlowProvisionStatus(t *testing.T) {
+ type args struct {
+ portNo string
+ }
+ voltServ := &VoltService{
+ VoltServiceCfg: VoltServiceCfg{
+ Port: "SDX6320031-1",
+ IsActivated: true,
+ },
+ VoltServiceOper: VoltServiceOper{
+ Device: "SDX6320031",
+ DsHSIAFlowsApplied: true,
+ UsHSIAFlowsApplied: true,
+ },
+ }
+ tests := []struct {
+ name string
+ args args
+ want FlowProvisionStatus
+ }{
+ {
+ name: "ALL_FLOWS_PROVISIONED",
+ args: args{
+ portNo: "SDX6320031-1",
+ },
+ want: FlowProvisionStatus{
+ FlowProvisionStatus: "ALL_FLOWS_PROVISIONED",
+ },
+ },
+ {
+ name: "SUBSCRIBER_DISABLED_IN_CONTROLLER",
+ args: args{
+ portNo: "SDX6320031-1",
+ },
+ want: FlowProvisionStatus{
+ FlowProvisionStatus: "DISABLED_IN_CONTROLLER",
+ },
+ },
+ {
+ name: "FLOWS_PROVISIONED_PARTIALLY",
+ args: args{
+ portNo: "SDX6320031-1",
+ },
+ want: FlowProvisionStatus{
+ FlowProvisionStatus: "FLOWS_PROVISIONED_PARTIALLY",
+ },
+ },
+ {
+ name: "NO_FLOWS_PROVISIONED",
+ args: args{
+ portNo: "SDX6320031-1",
+ },
+ want: FlowProvisionStatus{
+ FlowProvisionStatus: "NO_FLOWS_PROVISIONED",
+ },
+ },
+ }
+ for _, tt := range tests {
+ t.Run(tt.name, func(t *testing.T) {
+ va := &VoltApplication{}
+ switch tt.name {
+ case "ALL_FLOWS_PROVISIONED":
+ va.ServiceByName.Store("SCOM00001c75-1_SCOM00001c75-1-4096-2310-4096-65", voltServ)
+ if got := va.GetFlowProvisionStatus(tt.args.portNo); !reflect.DeepEqual(got, tt.want) {
+ t.Errorf("VoltApplication.GetFlowProvisionStatus() = %v, want %v", got, tt.want)
+ }
+ case "SUBSCRIBER_DISABLED_IN_CONTROLLER":
+ voltServ1 := &VoltService{
+ VoltServiceCfg: VoltServiceCfg{
+ Port: "SDX6320031-1",
+ IsActivated: false,
+ },
+ }
+ va.ServiceByName.Store("SCOM00001c75-1_SCOM00001c75-1-4096-2310-4096-65", voltServ1)
+ if got := va.GetFlowProvisionStatus(tt.args.portNo); !reflect.DeepEqual(got, tt.want) {
+ t.Errorf("VoltApplication.GetFlowProvisionStatus() = %v, want %v", got, tt.want)
+ }
+ case "FLOWS_PROVISIONED_PARTIALLY":
+ pendingFlows := map[string]bool{}
+ pendingFlows["test"] = true
+ voltServ.PendingFlows = pendingFlows
+ va.ServiceByName.Store("SCOM00001c75-1_SCOM00001c75-1-4096-2310-4096-65", voltServ)
+ if got := va.GetFlowProvisionStatus(tt.args.portNo); !reflect.DeepEqual(got, tt.want) {
+ t.Errorf("VoltApplication.GetFlowProvisionStatus() = %v, want %v", got, tt.want)
+ }
+ case "NO_FLOWS_PROVISIONED":
+ voltServ.UsHSIAFlowsApplied = false
+ voltServ.DsHSIAFlowsApplied = false
+ va.ServiceByName.Store("SCOM00001c75-1_SCOM00001c75-1-4096-2310-4096-65", voltServ)
+ if got := va.GetFlowProvisionStatus(tt.args.portNo); !reflect.DeepEqual(got, tt.want) {
+ t.Errorf("VoltApplication.GetFlowProvisionStatus() = %v, want %v", got, tt.want)
+ }
+ }
+ })
+ }
+}
diff --git a/internal/pkg/application/vnets_test.go b/internal/pkg/application/vnets_test.go
index 5a26bea..a8353d6 100644
--- a/internal/pkg/application/vnets_test.go
+++ b/internal/pkg/application/vnets_test.go
@@ -28,8 +28,10 @@
"voltha-go-controller/internal/test/mocks"
"github.com/golang/mock/gomock"
+ "github.com/google/gopacket/layers"
"github.com/opencord/voltha-lib-go/v7/pkg/db/kvstore"
"github.com/stretchr/testify/assert"
+ "go.uber.org/atomic"
)
func TestVoltPortVnet_JSONMarshal(t *testing.T) {
@@ -894,3 +896,470 @@
})
}
}
+
+func TestNewVoltPortVnet(t *testing.T) {
+ type args struct {
+ vnet *VoltVnet
+ }
+ usDhcpPbit := []of.PbitType{}
+ usDhcpPbit = append(usDhcpPbit, PbitMatchNone)
+ tests := []struct {
+ name string
+ args args
+ want *VoltPortVnet
+ }{
+ {
+ name: "NewVoltPortVnet",
+ args: args{
+ vnet: &VoltVnet{
+ VnetConfig: VnetConfig{
+ UsDhcpPbit: usDhcpPbit,
+ },
+ },
+ },
+ want: &VoltPortVnet{},
+ },
+ }
+ for _, tt := range tests {
+ t.Run(tt.name, func(t *testing.T) {
+ got := NewVoltPortVnet(tt.args.vnet)
+ assert.NotNil(t, got)
+ })
+ }
+}
+
+func TestVoltPortVnet_GetCircuitID(t *testing.T) {
+ vpv := &VoltPortVnet{}
+ got := vpv.GetCircuitID()
+ assert.Nil(t, got)
+ got1 := vpv.GetRemoteID()
+ assert.Nil(t, got1)
+ got3 := vpv.GetDhcpState()
+ assert.NotNil(t, got3)
+ got4 := vpv.GetPppoeIaState()
+ assert.NotNil(t, got4)
+ got5 := vpv.GetDhcpv6State()
+ assert.NotNil(t, got5)
+}
+
+func TestVoltPortVnet_GetNniVlans(t *testing.T) {
+ tests := []struct {
+ name string
+ want uint16
+ want1 uint16
+ }{
+ {
+ name: "GetNniVlans",
+ want: uint16(of.VlanAny),
+ want1: uint16(of.VlanAny),
+ },
+ {
+ name: "GetNniVlans_OLTSVlan",
+ want: uint16(of.VlanAny),
+ want1: uint16(of.VlanNone),
+ },
+ {
+ name: "GetNniVlans_Default",
+ want: uint16(of.VlanNone),
+ want1: uint16(of.VlanNone),
+ },
+ }
+ for _, tt := range tests {
+ t.Run(tt.name, func(t *testing.T) {
+ vpv := &VoltPortVnet{
+ VlanControl: ONUCVlanOLTSVlan,
+ SVlan: of.VlanAny,
+ CVlan: of.VlanAny,
+ }
+ switch tt.name {
+ case "GetNniVlans":
+ got, got1 := vpv.GetNniVlans()
+ if got != tt.want {
+ t.Errorf("VoltPortVnet.GetNniVlans() got = %v, want %v", got, tt.want)
+ }
+ if got1 != tt.want1 {
+ t.Errorf("VoltPortVnet.GetNniVlans() got1 = %v, want %v", got1, tt.want1)
+ }
+ case "GetNniVlans_OLTSVlan":
+ vpv.VlanControl = OLTSVlan
+ got, got1 := vpv.GetNniVlans()
+ if got != tt.want {
+ t.Errorf("VoltPortVnet.GetNniVlans() got = %v, want %v", got, tt.want)
+ }
+ if got1 != tt.want1 {
+ t.Errorf("VoltPortVnet.GetNniVlans() got1 = %v, want %v", got1, tt.want1)
+ }
+ case "GetNniVlans_Default":
+ vpv.VlanControl = opt82
+ got, got1 := vpv.GetNniVlans()
+ if got != tt.want {
+ t.Errorf("VoltPortVnet.GetNniVlans() got = %v, want %v", got, tt.want)
+ }
+ if got1 != tt.want1 {
+ t.Errorf("VoltPortVnet.GetNniVlans() got1 = %v, want %v", got1, tt.want1)
+ }
+ }
+ })
+ }
+}
+
+func TestVoltPortVnet_GetService(t *testing.T) {
+ type args struct {
+ name string
+ }
+ voltServ := &VoltService{
+ VoltServiceOper: VoltServiceOper{
+ Device: "SDX6320031",
+ },
+ VoltServiceCfg: VoltServiceCfg{
+ IsActivated: true,
+ },
+ }
+ tests := []struct {
+ name string
+ args args
+ want *VoltService
+ want1 bool
+ }{
+ {
+ name: "GetService",
+ args: args{
+ name: "SDX6320031-1_SDX6320031-1-4096-2310-4096-65",
+ },
+ want: voltServ,
+ want1: true,
+ },
+ }
+ for _, tt := range tests {
+ t.Run(tt.name, func(t *testing.T) {
+ vpv := &VoltPortVnet{}
+ vpv.services.Store("SDX6320031-1_SDX6320031-1-4096-2310-4096-65", voltServ)
+ got, got1 := vpv.GetService(tt.args.name)
+ if !reflect.DeepEqual(got, tt.want) {
+ t.Errorf("VoltPortVnet.GetService() got = %v, want %v", got, tt.want)
+ }
+ if got1 != tt.want1 {
+ t.Errorf("VoltPortVnet.GetService() got1 = %v, want %v", got1, tt.want1)
+ }
+ })
+ }
+}
+
+func TestVoltPortVnet_ProcessDhcpSuccess(t *testing.T) {
+ type args struct {
+ cntx context.Context
+ res *layers.DHCPv4
+ }
+ tests := []struct {
+ name string
+ args args
+ }{
+ {
+ name: "ProcessDhcpSuccess",
+ args: args{
+ cntx: context.Background(),
+ res: &layers.DHCPv4{},
+ },
+ },
+ }
+ for _, tt := range tests {
+ t.Run(tt.name, func(t *testing.T) {
+ vpv := &VoltPortVnet{
+ servicesCount: atomic.NewUint64(0),
+ }
+ vpv.ProcessDhcpSuccess(tt.args.cntx, tt.args.res)
+ })
+ }
+}
+
+func TestVoltPortVnet_ProcessDhcpResult(t *testing.T) {
+ type args struct {
+ cntx context.Context
+ res *layers.DHCPv4
+ }
+ tests := []struct {
+ name string
+ args args
+ }{
+ {
+ name: "ProcessDhcpResult",
+ args: args{
+ cntx: context.Background(),
+ res: &layers.DHCPv4{},
+ },
+ },
+ }
+ for _, tt := range tests {
+ t.Run(tt.name, func(t *testing.T) {
+ vpv := &VoltPortVnet{}
+ dbintf := mocks.NewMockDBIntf(gomock.NewController(t))
+ db = dbintf
+ dbintf.EXPECT().PutVpv(gomock.Any(), gomock.Any(), gomock.Any(), gomock.Any(), gomock.Any(), gomock.Any()).Return(nil).AnyTimes()
+ vpv.ProcessDhcpResult(tt.args.cntx, tt.args.res)
+ })
+ }
+}
+
+func TestVoltVnet_associatePortToVnet(t *testing.T) {
+ type args struct {
+ port string
+ }
+ tests := []struct {
+ name string
+ args args
+ }{
+ {
+ name: "ProcessDhcpResult",
+ args: args{
+ port: "SDX6320031-1",
+ },
+ },
+ }
+ for _, tt := range tests {
+ t.Run(tt.name, func(t *testing.T) {
+ vv := &VoltVnet{}
+ vv.associatePortToVnet(tt.args.port)
+ })
+ }
+}
+
+func TestVoltPortVnet_ProcessDhcpv6Result(t *testing.T) {
+ type args struct {
+ cntx context.Context
+ ipv6Addr net.IP
+ leaseTime uint32
+ }
+ tests := []struct {
+ name string
+ args args
+ }{
+ {
+ name: "ProcessDhcpResult",
+ args: args{
+ cntx: context.Background(),
+ ipv6Addr: AllSystemsMulticastGroupIP,
+ leaseTime: uint32(128),
+ },
+ },
+ }
+ for _, tt := range tests {
+ t.Run(tt.name, func(t *testing.T) {
+ vpv := &VoltPortVnet{}
+ dbintf := mocks.NewMockDBIntf(gomock.NewController(t))
+ db = dbintf
+ dbintf.EXPECT().PutVpv(gomock.Any(), gomock.Any(), gomock.Any(), gomock.Any(), gomock.Any(), gomock.Any()).Return(nil).AnyTimes()
+ vpv.ProcessDhcpv6Result(tt.args.cntx, tt.args.ipv6Addr, tt.args.leaseTime)
+ })
+ }
+}
+
+func TestAddSvcUsMeterToDevice(t *testing.T) {
+ type args struct {
+ cntx context.Context
+ key interface{}
+ value interface{}
+ flag bool
+ }
+ vpv := &VoltApplication{}
+ voltServ := &VoltService{
+ VoltServiceOper: VoltServiceOper{
+ Device: test_device,
+ ForceDelete: true,
+ },
+ }
+ vpv.ServiceByName.Store(test_device, voltServ)
+ tests := []struct {
+ name string
+ args args
+ want bool
+ }{
+ {
+ name: "ProcessDhcpResult",
+ args: args{
+ cntx: context.Background(),
+ key: test_device,
+ value: voltServ,
+ },
+ },
+ }
+ for _, tt := range tests {
+ t.Run(tt.name, func(t *testing.T) {
+ if got := AddSvcUsMeterToDevice(tt.args.cntx, tt.args.key, tt.args.value, tt.args.flag); got != tt.want {
+ t.Errorf("AddSvcUsMeterToDevice() = %v, want %v", got, tt.want)
+ }
+ })
+ }
+}
+
+func TestClearFlagsInService(t *testing.T) {
+ type args struct {
+ cntx context.Context
+ key interface{}
+ value interface{}
+ flag bool
+ }
+ vpv := &VoltPortVnet{}
+ voltServ := &VoltService{
+ VoltServiceOper: VoltServiceOper{
+ Device: "SDX6320031",
+ },
+ VoltServiceCfg: VoltServiceCfg{
+ IsActivated: true,
+ },
+ }
+ vpv.services.Store("SDX6320031-1_SDX6320031-1-4096-2310-4096-65", voltServ)
+ tests := []struct {
+ name string
+ args args
+ want bool
+ }{
+ {
+ name: "ClearFlagsInService",
+ args: args{
+ cntx: context.Background(),
+ key: test_device,
+ value: voltServ,
+ },
+ },
+ }
+ for _, tt := range tests {
+ t.Run(tt.name, func(t *testing.T) {
+ dbintf := mocks.NewMockDBIntf(gomock.NewController(t))
+ db = dbintf
+ dbintf.EXPECT().PutService(gomock.Any(), gomock.Any(), gomock.Any()).Return(nil).AnyTimes()
+ got := ClearFlagsInService(tt.args.cntx, tt.args.key, tt.args.value, tt.args.flag)
+ assert.NotNil(t, got)
+ })
+ }
+}
+
+func TestVoltPortVnet_DelDhcpFlows(t *testing.T) {
+ type args struct {
+ cntx context.Context
+ }
+ tests := []struct {
+ name string
+ args args
+ }{
+ {
+ name: "DelDhcpFlows",
+ args: args{
+ cntx: context.Background(),
+ },
+ },
+ }
+ for _, tt := range tests {
+ t.Run(tt.name, func(t *testing.T) {
+ vpv := &VoltPortVnet{}
+ vpv.DelDhcpFlows(tt.args.cntx)
+ })
+ }
+}
+
+func TestVoltPortVnet_AddDsDhcpFlows(t *testing.T) {
+ type args struct {
+ cntx context.Context
+ }
+ va := GetApplication()
+ voltDev := &VoltDevice{
+ Name: "49686e2d-618f-4e8e-bca0-442ab850a63a",
+ SerialNum: "SDX6320031",
+ NniDhcpTrapVid: 123,
+ State: cntlr.DeviceStateUP,
+ FlowAddEventMap: util.NewConcurrentMap(),
+ }
+ va.DevicesDisc.Store("SDX6320031", voltDev)
+ voltPort := &VoltPort{
+ Name: "49686e2d-618f-4e8e-bca0-442ab850a63a",
+ Device: "SDX6320031",
+ ID: 16777472,
+ State: PortStateDown,
+ ChannelPerSubAlarmRaised: false,
+ Type: VoltPortTypeNni,
+ }
+ tests := []struct {
+ name string
+ args args
+ wantErr bool
+ }{
+ {
+ name: "AddDsDhcpFlows",
+ args: args{
+ cntx: context.Background(),
+ },
+ },
+ {
+ name: "AddDsDhcpFlows_DeviceNotFound",
+ args: args{
+ cntx: context.Background(),
+ },
+ wantErr: true,
+ },
+ {
+ name: "AddDsDhcpFlows_StateDown",
+ args: args{
+ cntx: context.Background(),
+ },
+ },
+ {
+ name: "AddDsDhcpFlows_GlobalDhcpFlowAdded",
+ args: args{
+ cntx: context.Background(),
+ },
+ },
+ {
+ name: "AddDsDhcpFlows_PositiveSenario",
+ args: args{
+ cntx: context.Background(),
+ },
+ },
+ }
+ for _, tt := range tests {
+ t.Run(tt.name, func(t *testing.T) {
+ vpv := &VoltPortVnet{
+ Device: "SDX6320031",
+ }
+ switch tt.name {
+ case "AddDsDhcpFlows":
+ if err := vpv.AddDsDhcpFlows(tt.args.cntx); (err != nil) != tt.wantErr {
+ t.Errorf("VoltPortVnet.AddDsDhcpFlows() error = %v, wantErr %v", err, tt.wantErr)
+ }
+ case "AddDsDhcpFlows_DeviceNotFound":
+ vpv.Device = ""
+ if err := vpv.AddDsDhcpFlows(tt.args.cntx); (err != nil) != tt.wantErr {
+ t.Errorf("VoltPortVnet.AddDsDhcpFlows() error = %v, wantErr %v", err, tt.wantErr)
+ }
+ case "AddDsDhcpFlows_StateDown":
+ voltDev.State = cntlr.DeviceStateDOWN
+ if err := vpv.AddDsDhcpFlows(tt.args.cntx); (err != nil) != tt.wantErr {
+ t.Errorf("VoltPortVnet.AddDsDhcpFlows() error = %v, wantErr %v", err, tt.wantErr)
+ }
+ case "AddDsDhcpFlows_GlobalDhcpFlowAdded":
+ vpv.Device = "SDX6320031"
+ voltDev.State = cntlr.DeviceStateUP
+ voltDev.GlobalDhcpFlowAdded = true
+ if err := vpv.AddDsDhcpFlows(tt.args.cntx); (err != nil) != tt.wantErr {
+ t.Errorf("VoltPortVnet.AddDsDhcpFlows() error = %v, wantErr %v", err, tt.wantErr)
+ }
+ case "AddDsDhcpFlows_PositiveSenario":
+ vpv.Device = "SDX6320031"
+ voltDev.State = cntlr.DeviceStateUP
+ voltDev.GlobalDhcpFlowAdded = false
+ voltDev.NniPort = "16777472"
+ va.PortsDisc.Store("16777472", voltPort)
+ appMock := mocks.NewMockApp(gomock.NewController(t))
+ cntlr.NewController(ctx, appMock)
+ vc := cntlr.GetController()
+ device := &cntlr.Device{
+ ID: "SDX6320031",
+ }
+ dev := map[string]*cntlr.Device{}
+ dev["SDX6320031"] = device
+ vc.Devices = dev
+ if err := vpv.AddDsDhcpFlows(tt.args.cntx); (err != nil) != tt.wantErr {
+ t.Errorf("VoltPortVnet.AddDsDhcpFlows() error = %v, wantErr %v", err, tt.wantErr)
+ }
+ }
+ })
+ }
+}
diff --git a/internal/pkg/controller/controller.go b/internal/pkg/controller/controller.go
index 7e1a726..c31d892 100644
--- a/internal/pkg/controller/controller.go
+++ b/internal/pkg/controller/controller.go
@@ -68,7 +68,7 @@
BlockedDeviceList *util.ConcurrentMap
deviceTaskQueue *util.ConcurrentMap
vagent map[string]*vpagent.VPAgent
- devices map[string]*Device
+ Devices map[string]*Device
rebootInProgressDevices map[string]string
deviceLock sync.RWMutex
rebootLock sync.Mutex
@@ -83,7 +83,7 @@
var controller VoltController
controller.rebootInProgressDevices = make(map[string]string)
- controller.devices = make(map[string]*Device)
+ controller.Devices = make(map[string]*Device)
controller.deviceLock = sync.RWMutex{}
controller.ctx = ctx
controller.app = app
@@ -108,7 +108,7 @@
// AddDevice to add device
func (v *VoltController) AddDevice(cntx context.Context, config *intf.VPClientCfg) intf.IVPClient {
d := NewDevice(cntx, config.DeviceID, config.SerialNum, config.VolthaClient, config.SouthBoundID, config.MfrDesc, config.HwDesc, config.SwDesc)
- v.devices[config.DeviceID] = d
+ v.Devices[config.DeviceID] = d
v.app.AddDevice(cntx, d.ID, d.SerialNum, config.SouthBoundID)
d.RestoreMetersFromDb(cntx)
@@ -125,9 +125,9 @@
// DelDevice to delete device
func (v *VoltController) DelDevice(cntx context.Context, id string) {
- d, ok := v.devices[id]
+ d, ok := v.Devices[id]
if ok {
- delete(v.devices, id)
+ delete(v.Devices, id)
d.Delete()
}
v.app.DelDevice(cntx, id)
@@ -159,7 +159,7 @@
// GetDevice to get device info
func (v *VoltController) GetDevice(id string) (*Device, error) {
- d, ok := v.devices[id]
+ d, ok := v.Devices[id]
if ok {
return d, nil
}
@@ -572,7 +572,7 @@
// GetAllFlows returns list of all flows
func (v *VoltController) GetAllFlows() ([]*of.VoltSubFlow, error) {
var flows []*of.VoltSubFlow
- for _, d := range v.devices {
+ for _, d := range v.Devices {
flows = append(flows, d.GetAllFlows()...)
}
return flows, nil
@@ -581,7 +581,7 @@
// GetAllPendingFlows returns list of all flows
func (v *VoltController) GetAllPendingFlows() ([]*of.VoltSubFlow, error) {
var flows []*of.VoltSubFlow
- for _, d := range v.devices {
+ for _, d := range v.Devices {
flows = append(flows, d.GetAllPendingFlows()...)
}
return flows, nil
@@ -589,7 +589,7 @@
func (v *VoltController) GetAllMeterInfo() (map[string][]*of.Meter, error) {
logger.Info(ctx, "Entering into GetAllMeterInfo method")
meters := map[string][]*of.Meter{}
- for _, device := range v.devices {
+ for _, device := range v.Devices {
logger.Debugw(ctx, "Inside GetAllMeterInfo method", log.Fields{"deviceId": device.ID, "southbound": device.SouthBoundID, "serial no": device.SerialNum})
for _, meter := range device.meters {
meters[device.ID] = append(meters[device.ID], meter)
@@ -602,7 +602,7 @@
func (v *VoltController) GetMeterInfo(cntx context.Context, id uint32) (map[string]*of.Meter, error) {
logger.Info(ctx, "Entering into GetMeterInfo method")
meters := map[string]*of.Meter{}
- for _, device := range v.devices {
+ for _, device := range v.Devices {
logger.Debugw(ctx, "Inside GetMeterInfo method", log.Fields{"deviceId": device.ID})
meter, err := device.GetMeter(id)
if err != nil {
@@ -618,7 +618,7 @@
func (v *VoltController) GetGroupList() ([]*of.Group, error) {
logger.Info(ctx, "Entering into GetGroupList method")
groups := []*of.Group{}
- for _, device := range v.devices {
+ for _, device := range v.Devices {
device.groups.Range(func(key, value interface{}) bool {
groupID := key.(uint32)
logger.Debugw(ctx, "Inside GetGroupList method", log.Fields{"groupID": groupID})
@@ -639,7 +639,7 @@
func (v *VoltController) GetGroups(cntx context.Context, id uint32) (*of.Group, error) {
logger.Info(ctx, "Entering into GetGroupList method")
var groups *of.Group
- for _, device := range v.devices {
+ for _, device := range v.Devices {
logger.Debugw(ctx, "Inside GetGroupList method", log.Fields{"groupID": id})
grps, ok := device.groups.Load(id)
if !ok {
diff --git a/internal/pkg/controller/controller_test.go b/internal/pkg/controller/controller_test.go
index 235bffe..5b67d14 100644
--- a/internal/pkg/controller/controller_test.go
+++ b/internal/pkg/controller/controller_test.go
@@ -54,9 +54,8 @@
}
for _, tt := range tests {
t.Run(tt.name, func(t *testing.T) {
- if got := NewController(tt.args.ctx, tt.args.app); !reflect.DeepEqual(got, tt.want) {
- t.Errorf("NewController() = %v, want %v", got, tt.want)
- }
+ got := NewController(tt.args.ctx, tt.args.app)
+ assert.NotNil(t, got)
})
}
}
@@ -92,7 +91,7 @@
for _, tt := range tests {
t.Run(tt.name, func(t *testing.T) {
v := &VoltController{
- devices: dev,
+ Devices: dev,
app: GetController().app,
}
v.DelDevice(tt.args.cntx, tt.args.id)
@@ -164,7 +163,7 @@
for _, tt := range tests {
t.Run(tt.name, func(t *testing.T) {
v := &VoltController{
- devices: dev,
+ Devices: dev,
}
if err := v.AddFlows(tt.args.cntx, tt.args.port, tt.args.device, tt.args.flow); (err != nil) != tt.wantErr {
t.Errorf("VoltController.AddFlows() error = %v, wantErr %v", err, tt.wantErr)
@@ -237,7 +236,7 @@
for _, tt := range tests {
t.Run(tt.name, func(t *testing.T) {
v := &VoltController{
- devices: dev,
+ Devices: dev,
}
if err := v.DelFlows(tt.args.cntx, tt.args.port, tt.args.device, tt.args.flow, false); (err != nil) != tt.wantErr {
t.Errorf("VoltController.DelFlows() error = %v, wantErr %v", err, tt.wantErr)
@@ -293,7 +292,7 @@
for _, tt := range tests {
t.Run(tt.name, func(t *testing.T) {
v := &VoltController{
- devices: dev,
+ Devices: dev,
}
switch tt.name {
case "VoltController_GetGroups":
@@ -350,7 +349,7 @@
for _, tt := range tests {
t.Run(tt.name, func(t *testing.T) {
v := &VoltController{
- devices: dev,
+ Devices: dev,
}
device.groups.Store(uint32(256), grp)
got, err := v.GetGroupList()
@@ -413,7 +412,7 @@
for _, tt := range tests {
t.Run(tt.name, func(t *testing.T) {
v := &VoltController{
- devices: dev,
+ Devices: dev,
}
switch tt.name {
case "VoltController_GetMeterInfo":
@@ -471,7 +470,7 @@
for _, tt := range tests {
t.Run(tt.name, func(t *testing.T) {
v := &VoltController{
- devices: dev,
+ Devices: dev,
}
got, err := v.GetAllMeterInfo()
if (err != nil) != tt.wantErr {
@@ -583,7 +582,7 @@
for _, tt := range tests {
t.Run(tt.name, func(t *testing.T) {
v := &VoltController{
- devices: dev,
+ Devices: dev,
}
got, err := v.GetAllPendingFlows()
if (err != nil) != tt.wantErr {
@@ -602,7 +601,7 @@
for _, tt := range tests1 {
t.Run(tt.name, func(t *testing.T) {
v := &VoltController{
- devices: dev,
+ Devices: dev,
}
switch tt.name {
case "GetFlows_with_DeviceID":
@@ -625,7 +624,7 @@
for _, tt := range tests2 {
t.Run(tt.name, func(t *testing.T) {
v := &VoltController{
- devices: dev,
+ Devices: dev,
}
switch tt.name {
case "GetFlow_with_DeviceID_and_cookie":
@@ -680,7 +679,7 @@
for _, tt := range tests {
t.Run(tt.name, func(t *testing.T) {
v := &VoltController{
- devices: dev,
+ Devices: dev,
}
switch tt.name {
case "GetTaskList":
@@ -740,7 +739,7 @@
for _, tt := range tests {
t.Run(tt.name, func(t *testing.T) {
v := &VoltController{
- devices: dev,
+ Devices: dev,
}
switch tt.name {
case "GetPortState":
@@ -826,7 +825,7 @@
for _, tt := range tests {
t.Run(tt.name, func(t *testing.T) {
v := &VoltController{
- devices: dev,
+ Devices: dev,
}
switch tt.name {
case "ModMeter":
@@ -947,7 +946,7 @@
type args struct {
device string
}
- rebootInProgressdevices := map[string]string{}
+ rebootInProgressDevices := map[string]string{}
device := &Device{
ctx: context.Background(),
ID: "SDX6320031",
@@ -977,8 +976,8 @@
for _, tt := range tests {
t.Run(tt.name, func(t *testing.T) {
v := &VoltController{
- rebootInProgressDevices: rebootInProgressdevices,
- devices: dev,
+ rebootInProgressDevices: rebootInProgressDevices,
+ Devices: dev,
}
switch tt.name {
case "SetRebootInProgressForDevice":
@@ -998,12 +997,12 @@
type args struct {
device string
}
- rebootInProgressdevices := map[string]string{}
+ rebootInProgressDevices := map[string]string{}
device := &Device{
ctx: context.Background(),
ID: "SDX6320031",
}
- rebootInProgressdevices["SDX6320031"] = "done"
+ rebootInProgressDevices["SDX6320031"] = "done"
dev := map[string]*Device{}
dev["SDX6320031"] = device
tests := []struct {
@@ -1022,8 +1021,8 @@
for _, tt := range tests {
t.Run(tt.name, func(t *testing.T) {
v := &VoltController{
- rebootInProgressDevices: rebootInProgressdevices,
- devices: dev,
+ rebootInProgressDevices: rebootInProgressDevices,
+ Devices: dev,
}
if got := v.ReSetRebootInProgressForDevice(tt.args.device); got != tt.want {
t.Errorf("VoltController.ReSetRebootInProgressForDevice() = %v, want %v", got, tt.want)
@@ -1034,7 +1033,7 @@
func TestVoltController_IsBlockedDevice(t *testing.T) {
type args struct {
- deviceserialNumber string
+ DeviceserialNumber string
}
tests := []struct {
name string
@@ -1044,21 +1043,21 @@
{
name: "IsBlockedDevice",
args: args{
- deviceserialNumber: "SDX6320031",
+ DeviceserialNumber: "SDX6320031",
},
want: false,
},
{
- name: "deviceserialNumber",
+ name: "DeviceserialNumber",
args: args{
- deviceserialNumber: "SDX6320031",
+ DeviceserialNumber: "SDX6320031",
},
want: false,
},
{
- name: "AddBlockeddevices",
+ name: "AddBlockedDevices",
args: args{
- deviceserialNumber: "SDX6320031",
+ DeviceserialNumber: "SDX6320031",
},
want: false,
},
@@ -1070,13 +1069,13 @@
}
switch tt.name {
case "IsBlockedDevice":
- if got := v.IsBlockedDevice(tt.args.deviceserialNumber); got != tt.want {
+ if got := v.IsBlockedDevice(tt.args.DeviceserialNumber); got != tt.want {
t.Errorf("VoltController.IsBlockedDevice() = %v, want %v", got, tt.want)
}
- case "deviceserialNumber":
- v.DelBlockedDevices(tt.args.deviceserialNumber)
- case "AddBlockeddevices":
- v.AddBlockedDevices(tt.args.deviceserialNumber)
+ case "DeviceserialNumber":
+ v.DelBlockedDevices(tt.args.DeviceserialNumber)
+ case "AddBlockedDevices":
+ v.AddBlockedDevices(tt.args.DeviceserialNumber)
}
})
}
@@ -1206,7 +1205,7 @@
switch tt.name {
case "GroupUpdate", "DeviceNOtFound_Error", "PortNOtFound_Error":
v := &VoltController{
- devices: dev,
+ Devices: dev,
}
if err := v.GroupUpdate(tt.args.port, tt.args.device, tt.args.group); (err != nil) != tt.wantErr {
t.Errorf("VoltController.GroupUpdate() error = %v, wantErr %v", err, tt.wantErr)
@@ -1220,7 +1219,7 @@
dev := map[string]*Device{}
dev["SDX6320031"] = device
v := &VoltController{
- devices: dev,
+ Devices: dev,
}
if err := v.GroupUpdate(tt.args.port, tt.args.device, tt.args.group); (err != nil) != tt.wantErr {
t.Errorf("VoltController.GroupUpdate() error = %v, wantErr %v", err, tt.wantErr)