VOL-5219 core should be able to refire the missed reconcile requests

Change-Id: I661e21223a11842478f28349a24a4bb1c35d7c56
diff --git a/VERSION b/VERSION
index 1545d96..d5c0c99 100644
--- a/VERSION
+++ b/VERSION
@@ -1 +1 @@
-3.5.0
+3.5.1
diff --git a/rw_core/core/device/agent.go b/rw_core/core/device/agent.go
index bc3eaed..aaef7b1 100755
--- a/rw_core/core/device/agent.go
+++ b/rw_core/core/device/agent.go
@@ -557,7 +557,7 @@
 	prevAdminState = agent.device.AdminState
 
 	if !agent.proceedWithRequest(cloned) {
-		err = status.Errorf(codes.FailedPrecondition, "cannot complete operation as device deletion is in progress or reconciling is in progress/failed: %s", agent.deviceID)
+		err = status.Errorf(codes.FailedPrecondition, "cannot complete operation as device deletion is in progress/failed: %s", agent.deviceID)
 		agent.requestQueue.RequestComplete()
 		return err
 	}
@@ -1490,9 +1490,9 @@
 		return
 	}
 
-	if !agent.proceedWithRequest(device) {
+	if agent.isDeletionInProgress() {
 		agent.requestQueue.RequestComplete()
-		err := fmt.Errorf("cannot complete operation as device deletion/reconciling is in progress or reconcile failed for device : %s", device.Id)
+		err := fmt.Errorf("cannot complete operation as device deletion is in progress device : %s", device.Id)
 		logger.Errorw(ctx, "reconcile-failed", log.Fields{"error": err})
 		agent.logDeviceUpdate(ctx, nil, nil, requestStatus, err, desc)
 		return
diff --git a/rw_core/core/device/manager.go b/rw_core/core/device/manager.go
index 3368749..e098f1e 100755
--- a/rw_core/core/device/manager.go
+++ b/rw_core/core/device/manager.go
@@ -19,6 +19,7 @@
 import (
 	"context"
 	"fmt"
+	"github.com/opencord/voltha-protos/v5/go/common"
 	"sync"
 	"time"
 
@@ -121,10 +122,11 @@
 		} else {
 			dMgr.addDeviceAgentToMap(agent)
 		}
+		// In case core goes down after it sets the transient state as reconciling but missed to fire the reconcile request to the adaptors, it should refire those reconcile requests on restart
+		if device.OperStatus != common.OperStatus_RECONCILING && (device.OperStatus == common.OperStatus_RECONCILING_FAILED || agent.matchTransientState(core.DeviceTransientState_RECONCILE_IN_PROGRESS)) {
+			go agent.ReconcileDevice(ctx)
+		}
 	}
-
-	// TODO: Need to trigger a reconcile at this point
-
 	logger.Info(ctx, "device-manager-started")
 
 	return nil