VOL-3896: ONU fails to activate again if ONU is deleted after OLT disable
- When OLT is disabled the local cache of child devices are cleared in openolt adapter.
  If ONU delete were triggered post OLT disable, the openolt adapter does not
  have relevant information (esp. ONU serial number) in Child_device_lost API
  call to pass down to OLT agent to delete the ONU context. The local cache too is void
  of this information as it was cleared on OLT disable.
  A possible fix is to pass down the entire ONU Device struct in Child_device_lost
  API which contains all the relevant information to clear the ONU context on the OLT.

Change-Id: I76e28a0a46c1c82b25c859160466abfff693ed09
diff --git a/internal/pkg/core/device_handler.go b/internal/pkg/core/device_handler.go
index ec5bf84..1e86007 100644
--- a/internal/pkg/core/device_handler.go
+++ b/internal/pkg/core/device_handler.go
@@ -2146,25 +2146,18 @@
 }
 
 // ChildDeviceLost deletes ONU and clears pon resources related to it.
-func (dh *DeviceHandler) ChildDeviceLost(ctx context.Context, pPortNo uint32, onuID uint32) error {
+func (dh *DeviceHandler) ChildDeviceLost(ctx context.Context, pPortNo uint32, onuID uint32, onuSn string) error {
 	logger.Debugw(ctx, "child-device-lost", log.Fields{"parent-device-id": dh.device.Id})
 	intfID := PortNoToIntfID(pPortNo, voltha.Port_PON_OLT)
 	onuKey := dh.formOnuKey(intfID, onuID)
-	onuDevice, ok := dh.onus.Load(onuKey)
-	if !ok {
-		return olterrors.NewErrAdapter("failed-to-load-onu-details",
-			log.Fields{
-				"device-id": dh.device.Id,
-				"onu-id":    onuID,
-				"intf-id":   intfID}, nil).Log()
-	}
+
 	var sn *oop.SerialNumber
 	var err error
-	if sn, err = dh.deStringifySerialNumber(onuDevice.(*OnuDevice).serialNumber); err != nil {
+	if sn, err = dh.deStringifySerialNumber(onuSn); err != nil {
 		return olterrors.NewErrAdapter("failed-to-destringify-serial-number",
 			log.Fields{
 				"devicer-id":    dh.device.Id,
-				"serial-number": onuDevice.(*OnuDevice).serialNumber}, err).Log()
+				"serial-number": onuSn}, err).Log()
 	}
 
 	onu := &oop.Onu{IntfId: intfID, OnuId: onuID, SerialNumber: sn}
@@ -2187,7 +2180,7 @@
 				"error":     err})
 		} else {
 			for i, onu := range onuGemData {
-				if onu.OnuID == onuID && onu.SerialNumber == onuDevice.(*OnuDevice).serialNumber {
+				if onu.OnuID == onuID && onu.SerialNumber == onuSn {
 					logger.Debugw(ctx, "onu-data", log.Fields{"onu": onu})
 					if err := dh.clearUNIData(ctx, &onu); err != nil {
 						logger.Warnw(ctx, "failed-to-clear-uni-data-for-onu", log.Fields{
@@ -2217,7 +2210,7 @@
 		}
 	}
 	dh.onus.Delete(onuKey)
-	dh.discOnus.Delete(onuDevice.(*OnuDevice).serialNumber)
+	dh.discOnus.Delete(onuSn)
 	return nil
 }