VOL-1900 lint warning fixes ro_core

Change-Id: I5ce82f2d188d215ba9620d0923a1101ed4e5e4a8
diff --git a/ro_core/core/device_manager.go b/ro_core/core/device_manager.go
index fd69705..634566c 100644
--- a/ro_core/core/device_manager.go
+++ b/ro_core/core/device_manager.go
@@ -13,31 +13,34 @@
  * See the License for the specific language governing permissions and
  * limitations under the License.
  */
+
 package core
 
 import (
 	"context"
+	"sync"
+
 	"github.com/opencord/voltha-go/db/model"
 	"github.com/opencord/voltha-lib-go/v2/pkg/log"
 	"github.com/opencord/voltha-lib-go/v2/pkg/probe"
 	"github.com/opencord/voltha-protos/v2/go/voltha"
 	"google.golang.org/grpc/codes"
 	"google.golang.org/grpc/status"
-	"sync"
 )
 
+// DeviceManager represents device manager related information
 type DeviceManager struct {
 	deviceAgents     sync.Map
 	logicalDeviceMgr *LogicalDeviceManager
 	clusterDataProxy *model.Proxy
-	coreInstanceId   string
+	coreInstanceID   string
 	exitChannel      chan int
 }
 
-func newDeviceManager(cdProxy *model.Proxy, coreInstanceId string) *DeviceManager {
+func newDeviceManager(cdProxy *model.Proxy, coreInstanceID string) *DeviceManager {
 	var deviceMgr DeviceManager
 	deviceMgr.exitChannel = make(chan int, 1)
-	deviceMgr.coreInstanceId = coreInstanceId
+	deviceMgr.coreInstanceID = coreInstanceID
 	deviceMgr.clusterDataProxy = cdProxy
 	return &deviceMgr
 }
@@ -69,31 +72,30 @@
 }
 
 func (dMgr *DeviceManager) addDeviceAgentToMap(agent *DeviceAgent) {
-	if _, exist := dMgr.deviceAgents.Load(agent.deviceId); !exist {
-		dMgr.deviceAgents.Store(agent.deviceId, agent)
+	if _, exist := dMgr.deviceAgents.Load(agent.deviceID); !exist {
+		dMgr.deviceAgents.Store(agent.deviceID, agent)
 	}
 }
 
 func (dMgr *DeviceManager) deleteDeviceAgentToMap(agent *DeviceAgent) {
-	dMgr.deviceAgents.Delete(agent.deviceId)
+	dMgr.deviceAgents.Delete(agent.deviceID)
 }
 
-func (dMgr *DeviceManager) getDeviceAgent(deviceId string) *DeviceAgent {
-	if agent, ok := dMgr.deviceAgents.Load(deviceId); ok {
+func (dMgr *DeviceManager) getDeviceAgent(deviceID string) *DeviceAgent {
+	if agent, ok := dMgr.deviceAgents.Load(deviceID); ok {
 		return agent.(*DeviceAgent)
-	} else {
-		//	Try to load into memory - loading will also create the device agent
-		if err := dMgr.load(deviceId); err == nil {
-			if agent, ok = dMgr.deviceAgents.Load(deviceId); ok {
-				return agent.(*DeviceAgent)
-			}
+	}
+	//	Try to load into memory - loading will also create the device agent
+	if err := dMgr.load(deviceID); err == nil {
+		if agent, ok := dMgr.deviceAgents.Load(deviceID); ok {
+			return agent.(*DeviceAgent)
 		}
 	}
 	return nil
 }
 
-// listDeviceIdsFromMap returns the list of device IDs that are in memory
-func (dMgr *DeviceManager) listDeviceIdsFromMap() *voltha.IDs {
+// listDeviceIDsFromMap returns the list of device IDs that are in memory
+func (dMgr *DeviceManager) listDeviceIDsFromMap() *voltha.IDs {
 	result := &voltha.IDs{Items: make([]*voltha.ID, 0)}
 	dMgr.deviceAgents.Range(func(key, value interface{}) bool {
 		result.Items = append(result.Items, &voltha.ID{Id: key.(string)})
@@ -111,11 +113,13 @@
 	return nil, status.Errorf(codes.NotFound, "%s", id)
 }
 
+// IsDeviceInCache returns true if device exists in cache
 func (dMgr *DeviceManager) IsDeviceInCache(id string) bool {
 	_, exist := dMgr.deviceAgents.Load(id)
 	return exist
 }
 
+// IsRootDevice returns true if root device is present in either memory or db
 func (dMgr *DeviceManager) IsRootDevice(id string) (bool, error) {
 	device, err := dMgr.GetDevice(id)
 	if err != nil {
@@ -133,9 +137,9 @@
 			// If device is not in memory then set it up
 			if !dMgr.IsDeviceInCache(device.(*voltha.Device).Id) {
 				agent := newDeviceAgent(device.(*voltha.Device), dMgr, dMgr.clusterDataProxy)
-				if err := agent.start(nil, true); err != nil {
-					log.Warnw("failure-starting-agent", log.Fields{"deviceId": device.(*voltha.Device).Id})
-					agent.stop(nil)
+				if err := agent.start(context.TODO(), true); err != nil {
+					log.Warnw("failure-starting-agent", log.Fields{"deviceID": device.(*voltha.Device).Id})
+					agent.stop(context.TODO())
 				} else {
 					dMgr.addDeviceAgentToMap(agent)
 				}
@@ -146,67 +150,67 @@
 	return result, nil
 }
 
-// loadDevice loads the deviceId in memory, if not present
-func (dMgr *DeviceManager) loadDevice(deviceId string) (*DeviceAgent, error) {
-	log.Debugw("loading-device", log.Fields{"deviceId": deviceId})
+// loadDevice loads the deviceID in memory, if not present
+func (dMgr *DeviceManager) loadDevice(deviceID string) (*DeviceAgent, error) {
+	log.Debugw("loading-device", log.Fields{"deviceID": deviceID})
 	// Sanity check
-	if deviceId == "" {
-		return nil, status.Error(codes.InvalidArgument, "deviceId empty")
+	if deviceID == "" {
+		return nil, status.Error(codes.InvalidArgument, "deviceID empty")
 	}
-	if !dMgr.IsDeviceInCache(deviceId) {
-		agent := newDeviceAgent(&voltha.Device{Id: deviceId}, dMgr, dMgr.clusterDataProxy)
-		if err := agent.start(nil, true); err != nil {
-			agent.stop(nil)
+	if !dMgr.IsDeviceInCache(deviceID) {
+		agent := newDeviceAgent(&voltha.Device{Id: deviceID}, dMgr, dMgr.clusterDataProxy)
+		if err := agent.start(context.TODO(), true); err != nil {
+			agent.stop(context.TODO())
 			return nil, err
 		}
 		dMgr.addDeviceAgentToMap(agent)
 	}
-	if agent := dMgr.getDeviceAgent(deviceId); agent != nil {
+	if agent := dMgr.getDeviceAgent(deviceID); agent != nil {
 		return agent, nil
 	}
-	return nil, status.Error(codes.NotFound, deviceId) // This should nto happen
+	return nil, status.Error(codes.NotFound, deviceID) // This should nto happen
 }
 
 // loadRootDeviceParentAndChildren loads the children and parents of a root device in memory
 func (dMgr *DeviceManager) loadRootDeviceParentAndChildren(device *voltha.Device) error {
-	log.Debugw("loading-parent-and-children", log.Fields{"deviceId": device.Id})
+	log.Debugw("loading-parent-and-children", log.Fields{"deviceID": device.Id})
 	if device.Root {
 		// Scenario A
 		if device.ParentId != "" {
 			//	 Load logical device if needed.
 			if err := dMgr.logicalDeviceMgr.load(device.ParentId); err != nil {
-				log.Warnw("failure-loading-logical-device", log.Fields{"lDeviceId": device.ParentId})
+				log.Warnw("failure-loading-logical-device", log.Fields{"lDeviceID": device.ParentId})
 			}
 		} else {
-			log.Debugw("no-parent-to-load", log.Fields{"deviceId": device.Id})
+			log.Debugw("no-parent-to-load", log.Fields{"deviceID": device.Id})
 		}
 		//	Load all child devices, if needed
-		if childDeviceIds, err := dMgr.getAllChildDeviceIds(device); err == nil {
-			for _, childDeviceId := range childDeviceIds {
-				if _, err := dMgr.loadDevice(childDeviceId); err != nil {
-					log.Warnw("failure-loading-device", log.Fields{"deviceId": childDeviceId})
+		if childDeviceIDs, err := dMgr.getAllChildDeviceIDs(device); err == nil {
+			for _, childDeviceID := range childDeviceIDs {
+				if _, err := dMgr.loadDevice(childDeviceID); err != nil {
+					log.Warnw("failure-loading-device", log.Fields{"deviceID": childDeviceID})
 					return err
 				}
 			}
-			log.Debugw("loaded-children", log.Fields{"deviceId": device.Id, "numChildren": len(childDeviceIds)})
+			log.Debugw("loaded-children", log.Fields{"deviceID": device.Id, "numChildren": len(childDeviceIDs)})
 		} else {
-			log.Debugw("no-child-to-load", log.Fields{"deviceId": device.Id})
+			log.Debugw("no-child-to-load", log.Fields{"deviceID": device.Id})
 		}
 	}
 	return nil
 }
 
-// load loads the deviceId in memory, if not present, and also loads its accompanying parents and children.  Loading
+// load loads the deviceID in memory, if not present, and also loads its accompanying parents and children.  Loading
 // in memory is for improved performance.  It is not imperative that a device needs to be in memory when a request
 // acting on the device is received by the core. In such a scenario, the Core will load the device in memory first
 // and the proceed with the request.
-func (dMgr *DeviceManager) load(deviceId string) error {
+func (dMgr *DeviceManager) load(deviceID string) error {
 	log.Debug("load...")
 	// First load the device - this may fail in case the device was deleted intentionally by the other core
 	var dAgent *DeviceAgent
 	var err error
-	if dAgent, err = dMgr.loadDevice(deviceId); err != nil {
-		log.Warnw("failure-loading-device", log.Fields{"deviceId": deviceId})
+	if dAgent, err = dMgr.loadDevice(deviceID); err != nil {
+		log.Warnw("failure-loading-device", log.Fields{"deviceID": deviceID})
 		return err
 	}
 	// Get the loaded device details
@@ -224,12 +228,12 @@
 	if device.Root {
 		// Load all children as well as the parent of this device (logical_device)
 		if err := dMgr.loadRootDeviceParentAndChildren(device); err != nil {
-			log.Warnw("failure-loading-device-parent-and-children", log.Fields{"deviceId": deviceId})
+			log.Warnw("failure-loading-device-parent-and-children", log.Fields{"deviceID": deviceID})
 			return err
 		}
-		log.Debugw("successfully-loaded-parent-and-children", log.Fields{"deviceId": deviceId})
+		log.Debugw("successfully-loaded-parent-and-children", log.Fields{"deviceID": deviceID})
 	} else {
-		//	Scenario B - use the parentId of that device (root device) to trigger the loading
+		//	Scenario B - use the parentID of that device (root device) to trigger the loading
 		if device.ParentId != "" {
 			return dMgr.load(device.ParentId)
 		}
@@ -237,11 +241,11 @@
 	return nil
 }
 
-// ListDeviceIds retrieves the latest device IDs information from the data model (memory data only)
-func (dMgr *DeviceManager) ListDeviceIds() (*voltha.IDs, error) {
+// ListDeviceIDs retrieves the latest device IDs information from the data model (memory data only)
+func (dMgr *DeviceManager) ListDeviceIDs() (*voltha.IDs, error) {
 	log.Debug("ListDeviceIDs")
 	// Report only device IDs that are in the device agent map
-	return dMgr.listDeviceIdsFromMap(), nil
+	return dMgr.listDeviceIDsFromMap(), nil
 }
 
 //ReconcileDevices is a request to a voltha core to managed a list of devices based on their IDs
@@ -254,19 +258,19 @@
 		for _, id := range ids.Items {
 			//	 Act on the device only if its not present in the agent map
 			if !dMgr.IsDeviceInCache(id.Id) {
-				//	Device Id not in memory
+				//	Device ID not in memory
 				log.Debugw("reconciling-device", log.Fields{"id": id.Id})
 				// Load device from dB
 				agent := newDeviceAgent(&voltha.Device{Id: id.Id}, dMgr, dMgr.clusterDataProxy)
-				if err := agent.start(nil, true); err != nil {
-					log.Warnw("failure-loading-device", log.Fields{"deviceId": id.Id})
-					agent.stop(nil)
+				if err := agent.start(context.TODO(), true); err != nil {
+					log.Warnw("failure-loading-device", log.Fields{"deviceID": id.Id})
+					agent.stop(context.TODO())
 				} else {
 					dMgr.addDeviceAgentToMap(agent)
-					reconciled += 1
+					reconciled++
 				}
 			} else {
-				reconciled += 1
+				reconciled++
 			}
 		}
 		if toReconcile != reconciled {
@@ -278,83 +282,82 @@
 	sendResponse(ctx, ch, res)
 }
 
-func (dMgr *DeviceManager) getPorts(ctx context.Context, deviceId string, portType voltha.Port_PortType) (*voltha.Ports, error) {
-	log.Debugw("getPorts", log.Fields{"deviceid": deviceId, "portType": portType})
-	if agent := dMgr.getDeviceAgent(deviceId); agent != nil {
-		return agent.getPorts(ctx, portType), nil
-	}
-	return nil, status.Errorf(codes.NotFound, "%s", deviceId)
-
-}
-
-func (dMgr *DeviceManager) ListDevicePorts(ctx context.Context, deviceId string) (*voltha.Ports, error) {
-	log.Debugw("ListDevicePorts", log.Fields{"deviceid": deviceId})
-	if agent := dMgr.getDeviceAgent(deviceId); agent != nil {
+// ListDevicePorts returns ports details for a specific device
+func (dMgr *DeviceManager) ListDevicePorts(ctx context.Context, deviceID string) (*voltha.Ports, error) {
+	log.Debugw("ListDevicePorts", log.Fields{"deviceid": deviceID})
+	if agent := dMgr.getDeviceAgent(deviceID); agent != nil {
 		return agent.ListDevicePorts(ctx)
 	}
-	return nil, status.Errorf(codes.NotFound, "%s", deviceId)
+	return nil, status.Errorf(codes.NotFound, "%s", deviceID)
 
 }
 
-func (dMgr *DeviceManager) ListDevicePmConfigs(ctx context.Context, deviceId string) (*voltha.PmConfigs, error) {
-	log.Debugw("ListDevicePmConfigs", log.Fields{"deviceid": deviceId})
-	if agent := dMgr.getDeviceAgent(deviceId); agent != nil {
+// ListDevicePmConfigs returns PM config details for a specific device
+func (dMgr *DeviceManager) ListDevicePmConfigs(ctx context.Context, deviceID string) (*voltha.PmConfigs, error) {
+	log.Debugw("ListDevicePmConfigs", log.Fields{"deviceid": deviceID})
+	if agent := dMgr.getDeviceAgent(deviceID); agent != nil {
 		return agent.ListDevicePmConfigs(ctx)
 	}
-	return nil, status.Errorf(codes.NotFound, "%s", deviceId)
+	return nil, status.Errorf(codes.NotFound, "%s", deviceID)
 
 }
 
-func (dMgr *DeviceManager) ListDeviceFlows(ctx context.Context, deviceId string) (*voltha.Flows, error) {
-	log.Debugw("ListDeviceFlows", log.Fields{"deviceid": deviceId})
-	if agent := dMgr.getDeviceAgent(deviceId); agent != nil {
+// ListDeviceFlows returns flow details for a specific device
+func (dMgr *DeviceManager) ListDeviceFlows(ctx context.Context, deviceID string) (*voltha.Flows, error) {
+	log.Debugw("ListDeviceFlows", log.Fields{"deviceid": deviceID})
+	if agent := dMgr.getDeviceAgent(deviceID); agent != nil {
 		return agent.ListDeviceFlows(ctx)
 	}
-	return nil, status.Errorf(codes.NotFound, "%s", deviceId)
+	return nil, status.Errorf(codes.NotFound, "%s", deviceID)
 }
 
-func (dMgr *DeviceManager) ListDeviceFlowGroups(ctx context.Context, deviceId string) (*voltha.FlowGroups, error) {
-	log.Debugw("ListDeviceFlowGroups", log.Fields{"deviceid": deviceId})
-	if agent := dMgr.getDeviceAgent(deviceId); agent != nil {
+// ListDeviceFlowGroups returns flow group details for a specific device
+func (dMgr *DeviceManager) ListDeviceFlowGroups(ctx context.Context, deviceID string) (*voltha.FlowGroups, error) {
+	log.Debugw("ListDeviceFlowGroups", log.Fields{"deviceid": deviceID})
+	if agent := dMgr.getDeviceAgent(deviceID); agent != nil {
 		return agent.ListDeviceFlowGroups(ctx)
 	}
-	return nil, status.Errorf(codes.NotFound, "%s", deviceId)
+	return nil, status.Errorf(codes.NotFound, "%s", deviceID)
 
 }
 
-func (dMgr *DeviceManager) GetImageDownloadStatus(ctx context.Context, deviceId string, imageName string) (*voltha.ImageDownload, error) {
-	log.Debugw("GetImageDownloadStatus", log.Fields{"deviceid": deviceId, "imagename": imageName})
-	if agent := dMgr.getDeviceAgent(deviceId); agent != nil {
+// GetImageDownloadStatus returns the download status of an image of a particular device
+func (dMgr *DeviceManager) GetImageDownloadStatus(ctx context.Context, deviceID string, imageName string) (*voltha.ImageDownload, error) {
+	log.Debugw("GetImageDownloadStatus", log.Fields{"deviceid": deviceID, "imagename": imageName})
+	if agent := dMgr.getDeviceAgent(deviceID); agent != nil {
 		return agent.GetImageDownloadStatus(ctx, imageName)
 	}
-	return nil, status.Errorf(codes.NotFound, "%s", deviceId)
+	return nil, status.Errorf(codes.NotFound, "%s", deviceID)
 
 }
 
-func (dMgr *DeviceManager) GetImageDownload(ctx context.Context, deviceId string, imageName string) (*voltha.ImageDownload, error) {
-	log.Debugw("GetImageDownload", log.Fields{"deviceid": deviceId, "imagename": imageName})
-	if agent := dMgr.getDeviceAgent(deviceId); agent != nil {
+// GetImageDownload return the download details for a specific image entry
+func (dMgr *DeviceManager) GetImageDownload(ctx context.Context, deviceID string, imageName string) (*voltha.ImageDownload, error) {
+	log.Debugw("GetImageDownload", log.Fields{"deviceid": deviceID, "imagename": imageName})
+	if agent := dMgr.getDeviceAgent(deviceID); agent != nil {
 		return agent.GetImageDownload(ctx, imageName)
 	}
-	return nil, status.Errorf(codes.NotFound, "%s", deviceId)
+	return nil, status.Errorf(codes.NotFound, "%s", deviceID)
 
 }
 
-func (dMgr *DeviceManager) ListImageDownloads(ctx context.Context, deviceId string) (*voltha.ImageDownloads, error) {
-	log.Debugw("ListImageDownloads", log.Fields{"deviceid": deviceId})
-	if agent := dMgr.getDeviceAgent(deviceId); agent != nil {
+// ListImageDownloads returns all image downloads known to the system
+func (dMgr *DeviceManager) ListImageDownloads(ctx context.Context, deviceID string) (*voltha.ImageDownloads, error) {
+	log.Debugw("ListImageDownloads", log.Fields{"deviceid": deviceID})
+	if agent := dMgr.getDeviceAgent(deviceID); agent != nil {
 		return agent.ListImageDownloads(ctx)
 	}
-	return nil, status.Errorf(codes.NotFound, "%s", deviceId)
+	return nil, status.Errorf(codes.NotFound, "%s", deviceID)
 
 }
 
-func (dMgr *DeviceManager) GetImages(ctx context.Context, deviceId string) (*voltha.Images, error) {
-	log.Debugw("GetImages", log.Fields{"deviceid": deviceId})
-	if agent := dMgr.getDeviceAgent(deviceId); agent != nil {
+// GetImages returns all images for a specific device entry
+func (dMgr *DeviceManager) GetImages(ctx context.Context, deviceID string) (*voltha.Images, error) {
+	log.Debugw("GetImages", log.Fields{"deviceid": deviceID})
+	if agent := dMgr.getDeviceAgent(deviceID); agent != nil {
 		return agent.GetImages(ctx)
 	}
-	return nil, status.Errorf(codes.NotFound, "%s", deviceId)
+	return nil, status.Errorf(codes.NotFound, "%s", deviceID)
 
 }
 
@@ -368,16 +371,16 @@
 	return parentDevice
 }
 
-//getAllChildDeviceIds is a helper method to get all the child device IDs from the device passed as parameter
-func (dMgr *DeviceManager) getAllChildDeviceIds(parentDevice *voltha.Device) ([]string, error) {
-	log.Debugw("getAllChildDeviceIds", log.Fields{"parentDeviceId": parentDevice.Id})
-	childDeviceIds := make([]string, 0)
+//getAllChildDeviceIDs is a helper method to get all the child device IDs from the device passed as parameter
+func (dMgr *DeviceManager) getAllChildDeviceIDs(parentDevice *voltha.Device) ([]string, error) {
+	log.Debugw("getAllChildDeviceIDs", log.Fields{"parentDeviceID": parentDevice.Id})
+	childDeviceIDs := make([]string, 0)
 	if parentDevice != nil {
 		for _, port := range parentDevice.Ports {
 			for _, peer := range port.Peers {
-				childDeviceIds = append(childDeviceIds, peer.DeviceId)
+				childDeviceIDs = append(childDeviceIDs, peer.DeviceId)
 			}
 		}
 	}
-	return childDeviceIds, nil
+	return childDeviceIDs, nil
 }