[VOL-5403] Changed the devices map in volthaController from normal map to sync map

Signed-off-by: bseeniva <balaji.seenivasan@radisys.com>
Change-Id: Ibbb3dcc7555d1325ae8dc205e22ccd94478c1ddd
diff --git a/internal/pkg/application/vnets_test.go b/internal/pkg/application/vnets_test.go
index f224278..d0f56ae 100644
--- a/internal/pkg/application/vnets_test.go
+++ b/internal/pkg/application/vnets_test.go
@@ -690,7 +690,6 @@
 				appMock := mocks.NewMockApp(gomock.NewController(t))
 				cntlr.NewController(ctx, appMock)
 				vc := cntlr.GetController()
-				dev := map[string]*cntlr.Device{}
 				portsByName := map[string]*cntlr.DevicePort{}
 				portsByName["16777472"] = &cntlr.DevicePort{
 					Name:  "16777472",
@@ -701,8 +700,7 @@
 					ID:          "SDX6320031",
 					PortsByName: portsByName,
 				}
-				dev["SDX6320031"] = device
-				vc.Devices = dev
+				vc.Devices.Store("SDX6320031", device)
 				va.DeleteDevFlowForVlanFromDevice(tt.args.cntx, tt.args.vnet, tt.args.deviceSerialNum)
 			case "DeleteDevFlowForVlanFromDevice_PortStateDown":
 				voltDev.Name = ""
@@ -713,7 +711,6 @@
 				appMock := mocks.NewMockApp(gomock.NewController(t))
 				cntlr.NewController(ctx, appMock)
 				vc := cntlr.GetController()
-				dev := map[string]*cntlr.Device{}
 				portsByName := map[string]*cntlr.DevicePort{}
 				portsByName["16777472"] = &cntlr.DevicePort{
 					Name:  "16777472",
@@ -724,8 +721,7 @@
 					ID:          "SDX6320031",
 					PortsByName: portsByName,
 				}
-				dev["SDX6320031"] = device
-				vc.Devices = dev
+				vc.Devices.Store("SDX6320031", device)
 				va.DeleteDevFlowForVlanFromDevice(tt.args.cntx, tt.args.vnet, tt.args.deviceSerialNum)
 			}
 		})
@@ -834,7 +830,6 @@
 				appMock := mocks.NewMockApp(gomock.NewController(t))
 				cntlr.NewController(ctx, appMock)
 				vc := cntlr.GetController()
-				dev := map[string]*cntlr.Device{}
 				portsByName := map[string]*cntlr.DevicePort{}
 				portsByName["16777472"] = &cntlr.DevicePort{
 					Name:  "16777472",
@@ -845,8 +840,7 @@
 					ID:          "SDX6320031",
 					PortsByName: portsByName,
 				}
-				dev["SDX6320031"] = device
-				vc.Devices = dev
+				vc.Devices.Store("SDX6320031", device)
 				va.DeleteDevFlowForDevice(tt.args.cntx, tt.args.device)
 			}
 		})
@@ -1657,7 +1651,6 @@
 			appMock := mocks.NewMockApp(gomock.NewController(t))
 			cntlr.NewController(ctx, appMock)
 			vc := cntlr.GetController()
-			dev := map[string]*cntlr.Device{}
 			portsByName := map[string]*cntlr.DevicePort{}
 			portsByName["16777472"] = &cntlr.DevicePort{
 				Name: "16777472",
@@ -1667,8 +1660,7 @@
 				ID:          deviceName,
 				PortsByName: portsByName,
 			}
-			dev["SDX6320031"] = device
-			vc.Devices = dev
+			vc.Devices.Store("SDX6320031", device)
 			switch tt.name {
 			case "AddUsArpFlows":
 				if err := vpv.AddUsArpFlows(tt.args.cntx); (err != nil) != tt.wantErr {
@@ -1787,9 +1779,7 @@
 				device := &cntlr.Device{
 					ID: "SDX6320031",
 				}
-				dev := map[string]*cntlr.Device{}
-				dev["SDX6320031"] = device
-				vc.Devices = dev
+				vc.Devices.Store("SDX6320031", device)
 				if err := vpv.AddDsDhcpFlows(tt.args.cntx); (err != nil) != tt.wantErr {
 					t.Errorf("VoltPortVnet.AddDsDhcpFlows() error = %v, wantErr %v", err, tt.wantErr)
 				}
@@ -1867,9 +1857,7 @@
 				device := &cntlr.Device{
 					ID: "SDX6320031",
 				}
-				dev := map[string]*cntlr.Device{}
-				dev["SDX6320031"] = device
-				vc.Devices = dev
+				vc.Devices.Store("SDX6320031", device)
 				if err := vpv.AddUsDhcpFlows(tt.args.cntx); (err != nil) != tt.wantErr {
 					t.Errorf("VoltPortVnet.AddDsDhcpFlows() error = %v, wantErr %v", err, tt.wantErr)
 				}
@@ -1979,7 +1967,6 @@
 				appMock := mocks.NewMockApp(gomock.NewController(t))
 				cntlr.NewController(ctx, appMock)
 				vc := cntlr.GetController()
-				dev := map[string]*cntlr.Device{}
 				portsByName := map[string]*cntlr.DevicePort{}
 				portsByName["16777472"] = &cntlr.DevicePort{
 					Name: "16777472",
@@ -1989,8 +1976,7 @@
 					ID:          "SDX6320031",
 					PortsByName: portsByName,
 				}
-				dev["SDX6320031"] = device
-				vc.Devices = dev
+				vc.Devices.Store("SDX6320031", device)
 				if err := vpv.AddDsPppoeFlows(tt.args.cntx); (err != nil) != tt.wantErr {
 					t.Errorf("VoltPortVnet.AddUsPppoeFlows() error = %v, wantErr %v", err, tt.wantErr)
 				}
@@ -2485,7 +2471,6 @@
 	appMock := mocks.NewMockApp(gomock.NewController(t))
 	controller.NewController(ctx, appMock)
 	vc := cntlr.GetController()
-	dev := map[string]*cntlr.Device{}
 	portsByName := map[string]*cntlr.DevicePort{}
 	portsByName["16777472"] = &cntlr.DevicePort{
 		Name: "16777472",
@@ -2495,8 +2480,7 @@
 		ID:          deviceName,
 		PortsByName: portsByName,
 	}
-	dev["SDX6320031"] = device
-	vc.Devices = dev
+	vc.Devices.Store("SDX6320031", device)
 	tests := []struct {
 		name    string
 		args    args
@@ -2595,7 +2579,6 @@
 				appMock := mocks.NewMockApp(gomock.NewController(t))
 				cntlr.NewController(ctx, appMock)
 				vc := cntlr.GetController()
-				dev := map[string]*cntlr.Device{}
 				portsByName := map[string]*cntlr.DevicePort{}
 				portsByName["16777472"] = &cntlr.DevicePort{
 					Name:  "16777472",
@@ -2606,8 +2589,7 @@
 					ID:          "SDX6320031",
 					PortsByName: portsByName,
 				}
-				dev["SDX6320031"] = device
-				vc.Devices = dev
+				vc.Devices.Store("SDX6320031", device)
 				va.DeleteDevFlowForVlan(tt.args.cntx, tt.args.vnet)
 			case "DeleteDevFlowForVlan_PortStateDown":
 				voltDev.Name = ""
@@ -2618,7 +2600,6 @@
 				appMock := mocks.NewMockApp(gomock.NewController(t))
 				cntlr.NewController(ctx, appMock)
 				vc := cntlr.GetController()
-				dev := map[string]*cntlr.Device{}
 				portsByName := map[string]*cntlr.DevicePort{}
 				portsByName["16777472"] = &cntlr.DevicePort{
 					Name:  "16777472",
@@ -2629,8 +2610,7 @@
 					ID:          "SDX6320031",
 					PortsByName: portsByName,
 				}
-				dev["SDX6320031"] = device
-				vc.Devices = dev
+				vc.Devices.Store("SDX6320031", device)
 				va.DeleteDevFlowForVlan(tt.args.cntx, tt.args.vnet)
 			}
 		})
diff --git a/internal/pkg/controller/controller.go b/internal/pkg/controller/controller.go
index 7d974f8..d04e00e 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                 sync.Map
 	rebootInProgressDevices map[string]string
 	deviceLock              sync.RWMutex
 	rebootLock              sync.Mutex
@@ -85,7 +85,6 @@
 	var controller VoltController
 
 	controller.rebootInProgressDevices = make(map[string]string)
-	controller.Devices = make(map[string]*Device)
 	controller.deviceLock = sync.RWMutex{}
 	controller.ctx = ctx
 	controller.app = app
@@ -125,7 +124,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.Store(config.DeviceID, d)
 	v.app.AddDevice(cntx, d.ID, d.SerialNum, config.SouthBoundID)
 
 	d.RestoreMetersFromDb(cntx)
@@ -142,13 +141,17 @@
 
 // DelDevice to delete device
 func (v *VoltController) DelDevice(cntx context.Context, id string) {
-	d, ok := v.Devices[id]
+	var device *Device
+	d, ok := v.Devices.Load(id)
 	if ok {
-		delete(v.Devices, id)
-		d.Delete()
+		v.Devices.Delete(id)
+		device, ok = d.(*Device)
+		if ok {
+			device.Delete()
+		}
 	}
 	v.app.DelDevice(cntx, id)
-	d.cancel() // To stop the device tables sync routine
+	device.cancel() // To stop the device tables sync routine
 	logger.Debugw(ctx, "Deleted device", log.Fields{"Device": id})
 }
 
@@ -176,9 +179,14 @@
 
 // GetDevice to get device info
 func (v *VoltController) GetDevice(id string) (*Device, error) {
-	d, ok := v.Devices[id]
+	var device *Device
+	d, ok := v.Devices.Load(id)
+	if !ok {
+		return nil, errorCodes.ErrDeviceNotFound
+	}
+	device, ok = d.(*Device)
 	if ok {
-		return d, nil
+		return device, nil
 	}
 	return nil, errorCodes.ErrDeviceNotFound
 }
@@ -593,45 +601,66 @@
 // GetAllFlows returns list of all flows
 func (v *VoltController) GetAllFlows() ([]*of.VoltSubFlow, error) {
 	var flows []*of.VoltSubFlow
-	for _, d := range v.Devices {
-		flows = append(flows, d.GetAllFlows()...)
-	}
+	v.Devices.Range(func(_, value interface{}) bool {
+		d, ok := value.(*Device)
+		if ok {
+			flows = append(flows, d.GetAllFlows()...)
+		}
+		return true
+	})
 	return flows, nil
 }
 
 // GetAllPendingFlows returns list of all flows
 func (v *VoltController) GetAllPendingFlows() ([]*of.VoltSubFlow, error) {
 	var flows []*of.VoltSubFlow
-	for _, d := range v.Devices {
-		flows = append(flows, d.GetAllPendingFlows()...)
-	}
+	v.Devices.Range(func(_, value interface{}) bool {
+		d, ok := value.(*Device)
+		if ok {
+			flows = append(flows, d.GetAllPendingFlows()...)
+		}
+		return true
+	})
 	return flows, nil
 }
 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 {
-		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)
+	v.Devices.Range(func(_, value interface{}) bool {
+		device, ok := value.(*Device)
+		if ok {
+			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)
+			}
+			logger.Debugw(ctx, "Inside GetAllMeterInfo method", log.Fields{"meters": meters})
 		}
-		logger.Debugw(ctx, "Inside GetAllMeterInfo method", log.Fields{"meters": meters})
-	}
+		return true
+	})
 	return meters, nil
 }
 
 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 {
-		logger.Debugw(ctx, "Inside GetMeterInfo method", log.Fields{"deviceId": device.ID})
-		meter, err := device.GetMeter(id)
-		if err != nil {
-			logger.Errorw(ctx, "Failed to fetch the meter", log.Fields{"Reason": err.Error()})
-			return nil, err
+	var errResult error
+	v.Devices.Range(func(_, value interface{}) bool {
+		device, ok := value.(*Device)
+		if ok {
+			logger.Debugw(ctx, "Inside GetMeterInfo method", log.Fields{"deviceId": device.ID})
+			meter, err := device.GetMeter(id)
+			if err != nil {
+				logger.Errorw(ctx, "Failed to fetch the meter", log.Fields{"Reason": err.Error()})
+				errResult = err
+				return false
+			}
+			meters[device.ID] = meter
+			logger.Debugw(ctx, "meters", log.Fields{"Meter": meters})
 		}
-		meters[device.ID] = meter
-		logger.Debugw(ctx, "meters", log.Fields{"Meter": meters})
+		return true
+	})
+	if errResult != nil {
+		return nil, errResult
 	}
 	return meters, nil
 }
@@ -639,20 +668,24 @@
 func (v *VoltController) GetGroupList() ([]*of.Group, error) {
 	logger.Info(ctx, "Entering into GetGroupList method")
 	groups := []*of.Group{}
-	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})
-			//Obtain all groups associated with the device
-			grps, ok := device.groups.Load(groupID)
-			if !ok {
+	v.Devices.Range(func(_, value interface{}) bool {
+		device, ok := value.(*Device)
+		if ok {
+			device.groups.Range(func(key, value interface{}) bool {
+				groupID := key.(uint32)
+				logger.Debugw(ctx, "Inside GetGroupList method", log.Fields{"groupID": groupID})
+				//Obtain all groups associated with the device
+				grps, ok := device.groups.Load(groupID)
+				if !ok {
+					return true
+				}
+				grp := grps.(*of.Group)
+				groups = append(groups, grp)
 				return true
-			}
-			grp := grps.(*of.Group)
-			groups = append(groups, grp)
-			return true
-		})
-	}
+			})
+		}
+		return true
+	})
 	logger.Debugw(ctx, "Groups", log.Fields{"groups": groups})
 	return groups, nil
 }
@@ -660,14 +693,23 @@
 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 {
-		logger.Debugw(ctx, "Inside GetGroupList method", log.Fields{"groupID": id})
-		grps, ok := device.groups.Load(id)
-		if !ok {
-			return nil, errors.New("group not found")
+	var err error
+	v.Devices.Range(func(_, value interface{}) bool {
+		device, ok := value.(*Device)
+		if ok {
+			logger.Debugw(ctx, "Inside GetGroupList method", log.Fields{"groupID": id})
+			grps, ok := device.groups.Load(id)
+			if !ok {
+				err = errors.New("group not found")
+				return false
+			}
+			groups = grps.(*of.Group)
+			logger.Debugw(ctx, "Groups", log.Fields{"groups": groups})
 		}
-		groups = grps.(*of.Group)
-		logger.Debugw(ctx, "Groups", log.Fields{"groups": groups})
+		return true
+	})
+	if err != nil {
+		return nil, err
 	}
 	return groups, nil
 }
diff --git a/internal/pkg/controller/controller_test.go b/internal/pkg/controller/controller_test.go
index 5b67d14..18b16bc 100644
--- a/internal/pkg/controller/controller_test.go
+++ b/internal/pkg/controller/controller_test.go
@@ -71,8 +71,8 @@
 		ID:     "SDX6320031",
 		cancel: Cancel,
 	}
-	dev := map[string]*Device{}
-	dev["SDX6320031"] = device
+	var dev sync.Map
+	dev.Store("SDX6320031", device)
 	appMock := mocks.NewMockApp(gomock.NewController(t))
 	NewController(ctx, appMock)
 	appMock.EXPECT().DelDevice(gomock.Any(), gomock.Any()).AnyTimes()
@@ -91,9 +91,13 @@
 	for _, tt := range tests {
 		t.Run(tt.name, func(t *testing.T) {
 			v := &VoltController{
-				Devices: dev,
+				Devices: sync.Map{},
 				app:     GetController().app,
 			}
+			dev.Range(func(key, value interface{}) bool {
+				v.Devices.Store(key, value)
+				return true
+			})
 			v.DelDevice(tt.args.cntx, tt.args.id)
 		})
 	}
@@ -137,8 +141,8 @@
 		flows:       subFlows,
 		PortsByName: portsByName,
 	}
-	dev := map[string]*Device{}
-	dev["SDX6320031"] = device
+	var dev sync.Map
+	dev.Store("SDX6320031", device)
 	flow := &of.VoltFlow{
 		PortName:      "SDX6320031-1",
 		PortID:        256,
@@ -163,8 +167,12 @@
 	for _, tt := range tests {
 		t.Run(tt.name, func(t *testing.T) {
 			v := &VoltController{
-				Devices: dev,
+				Devices: sync.Map{},
 			}
+			dev.Range(func(key, value interface{}) bool {
+				v.Devices.Store(key, value)
+				return true
+			})
 			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)
 			}
@@ -210,8 +218,8 @@
 		flows:       subFlows,
 		PortsByName: portsByName,
 	}
-	dev := map[string]*Device{}
-	dev["SDX6320031"] = device
+	var dev sync.Map
+	dev.Store("SDX6320031", device)
 	flow := &of.VoltFlow{
 		PortName:      "SDX6320031-1",
 		PortID:        256,
@@ -236,8 +244,12 @@
 	for _, tt := range tests {
 		t.Run(tt.name, func(t *testing.T) {
 			v := &VoltController{
-				Devices: dev,
+				Devices: sync.Map{},
 			}
+			dev.Range(func(key, value interface{}) bool {
+				v.Devices.Store(key, value)
+				return true
+			})
 			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)
 			}
@@ -261,8 +273,8 @@
 		State:   1,
 		SetVlan: of.VlanAny,
 	}
-	dev := map[string]*Device{}
-	dev["SDX6320031"] = device
+	var dev sync.Map
+	dev.Store("SDX6320031", device)
 	tests := []struct {
 		name    string
 		args    args
@@ -292,8 +304,12 @@
 	for _, tt := range tests {
 		t.Run(tt.name, func(t *testing.T) {
 			v := &VoltController{
-				Devices: dev,
+				Devices: sync.Map{},
 			}
+			dev.Range(func(key, value interface{}) bool {
+				v.Devices.Store(key, value)
+				return true
+			})
 			switch tt.name {
 			case "VoltController_GetGroups":
 				device.groups.Store(uint32(256), grp)
@@ -333,8 +349,8 @@
 		SetVlan: of.VlanAny,
 	}
 	grpList = append(grpList, grp)
-	dev := map[string]*Device{}
-	dev["SDX6320031"] = device
+	var dev sync.Map
+	dev.Store("SDX6320031", device)
 	tests := []struct {
 		name    string
 		want    []*of.Group
@@ -349,8 +365,12 @@
 	for _, tt := range tests {
 		t.Run(tt.name, func(t *testing.T) {
 			v := &VoltController{
-				Devices: dev,
+				Devices: sync.Map{},
 			}
+			dev.Range(func(key, value interface{}) bool {
+				v.Devices.Store(key, value)
+				return true
+			})
 			device.groups.Store(uint32(256), grp)
 			got, err := v.GetGroupList()
 			if (err != nil) != tt.wantErr {
@@ -382,8 +402,8 @@
 		ID:     "SDX6320031",
 		meters: devMtr,
 	}
-	dev := map[string]*Device{}
-	dev["SDX6320031"] = device
+	var dev sync.Map
+	dev.Store("SDX6320031", device)
 	tests := []struct {
 		name    string
 		args    args
@@ -412,8 +432,12 @@
 	for _, tt := range tests {
 		t.Run(tt.name, func(t *testing.T) {
 			v := &VoltController{
-				Devices: dev,
+				Devices: sync.Map{},
 			}
+			dev.Range(func(key, value interface{}) bool {
+				v.Devices.Store(key, value)
+				return true
+			})
 			switch tt.name {
 			case "VoltController_GetMeterInfo":
 				got, err := v.GetMeterInfo(tt.args.cntx, tt.args.id)
@@ -454,8 +478,8 @@
 		ID:     "SDX6320031",
 		meters: devMtr,
 	}
-	dev := map[string]*Device{}
-	dev["SDX6320031"] = device
+	var dev sync.Map
+	dev.Store("SDX6320031", device)
 	tests := []struct {
 		name    string
 		want    map[string][]*of.Meter
@@ -470,8 +494,12 @@
 	for _, tt := range tests {
 		t.Run(tt.name, func(t *testing.T) {
 			v := &VoltController{
-				Devices: dev,
+				Devices: sync.Map{},
 			}
+			dev.Range(func(key, value interface{}) bool {
+				v.Devices.Store(key, value)
+				return true
+			})
 			got, err := v.GetAllMeterInfo()
 			if (err != nil) != tt.wantErr {
 				t.Errorf("VoltController.GetAllMeterInfo() error = %v, wantErr %v", err, tt.wantErr)
@@ -512,8 +540,8 @@
 		ID:    "SDX6320031",
 		flows: subFlows,
 	}
-	dev := map[string]*Device{}
-	dev["SDX6320031"] = device
+	var dev sync.Map
+	dev.Store("SDX6320031", device)
 	tests := []struct {
 		name    string
 		want    []*of.VoltSubFlow
@@ -582,8 +610,12 @@
 	for _, tt := range tests {
 		t.Run(tt.name, func(t *testing.T) {
 			v := &VoltController{
-				Devices: dev,
+				Devices: sync.Map{},
 			}
+			dev.Range(func(key, value interface{}) bool {
+				v.Devices.Store(key, value)
+				return true
+			})
 			got, err := v.GetAllPendingFlows()
 			if (err != nil) != tt.wantErr {
 				t.Errorf("VoltController.GetAllPendingFlows() error = %v, wantErr %v", err, tt.wantErr)
@@ -601,8 +633,12 @@
 	for _, tt := range tests1 {
 		t.Run(tt.name, func(t *testing.T) {
 			v := &VoltController{
-				Devices: dev,
+				Devices: sync.Map{},
 			}
+			dev.Range(func(key, value interface{}) bool {
+				v.Devices.Store(key, value)
+				return true
+			})
 			switch tt.name {
 			case "GetFlows_with_DeviceID":
 				got, err := v.GetFlows(tt.args.deviceId)
@@ -624,8 +660,12 @@
 	for _, tt := range tests2 {
 		t.Run(tt.name, func(t *testing.T) {
 			v := &VoltController{
-				Devices: dev,
+				Devices: sync.Map{},
 			}
+			dev.Range(func(key, value interface{}) bool {
+				v.Devices.Store(key, value)
+				return true
+			})
 			switch tt.name {
 			case "GetFlow_with_DeviceID_and_cookie":
 				got, err := v.GetFlow(tt.args.deviceId, tt.args.cookie)
@@ -654,8 +694,8 @@
 		ctx: context.Background(),
 		ID:  "SDX6320031",
 	}
-	dev := map[string]*Device{}
-	dev["SDX6320031"] = device
+	var dev sync.Map
+	dev.Store("SDX6320031", device)
 	tests := []struct {
 		name string
 		args args
@@ -679,8 +719,12 @@
 	for _, tt := range tests {
 		t.Run(tt.name, func(t *testing.T) {
 			v := &VoltController{
-				Devices: dev,
+				Devices: sync.Map{},
 			}
+			dev.Range(func(key, value interface{}) bool {
+				v.Devices.Store(key, value)
+				return true
+			})
 			switch tt.name {
 			case "GetTaskList":
 				if got := v.GetTaskList(tt.args.device); !reflect.DeepEqual(got, tt.want) {
@@ -710,8 +754,8 @@
 		ID:          "SDX6320031",
 		PortsByName: portsByName,
 	}
-	dev := map[string]*Device{}
-	dev["SDX6320031"] = device
+	var dev sync.Map
+	dev.Store("SDX6320031", device)
 	tests := []struct {
 		name    string
 		args    args
@@ -739,8 +783,12 @@
 	for _, tt := range tests {
 		t.Run(tt.name, func(t *testing.T) {
 			v := &VoltController{
-				Devices: dev,
+				Devices: sync.Map{},
 			}
+			dev.Range(func(key, value interface{}) bool {
+				v.Devices.Store(key, value)
+				return true
+			})
 			switch tt.name {
 			case "GetPortState":
 				got, err := v.GetPortState(tt.args.device, tt.args.name)
@@ -787,8 +835,8 @@
 		PortsByName: portsByName,
 		meters:      devMtr,
 	}
-	dev := map[string]*Device{}
-	dev["SDX6320031"] = device
+	var dev sync.Map
+	dev.Store("SDX6320031", device)
 	tests := []struct {
 		name    string
 		args    args
@@ -825,8 +873,12 @@
 	for _, tt := range tests {
 		t.Run(tt.name, func(t *testing.T) {
 			v := &VoltController{
-				Devices: dev,
+				Devices: sync.Map{},
 			}
+			dev.Range(func(key, value interface{}) bool {
+				v.Devices.Store(key, value)
+				return true
+			})
 			switch tt.name {
 			case "ModMeter":
 				if err := v.ModMeter(tt.args.port, tt.args.device, tt.args.command, tt.args.meter); (err != nil) != tt.wantErr {
@@ -951,8 +1003,8 @@
 		ctx: context.Background(),
 		ID:  "SDX6320031",
 	}
-	dev := map[string]*Device{}
-	dev["SDX6320031"] = device
+	var dev sync.Map
+	dev.Store("SDX6320031", device)
 	tests := []struct {
 		name string
 		args args
@@ -977,8 +1029,12 @@
 		t.Run(tt.name, func(t *testing.T) {
 			v := &VoltController{
 				rebootInProgressDevices: rebootInProgressDevices,
-				Devices:                 dev,
+				Devices:                 sync.Map{},
 			}
+			dev.Range(func(key, value interface{}) bool {
+				v.Devices.Store(key, value)
+				return true
+			})
 			switch tt.name {
 			case "SetRebootInProgressForDevice":
 				if got := v.SetRebootInProgressForDevice(tt.args.device); got != tt.want {
@@ -1003,8 +1059,8 @@
 		ID:  "SDX6320031",
 	}
 	rebootInProgressDevices["SDX6320031"] = "done"
-	dev := map[string]*Device{}
-	dev["SDX6320031"] = device
+	var dev sync.Map
+	dev.Store("SDX6320031", device)
 	tests := []struct {
 		name string
 		args args
@@ -1022,8 +1078,12 @@
 		t.Run(tt.name, func(t *testing.T) {
 			v := &VoltController{
 				rebootInProgressDevices: rebootInProgressDevices,
-				Devices:                 dev,
+				Devices:                 sync.Map{},
 			}
+			dev.Range(func(key, value interface{}) bool {
+				v.Devices.Store(key, value)
+				return true
+			})
 			if got := v.ReSetRebootInProgressForDevice(tt.args.device); got != tt.want {
 				t.Errorf("VoltController.ReSetRebootInProgressForDevice() = %v, want %v", got, tt.want)
 			}
@@ -1151,8 +1211,8 @@
 		groups:      sync.Map{},
 		PortsByName: portsByName,
 	}
-	dev := map[string]*Device{}
-	dev["SDX6320031"] = device
+	var dev sync.Map
+	dev.Store("SDX6320031", device)
 	grp := &of.Group{
 		Device:  "SDX6320031",
 		GroupID: uint32(256),
@@ -1205,8 +1265,12 @@
 			switch tt.name {
 			case "GroupUpdate", "DeviceNOtFound_Error", "PortNOtFound_Error":
 				v := &VoltController{
-					Devices: dev,
+					Devices: sync.Map{},
 				}
+				dev.Range(func(key, value interface{}) bool {
+					v.Devices.Store(key, value)
+					return true
+				})
 				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)
 				}
@@ -1216,11 +1280,15 @@
 					groups:      sync.Map{},
 					PortsByName: portsByName,
 				}
-				dev := map[string]*Device{}
-				dev["SDX6320031"] = device
+				var dev sync.Map
+				dev.Store("SDX6320031", device)
 				v := &VoltController{
-					Devices: dev,
+					Devices: sync.Map{},
 				}
+				dev.Range(func(key, value interface{}) bool {
+					v.Devices.Store(key, value)
+					return true
+				})
 				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)
 				}