VOL-4435 checks for parent device in reconcilation + flow timeout

Change-Id: I6de908454775d9c4ff98cf13682567241dd77ebb
diff --git a/rw_core/core/device/manager.go b/rw_core/core/device/manager.go
index 9f7e656..c8322a2 100755
--- a/rw_core/core/device/manager.go
+++ b/rw_core/core/device/manager.go
@@ -54,6 +54,7 @@
 	coreInstanceID          string
 	internalTimeout         time.Duration
 	rpcTimeout              time.Duration
+	flowTimeout             time.Duration
 	devicesLoadingLock      sync.RWMutex
 	deviceLoadingInProgress map[string][]chan int
 	config                  *config.RWCoreFlags
@@ -69,6 +70,7 @@
 		adapterMgr:              adapterMgr,
 		internalTimeout:         cf.InternalTimeout,
 		rpcTimeout:              cf.RPCTimeout,
+		flowTimeout:             cf.FlowTimeout,
 		Agent:                   event.NewAgent(eventProxy, coreInstanceID, cf.VolthaStackID),
 		deviceLoadingInProgress: make(map[string][]chan int),
 		config:                  cf,
@@ -111,7 +113,7 @@
 
 	for _, device := range devices {
 		// Create an agent for each device
-		agent := newAgent(device, dMgr, dMgr.dbPath, dMgr.dProxy, dMgr.internalTimeout, dMgr.rpcTimeout)
+		agent := newAgent(device, dMgr, dMgr.dbPath, dMgr.dProxy, dMgr.internalTimeout, dMgr.rpcTimeout, dMgr.flowTimeout)
 		if _, err := agent.start(ctx, true, device); err != nil {
 			logger.Warnw(ctx, "failure-starting-agent", log.Fields{"device-id": device.Id})
 		} else {
@@ -269,7 +271,7 @@
 			// Proceed with the loading only if the device exist in the Model (could have been deleted)
 			if device, err = dMgr.getDeviceFromModel(ctx, deviceID); err == nil {
 				logger.Debugw(ctx, "loading-device", log.Fields{"device-id": deviceID})
-				agent := newAgent(device, dMgr, dMgr.dbPath, dMgr.dProxy, dMgr.internalTimeout, dMgr.rpcTimeout)
+				agent := newAgent(device, dMgr, dMgr.dbPath, dMgr.dProxy, dMgr.internalTimeout, dMgr.rpcTimeout, dMgr.flowTimeout)
 				if _, err = agent.start(ctx, true, device); err != nil {
 					logger.Warnw(ctx, "failure-loading-device", log.Fields{"device-id": deviceID, "error": err})
 				} else {
@@ -470,6 +472,18 @@
 		if err := agent.canDeviceRequestProceed(ctx); err != nil {
 			return err
 		}
+		// Perform the same checks for parent device
+		if !agent.isRootDevice {
+			parentDeviceAgent := dMgr.getDeviceAgent(ctx, agent.parentID)
+			if parentDeviceAgent == nil {
+				logger.Errorw(ctx, "parent-device-adapter-nil", log.Fields{"parent-id": agent.parentID})
+				return status.Errorf(codes.Unavailable, "parent-device-adapter-nil-for-%s", deviceID)
+			}
+			if err := parentDeviceAgent.canDeviceRequestProceed(ctx); err != nil {
+				return err
+			}
+		}
+
 	}
 	if !ready {
 		return status.Error(codes.Unavailable, "adapter(s)-not-ready")