Ignore operstatus change to DISCOVERED if ONU is in Cache

Change-Id: I6dc023f90268258dc9f33e0430c48b1a210ed9d5
diff --git a/adaptercore/device_handler.go b/adaptercore/device_handler.go
index a2dec0a..f468fd1 100644
--- a/adaptercore/device_handler.go
+++ b/adaptercore/device_handler.go
@@ -776,6 +776,8 @@
 	}
 	//Insert the ONU into cache to use in OnuIndication.
 	//TODO: Do we need to remove this from the cache on ONU change, or wait for overwritten on next discovery.
+	log.Debugw("ONU discovery indication key create", log.Fields{"onuID": onuID,
+		"intfId": onuDiscInd.GetIntfId()})
 	onuKey := dh.formOnuKey(onuDiscInd.GetIntfId(), onuID)
 	dh.onus[onuKey] = NewOnuDevice(onuDevice.Id, onuDevice.Type, onuDevice.SerialNumber, onuID, onuDiscInd.GetIntfId(), onuDevice.ProxyAddress.DeviceId)
 
@@ -800,6 +802,8 @@
 	ponPort := IntfIDToPortNo(onuInd.GetIntfId(), voltha.Port_PON_OLT)
 	var onuDevice *voltha.Device
 	foundInCache := false
+	log.Debugw("ONU indication key create", log.Fields{"onuId": onuInd.OnuId,
+		"intfId": onuInd.GetIntfId()})
 	onuKey := dh.formOnuKey(onuInd.GetIntfId(), onuInd.OnuId)
 	if onuInCache, ok := dh.onus[onuKey]; ok {
 		//If ONU id is discovered before then use GetDevice to get onuDevice because it is cheaper.
@@ -829,7 +833,7 @@
 			onuKey := dh.formOnuKey(onuInd.GetIntfId(), onuInd.GetOnuId())
 			dh.onus[onuKey] = NewOnuDevice(onuDevice.Id, onuDevice.Type, onuDevice.SerialNumber, onuInd.GetOnuId(), onuInd.GetIntfId(), onuDevice.ProxyAddress.DeviceId)
 		}
-		dh.updateOnuStates(onuDevice, onuInd)
+		dh.updateOnuStates(onuDevice, onuInd, foundInCache)
 
 	} else {
 		log.Errorw("onu not found", log.Fields{"intfID": onuInd.IntfId, "onuID": onuInd.OnuId})
@@ -838,7 +842,7 @@
 
 }
 
-func (dh *DeviceHandler) updateOnuStates(onuDevice *voltha.Device, onuInd *oop.OnuIndication) {
+func (dh *DeviceHandler) updateOnuStates(onuDevice *voltha.Device, onuInd *oop.OnuIndication, foundInCache bool) {
 	dh.updateOnuAdminState(onuInd)
 	// operState
 	if onuInd.OperState == "down" {
@@ -852,7 +856,8 @@
 				"From Adapter": "openolt", "DevieType": onuDevice.Type, "DeviceID": onuDevice.Id})
 		}
 	} else if onuInd.OperState == "up" {
-		if onuDevice.OperStatus != common.OperStatus_DISCOVERED {
+		// Ignore operstatus if device was found in cache
+		if !foundInCache && onuDevice.OperStatus != common.OperStatus_DISCOVERED {
 			log.Warnw("ignore onu indication", log.Fields{"intfID": onuInd.IntfId, "onuID": onuInd.OnuId, "operStatus": onuDevice.OperStatus, "msgOperStatus": onuInd.OperState})
 			return
 		}