[VOL-5507] fix for olt delete device context timeout issue

Change-Id: Ic4f022216e5c68002eae268eb5113cdea2737c2e
Signed-off-by: Abhay Kumar <abhay.kumar@radisys.com>
diff --git a/VERSION b/VERSION
index 0b2eb36..c1e43e6 100644
--- a/VERSION
+++ b/VERSION
@@ -1 +1 @@
-3.7.2
+3.7.3
diff --git a/rw_core/core/device/agent.go b/rw_core/core/device/agent.go
index 47e7ff3..ac9b2fa 100755
--- a/rw_core/core/device/agent.go
+++ b/rw_core/core/device/agent.go
@@ -704,7 +704,16 @@
 			agent.requestQueue.RequestComplete()
 			return fmt.Errorf("remote-not-reachable %w", errNoConnection)
 		}
-		subCtx, cancel := context.WithTimeout(coreutils.WithAllMetadataFromContext(ctx), agent.rpcTimeout)
+		// Use the incoming context deadline if it's longer than the configured rpcTimeout,
+		// otherwise use rpcTimeout. This allows clients to specify longer timeouts for
+		// operations like device delete that may take significant time.
+		timeout := agent.rpcTimeout
+		if deadline, ok := ctx.Deadline(); ok {
+			if ctxTimeout := time.Until(deadline); ctxTimeout > timeout {
+				timeout = ctxTimeout
+			}
+		}
+		subCtx, cancel := context.WithTimeout(coreutils.WithAllMetadataFromContext(ctx), timeout)
 		requestStatus.Code = common.OperationResp_OPERATION_IN_PROGRESS
 		go func() {
 			defer cancel()
@@ -790,7 +799,16 @@
 				})
 			return err
 		}
-		subCtx, cancel := context.WithTimeout(coreutils.WithAllMetadataFromContext(ctx), agent.rpcTimeout)
+		// Use the incoming context deadline if it's longer than the configured rpcTimeout,
+		// otherwise use rpcTimeout. This allows clients to specify longer timeouts for
+		// operations like device delete that may take significant time.
+		timeout := agent.rpcTimeout
+		if deadline, ok := ctx.Deadline(); ok {
+			if ctxTimeout := time.Until(deadline); ctxTimeout > timeout {
+				timeout = ctxTimeout
+			}
+		}
+		subCtx, cancel := context.WithTimeout(coreutils.WithAllMetadataFromContext(ctx), timeout)
 		requestStatus.Code = common.OperationResp_OPERATION_IN_PROGRESS
 		_, err = client.DeleteDevice(subCtx, device)
 		if (err == nil) || (status.Code(err) == codes.NotFound) {
@@ -1498,7 +1516,16 @@
 	agent.requestQueue.RequestComplete()
 
 	// Send the delete request to the adapter
-	subCtx, cancel := context.WithTimeout(coreutils.WithAllMetadataFromContext(ctx), agent.rpcTimeout)
+	// Use the incoming context deadline if it's longer than the configured rpcTimeout,
+	// otherwise use rpcTimeout. This allows clients to specify longer timeouts for
+	// operations like device delete that may take significant time.
+	timeout := agent.rpcTimeout
+	if deadline, ok := ctx.Deadline(); ok {
+		if ctxTimeout := time.Until(deadline); ctxTimeout > timeout {
+			timeout = ctxTimeout
+		}
+	}
+	subCtx, cancel := context.WithTimeout(coreutils.WithAllMetadataFromContext(ctx), timeout)
 	defer cancel()
 	_, err = client.DeleteDevice(subCtx, device)
 	agent.onForceDeleteResponse(subCtx, nil, nil, err)