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

Change-Id: I41aab571f57cde79c62d1ea3b4bef2c8cef58b97
diff --git a/VERSION b/VERSION
index 9575d51..6307708 100644
--- a/VERSION
+++ b/VERSION
@@ -1 +1 @@
-3.6.1
+3.6.2-dev
diff --git a/internal/pkg/core/openolt_flowmgr.go b/internal/pkg/core/openolt_flowmgr.go
index 1f4b116..d6bf38e 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/v6/pkg/meters"
 	"strconv"
 	"strings"
 	"sync"
 	"time"
 
+	"github.com/opencord/voltha-lib-go/v6/pkg/meters"
+
 	"github.com/opencord/voltha-lib-go/v6/pkg/flows"
 	"github.com/opencord/voltha-lib-go/v6/pkg/log"
 	tp "github.com/opencord/voltha-lib-go/v6/pkg/techprofile"
@@ -1819,17 +1820,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",
@@ -1878,6 +1872,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
 }