VOL-1900 lint warning fixes rw_core

Change-Id: Icaa84d7ce24163da90c91ff2babcbb78ff4e9141
diff --git a/rw_core/core/device_agent.go b/rw_core/core/device_agent.go
index 9dd41fb..0f4c177 100755
--- a/rw_core/core/device_agent.go
+++ b/rw_core/core/device_agent.go
@@ -13,6 +13,7 @@
  * See the License for the specific language governing permissions and
  * limitations under the License.
  */
+
 package core
 
 import (
@@ -35,9 +36,10 @@
 	"google.golang.org/grpc/status"
 )
 
+// DeviceAgent represents device agent attributes
 type DeviceAgent struct {
-	deviceId         string
-	parentId         string
+	deviceID         string
+	parentID         string
 	deviceType       string
 	isRootdevice     bool
 	adapterProxy     *AdapterProxy
@@ -55,13 +57,13 @@
 	var agent DeviceAgent
 	agent.adapterProxy = ap
 	if device.Id == "" {
-		agent.deviceId = CreateDeviceId()
+		agent.deviceID = CreateDeviceID()
 	} else {
-		agent.deviceId = device.Id
+		agent.deviceID = device.Id
 	}
 
 	agent.isRootdevice = device.Root
-	agent.parentId = device.ParentId
+	agent.parentID = device.ParentId
 	agent.deviceType = device.Type
 	agent.deviceMgr = deviceMgr
 	agent.adapterMgr = deviceMgr.adapterMgr
@@ -74,36 +76,36 @@
 
 // start()
 // save the device to the data model and registers for callbacks on that device if deviceToCreate!=nil.  Otherwise,
-// it will load the data from the dB and setup teh necessary callbacks and proxies. Returns the device that
+// it will load the data from the dB and setup the necessary callbacks and proxies. Returns the device that
 // was started.
 func (agent *DeviceAgent) start(ctx context.Context, deviceToCreate *voltha.Device) (*voltha.Device, error) {
 	var device *voltha.Device
 
 	agent.lockDevice.Lock()
 	defer agent.lockDevice.Unlock()
-	log.Debugw("starting-device-agent", log.Fields{"deviceId": agent.deviceId})
+	log.Debugw("starting-device-agent", log.Fields{"deviceId": agent.deviceID})
 	if deviceToCreate == nil {
 		// Load the existing device
-		if loadedDevice := agent.clusterDataProxy.Get(ctx, "/devices/"+agent.deviceId, 1, true, ""); loadedDevice != nil {
+		if loadedDevice := agent.clusterDataProxy.Get(ctx, "/devices/"+agent.deviceID, 1, true, ""); loadedDevice != nil {
 			var ok bool
 			if device, ok = loadedDevice.(*voltha.Device); ok {
 				agent.deviceType = device.Adapter
 			} else {
-				log.Errorw("failed-to-convert-device", log.Fields{"deviceId": agent.deviceId})
-				return nil, status.Errorf(codes.NotFound, "device-%s", agent.deviceId)
+				log.Errorw("failed-to-convert-device", log.Fields{"deviceId": agent.deviceID})
+				return nil, status.Errorf(codes.NotFound, "device-%s", agent.deviceID)
 			}
 		} else {
-			log.Errorw("failed-to-load-device", log.Fields{"deviceId": agent.deviceId})
-			return nil, status.Errorf(codes.NotFound, "device-%s", agent.deviceId)
+			log.Errorw("failed-to-load-device", log.Fields{"deviceId": agent.deviceID})
+			return nil, status.Errorf(codes.NotFound, "device-%s", agent.deviceID)
 		}
-		log.Debugw("device-loaded-from-dB", log.Fields{"deviceId": agent.deviceId})
+		log.Debugw("device-loaded-from-dB", log.Fields{"deviceId": agent.deviceID})
 	} else {
 		// Create a new device
 		// Assumption is that AdminState, FlowGroups, and Flows are unitialized since this
 		// is a new device, so populate them here before passing the device to clusterDataProxy.AddWithId.
 		// agent.deviceId will also have been set during newDeviceAgent().
 		device = (proto.Clone(deviceToCreate)).(*voltha.Device)
-		device.Id = agent.deviceId
+		device.Id = agent.deviceID
 		device.AdminState = voltha.AdminState_PREPROVISIONED
 		device.FlowGroups = &ofp.FlowGroups{Items: nil}
 		device.Flows = &ofp.Flows{Items: nil}
@@ -114,16 +116,16 @@
 		}
 
 		// Add the initial device to the local model
-		if added := agent.clusterDataProxy.AddWithID(ctx, "/devices", agent.deviceId, device, ""); added == nil {
-			log.Errorw("failed-to-add-device", log.Fields{"deviceId": agent.deviceId})
-			return nil, status.Errorf(codes.Aborted, "failed-adding-device-%s", agent.deviceId)
+		if added := agent.clusterDataProxy.AddWithID(ctx, "/devices", agent.deviceID, device, ""); added == nil {
+			log.Errorw("failed-to-add-device", log.Fields{"deviceId": agent.deviceID})
+			return nil, status.Errorf(codes.Aborted, "failed-adding-device-%s", agent.deviceID)
 		}
 	}
 
-	agent.deviceProxy = agent.clusterDataProxy.CreateProxy(ctx, "/devices/"+agent.deviceId, false)
+	agent.deviceProxy = agent.clusterDataProxy.CreateProxy(ctx, "/devices/"+agent.deviceID, false)
 	agent.deviceProxy.RegisterCallback(model.POST_UPDATE, agent.processUpdate)
 
-	log.Debugw("device-agent-started", log.Fields{"deviceId": agent.deviceId})
+	log.Debugw("device-agent-started", log.Fields{"deviceId": agent.deviceID})
 	return device, nil
 }
 
@@ -133,8 +135,8 @@
 	defer agent.lockDevice.Unlock()
 	log.Debug("stopping-device-agent")
 	//	Remove the device from the KV store
-	if removed := agent.clusterDataProxy.Remove(ctx, "/devices/"+agent.deviceId, ""); removed == nil {
-		log.Debugw("device-already-removed", log.Fields{"id": agent.deviceId})
+	if removed := agent.clusterDataProxy.Remove(ctx, "/devices/"+agent.deviceID, ""); removed == nil {
+		log.Debugw("device-already-removed", log.Fields{"id": agent.deviceID})
 	}
 	agent.exitChannel <- 1
 	log.Debug("device-agent-stopped")
@@ -147,10 +149,10 @@
 	defer agent.lockDevice.Unlock()
 	log.Debug("reconciling-device-agent-devicetype")
 	// TODO: context timeout
-	if device := agent.clusterDataProxy.Get(context.Background(), "/devices/"+agent.deviceId, 1, true, ""); device != nil {
+	if device := agent.clusterDataProxy.Get(context.Background(), "/devices/"+agent.deviceID, 1, true, ""); device != nil {
 		if d, ok := device.(*voltha.Device); ok {
 			agent.deviceType = d.Adapter
-			log.Debugw("reconciled-device-agent-devicetype", log.Fields{"Id": agent.deviceId, "type": agent.deviceType})
+			log.Debugw("reconciled-device-agent-devicetype", log.Fields{"Id": agent.deviceID, "type": agent.deviceType})
 		}
 	}
 }
@@ -159,81 +161,81 @@
 func (agent *DeviceAgent) getDevice() (*voltha.Device, error) {
 	agent.lockDevice.RLock()
 	defer agent.lockDevice.RUnlock()
-	if device := agent.clusterDataProxy.Get(context.Background(), "/devices/"+agent.deviceId, 0, false, ""); device != nil {
+	if device := agent.clusterDataProxy.Get(context.Background(), "/devices/"+agent.deviceID, 0, false, ""); device != nil {
 		if d, ok := device.(*voltha.Device); ok {
 			cloned := proto.Clone(d).(*voltha.Device)
 			return cloned, nil
 		}
 	}
-	return nil, status.Errorf(codes.NotFound, "device-%s", agent.deviceId)
+	return nil, status.Errorf(codes.NotFound, "device-%s", agent.deviceID)
 }
 
 // getDeviceWithoutLock is a helper function to be used ONLY by any device agent function AFTER it has acquired the device lock.
 // This function is meant so that we do not have duplicate code all over the device agent functions
 func (agent *DeviceAgent) getDeviceWithoutLock() (*voltha.Device, error) {
-	if device := agent.clusterDataProxy.Get(context.Background(), "/devices/"+agent.deviceId, 0, false, ""); device != nil {
+	if device := agent.clusterDataProxy.Get(context.Background(), "/devices/"+agent.deviceID, 0, false, ""); device != nil {
 		if d, ok := device.(*voltha.Device); ok {
 			cloned := proto.Clone(d).(*voltha.Device)
 			return cloned, nil
 		}
 	}
-	return nil, status.Errorf(codes.NotFound, "device-%s", agent.deviceId)
+	return nil, status.Errorf(codes.NotFound, "device-%s", agent.deviceID)
 }
 
 // enableDevice activates a preprovisioned or a disable device
 func (agent *DeviceAgent) enableDevice(ctx context.Context) error {
 	agent.lockDevice.Lock()
 	defer agent.lockDevice.Unlock()
-	log.Debugw("enableDevice", log.Fields{"id": agent.deviceId})
+	log.Debugw("enableDevice", log.Fields{"id": agent.deviceID})
 
-	if device, err := agent.getDeviceWithoutLock(); err != nil {
-		return status.Errorf(codes.NotFound, "%s", agent.deviceId)
+	device, err := agent.getDeviceWithoutLock()
+	if err != nil {
+		return status.Errorf(codes.NotFound, "%s", agent.deviceID)
+	}
+	// First figure out which adapter will handle this device type.  We do it at this stage as allow devices to be
+	// pre-provisionned with the required adapter not registered.   At this stage, since we need to communicate
+	// with the adapter then we need to know the adapter that will handle this request
+	adapterName, err := agent.adapterMgr.getAdapterName(device.Type)
+	if err != nil {
+		log.Warnw("no-adapter-registered-for-device-type", log.Fields{"deviceType": device.Type, "deviceAdapter": device.Adapter})
+		return err
+	}
+	device.Adapter = adapterName
+
+	if device.AdminState == voltha.AdminState_ENABLED {
+		log.Debugw("device-already-enabled", log.Fields{"id": agent.deviceID})
+		return nil
+	}
+
+	if device.AdminState == voltha.AdminState_DELETED {
+		// This is a temporary state when a device is deleted before it gets removed from the model.
+		err = status.Error(codes.FailedPrecondition, fmt.Sprintf("cannot-enable-a-deleted-device: %s ", device.Id))
+		log.Warnw("invalid-state", log.Fields{"id": agent.deviceID, "state": device.AdminState, "error": err})
+		return err
+	}
+
+	previousAdminState := device.AdminState
+
+	// Update the Admin State and set the operational state to activating before sending the request to the
+	// Adapters
+	cloned := proto.Clone(device).(*voltha.Device)
+	cloned.AdminState = voltha.AdminState_ENABLED
+	cloned.OperStatus = voltha.OperStatus_ACTIVATING
+
+	if err := agent.updateDeviceInStoreWithoutLock(cloned, false, ""); err != nil {
+		return err
+	}
+
+	// Adopt the device if it was in preprovision state.  In all other cases, try to reenable it.
+	if previousAdminState == voltha.AdminState_PREPROVISIONED {
+		if err := agent.adapterProxy.AdoptDevice(ctx, device); err != nil {
+			log.Debugw("adoptDevice-error", log.Fields{"id": agent.deviceID, "error": err})
+			return err
+		}
 	} else {
-		// First figure out which adapter will handle this device type.  We do it at this stage as allow devices to be
-		// pre-provisionned with the required adapter not registered.   At this stage, since we need to communicate
-		// with the adapter then we need to know the adapter that will handle this request
-		if adapterName, err := agent.adapterMgr.getAdapterName(device.Type); err != nil {
-			log.Warnw("no-adapter-registered-for-device-type", log.Fields{"deviceType": device.Type, "deviceAdapter": device.Adapter})
+		if err := agent.adapterProxy.ReEnableDevice(ctx, device); err != nil {
+			log.Debugw("renableDevice-error", log.Fields{"id": agent.deviceID, "error": err})
 			return err
-		} else {
-			device.Adapter = adapterName
-		}
-
-		if device.AdminState == voltha.AdminState_ENABLED {
-			log.Debugw("device-already-enabled", log.Fields{"id": agent.deviceId})
-			return nil
-		}
-
-		if device.AdminState == voltha.AdminState_DELETED {
-			// This is a temporary state when a device is deleted before it gets removed from the model.
-			err = status.Error(codes.FailedPrecondition, fmt.Sprintf("cannot-enable-a-deleted-device: %s ", device.Id))
-			log.Warnw("invalid-state", log.Fields{"id": agent.deviceId, "state": device.AdminState, "error": err})
-			return err
-		}
-
-		previousAdminState := device.AdminState
-
-		// Update the Admin State and set the operational state to activating before sending the request to the
-		// Adapters
-		cloned := proto.Clone(device).(*voltha.Device)
-		cloned.AdminState = voltha.AdminState_ENABLED
-		cloned.OperStatus = voltha.OperStatus_ACTIVATING
-
-		if err := agent.updateDeviceInStoreWithoutLock(cloned, false, ""); err != nil {
-			return err
-		}
-
-		// Adopt the device if it was in preprovision state.  In all other cases, try to reenable it.
-		if previousAdminState == voltha.AdminState_PREPROVISIONED {
-			if err := agent.adapterProxy.AdoptDevice(ctx, device); err != nil {
-				log.Debugw("adoptDevice-error", log.Fields{"id": agent.deviceId, "error": err})
-				return err
-			}
-		} else {
-			if err := agent.adapterProxy.ReEnableDevice(ctx, device); err != nil {
-				log.Debugw("renableDevice-error", log.Fields{"id": agent.deviceId, "error": err})
-				return err
-			}
 		}
 	}
 	return nil
@@ -241,7 +243,7 @@
 
 func (agent *DeviceAgent) sendBulkFlowsToAdapters(device *voltha.Device, flows *voltha.Flows, groups *voltha.FlowGroups, flowMetadata *voltha.FlowMetadata, response coreutils.Response) {
 	if err := agent.adapterProxy.UpdateFlowsBulk(device, flows, groups, flowMetadata); err != nil {
-		log.Debugw("update-flow-bulk-error", log.Fields{"id": agent.deviceId, "error": err})
+		log.Debugw("update-flow-bulk-error", log.Fields{"id": agent.deviceID, "error": err})
 		response.Error(err)
 	}
 	response.Done()
@@ -249,7 +251,7 @@
 
 func (agent *DeviceAgent) sendIncrementalFlowsToAdapters(device *voltha.Device, flows *ofp.FlowChanges, groups *ofp.FlowGroupChanges, flowMetadata *voltha.FlowMetadata, response coreutils.Response) {
 	if err := agent.adapterProxy.UpdateFlowsIncremental(device, flows, groups, flowMetadata); err != nil {
-		log.Debugw("update-flow-incremental-error", log.Fields{"id": agent.deviceId, "error": err})
+		log.Debugw("update-flow-incremental-error", log.Fields{"id": agent.deviceID, "error": err})
 		response.Error(err)
 	}
 	response.Done()
@@ -258,10 +260,10 @@
 //addFlowsAndGroups adds the "newFlows" and "newGroups" from the existing flows/groups and sends the update to the
 //adapters
 func (agent *DeviceAgent) addFlowsAndGroups(newFlows []*ofp.OfpFlowStats, newGroups []*ofp.OfpGroupEntry, flowMetadata *voltha.FlowMetadata) error {
-	log.Debugw("addFlowsAndGroups", log.Fields{"deviceId": agent.deviceId, "flows": newFlows, "groups": newGroups, "flowMetadata": flowMetadata})
+	log.Debugw("addFlowsAndGroups", log.Fields{"deviceId": agent.deviceID, "flows": newFlows, "groups": newGroups, "flowMetadata": flowMetadata})
 
 	if (len(newFlows) | len(newGroups)) == 0 {
-		log.Debugw("nothing-to-update", log.Fields{"deviceId": agent.deviceId, "flows": newFlows, "groups": newGroups})
+		log.Debugw("nothing-to-update", log.Fields{"deviceId": agent.deviceID, "flows": newFlows, "groups": newGroups})
 		return nil
 	}
 
@@ -271,7 +273,7 @@
 	var device *voltha.Device
 	var err error
 	if device, err = agent.getDeviceWithoutLock(); err != nil {
-		return status.Errorf(codes.NotFound, "%s", agent.deviceId)
+		return status.Errorf(codes.NotFound, "%s", agent.deviceID)
 	}
 
 	existingFlows := proto.Clone(device.Flows).(*voltha.Flows)
@@ -283,9 +285,7 @@
 	var updatedGroups []*ofp.OfpGroupEntry
 
 	// Process flows
-	for _, flow := range newFlows {
-		updatedFlows = append(updatedFlows, flow)
-	}
+	updatedFlows = append(updatedFlows, newFlows...)
 	for _, flow := range existingFlows.Items {
 		if idx := fu.FindFlows(newFlows, flow); idx == -1 {
 			updatedFlows = append(updatedFlows, flow)
@@ -295,9 +295,7 @@
 	}
 
 	// Process groups
-	for _, g := range newGroups {
-		updatedGroups = append(updatedGroups, g)
-	}
+	updatedGroups = append(updatedGroups, newGroups...)
 	for _, group := range existingGroups.Items {
 		if fu.FindGroup(newGroups, group.Desc.GroupId) == -1 { // does not exist now
 			updatedGroups = append(updatedGroups, group)
@@ -308,7 +306,7 @@
 
 	// Sanity check
 	if (len(updatedFlows) | len(flowsToDelete) | len(updatedGroups) | len(groupsToDelete)) == 0 {
-		log.Debugw("nothing-to-update", log.Fields{"deviceId": agent.deviceId, "flows": newFlows, "groups": newGroups})
+		log.Debugw("nothing-to-update", log.Fields{"deviceId": agent.deviceID, "flows": newFlows, "groups": newGroups})
 		return nil
 	}
 
@@ -322,7 +320,7 @@
 	if !dType.AcceptsAddRemoveFlowUpdates {
 
 		if len(updatedGroups) != 0 && reflect.DeepEqual(existingGroups.Items, updatedGroups) && len(updatedFlows) != 0 && reflect.DeepEqual(existingFlows.Items, updatedFlows) {
-			log.Debugw("nothing-to-update", log.Fields{"deviceId": agent.deviceId, "flows": newFlows, "groups": newGroups})
+			log.Debugw("nothing-to-update", log.Fields{"deviceId": agent.deviceID, "flows": newFlows, "groups": newGroups})
 			return nil
 		}
 		go agent.sendBulkFlowsToAdapters(device, &voltha.Flows{Items: updatedFlows}, &voltha.FlowGroups{Items: updatedGroups}, flowMetadata, response)
@@ -344,7 +342,7 @@
 	device.Flows = &voltha.Flows{Items: updatedFlows}
 	device.FlowGroups = &voltha.FlowGroups{Items: updatedGroups}
 	if err := agent.updateDeviceWithoutLock(device); err != nil {
-		return status.Errorf(codes.Internal, "failure-updating-%s", agent.deviceId)
+		return status.Errorf(codes.Internal, "failure-updating-%s", agent.deviceID)
 	}
 
 	if res := coreutils.WaitForNilOrErrorResponses(agent.defaultTimeout, response); res != nil {
@@ -358,10 +356,10 @@
 //deleteFlowsAndGroups removes the "flowsToDel" and "groupsToDel" from the existing flows/groups and sends the update to the
 //adapters
 func (agent *DeviceAgent) deleteFlowsAndGroups(flowsToDel []*ofp.OfpFlowStats, groupsToDel []*ofp.OfpGroupEntry, flowMetadata *voltha.FlowMetadata) error {
-	log.Debugw("deleteFlowsAndGroups", log.Fields{"deviceId": agent.deviceId, "flows": flowsToDel, "groups": groupsToDel})
+	log.Debugw("deleteFlowsAndGroups", log.Fields{"deviceId": agent.deviceID, "flows": flowsToDel, "groups": groupsToDel})
 
 	if (len(flowsToDel) | len(groupsToDel)) == 0 {
-		log.Debugw("nothing-to-update", log.Fields{"deviceId": agent.deviceId, "flows": flowsToDel, "groups": groupsToDel})
+		log.Debugw("nothing-to-update", log.Fields{"deviceId": agent.deviceID, "flows": flowsToDel, "groups": groupsToDel})
 		return nil
 	}
 
@@ -372,7 +370,7 @@
 	var err error
 
 	if device, err = agent.getDeviceWithoutLock(); err != nil {
-		return status.Errorf(codes.NotFound, "%s", agent.deviceId)
+		return status.Errorf(codes.NotFound, "%s", agent.deviceID)
 	}
 
 	existingFlows := proto.Clone(device.Flows).(*voltha.Flows)
@@ -397,7 +395,7 @@
 
 	log.Debugw("deleteFlowsAndGroups",
 		log.Fields{
-			"deviceId":     agent.deviceId,
+			"deviceId":     agent.deviceID,
 			"flowsToDel":   len(flowsToDel),
 			"flowsToKeep":  len(flowsToKeep),
 			"groupsToDel":  len(groupsToDel),
@@ -406,7 +404,7 @@
 
 	// Sanity check
 	if (len(flowsToKeep) | len(flowsToDel) | len(groupsToKeep) | len(groupsToDel)) == 0 {
-		log.Debugw("nothing-to-update", log.Fields{"deviceId": agent.deviceId, "flowsToDel": flowsToDel, "groupsToDel": groupsToDel})
+		log.Debugw("nothing-to-update", log.Fields{"deviceId": agent.deviceID, "flowsToDel": flowsToDel, "groupsToDel": groupsToDel})
 		return nil
 	}
 
@@ -415,7 +413,7 @@
 	dType := agent.adapterMgr.getDeviceType(device.Type)
 	if !dType.AcceptsAddRemoveFlowUpdates {
 		if len(groupsToKeep) != 0 && reflect.DeepEqual(existingGroups.Items, groupsToKeep) && len(flowsToKeep) != 0 && reflect.DeepEqual(existingFlows.Items, flowsToKeep) {
-			log.Debugw("nothing-to-update", log.Fields{"deviceId": agent.deviceId, "flowsToDel": flowsToDel, "groupsToDel": groupsToDel})
+			log.Debugw("nothing-to-update", log.Fields{"deviceId": agent.deviceID, "flowsToDel": flowsToDel, "groupsToDel": groupsToDel})
 			return nil
 		}
 		go agent.sendBulkFlowsToAdapters(device, &voltha.Flows{Items: flowsToKeep}, &voltha.FlowGroups{Items: groupsToKeep}, flowMetadata, response)
@@ -436,7 +434,7 @@
 	device.Flows = &voltha.Flows{Items: flowsToKeep}
 	device.FlowGroups = &voltha.FlowGroups{Items: groupsToKeep}
 	if err := agent.updateDeviceWithoutLock(device); err != nil {
-		return status.Errorf(codes.Internal, "failure-updating-%s", agent.deviceId)
+		return status.Errorf(codes.Internal, "failure-updating-%s", agent.deviceID)
 	}
 
 	if res := coreutils.WaitForNilOrErrorResponses(agent.defaultTimeout, response); res != nil {
@@ -449,10 +447,10 @@
 //updateFlowsAndGroups replaces the existing flows and groups with "updatedFlows" and "updatedGroups" respectively. It
 //also sends the updates to the adapters
 func (agent *DeviceAgent) updateFlowsAndGroups(updatedFlows []*ofp.OfpFlowStats, updatedGroups []*ofp.OfpGroupEntry, flowMetadata *voltha.FlowMetadata) error {
-	log.Debugw("updateFlowsAndGroups", log.Fields{"deviceId": agent.deviceId, "flows": updatedFlows, "groups": updatedGroups})
+	log.Debugw("updateFlowsAndGroups", log.Fields{"deviceId": agent.deviceID, "flows": updatedFlows, "groups": updatedGroups})
 
 	if (len(updatedFlows) | len(updatedGroups)) == 0 {
-		log.Debugw("nothing-to-update", log.Fields{"deviceId": agent.deviceId, "flows": updatedFlows, "groups": updatedGroups})
+		log.Debugw("nothing-to-update", log.Fields{"deviceId": agent.deviceID, "flows": updatedFlows, "groups": updatedGroups})
 		return nil
 	}
 
@@ -461,19 +459,19 @@
 	var device *voltha.Device
 	var err error
 	if device, err = agent.getDeviceWithoutLock(); err != nil {
-		return status.Errorf(codes.NotFound, "%s", agent.deviceId)
+		return status.Errorf(codes.NotFound, "%s", agent.deviceID)
 	}
 	existingFlows := proto.Clone(device.Flows).(*voltha.Flows)
 	existingGroups := proto.Clone(device.FlowGroups).(*ofp.FlowGroups)
 
 	if len(updatedGroups) != 0 && reflect.DeepEqual(existingGroups.Items, updatedGroups) && len(updatedFlows) != 0 && reflect.DeepEqual(existingFlows.Items, updatedFlows) {
-		log.Debugw("nothing-to-update", log.Fields{"deviceId": agent.deviceId, "flows": updatedFlows, "groups": updatedGroups})
+		log.Debugw("nothing-to-update", log.Fields{"deviceId": agent.deviceID, "flows": updatedFlows, "groups": updatedGroups})
 		return nil
 	}
 
 	log.Debugw("updating-flows-and-groups",
 		log.Fields{
-			"deviceId":      agent.deviceId,
+			"deviceId":      agent.deviceID,
 			"updatedFlows":  updatedFlows,
 			"updatedGroups": updatedGroups,
 		})
@@ -516,7 +514,7 @@
 
 		log.Debugw("updating-flows-and-groups",
 			log.Fields{
-				"deviceId":       agent.deviceId,
+				"deviceId":       agent.deviceID,
 				"flowsToAdd":     flowsToAdd,
 				"flowsToDelete":  flowsToDelete,
 				"groupsToAdd":    groupsToAdd,
@@ -525,7 +523,7 @@
 
 		// Sanity check
 		if (len(flowsToAdd) | len(flowsToDelete) | len(groupsToAdd) | len(groupsToDelete) | len(updatedGroups)) == 0 {
-			log.Debugw("nothing-to-update", log.Fields{"deviceId": agent.deviceId, "flows": updatedFlows, "groups": updatedGroups})
+			log.Debugw("nothing-to-update", log.Fields{"deviceId": agent.deviceID, "flows": updatedFlows, "groups": updatedGroups})
 			return nil
 		}
 
@@ -545,7 +543,7 @@
 	device.Flows = &voltha.Flows{Items: updatedFlows}
 	device.FlowGroups = &voltha.FlowGroups{Items: updatedGroups}
 	if err := agent.updateDeviceWithoutLock(device); err != nil {
-		return status.Errorf(codes.Internal, "failure-updating-%s", agent.deviceId)
+		return status.Errorf(codes.Internal, "failure-updating-%s", agent.deviceID)
 	}
 
 	if res := coreutils.WaitForNilOrErrorResponses(agent.defaultTimeout, response); res != nil {
@@ -558,33 +556,33 @@
 func (agent *DeviceAgent) disableDevice(ctx context.Context) error {
 	agent.lockDevice.Lock()
 	defer agent.lockDevice.Unlock()
-	log.Debugw("disableDevice", log.Fields{"id": agent.deviceId})
+	log.Debugw("disableDevice", log.Fields{"id": agent.deviceID})
 	// Get the most up to date the device info
-	if device, err := agent.getDeviceWithoutLock(); err != nil {
-		return status.Errorf(codes.NotFound, "%s", agent.deviceId)
-	} else {
-		if device.AdminState == voltha.AdminState_DISABLED {
-			log.Debugw("device-already-disabled", log.Fields{"id": agent.deviceId})
-			return nil
-		}
-		if device.AdminState == voltha.AdminState_PREPROVISIONED ||
-			device.AdminState == voltha.AdminState_DELETED {
-			log.Debugw("device-not-enabled", log.Fields{"id": agent.deviceId})
-			return status.Errorf(codes.FailedPrecondition, "deviceId:%s, invalid-admin-state:%s", agent.deviceId, device.AdminState)
-		}
+	device, err := agent.getDeviceWithoutLock()
+	if err != nil {
+		return status.Errorf(codes.NotFound, "%s", agent.deviceID)
+	}
+	if device.AdminState == voltha.AdminState_DISABLED {
+		log.Debugw("device-already-disabled", log.Fields{"id": agent.deviceID})
+		return nil
+	}
+	if device.AdminState == voltha.AdminState_PREPROVISIONED ||
+		device.AdminState == voltha.AdminState_DELETED {
+		log.Debugw("device-not-enabled", log.Fields{"id": agent.deviceID})
+		return status.Errorf(codes.FailedPrecondition, "deviceId:%s, invalid-admin-state:%s", agent.deviceID, device.AdminState)
+	}
 
-		// Update the Admin State and operational state before sending the request out
-		cloned := proto.Clone(device).(*voltha.Device)
-		cloned.AdminState = voltha.AdminState_DISABLED
-		cloned.OperStatus = voltha.OperStatus_UNKNOWN
-		if err := agent.updateDeviceInStoreWithoutLock(cloned, false, ""); err != nil {
-			return err
-		}
+	// Update the Admin State and operational state before sending the request out
+	cloned := proto.Clone(device).(*voltha.Device)
+	cloned.AdminState = voltha.AdminState_DISABLED
+	cloned.OperStatus = voltha.OperStatus_UNKNOWN
+	if err := agent.updateDeviceInStoreWithoutLock(cloned, false, ""); err != nil {
+		return err
+	}
 
-		if err := agent.adapterProxy.DisableDevice(ctx, device); err != nil {
-			log.Debugw("disableDevice-error", log.Fields{"id": agent.deviceId, "error": err})
-			return err
-		}
+	if err := agent.adapterProxy.DisableDevice(ctx, device); err != nil {
+		log.Debugw("disableDevice-error", log.Fields{"id": agent.deviceID, "error": err})
+		return err
 	}
 	return nil
 }
@@ -592,21 +590,21 @@
 func (agent *DeviceAgent) updateAdminState(adminState voltha.AdminState_AdminState) error {
 	agent.lockDevice.Lock()
 	defer agent.lockDevice.Unlock()
-	log.Debugw("updateAdminState", log.Fields{"id": agent.deviceId})
+	log.Debugw("updateAdminState", log.Fields{"id": agent.deviceID})
 	// Get the most up to date the device info
-	if device, err := agent.getDeviceWithoutLock(); err != nil {
-		return status.Errorf(codes.NotFound, "%s", agent.deviceId)
-	} else {
-		if device.AdminState == adminState {
-			log.Debugw("no-change-needed", log.Fields{"id": agent.deviceId, "state": adminState})
-			return nil
-		}
-		// Received an Ack (no error found above).  Now update the device in the model to the expected state
-		cloned := proto.Clone(device).(*voltha.Device)
-		cloned.AdminState = adminState
-		if err := agent.updateDeviceInStoreWithoutLock(cloned, false, ""); err != nil {
-			return err
-		}
+	device, err := agent.getDeviceWithoutLock()
+	if err != nil {
+		return status.Errorf(codes.NotFound, "%s", agent.deviceID)
+	}
+	if device.AdminState == adminState {
+		log.Debugw("no-change-needed", log.Fields{"id": agent.deviceID, "state": adminState})
+		return nil
+	}
+	// Received an Ack (no error found above).  Now update the device in the model to the expected state
+	cloned := proto.Clone(device).(*voltha.Device)
+	cloned.AdminState = adminState
+	if err := agent.updateDeviceInStoreWithoutLock(cloned, false, ""); err != nil {
+		return err
 	}
 	return nil
 }
@@ -614,15 +612,15 @@
 func (agent *DeviceAgent) rebootDevice(ctx context.Context) error {
 	agent.lockDevice.Lock()
 	defer agent.lockDevice.Unlock()
-	log.Debugw("rebootDevice", log.Fields{"id": agent.deviceId})
+	log.Debugw("rebootDevice", log.Fields{"id": agent.deviceID})
 	// Get the most up to date the device info
-	if device, err := agent.getDeviceWithoutLock(); err != nil {
-		return status.Errorf(codes.NotFound, "%s", agent.deviceId)
-	} else {
-		if err := agent.adapterProxy.RebootDevice(ctx, device); err != nil {
-			log.Debugw("rebootDevice-error", log.Fields{"id": agent.deviceId, "error": err})
-			return err
-		}
+	device, err := agent.getDeviceWithoutLock()
+	if err != nil {
+		return status.Errorf(codes.NotFound, "%s", agent.deviceID)
+	}
+	if err := agent.adapterProxy.RebootDevice(ctx, device); err != nil {
+		log.Debugw("rebootDevice-error", log.Fields{"id": agent.deviceID, "error": err})
+		return err
 	}
 	return nil
 }
@@ -630,59 +628,64 @@
 func (agent *DeviceAgent) deleteDevice(ctx context.Context) error {
 	agent.lockDevice.Lock()
 	defer agent.lockDevice.Unlock()
-	log.Debugw("deleteDevice", log.Fields{"id": agent.deviceId})
+	log.Debugw("deleteDevice", log.Fields{"id": agent.deviceID})
 	// Get the most up to date the device info
-	if device, err := agent.getDeviceWithoutLock(); err != nil {
-		return status.Errorf(codes.NotFound, "%s", agent.deviceId)
-	} else {
-		if device.AdminState == voltha.AdminState_DELETED {
-			log.Debugw("device-already-in-deleted-state", log.Fields{"id": agent.deviceId})
-			return nil
-		}
-		if (device.AdminState != voltha.AdminState_DISABLED) &&
-			(device.AdminState != voltha.AdminState_PREPROVISIONED) {
-			log.Debugw("device-not-disabled", log.Fields{"id": agent.deviceId})
-			//TODO:  Needs customized error message
-			return status.Errorf(codes.FailedPrecondition, "deviceId:%s, expected-admin-state:%s", agent.deviceId, voltha.AdminState_DISABLED)
-		}
-		if device.AdminState != voltha.AdminState_PREPROVISIONED {
-			// Send the request to an Adapter only if the device is not in poreporovision state and wait for a response
-			if err := agent.adapterProxy.DeleteDevice(ctx, device); err != nil {
-				log.Debugw("deleteDevice-error", log.Fields{"id": agent.deviceId, "error": err})
-				return err
-			}
-		}
-		//	Set the state to deleted after we recieve an Ack - this will trigger some background process to clean up
-		//	the device as well as its association with the logical device
-		cloned := proto.Clone(device).(*voltha.Device)
-		cloned.AdminState = voltha.AdminState_DELETED
-		if err := agent.updateDeviceInStoreWithoutLock(cloned, false, ""); err != nil {
+	device, err := agent.getDeviceWithoutLock()
+	if err != nil {
+		return status.Errorf(codes.NotFound, "%s", agent.deviceID)
+	}
+	if device.AdminState == voltha.AdminState_DELETED {
+		log.Debugw("device-already-in-deleted-state", log.Fields{"id": agent.deviceID})
+		return nil
+	}
+	if (device.AdminState != voltha.AdminState_DISABLED) &&
+		(device.AdminState != voltha.AdminState_PREPROVISIONED) {
+		log.Debugw("device-not-disabled", log.Fields{"id": agent.deviceID})
+		//TODO:  Needs customized error message
+		return status.Errorf(codes.FailedPrecondition, "deviceId:%s, expected-admin-state:%s", agent.deviceID, voltha.AdminState_DISABLED)
+	}
+	if device.AdminState != voltha.AdminState_PREPROVISIONED {
+		// Send the request to an Adapter only if the device is not in poreporovision state and wait for a response
+		if err := agent.adapterProxy.DeleteDevice(ctx, device); err != nil {
+			log.Debugw("deleteDevice-error", log.Fields{"id": agent.deviceID, "error": err})
 			return err
 		}
-		//	If this is a child device then remove the associated peer ports on the parent device
-		if !device.Root {
-			go agent.deviceMgr.deletePeerPorts(device.ParentId, device.Id)
-		}
+	}
+	//	Set the state to deleted after we receive an Ack - this will trigger some background process to clean up
+	//	the device as well as its association with the logical device
+	cloned := proto.Clone(device).(*voltha.Device)
+	cloned.AdminState = voltha.AdminState_DELETED
+	if err := agent.updateDeviceInStoreWithoutLock(cloned, false, ""); err != nil {
+		return err
+	}
+	//	If this is a child device then remove the associated peer ports on the parent device
+	if !device.Root {
+		go func() {
+			err := agent.deviceMgr.deletePeerPorts(device.ParentId, device.Id)
+			if err != nil {
+				log.Errorw("unable-to-delete-peer-ports", log.Fields{"error": err})
+			}
+		}()
 	}
 	return nil
 }
 
-func (agent *DeviceAgent) setParentId(device *voltha.Device, parentId string) error {
+func (agent *DeviceAgent) setParentID(device *voltha.Device, parentID string) error {
 	agent.lockDevice.Lock()
 	defer agent.lockDevice.Unlock()
-	log.Debugw("setParentId", log.Fields{"deviceId": device.Id, "parentId": parentId})
-	if storeDevice, err := agent.getDeviceWithoutLock(); err != nil {
-		return status.Errorf(codes.NotFound, "%s", agent.deviceId)
-	} else {
-		// clone the device
-		cloned := proto.Clone(storeDevice).(*voltha.Device)
-		cloned.ParentId = parentId
-		// Store the device
-		if err := agent.updateDeviceInStoreWithoutLock(cloned, false, ""); err != nil {
-			return err
-		}
-		return nil
+	log.Debugw("setParentId", log.Fields{"deviceId": device.Id, "parentId": parentID})
+	storeDevice, err := agent.getDeviceWithoutLock()
+	if err != nil {
+		return status.Errorf(codes.NotFound, "%s", agent.deviceID)
 	}
+	// clone the device
+	cloned := proto.Clone(storeDevice).(*voltha.Device)
+	cloned.ParentId = parentID
+	// Store the device
+	if err := agent.updateDeviceInStoreWithoutLock(cloned, false, ""); err != nil {
+		return err
+	}
+	return nil
 }
 
 func (agent *DeviceAgent) updatePmConfigs(ctx context.Context, pmConfigs *voltha.PmConfigs) error {
@@ -690,23 +693,23 @@
 	defer agent.lockDevice.Unlock()
 	log.Debugw("updatePmConfigs", log.Fields{"id": pmConfigs.Id})
 	// Work only on latest data
-	if storeDevice, err := agent.getDeviceWithoutLock(); err != nil {
-		return status.Errorf(codes.NotFound, "%s", agent.deviceId)
-	} else {
-		// clone the device
-		cloned := proto.Clone(storeDevice).(*voltha.Device)
-		cloned.PmConfigs = proto.Clone(pmConfigs).(*voltha.PmConfigs)
-		// Store the device
-		if err := agent.updateDeviceInStoreWithoutLock(cloned, false, ""); err != nil {
-			return err
-		}
-		// Send the request to the adapter
-		if err := agent.adapterProxy.UpdatePmConfigs(ctx, cloned, pmConfigs); err != nil {
-			log.Errorw("update-pm-configs-error", log.Fields{"id": agent.deviceId, "error": err})
-			return err
-		}
-		return nil
+	storeDevice, err := agent.getDeviceWithoutLock()
+	if err != nil {
+		return status.Errorf(codes.NotFound, "%s", agent.deviceID)
 	}
+	// clone the device
+	cloned := proto.Clone(storeDevice).(*voltha.Device)
+	cloned.PmConfigs = proto.Clone(pmConfigs).(*voltha.PmConfigs)
+	// Store the device
+	if err := agent.updateDeviceInStoreWithoutLock(cloned, false, ""); err != nil {
+		return err
+	}
+	// Send the request to the adapter
+	if err := agent.adapterProxy.UpdatePmConfigs(ctx, cloned, pmConfigs); err != nil {
+		log.Errorw("update-pm-configs-error", log.Fields{"id": agent.deviceID, "error": err})
+		return err
+	}
+	return nil
 }
 
 func (agent *DeviceAgent) initPmConfigs(pmConfigs *voltha.PmConfigs) error {
@@ -714,46 +717,58 @@
 	defer agent.lockDevice.Unlock()
 	log.Debugw("initPmConfigs", log.Fields{"id": pmConfigs.Id})
 	// Work only on latest data
-	if storeDevice, err := agent.getDeviceWithoutLock(); err != nil {
-		return status.Errorf(codes.NotFound, "%s", agent.deviceId)
-	} else {
-		// clone the device
-		cloned := proto.Clone(storeDevice).(*voltha.Device)
-		cloned.PmConfigs = proto.Clone(pmConfigs).(*voltha.PmConfigs)
-		// Store the device
-		updateCtx := context.WithValue(context.Background(), model.RequestTimestamp, time.Now().UnixNano())
-		afterUpdate := agent.clusterDataProxy.Update(updateCtx, "/devices/"+agent.deviceId, cloned, false, "")
-		if afterUpdate == nil {
-			return status.Errorf(codes.Internal, "%s", agent.deviceId)
-		}
-		return nil
+	storeDevice, err := agent.getDeviceWithoutLock()
+	if err != nil {
+		return status.Errorf(codes.NotFound, "%s", agent.deviceID)
 	}
+	// clone the device
+	cloned := proto.Clone(storeDevice).(*voltha.Device)
+	cloned.PmConfigs = proto.Clone(pmConfigs).(*voltha.PmConfigs)
+	// Store the device
+	updateCtx := context.WithValue(context.Background(), model.RequestTimestamp, time.Now().UnixNano())
+	afterUpdate := agent.clusterDataProxy.Update(updateCtx, "/devices/"+agent.deviceID, cloned, false, "")
+	if afterUpdate == nil {
+		return status.Errorf(codes.Internal, "%s", agent.deviceID)
+	}
+	return nil
 }
 
 func (agent *DeviceAgent) listPmConfigs(ctx context.Context) (*voltha.PmConfigs, error) {
 	agent.lockDevice.RLock()
 	defer agent.lockDevice.RUnlock()
-	log.Debugw("listPmConfigs", log.Fields{"id": agent.deviceId})
+	log.Debugw("listPmConfigs", log.Fields{"id": agent.deviceID})
 	// Get the most up to date the device info
-	if device, err := agent.getDeviceWithoutLock(); err != nil {
-		return nil, status.Errorf(codes.NotFound, "%s", agent.deviceId)
-	} else {
-		cloned := proto.Clone(device).(*voltha.Device)
-		return cloned.PmConfigs, nil
+	device, err := agent.getDeviceWithoutLock()
+	if err != nil {
+		return nil, status.Errorf(codes.NotFound, "%s", agent.deviceID)
 	}
+	cloned := proto.Clone(device).(*voltha.Device)
+	return cloned.PmConfigs, nil
 }
 
 func (agent *DeviceAgent) downloadImage(ctx context.Context, img *voltha.ImageDownload) (*voltha.OperationResp, error) {
 	agent.lockDevice.Lock()
 	defer agent.lockDevice.Unlock()
-	log.Debugw("downloadImage", log.Fields{"id": agent.deviceId})
+	log.Debugw("downloadImage", log.Fields{"id": agent.deviceID})
 	// Get the most up to date the device info
-	if device, err := agent.getDeviceWithoutLock(); err != nil {
-		return nil, status.Errorf(codes.NotFound, "%s", agent.deviceId)
+	device, err := agent.getDeviceWithoutLock()
+	if err != nil {
+		return nil, status.Errorf(codes.NotFound, "%s", agent.deviceID)
+	}
+	if device.AdminState != voltha.AdminState_ENABLED {
+		log.Debugw("device-not-enabled", log.Fields{"id": agent.deviceID})
+		return nil, status.Errorf(codes.FailedPrecondition, "deviceId:%s, expected-admin-state:%s", agent.deviceID, voltha.AdminState_ENABLED)
+	}
+	// Save the image
+	clonedImg := proto.Clone(img).(*voltha.ImageDownload)
+	clonedImg.DownloadState = voltha.ImageDownload_DOWNLOAD_REQUESTED
+	cloned := proto.Clone(device).(*voltha.Device)
+	if cloned.ImageDownloads == nil {
+		cloned.ImageDownloads = []*voltha.ImageDownload{clonedImg}
 	} else {
 		if device.AdminState != voltha.AdminState_ENABLED {
-			log.Debugw("device-not-enabled", log.Fields{"id": agent.deviceId})
-			return nil, status.Errorf(codes.FailedPrecondition, "deviceId:%s, expected-admin-state:%s", agent.deviceId, voltha.AdminState_ENABLED)
+			log.Debugw("device-not-enabled", log.Fields{"id": agent.deviceID})
+			return nil, status.Errorf(codes.FailedPrecondition, "deviceId:%s, expected-admin-state:%s", agent.deviceID, voltha.AdminState_ENABLED)
 		}
 		// Save the image
 		clonedImg := proto.Clone(img).(*voltha.ImageDownload)
@@ -770,7 +785,7 @@
 		}
 		// Send the request to the adapter
 		if err := agent.adapterProxy.DownloadImage(ctx, cloned, clonedImg); err != nil {
-			log.Debugw("downloadImage-error", log.Fields{"id": agent.deviceId, "error": err, "image": img.Name})
+			log.Debugw("downloadImage-error", log.Fields{"id": agent.deviceID, "error": err, "image": img.Name})
 			return nil, err
 		}
 	}
@@ -790,35 +805,35 @@
 func (agent *DeviceAgent) cancelImageDownload(ctx context.Context, img *voltha.ImageDownload) (*voltha.OperationResp, error) {
 	agent.lockDevice.Lock()
 	defer agent.lockDevice.Unlock()
-	log.Debugw("cancelImageDownload", log.Fields{"id": agent.deviceId})
+	log.Debugw("cancelImageDownload", log.Fields{"id": agent.deviceID})
 	// Get the most up to date the device info
-	if device, err := agent.getDeviceWithoutLock(); err != nil {
-		return nil, status.Errorf(codes.NotFound, "%s", agent.deviceId)
-	} else {
-		// Verify whether the Image is in the list of image being downloaded
-		if !isImageRegistered(img, device) {
-			return nil, status.Errorf(codes.FailedPrecondition, "deviceId:%s, image-not-registered:%s", agent.deviceId, img.Name)
-		}
+	device, err := agent.getDeviceWithoutLock()
+	if err != nil {
+		return nil, status.Errorf(codes.NotFound, "%s", agent.deviceID)
+	}
+	// Verify whether the Image is in the list of image being downloaded
+	if !isImageRegistered(img, device) {
+		return nil, status.Errorf(codes.FailedPrecondition, "deviceId:%s, image-not-registered:%s", agent.deviceID, img.Name)
+	}
 
-		// Update image download state
-		cloned := proto.Clone(device).(*voltha.Device)
-		for _, image := range cloned.ImageDownloads {
-			if image.Id == img.Id && image.Name == img.Name {
-				image.DownloadState = voltha.ImageDownload_DOWNLOAD_CANCELLED
-			}
+	// Update image download state
+	cloned := proto.Clone(device).(*voltha.Device)
+	for _, image := range cloned.ImageDownloads {
+		if image.Id == img.Id && image.Name == img.Name {
+			image.DownloadState = voltha.ImageDownload_DOWNLOAD_CANCELLED
 		}
+	}
 
-		if device.AdminState == voltha.AdminState_DOWNLOADING_IMAGE {
-			// Set the device to Enabled
-			cloned.AdminState = voltha.AdminState_ENABLED
-			if err := agent.updateDeviceInStoreWithoutLock(cloned, false, ""); err != nil {
-				return nil, err
-			}
-			// Send the request to teh adapter
-			if err := agent.adapterProxy.CancelImageDownload(ctx, device, img); err != nil {
-				log.Debugw("cancelImageDownload-error", log.Fields{"id": agent.deviceId, "error": err, "image": img.Name})
-				return nil, err
-			}
+	if device.AdminState == voltha.AdminState_DOWNLOADING_IMAGE {
+		// Set the device to Enabled
+		cloned.AdminState = voltha.AdminState_ENABLED
+		if err := agent.updateDeviceInStoreWithoutLock(cloned, false, ""); err != nil {
+			return nil, err
+		}
+		// Send the request to the adapter
+		if err := agent.adapterProxy.CancelImageDownload(ctx, device, img); err != nil {
+			log.Debugw("cancelImageDownload-error", log.Fields{"id": agent.deviceID, "error": err, "image": img.Name})
+			return nil, err
 		}
 	}
 	return &voltha.OperationResp{Code: voltha.OperationResp_OPERATION_SUCCESS}, nil
@@ -827,74 +842,74 @@
 func (agent *DeviceAgent) activateImage(ctx context.Context, img *voltha.ImageDownload) (*voltha.OperationResp, error) {
 	agent.lockDevice.Lock()
 	defer agent.lockDevice.Unlock()
-	log.Debugw("activateImage", log.Fields{"id": agent.deviceId})
+	log.Debugw("activateImage", log.Fields{"id": agent.deviceID})
 	// Get the most up to date the device info
-	if device, err := agent.getDeviceWithoutLock(); err != nil {
-		return nil, status.Errorf(codes.NotFound, "%s", agent.deviceId)
-	} else {
-		// Verify whether the Image is in the list of image being downloaded
-		if !isImageRegistered(img, device) {
-			return nil, status.Errorf(codes.FailedPrecondition, "deviceId:%s, image-not-registered:%s", agent.deviceId, img.Name)
-		}
-
-		if device.AdminState == voltha.AdminState_DOWNLOADING_IMAGE {
-			return nil, status.Errorf(codes.FailedPrecondition, "deviceId:%s, device-in-downloading-state:%s", agent.deviceId, img.Name)
-		}
-		// Update image download state
-		cloned := proto.Clone(device).(*voltha.Device)
-		for _, image := range cloned.ImageDownloads {
-			if image.Id == img.Id && image.Name == img.Name {
-				image.ImageState = voltha.ImageDownload_IMAGE_ACTIVATING
-			}
-		}
-		// Set the device to downloading_image
-		cloned.AdminState = voltha.AdminState_DOWNLOADING_IMAGE
-		if err := agent.updateDeviceInStoreWithoutLock(cloned, false, ""); err != nil {
-			return nil, err
-		}
-
-		if err := agent.adapterProxy.ActivateImageUpdate(ctx, device, img); err != nil {
-			log.Debugw("activateImage-error", log.Fields{"id": agent.deviceId, "error": err, "image": img.Name})
-			return nil, err
-		}
-		// The status of the AdminState will be changed following the update_download_status response from the adapter
-		// The image name will also be removed from the device list
+	device, err := agent.getDeviceWithoutLock()
+	if err != nil {
+		return nil, status.Errorf(codes.NotFound, "%s", agent.deviceID)
 	}
+	// Verify whether the Image is in the list of image being downloaded
+	if !isImageRegistered(img, device) {
+		return nil, status.Errorf(codes.FailedPrecondition, "deviceId:%s, image-not-registered:%s", agent.deviceID, img.Name)
+	}
+
+	if device.AdminState == voltha.AdminState_DOWNLOADING_IMAGE {
+		return nil, status.Errorf(codes.FailedPrecondition, "deviceId:%s, device-in-downloading-state:%s", agent.deviceID, img.Name)
+	}
+	// Update image download state
+	cloned := proto.Clone(device).(*voltha.Device)
+	for _, image := range cloned.ImageDownloads {
+		if image.Id == img.Id && image.Name == img.Name {
+			image.ImageState = voltha.ImageDownload_IMAGE_ACTIVATING
+		}
+	}
+	// Set the device to downloading_image
+	cloned.AdminState = voltha.AdminState_DOWNLOADING_IMAGE
+	if err := agent.updateDeviceInStoreWithoutLock(cloned, false, ""); err != nil {
+		return nil, err
+	}
+
+	if err := agent.adapterProxy.ActivateImageUpdate(ctx, device, img); err != nil {
+		log.Debugw("activateImage-error", log.Fields{"id": agent.deviceID, "error": err, "image": img.Name})
+		return nil, err
+	}
+	// The status of the AdminState will be changed following the update_download_status response from the adapter
+	// The image name will also be removed from the device list
 	return &voltha.OperationResp{Code: voltha.OperationResp_OPERATION_SUCCESS}, nil
 }
 
 func (agent *DeviceAgent) revertImage(ctx context.Context, img *voltha.ImageDownload) (*voltha.OperationResp, error) {
 	agent.lockDevice.Lock()
 	defer agent.lockDevice.Unlock()
-	log.Debugw("revertImage", log.Fields{"id": agent.deviceId})
+	log.Debugw("revertImage", log.Fields{"id": agent.deviceID})
 	// Get the most up to date the device info
-	if device, err := agent.getDeviceWithoutLock(); err != nil {
-		return nil, status.Errorf(codes.NotFound, "%s", agent.deviceId)
-	} else {
-		// Verify whether the Image is in the list of image being downloaded
-		if !isImageRegistered(img, device) {
-			return nil, status.Errorf(codes.FailedPrecondition, "deviceId:%s, image-not-registered:%s", agent.deviceId, img.Name)
-		}
+	device, err := agent.getDeviceWithoutLock()
+	if err != nil {
+		return nil, status.Errorf(codes.NotFound, "%s", agent.deviceID)
+	}
+	// Verify whether the Image is in the list of image being downloaded
+	if !isImageRegistered(img, device) {
+		return nil, status.Errorf(codes.FailedPrecondition, "deviceId:%s, image-not-registered:%s", agent.deviceID, img.Name)
+	}
 
-		if device.AdminState != voltha.AdminState_ENABLED {
-			return nil, status.Errorf(codes.FailedPrecondition, "deviceId:%s, device-not-enabled-state:%s", agent.deviceId, img.Name)
+	if device.AdminState != voltha.AdminState_ENABLED {
+		return nil, status.Errorf(codes.FailedPrecondition, "deviceId:%s, device-not-enabled-state:%s", agent.deviceID, img.Name)
+	}
+	// Update image download state
+	cloned := proto.Clone(device).(*voltha.Device)
+	for _, image := range cloned.ImageDownloads {
+		if image.Id == img.Id && image.Name == img.Name {
+			image.ImageState = voltha.ImageDownload_IMAGE_REVERTING
 		}
-		// Update image download state
-		cloned := proto.Clone(device).(*voltha.Device)
-		for _, image := range cloned.ImageDownloads {
-			if image.Id == img.Id && image.Name == img.Name {
-				image.ImageState = voltha.ImageDownload_IMAGE_REVERTING
-			}
-		}
+	}
 
-		if err := agent.updateDeviceInStoreWithoutLock(cloned, false, ""); err != nil {
-			return nil, err
-		}
+	if err := agent.updateDeviceInStoreWithoutLock(cloned, false, ""); err != nil {
+		return nil, err
+	}
 
-		if err := agent.adapterProxy.RevertImageUpdate(ctx, device, img); err != nil {
-			log.Debugw("revertImage-error", log.Fields{"id": agent.deviceId, "error": err, "image": img.Name})
-			return nil, err
-		}
+	if err := agent.adapterProxy.RevertImageUpdate(ctx, device, img); err != nil {
+		log.Debugw("revertImage-error", log.Fields{"id": agent.deviceID, "error": err, "image": img.Name})
+		return nil, err
 	}
 	return &voltha.OperationResp{Code: voltha.OperationResp_OPERATION_SUCCESS}, nil
 }
@@ -902,49 +917,49 @@
 func (agent *DeviceAgent) getImageDownloadStatus(ctx context.Context, img *voltha.ImageDownload) (*voltha.ImageDownload, error) {
 	agent.lockDevice.Lock()
 	defer agent.lockDevice.Unlock()
-	log.Debugw("getImageDownloadStatus", log.Fields{"id": agent.deviceId})
+	log.Debugw("getImageDownloadStatus", log.Fields{"id": agent.deviceID})
 	// Get the most up to date the device info
-	if device, err := agent.getDeviceWithoutLock(); err != nil {
-		return nil, status.Errorf(codes.NotFound, "%s", agent.deviceId)
-	} else {
-		if resp, err := agent.adapterProxy.GetImageDownloadStatus(ctx, device, img); err != nil {
-			log.Debugw("getImageDownloadStatus-error", log.Fields{"id": agent.deviceId, "error": err, "image": img.Name})
-			return nil, err
-		} else {
-			return resp, nil
-		}
+	device, err := agent.getDeviceWithoutLock()
+	if err != nil {
+		return nil, status.Errorf(codes.NotFound, "%s", agent.deviceID)
 	}
+	resp, err := agent.adapterProxy.GetImageDownloadStatus(ctx, device, img)
+	if err != nil {
+		log.Debugw("getImageDownloadStatus-error", log.Fields{"id": agent.deviceID, "error": err, "image": img.Name})
+		return nil, err
+	}
+	return resp, nil
 }
 
 func (agent *DeviceAgent) updateImageDownload(img *voltha.ImageDownload) error {
 	agent.lockDevice.Lock()
 	defer agent.lockDevice.Unlock()
-	log.Debugw("updateImageDownload", log.Fields{"id": agent.deviceId})
+	log.Debugw("updateImageDownload", log.Fields{"id": agent.deviceID})
 	// Get the most up to date the device info
-	if device, err := agent.getDeviceWithoutLock(); err != nil {
-		return status.Errorf(codes.NotFound, "%s", agent.deviceId)
-	} else {
-		// Update the image as well as remove it if the download was cancelled
-		cloned := proto.Clone(device).(*voltha.Device)
-		clonedImages := make([]*voltha.ImageDownload, len(cloned.ImageDownloads))
-		for _, image := range cloned.ImageDownloads {
-			if image.Id == img.Id && image.Name == img.Name {
-				if image.DownloadState != voltha.ImageDownload_DOWNLOAD_CANCELLED {
-					clonedImages = append(clonedImages, img)
-				}
+	device, err := agent.getDeviceWithoutLock()
+	if err != nil {
+		return status.Errorf(codes.NotFound, "%s", agent.deviceID)
+	}
+	// Update the image as well as remove it if the download was cancelled
+	cloned := proto.Clone(device).(*voltha.Device)
+	clonedImages := make([]*voltha.ImageDownload, len(cloned.ImageDownloads))
+	for _, image := range cloned.ImageDownloads {
+		if image.Id == img.Id && image.Name == img.Name {
+			if image.DownloadState != voltha.ImageDownload_DOWNLOAD_CANCELLED {
+				clonedImages = append(clonedImages, img)
 			}
 		}
-		cloned.ImageDownloads = clonedImages
-		// Set the Admin state to enabled if required
-		if (img.DownloadState != voltha.ImageDownload_DOWNLOAD_REQUESTED &&
-			img.DownloadState != voltha.ImageDownload_DOWNLOAD_STARTED) ||
-			(img.ImageState != voltha.ImageDownload_IMAGE_ACTIVATING) {
-			cloned.AdminState = voltha.AdminState_ENABLED
-		}
+	}
+	cloned.ImageDownloads = clonedImages
+	// Set the Admin state to enabled if required
+	if (img.DownloadState != voltha.ImageDownload_DOWNLOAD_REQUESTED &&
+		img.DownloadState != voltha.ImageDownload_DOWNLOAD_STARTED) ||
+		(img.ImageState != voltha.ImageDownload_IMAGE_ACTIVATING) {
+		cloned.AdminState = voltha.AdminState_ENABLED
+	}
 
-		if err := agent.updateDeviceInStoreWithoutLock(cloned, false, ""); err != nil {
-			return err
-		}
+	if err := agent.updateDeviceInStoreWithoutLock(cloned, false, ""); err != nil {
+		return err
 	}
 	return nil
 }
@@ -952,37 +967,37 @@
 func (agent *DeviceAgent) getImageDownload(ctx context.Context, img *voltha.ImageDownload) (*voltha.ImageDownload, error) {
 	agent.lockDevice.RLock()
 	defer agent.lockDevice.RUnlock()
-	log.Debugw("getImageDownload", log.Fields{"id": agent.deviceId})
+	log.Debugw("getImageDownload", log.Fields{"id": agent.deviceID})
 	// Get the most up to date the device info
-	if device, err := agent.getDeviceWithoutLock(); err != nil {
-		return nil, status.Errorf(codes.NotFound, "%s", agent.deviceId)
-	} else {
-		for _, image := range device.ImageDownloads {
-			if image.Id == img.Id && image.Name == img.Name {
-				return image, nil
-			}
-		}
-		return nil, status.Errorf(codes.NotFound, "image-not-found:%s", img.Name)
+	device, err := agent.getDeviceWithoutLock()
+	if err != nil {
+		return nil, status.Errorf(codes.NotFound, "%s", agent.deviceID)
 	}
+	for _, image := range device.ImageDownloads {
+		if image.Id == img.Id && image.Name == img.Name {
+			return image, nil
+		}
+	}
+	return nil, status.Errorf(codes.NotFound, "image-not-found:%s", img.Name)
 }
 
-func (agent *DeviceAgent) listImageDownloads(ctx context.Context, deviceId string) (*voltha.ImageDownloads, error) {
+func (agent *DeviceAgent) listImageDownloads(ctx context.Context, deviceID string) (*voltha.ImageDownloads, error) {
 	agent.lockDevice.RLock()
 	defer agent.lockDevice.RUnlock()
-	log.Debugw("listImageDownloads", log.Fields{"id": agent.deviceId})
+	log.Debugw("listImageDownloads", log.Fields{"id": agent.deviceID})
 	// Get the most up to date the device info
-	if device, err := agent.getDeviceWithoutLock(); err != nil {
-		return nil, status.Errorf(codes.NotFound, "%s", agent.deviceId)
-	} else {
-		return &voltha.ImageDownloads{Items: device.ImageDownloads}, nil
+	device, err := agent.getDeviceWithoutLock()
+	if err != nil {
+		return nil, status.Errorf(codes.NotFound, "%s", agent.deviceID)
 	}
+	return &voltha.ImageDownloads{Items: device.ImageDownloads}, nil
 }
 
 // getPorts retrieves the ports information of the device based on the port type.
 func (agent *DeviceAgent) getPorts(ctx context.Context, portType voltha.Port_PortType) *voltha.Ports {
-	log.Debugw("getPorts", log.Fields{"id": agent.deviceId, "portType": portType})
+	log.Debugw("getPorts", log.Fields{"id": agent.deviceID, "portType": portType})
 	ports := &voltha.Ports{}
-	if device, _ := agent.deviceMgr.GetDevice(agent.deviceId); device != nil {
+	if device, _ := agent.deviceMgr.GetDevice(agent.deviceID); device != nil {
 		for _, port := range device.Ports {
 			if port.Type == portType {
 				ports.Items = append(ports.Items, port)
@@ -995,35 +1010,33 @@
 // getSwitchCapability is a helper method that a logical device agent uses to retrieve the switch capability of a
 // parent device
 func (agent *DeviceAgent) getSwitchCapability(ctx context.Context) (*ic.SwitchCapability, error) {
-	log.Debugw("getSwitchCapability", log.Fields{"deviceId": agent.deviceId})
-	if device, err := agent.deviceMgr.GetDevice(agent.deviceId); device == nil {
+	log.Debugw("getSwitchCapability", log.Fields{"deviceId": agent.deviceID})
+	device, err := agent.deviceMgr.GetDevice(agent.deviceID)
+	if device == nil {
 		return nil, err
-	} else {
-		var switchCap *ic.SwitchCapability
-		var err error
-		if switchCap, err = agent.adapterProxy.GetOfpDeviceInfo(ctx, device); err != nil {
-			log.Debugw("getSwitchCapability-error", log.Fields{"id": device.Id, "error": err})
-			return nil, err
-		}
-		return switchCap, nil
 	}
+	var switchCap *ic.SwitchCapability
+	if switchCap, err = agent.adapterProxy.GetOfpDeviceInfo(ctx, device); err != nil {
+		log.Debugw("getSwitchCapability-error", log.Fields{"id": device.Id, "error": err})
+		return nil, err
+	}
+	return switchCap, nil
 }
 
 // getPortCapability is a helper method that a logical device agent uses to retrieve the port capability of a
 // device
 func (agent *DeviceAgent) getPortCapability(ctx context.Context, portNo uint32) (*ic.PortCapability, error) {
-	log.Debugw("getPortCapability", log.Fields{"deviceId": agent.deviceId})
-	if device, err := agent.deviceMgr.GetDevice(agent.deviceId); device == nil {
+	log.Debugw("getPortCapability", log.Fields{"deviceId": agent.deviceID})
+	device, err := agent.deviceMgr.GetDevice(agent.deviceID)
+	if device == nil {
 		return nil, err
-	} else {
-		var portCap *ic.PortCapability
-		var err error
-		if portCap, err = agent.adapterProxy.GetOfpPortInfo(ctx, device, portNo); err != nil {
-			log.Debugw("getPortCapability-error", log.Fields{"id": device.Id, "error": err})
-			return nil, err
-		}
-		return portCap, nil
 	}
+	var portCap *ic.PortCapability
+	if portCap, err = agent.adapterProxy.GetOfpPortInfo(ctx, device, portNo); err != nil {
+		log.Debugw("getPortCapability-error", log.Fields{"id": device.Id, "error": err})
+		return nil, err
+	}
+	return portCap, nil
 }
 
 func (agent *DeviceAgent) packetOut(outPort uint32, packet *ofp.OfpPacketOut) error {
@@ -1033,9 +1046,9 @@
 		agent.reconcileWithKVStore()
 	}
 	//	Send packet to adapter
-	if err := agent.adapterProxy.packetOut(agent.deviceType, agent.deviceId, outPort, packet); err != nil {
+	if err := agent.adapterProxy.packetOut(agent.deviceType, agent.deviceID, outPort, packet); err != nil {
 		log.Debugw("packet-out-error", log.Fields{
-			"id":     agent.deviceId,
+			"id":     agent.deviceID,
 			"error":  err,
 			"packet": hex.EncodeToString(packet.Data),
 		})
@@ -1098,13 +1111,13 @@
 	agent.lockDevice.Lock()
 	defer agent.lockDevice.Unlock()
 	log.Debugw("updateDeviceUsingAdapterData", log.Fields{"deviceId": device.Id})
-	if updatedDevice, err := agent.mergeDeviceInfoFromAdapter(device); err != nil {
+	updatedDevice, err := agent.mergeDeviceInfoFromAdapter(device)
+	if err != nil {
 		log.Errorw("failed to update device ", log.Fields{"deviceId": device.Id})
 		return status.Errorf(codes.Internal, "%s", err.Error())
-	} else {
-		cloned := proto.Clone(updatedDevice).(*voltha.Device)
-		return agent.updateDeviceInStoreWithoutLock(cloned, false, "")
 	}
+	cloned := proto.Clone(updatedDevice).(*voltha.Device)
+	return agent.updateDeviceInStoreWithoutLock(cloned, false, "")
 }
 
 func (agent *DeviceAgent) updateDeviceWithoutLock(device *voltha.Device) error {
@@ -1117,59 +1130,59 @@
 	agent.lockDevice.Lock()
 	defer agent.lockDevice.Unlock()
 	// Work only on latest data
-	if storeDevice, err := agent.getDeviceWithoutLock(); err != nil {
-		return status.Errorf(codes.NotFound, "%s", agent.deviceId)
-	} else {
-		// clone the device
-		cloned := proto.Clone(storeDevice).(*voltha.Device)
-		// Ensure the enums passed in are valid - they will be invalid if they are not set when this function is invoked
-		if s, ok := voltha.ConnectStatus_ConnectStatus_value[connStatus.String()]; ok {
-			log.Debugw("updateDeviceStatus-conn", log.Fields{"ok": ok, "val": s})
-			cloned.ConnectStatus = connStatus
-		}
-		if s, ok := voltha.OperStatus_OperStatus_value[operStatus.String()]; ok {
-			log.Debugw("updateDeviceStatus-oper", log.Fields{"ok": ok, "val": s})
-			cloned.OperStatus = operStatus
-		}
-		log.Debugw("updateDeviceStatus", log.Fields{"deviceId": cloned.Id, "operStatus": cloned.OperStatus, "connectStatus": cloned.ConnectStatus})
-		// Store the device
-		return agent.updateDeviceInStoreWithoutLock(cloned, false, "")
+	storeDevice, err := agent.getDeviceWithoutLock()
+	if err != nil {
+		return status.Errorf(codes.NotFound, "%s", agent.deviceID)
 	}
+	// clone the device
+	cloned := proto.Clone(storeDevice).(*voltha.Device)
+	// Ensure the enums passed in are valid - they will be invalid if they are not set when this function is invoked
+	if s, ok := voltha.ConnectStatus_ConnectStatus_value[connStatus.String()]; ok {
+		log.Debugw("updateDeviceStatus-conn", log.Fields{"ok": ok, "val": s})
+		cloned.ConnectStatus = connStatus
+	}
+	if s, ok := voltha.OperStatus_OperStatus_value[operStatus.String()]; ok {
+		log.Debugw("updateDeviceStatus-oper", log.Fields{"ok": ok, "val": s})
+		cloned.OperStatus = operStatus
+	}
+	log.Debugw("updateDeviceStatus", log.Fields{"deviceId": cloned.Id, "operStatus": cloned.OperStatus, "connectStatus": cloned.ConnectStatus})
+	// Store the device
+	return agent.updateDeviceInStoreWithoutLock(cloned, false, "")
 }
 
 func (agent *DeviceAgent) enablePorts() error {
 	agent.lockDevice.Lock()
 	defer agent.lockDevice.Unlock()
-	if storeDevice, err := agent.getDeviceWithoutLock(); err != nil {
-		return status.Errorf(codes.NotFound, "%s", agent.deviceId)
-	} else {
-		// clone the device
-		cloned := proto.Clone(storeDevice).(*voltha.Device)
-		for _, port := range cloned.Ports {
-			port.AdminState = voltha.AdminState_ENABLED
-			port.OperStatus = voltha.OperStatus_ACTIVE
-		}
-		// Store the device
-		return agent.updateDeviceInStoreWithoutLock(cloned, false, "")
+	storeDevice, err := agent.getDeviceWithoutLock()
+	if err != nil {
+		return status.Errorf(codes.NotFound, "%s", agent.deviceID)
 	}
+	// clone the device
+	cloned := proto.Clone(storeDevice).(*voltha.Device)
+	for _, port := range cloned.Ports {
+		port.AdminState = voltha.AdminState_ENABLED
+		port.OperStatus = voltha.OperStatus_ACTIVE
+	}
+	// Store the device
+	return agent.updateDeviceInStoreWithoutLock(cloned, false, "")
 }
 
 func (agent *DeviceAgent) disablePorts() error {
-	log.Debugw("disablePorts", log.Fields{"deviceid": agent.deviceId})
+	log.Debugw("disablePorts", log.Fields{"deviceid": agent.deviceID})
 	agent.lockDevice.Lock()
 	defer agent.lockDevice.Unlock()
-	if storeDevice, err := agent.getDeviceWithoutLock(); err != nil {
-		return status.Errorf(codes.NotFound, "%s", agent.deviceId)
-	} else {
-		// clone the device
-		cloned := proto.Clone(storeDevice).(*voltha.Device)
-		for _, port := range cloned.Ports {
-			port.AdminState = voltha.AdminState_DISABLED
-			port.OperStatus = voltha.OperStatus_UNKNOWN
-		}
-		// Store the device
-		return agent.updateDeviceInStoreWithoutLock(cloned, false, "")
+	storeDevice, err := agent.getDeviceWithoutLock()
+	if err != nil {
+		return status.Errorf(codes.NotFound, "%s", agent.deviceID)
 	}
+	// clone the device
+	cloned := proto.Clone(storeDevice).(*voltha.Device)
+	for _, port := range cloned.Ports {
+		port.AdminState = voltha.AdminState_DISABLED
+		port.OperStatus = voltha.OperStatus_UNKNOWN
+	}
+	// Store the device
+	return agent.updateDeviceInStoreWithoutLock(cloned, false, "")
 }
 
 func (agent *DeviceAgent) updatePortState(portType voltha.Port_PortType, portNo uint32, operStatus voltha.OperStatus_OperStatus) error {
@@ -1177,90 +1190,90 @@
 	defer agent.lockDevice.Unlock()
 	// Work only on latest data
 	// TODO: Get list of ports from device directly instead of the entire device
-	if storeDevice, err := agent.getDeviceWithoutLock(); err != nil {
-		return status.Errorf(codes.NotFound, "%s", agent.deviceId)
-	} else {
-		// clone the device
-		cloned := proto.Clone(storeDevice).(*voltha.Device)
-		// Ensure the enums passed in are valid - they will be invalid if they are not set when this function is invoked
-		if _, ok := voltha.Port_PortType_value[portType.String()]; !ok {
-			return status.Errorf(codes.InvalidArgument, "%s", portType)
-		}
-		for _, port := range cloned.Ports {
-			if port.Type == portType && port.PortNo == portNo {
-				port.OperStatus = operStatus
-				// Set the admin status to ENABLED if the operational status is ACTIVE
-				// TODO: Set by northbound system?
-				if operStatus == voltha.OperStatus_ACTIVE {
-					port.AdminState = voltha.AdminState_ENABLED
-				}
-				break
-			}
-		}
-		log.Debugw("portStatusUpdate", log.Fields{"deviceId": cloned.Id})
-		// Store the device
-		return agent.updateDeviceInStoreWithoutLock(cloned, false, "")
+	storeDevice, err := agent.getDeviceWithoutLock()
+	if err != nil {
+		return status.Errorf(codes.NotFound, "%s", agent.deviceID)
 	}
+	// clone the device
+	cloned := proto.Clone(storeDevice).(*voltha.Device)
+	// Ensure the enums passed in are valid - they will be invalid if they are not set when this function is invoked
+	if _, ok := voltha.Port_PortType_value[portType.String()]; !ok {
+		return status.Errorf(codes.InvalidArgument, "%s", portType)
+	}
+	for _, port := range cloned.Ports {
+		if port.Type == portType && port.PortNo == portNo {
+			port.OperStatus = operStatus
+			// Set the admin status to ENABLED if the operational status is ACTIVE
+			// TODO: Set by northbound system?
+			if operStatus == voltha.OperStatus_ACTIVE {
+				port.AdminState = voltha.AdminState_ENABLED
+			}
+			break
+		}
+	}
+	log.Debugw("portStatusUpdate", log.Fields{"deviceId": cloned.Id})
+	// Store the device
+	return agent.updateDeviceInStoreWithoutLock(cloned, false, "")
 }
 
 func (agent *DeviceAgent) deleteAllPorts() error {
-	log.Debugw("deleteAllPorts", log.Fields{"deviceId": agent.deviceId})
+	log.Debugw("deleteAllPorts", log.Fields{"deviceId": agent.deviceID})
 	agent.lockDevice.Lock()
 	defer agent.lockDevice.Unlock()
 	// Work only on latest data
-	if storeDevice, err := agent.getDeviceWithoutLock(); err != nil {
-		return status.Errorf(codes.NotFound, "%s", agent.deviceId)
-	} else {
-		if storeDevice.AdminState != voltha.AdminState_DISABLED && storeDevice.AdminState != voltha.AdminState_DELETED {
-			err = status.Error(codes.FailedPrecondition, fmt.Sprintf("invalid-state-%v", storeDevice.AdminState))
-			log.Warnw("invalid-state-removing-ports", log.Fields{"state": storeDevice.AdminState, "error": err})
-			return err
-		}
-		if len(storeDevice.Ports) == 0 {
-			log.Debugw("no-ports-present", log.Fields{"deviceId": agent.deviceId})
-			return nil
-		}
-		// clone the device & set the fields to empty
-		cloned := proto.Clone(storeDevice).(*voltha.Device)
-		cloned.Ports = []*voltha.Port{}
-		log.Debugw("portStatusUpdate", log.Fields{"deviceId": cloned.Id})
-		// Store the device
-		return agent.updateDeviceInStoreWithoutLock(cloned, false, "")
+	storeDevice, err := agent.getDeviceWithoutLock()
+	if err != nil {
+		return status.Errorf(codes.NotFound, "%s", agent.deviceID)
 	}
+	if storeDevice.AdminState != voltha.AdminState_DISABLED && storeDevice.AdminState != voltha.AdminState_DELETED {
+		err = status.Error(codes.FailedPrecondition, fmt.Sprintf("invalid-state-%v", storeDevice.AdminState))
+		log.Warnw("invalid-state-removing-ports", log.Fields{"state": storeDevice.AdminState, "error": err})
+		return err
+	}
+	if len(storeDevice.Ports) == 0 {
+		log.Debugw("no-ports-present", log.Fields{"deviceId": agent.deviceID})
+		return nil
+	}
+	// clone the device & set the fields to empty
+	cloned := proto.Clone(storeDevice).(*voltha.Device)
+	cloned.Ports = []*voltha.Port{}
+	log.Debugw("portStatusUpdate", log.Fields{"deviceId": cloned.Id})
+	// Store the device
+	return agent.updateDeviceInStoreWithoutLock(cloned, false, "")
 }
 
 func (agent *DeviceAgent) addPort(port *voltha.Port) error {
 	agent.lockDevice.Lock()
 	defer agent.lockDevice.Unlock()
-	log.Debugw("addPort", log.Fields{"deviceId": agent.deviceId})
+	log.Debugw("addPort", log.Fields{"deviceId": agent.deviceID})
 	// Work only on latest data
-	if storeDevice, err := agent.getDeviceWithoutLock(); err != nil {
-		return status.Errorf(codes.NotFound, "%s", agent.deviceId)
+	storeDevice, err := agent.getDeviceWithoutLock()
+	if err != nil {
+		return status.Errorf(codes.NotFound, "%s", agent.deviceID)
+	}
+	// clone the device
+	cloned := proto.Clone(storeDevice).(*voltha.Device)
+	if cloned.Ports == nil {
+		//	First port
+		log.Debugw("addPort-first-port-to-add", log.Fields{"deviceId": agent.deviceID})
+		cloned.Ports = make([]*voltha.Port, 0)
 	} else {
-		// clone the device
-		cloned := proto.Clone(storeDevice).(*voltha.Device)
-		if cloned.Ports == nil {
-			//	First port
-			log.Debugw("addPort-first-port-to-add", log.Fields{"deviceId": agent.deviceId})
-			cloned.Ports = make([]*voltha.Port, 0)
-		} else {
-			for _, p := range cloned.Ports {
-				if p.Type == port.Type && p.PortNo == port.PortNo {
-					log.Debugw("port already exists", log.Fields{"port": *port})
-					return nil
-				}
+		for _, p := range cloned.Ports {
+			if p.Type == port.Type && p.PortNo == port.PortNo {
+				log.Debugw("port already exists", log.Fields{"port": *port})
+				return nil
 			}
 		}
-		cp := proto.Clone(port).(*voltha.Port)
-		// Set the admin state of the port to ENABLE if the operational state is ACTIVE
-		// TODO: Set by northbound system?
-		if cp.OperStatus == voltha.OperStatus_ACTIVE {
-			cp.AdminState = voltha.AdminState_ENABLED
-		}
-		cloned.Ports = append(cloned.Ports, cp)
-		// Store the device
-		return agent.updateDeviceInStoreWithoutLock(cloned, false, "")
 	}
+	cp := proto.Clone(port).(*voltha.Port)
+	// Set the admin state of the port to ENABLE if the operational state is ACTIVE
+	// TODO: Set by northbound system?
+	if cp.OperStatus == voltha.OperStatus_ACTIVE {
+		cp.AdminState = voltha.AdminState_ENABLED
+	}
+	cloned.Ports = append(cloned.Ports, cp)
+	// Store the device
+	return agent.updateDeviceInStoreWithoutLock(cloned, false, "")
 }
 
 func (agent *DeviceAgent) addPeerPort(port *voltha.Port_PeerPort) error {
@@ -1268,49 +1281,49 @@
 	defer agent.lockDevice.Unlock()
 	log.Debug("addPeerPort")
 	// Work only on latest data
-	if storeDevice, err := agent.getDeviceWithoutLock(); err != nil {
-		return status.Errorf(codes.NotFound, "%s", agent.deviceId)
-	} else {
-		// clone the device
-		cloned := proto.Clone(storeDevice).(*voltha.Device)
-		// Get the peer port on the device based on the port no
-		for _, peerPort := range cloned.Ports {
-			if peerPort.PortNo == port.PortNo { // found port
-				cp := proto.Clone(port).(*voltha.Port_PeerPort)
-				peerPort.Peers = append(peerPort.Peers, cp)
-				log.Debugw("found-peer", log.Fields{"portNo": port.PortNo, "deviceId": agent.deviceId})
-				break
-			}
-		}
-		// Store the device
-		return agent.updateDeviceInStoreWithoutLock(cloned, false, "")
+	storeDevice, err := agent.getDeviceWithoutLock()
+	if err != nil {
+		return status.Errorf(codes.NotFound, "%s", agent.deviceID)
 	}
+	// clone the device
+	cloned := proto.Clone(storeDevice).(*voltha.Device)
+	// Get the peer port on the device based on the port no
+	for _, peerPort := range cloned.Ports {
+		if peerPort.PortNo == port.PortNo { // found port
+			cp := proto.Clone(port).(*voltha.Port_PeerPort)
+			peerPort.Peers = append(peerPort.Peers, cp)
+			log.Debugw("found-peer", log.Fields{"portNo": port.PortNo, "deviceId": agent.deviceID})
+			break
+		}
+	}
+	// Store the device
+	return agent.updateDeviceInStoreWithoutLock(cloned, false, "")
 }
 
-func (agent *DeviceAgent) deletePeerPorts(deviceId string) error {
+func (agent *DeviceAgent) deletePeerPorts(deviceID string) error {
 	agent.lockDevice.Lock()
 	defer agent.lockDevice.Unlock()
 	log.Debug("deletePeerPorts")
 	// Work only on latest data
-	if storeDevice, err := agent.getDeviceWithoutLock(); err != nil {
-		return status.Errorf(codes.NotFound, "%s", agent.deviceId)
-	} else {
-		// clone the device
-		cloned := proto.Clone(storeDevice).(*voltha.Device)
-		var updatedPeers []*voltha.Port_PeerPort
-		for _, port := range cloned.Ports {
-			updatedPeers = make([]*voltha.Port_PeerPort, 0)
-			for _, peerPort := range port.Peers {
-				if peerPort.DeviceId != deviceId {
-					updatedPeers = append(updatedPeers, peerPort)
-				}
-			}
-			port.Peers = updatedPeers
-		}
-
-		// Store the device with updated peer ports
-		return agent.updateDeviceInStoreWithoutLock(cloned, false, "")
+	storeDevice, err := agent.getDeviceWithoutLock()
+	if err != nil {
+		return status.Errorf(codes.NotFound, "%s", agent.deviceID)
 	}
+	// clone the device
+	cloned := proto.Clone(storeDevice).(*voltha.Device)
+	var updatedPeers []*voltha.Port_PeerPort
+	for _, port := range cloned.Ports {
+		updatedPeers = make([]*voltha.Port_PeerPort, 0)
+		for _, peerPort := range port.Peers {
+			if peerPort.DeviceId != deviceID {
+				updatedPeers = append(updatedPeers, peerPort)
+			}
+		}
+		port.Peers = updatedPeers
+	}
+
+	// Store the device with updated peer ports
+	return agent.updateDeviceInStoreWithoutLock(cloned, false, "")
 }
 
 // TODO: A generic device update by attribute
@@ -1350,22 +1363,21 @@
 	if err = agent.updateDeviceInStoreWithoutLock(cloned, false, ""); err != nil {
 		log.Warnw("attribute-update-failed", log.Fields{"attribute": name, "value": value})
 	}
-	return
 }
 
 func (agent *DeviceAgent) simulateAlarm(ctx context.Context, simulatereq *voltha.SimulateAlarmRequest) error {
 	agent.lockDevice.Lock()
 	defer agent.lockDevice.Unlock()
-	log.Debugw("simulateAlarm", log.Fields{"id": agent.deviceId})
+	log.Debugw("simulateAlarm", log.Fields{"id": agent.deviceID})
 	// Get the most up to date the device info
-	if device, err := agent.getDeviceWithoutLock(); err != nil {
-		return status.Errorf(codes.NotFound, "%s", agent.deviceId)
-	} else {
-		// First send the request to an Adapter and wait for a response
-		if err := agent.adapterProxy.SimulateAlarm(ctx, device, simulatereq); err != nil {
-			log.Debugw("simulateAlarm-error", log.Fields{"id": agent.deviceId, "error": err})
-			return err
-		}
+	device, err := agent.getDeviceWithoutLock()
+	if err != nil {
+		return status.Errorf(codes.NotFound, "%s", agent.deviceID)
+	}
+	// First send the request to an Adapter and wait for a response
+	if err := agent.adapterProxy.SimulateAlarm(ctx, device, simulatereq); err != nil {
+		log.Debugw("simulateAlarm-error", log.Fields{"id": agent.deviceID, "error": err})
+		return err
 	}
 	return nil
 }
@@ -1374,10 +1386,10 @@
 // It is an internal helper function.
 func (agent *DeviceAgent) updateDeviceInStoreWithoutLock(device *voltha.Device, strict bool, txid string) error {
 	updateCtx := context.WithValue(context.Background(), model.RequestTimestamp, time.Now().UnixNano())
-	if afterUpdate := agent.clusterDataProxy.Update(updateCtx, "/devices/"+agent.deviceId, device, strict, txid); afterUpdate == nil {
-		return status.Errorf(codes.Internal, "failed-update-device:%s", agent.deviceId)
+	if afterUpdate := agent.clusterDataProxy.Update(updateCtx, "/devices/"+agent.deviceID, device, strict, txid); afterUpdate == nil {
+		return status.Errorf(codes.Internal, "failed-update-device:%s", agent.deviceID)
 	}
-	log.Debugw("updated-device-in-store", log.Fields{"deviceId: ": agent.deviceId})
+	log.Debugw("updated-device-in-store", log.Fields{"deviceId: ": agent.deviceID})
 
 	return nil
 }
@@ -1386,14 +1398,14 @@
 	agent.lockDevice.Lock()
 	defer agent.lockDevice.Unlock()
 	// Work only on latest data
-	if storeDevice, err := agent.getDeviceWithoutLock(); err != nil {
-		return status.Errorf(codes.NotFound, "%s", agent.deviceId)
-	} else {
-		// clone the device
-		cloned := proto.Clone(storeDevice).(*voltha.Device)
-		cloned.Reason = reason
-		log.Debugw("updateDeviceReason", log.Fields{"deviceId": cloned.Id, "reason": cloned.Reason})
-		// Store the device
-		return agent.updateDeviceInStoreWithoutLock(cloned, false, "")
+	storeDevice, err := agent.getDeviceWithoutLock()
+	if err != nil {
+		return status.Errorf(codes.NotFound, "%s", agent.deviceID)
 	}
+	// clone the device
+	cloned := proto.Clone(storeDevice).(*voltha.Device)
+	cloned.Reason = reason
+	log.Debugw("updateDeviceReason", log.Fields{"deviceId": cloned.Id, "reason": cloned.Reason})
+	// Store the device
+	return agent.updateDeviceInStoreWithoutLock(cloned, false, "")
 }