VOL-4276 olt-adapter should change device's operational-state to FAILED if EnableDevice fails in adapter.

Change-Id: I26874844f4baba960eaa2241574454328d8e915f
diff --git a/internal/pkg/core/device_handler.go b/internal/pkg/core/device_handler.go
index 55a404e..33e2f5a 100644
--- a/internal/pkg/core/device_handler.go
+++ b/internal/pkg/core/device_handler.go
@@ -1760,14 +1760,21 @@
 
 	// Update the all ports state on that device to enable
 	ports, err := dh.listDevicePortsFromCore(ctx, device.Id)
+	var retError error
 	if err != nil {
-		return olterrors.NewErrAdapter("list-ports-failed", log.Fields{"device-id": device.Id}, err)
+		retError = olterrors.NewErrAdapter("list-ports-failed", log.Fields{"device-id": device.Id}, err)
+	} else {
+		if err := dh.disableAdminDownPorts(ctx, ports.Items); err != nil {
+			retError = olterrors.NewErrAdapter("port-status-update-failed-after-olt-reenable", log.Fields{"device": device}, err)
+		}
 	}
-	if err := dh.disableAdminDownPorts(ctx, ports.Items); err != nil {
-		return olterrors.NewErrAdapter("port-status-update-failed-after-olt-reenable", log.Fields{"device": device}, err)
+	if retError == nil {
+		//Update the device oper status as ACTIVE
+		device.OperStatus = voltha.OperStatus_ACTIVE
+	} else {
+		//Update the device oper status as FAILED
+		device.OperStatus = voltha.OperStatus_FAILED
 	}
-	//Update the device oper status as ACTIVE
-	device.OperStatus = voltha.OperStatus_ACTIVE
 	dh.device = device
 
 	if err := dh.updateDeviceStateInCore(ctx, &ic.DeviceStateFilter{
@@ -1783,7 +1790,7 @@
 
 	logger.Debugw(ctx, "reenabledevice-end", log.Fields{"device-id": device.Id})
 
-	return nil
+	return retError
 }
 
 func (dh *DeviceHandler) clearUNIData(ctx context.Context, onu *rsrcMgr.OnuGemInfo) error {