VOL-4215 :Rearrange tech-profile delete to trigger ani config deletion by Gem deletion

Change-Id: I41aab571f57cde79c62d1ea3b4bef2c8cef58b97
diff --git a/VERSION b/VERSION
index d5c0c99..87ce492 100644
--- a/VERSION
+++ b/VERSION
@@ -1 +1 @@
-3.5.1
+3.5.2
diff --git a/internal/pkg/core/openolt_flowmgr.go b/internal/pkg/core/openolt_flowmgr.go
index 978cea8..d0a9875 100644
--- a/internal/pkg/core/openolt_flowmgr.go
+++ b/internal/pkg/core/openolt_flowmgr.go
@@ -22,12 +22,13 @@
 	"encoding/hex"
 	"errors"
 	"fmt"
-	"github.com/opencord/voltha-lib-go/v5/pkg/meters"
 	"strconv"
 	"strings"
 	"sync"
 	"time"
 
+	"github.com/opencord/voltha-lib-go/v5/pkg/meters"
+
 	"github.com/opencord/voltha-lib-go/v5/pkg/flows"
 	"github.com/opencord/voltha-lib-go/v5/pkg/log"
 	tp "github.com/opencord/voltha-lib-go/v5/pkg/techprofile"
@@ -1813,17 +1814,10 @@
 
 	f.resourceMgr.FreeGemPortID(ctx, intfID, uint32(onuID), uint32(uniID), uint32(gemPortID))
 
-	// Delete the gem port on the ONU.
-	if err := f.sendDeleteGemPortToChild(ctx, intfID, uint32(onuID), uint32(uniID), uint32(gemPortID), tpPath); err != nil {
-		logger.Errorw(ctx, "error-processing-delete-gem-port-towards-onu",
-			log.Fields{
-				"err":        err,
-				"intfID":     intfID,
-				"onu-id":     onuID,
-				"uni-id":     uniID,
-				"device-id":  f.deviceHandler.device.Id,
-				"gemport-id": gemPortID})
-	}
+	//First remove TCONT from child if needed. Then remove the GEM.
+	//It is expected from child to clean ani side conf if all GEMs of TP are deleted.
+	//Before this, ensure that the related TCONT deletions are informed to child.
+	//Refer to VOL-4215.
 	techprofileInst, err := f.techprofile.GetTPInstance(ctx, tpPath)
 	if err != nil || techprofileInst == nil { // This should not happen, something wrong in KV backend transaction
 		return olterrors.NewErrNotFound("tech-profile-in-kv-store",
@@ -1872,6 +1866,17 @@
 				"techprofileInst": techprofileInst})
 	}
 
+	// Delete the gem port on the ONU. Send Gem Removal After TCONT removal.
+	if err := f.sendDeleteGemPortToChild(ctx, intfID, uint32(onuID), uint32(uniID), uint32(gemPortID), tpPath); err != nil {
+		logger.Errorw(ctx, "error-processing-delete-gem-port-towards-onu",
+			log.Fields{
+				"err":        err,
+				"intfID":     intfID,
+				"onu-id":     onuID,
+				"uni-id":     uniID,
+				"device-id":  f.deviceHandler.device.Id,
+				"gemport-id": gemPortID})
+	}
 	return nil
 }