[VOL-5303]:Avoid reconciling the MEs with ONT

[VOL-5331] - Voltha DT PODTesets :: E2E pingtest fail

Change-Id: I7b105720435b970923b3ce86a7d37ed98a06c911
Signed-off-by: Praneeth Kumar Nalmas <praneeth.nalmas@radisys.com>
diff --git a/internal/pkg/common/interfaces.go b/internal/pkg/common/interfaces.go
index eff1cd5..0001ecb 100755
--- a/internal/pkg/common/interfaces.go
+++ b/internal/pkg/common/interfaces.go
@@ -127,6 +127,7 @@
 
 	PerOnuFlowHandlerRoutine(uniID uint8)
 	GetDeviceDeleteCommChan(context.Context) chan bool
+	GetSkipOnuConfigEnabled() bool
 }
 
 // IonuDeviceEntry interface to onuDeviceEntry
diff --git a/internal/pkg/config/config.go b/internal/pkg/config/config.go
index 8413bc8..08ecfa3 100644
--- a/internal/pkg/config/config.go
+++ b/internal/pkg/config/config.go
@@ -75,6 +75,7 @@
 	MaxConcurrentFlowsPerUni    int
 	PerRPCRetryTimeout          time.Duration
 	MaxRetries                  uint
+	SkipOnuConfig               bool
 }
 
 // ParseCommandArguments parses the arguments when running read-write adaptercore service
@@ -287,6 +288,10 @@
 		"per_rpc_retry_timeout",
 		0*time.Second,
 		"The default timeout per RPC retry")
+	fs.BoolVar(&(so.SkipOnuConfig),
+		"skip_onu_config_enabled",
+		false,
+		"Whether to enable/disable the Skipping of the ONU configuration via OMCI during reconciling")
 	fs.UintVar(&(so.MaxRetries),
 		"max_grpc_client_retry",
 		0,
diff --git a/internal/pkg/core/device_handler.go b/internal/pkg/core/device_handler.go
index 929d117..c5e03c4 100755
--- a/internal/pkg/core/device_handler.go
+++ b/internal/pkg/core/device_handler.go
@@ -2032,25 +2032,26 @@
 		return err
 	}
 	_ = dh.ReasonUpdate(ctx, cmn.DrStartingOpenomci, !dh.IsReconciling() || dh.IsReconcilingReasonUpdate())
+	if !dh.IsReconciling() && !dh.GetSkipOnuConfigEnabled() {
+		/* this might be a good time for Omci Verify message?  */
+		verifyExec := make(chan bool)
+		omciVerify := otst.NewOmciTestRequest(log.WithSpanFromContext(context.TODO(), ctx),
+			dh.device.Id, pDevEntry.PDevOmciCC, false,
+			true, true) //exclusive and allowFailure (anyway not yet checked)
+		omciVerify.PerformOmciTest(log.WithSpanFromContext(context.TODO(), ctx), verifyExec)
 
-	/* this might be a good time for Omci Verify message?  */
-	verifyExec := make(chan bool)
-	omciVerify := otst.NewOmciTestRequest(log.WithSpanFromContext(context.TODO(), ctx),
-		dh.device.Id, pDevEntry.PDevOmciCC, false,
-		true, true) //exclusive and allowFailure (anyway not yet checked)
-	omciVerify.PerformOmciTest(log.WithSpanFromContext(context.TODO(), ctx), verifyExec)
-
-	/* 	give the handler some time here to wait for the OMCi verification result
-	after Timeout start and try MibUpload FSM anyway
-	(to prevent stopping on just not supported OMCI verification from ONU) */
-	select {
-	case <-time.After(((cmn.CDefaultRetries+1)*otst.CTestRequestOmciTimeout + 1) * time.Second):
-		logger.Warnw(ctx, "omci start-verification timed out (continue normal)", log.Fields{"device-id": dh.DeviceID})
-	case testresult := <-verifyExec:
-		logger.Infow(ctx, "Omci start verification done", log.Fields{"device-id": dh.DeviceID, "result": testresult})
-	case <-dh.deviceDeleteCommChan:
-		logger.Warnw(ctx, "Deleting device, stopping the omci test activity", log.Fields{"device-id": dh.DeviceID})
-		return nil
+		/* 	give the handler some time here to wait for the OMCi verification result
+		after Timeout start and try MibUpload FSM anyway
+		(to prevent stopping on just not supported OMCI verification from ONU) */
+		select {
+		case <-time.After(((cmn.CDefaultRetries+1)*otst.CTestRequestOmciTimeout + 1) * time.Second):
+			logger.Warnw(ctx, "omci start-verification timed out (continue normal)", log.Fields{"device-id": dh.DeviceID})
+		case testresult := <-verifyExec:
+			logger.Infow(ctx, "Omci start verification done", log.Fields{"device-id": dh.DeviceID, "result": testresult})
+		case <-dh.deviceDeleteCommChan:
+			logger.Warnw(ctx, "Deleting device, stopping the omci test activity", log.Fields{"device-id": dh.DeviceID})
+			return nil
+		}
 	}
 
 	/* In py code it looks earlier (on activate ..)
@@ -4205,7 +4206,7 @@
 		}()
 	}
 	dh.mutexReconcilingFlag.Lock()
-	if skipOnuConfig {
+	if skipOnuConfig || dh.GetSkipOnuConfigEnabled() {
 		dh.reconciling = cSkipOnuConfigReconciling
 	} else {
 		dh.reconciling = cOnuConfigReconciling
@@ -4677,6 +4678,11 @@
 	return dh.pOpenOnuAc.ExtendedOmciSupportEnabled
 }
 
+// GetExtendedOmciSupportEnabled - TODO: add comment
+func (dh *deviceHandler) GetSkipOnuConfigEnabled() bool {
+	return dh.pOpenOnuAc.skipOnuConfig
+}
+
 // InitPmConfigs - TODO: add comment
 func (dh *deviceHandler) InitPmConfigs() {
 	dh.pmConfigs = &voltha.PmConfigs{}
diff --git a/internal/pkg/core/openonu.go b/internal/pkg/core/openonu.go
index 9fa2597..f1b5581 100755
--- a/internal/pkg/core/openonu.go
+++ b/internal/pkg/core/openonu.go
@@ -21,15 +21,16 @@
 	"context"
 	"errors"
 	"fmt"
-	grpc_retry "github.com/grpc-ecosystem/go-grpc-middleware/retry"
-	"github.com/opencord/voltha-lib-go/v7/pkg/db"
-	vgrpc "github.com/opencord/voltha-lib-go/v7/pkg/grpc"
-	codes "google.golang.org/grpc/codes"
 	"hash/fnv"
 	"strings"
 	"sync"
 	"time"
 
+	grpc_retry "github.com/grpc-ecosystem/go-grpc-middleware/retry"
+	"github.com/opencord/voltha-lib-go/v7/pkg/db"
+	vgrpc "github.com/opencord/voltha-lib-go/v7/pkg/grpc"
+	codes "google.golang.org/grpc/codes"
+
 	conf "github.com/opencord/voltha-lib-go/v7/pkg/config"
 	"github.com/opencord/voltha-protos/v5/go/adapter_service"
 	"github.com/opencord/voltha-protos/v5/go/common"
@@ -97,6 +98,7 @@
 	dlToOnuTimeout4M            time.Duration
 	rpcTimeout                  time.Duration
 	maxConcurrentFlowsPerUni    int
+	skipOnuConfig               bool
 }
 
 // NewOpenONUAC returns a new instance of OpenONU_AC
@@ -156,6 +158,7 @@
 	openOnuAc.pDownloadManager = swupg.NewAdapterDownloadManager(ctx)
 	openOnuAc.pFileManager = swupg.NewFileDownloadManager(ctx)
 	openOnuAc.pFileManager.SetDownloadTimeout(ctx, cfg.DownloadToAdapterTimeout)
+	openOnuAc.skipOnuConfig = cfg.SkipOnuConfig
 
 	return &openOnuAc
 }
@@ -265,6 +268,7 @@
 	var handler *deviceHandler
 	if handler = oo.getDeviceHandler(ctx, device.Id, false); handler == nil {
 		handler := newDeviceHandler(ctx, oo.coreClient, oo.eventProxy, device, oo)
+		logger.Infow(ctx, "reconciling-device  skip-onu-config value ", log.Fields{"device-id": device.Id, "parent-id": device.ParentId, "skip-onu-config": oo.skipOnuConfig})
 		oo.addDeviceHandlerToMap(ctx, handler)
 		handler.device = device
 		if err := handler.updateDeviceStateInCore(log.WithSpanFromContext(context.Background(), ctx), &ca.DeviceStateFilter{
diff --git a/internal/pkg/mib/mib_sync.go b/internal/pkg/mib/mib_sync.go
index 954265d..9353d90 100755
--- a/internal/pkg/mib/mib_sync.go
+++ b/internal/pkg/mib/mib_sync.go
@@ -391,7 +391,17 @@
 
 func (oo *OnuDeviceEntry) enterExaminingMdsState(ctx context.Context, e *fsm.Event) {
 	logger.Debugw(ctx, "MibSync FSM", log.Fields{"Start GetMds processing in State": e.FSM.Current(), "device-id": oo.deviceID})
-	oo.requestMdsValue(ctx)
+	oo.pOpenOnuAc.RLockMutexDeviceHandlersMap()
+	dh, _ := oo.pOpenOnuAc.GetDeviceHandler(oo.deviceID)
+	oo.pOpenOnuAc.RUnlockMutexDeviceHandlersMap()
+	if dh.GetSkipOnuConfigEnabled() {
+		go func() {
+			_ = oo.PMibUploadFsm.PFsm.Event(UlEvSuccess)
+		}()
+	} else {
+		oo.requestMdsValue(ctx)
+	}
+
 }
 
 func (oo *OnuDeviceEntry) enterResynchronizingState(ctx context.Context, e *fsm.Event) {