[VOL-3631] Parametrizing KV_STORE path for TechProfiles and Onu data

Change-Id: I9598f3aa42d848786eaad89e260a71f9563bfa0c
diff --git a/cmd/openonu-adapter/main.go b/cmd/openonu-adapter/main.go
index 486188d..df7c327 100644
--- a/cmd/openonu-adapter/main.go
+++ b/cmd/openonu-adapter/main.go
@@ -131,7 +131,7 @@
 
 	// Create the open ONU interface adapter
 	if a.iAdapter, err = a.startVolthaInterfaceAdapter(ctx, a.kip, a.coreProxy, a.adapterProxy, a.eventProxy,
-		a.config); err != nil {
+		a.config, cm); err != nil {
 		logger.Fatalw("error-starting-volthaInterfaceAdapter for OpenOnt", log.Fields{"error": err})
 	}
 
@@ -249,9 +249,9 @@
 
 func (a *adapter) startVolthaInterfaceAdapter(ctx context.Context, kip kafka.InterContainerProxy,
 	cp adapterif.CoreProxy, ap adapterif.AdapterProxy, ep adapterif.EventProxy,
-	cfg *config.AdapterFlags) (*ac.OpenONUAC, error) {
+	cfg *config.AdapterFlags, cm *conf.ConfigManager) (*ac.OpenONUAC, error) {
 	var err error
-	sAcONU := ac.NewOpenONUAC(ctx, a.kip, cp, ap, ep, a.kvClient, cfg)
+	sAcONU := ac.NewOpenONUAC(ctx, a.kip, cp, ap, ep, a.kvClient, cfg, cm)
 
 	if err = sAcONU.Start(ctx); err != nil {
 		logger.Fatalw("error-starting-OpenOnuAdapterCore", log.Fields{"error": err})
diff --git a/internal/pkg/onuadaptercore/mib_sync.go b/internal/pkg/onuadaptercore/mib_sync.go
index 7d52b36..2163b6c 100644
--- a/internal/pkg/onuadaptercore/mib_sync.go
+++ b/internal/pkg/onuadaptercore/mib_sync.go
@@ -135,7 +135,7 @@
 
 	meStoredFromTemplate := false
 	oo.mibTemplatePath = fmt.Sprintf(cSuffixMibTemplateKvStore, oo.vendorID, oo.equipmentID, oo.activeSwVersion)
-	logger.Debugw("MibSync FSM - MibTemplate - etcd search string", log.Fields{"path": oo.mibTemplatePath})
+	logger.Debugw("MibSync FSM - MibTemplate - etcd search string", log.Fields{"path": fmt.Sprintf("%s/%s", cBasePathMibTemplateKvStore, oo.mibTemplatePath)})
 	Value, err := oo.mibTemplateKVStore.Get(context.TODO(), oo.mibTemplatePath)
 	if err == nil {
 		if Value != nil {
diff --git a/internal/pkg/onuadaptercore/onu_device_entry.go b/internal/pkg/onuadaptercore/onu_device_entry.go
index 7cd20e5..adf630e 100644
--- a/internal/pkg/onuadaptercore/onu_device_entry.go
+++ b/internal/pkg/onuadaptercore/onu_device_entry.go
@@ -106,9 +106,10 @@
 )
 
 const (
+	// NOTE that this hardcoded to service/voltha as the MIB template is shared across stacks
 	cBasePathMibTemplateKvStore = "service/voltha/omci_mibs/go_templates"
 	cSuffixMibTemplateKvStore   = "%s/%s/%s"
-	cBasePathOnuKVStore         = "service/voltha/openonu"
+	cBasePathOnuKVStore         = "%s/openonu"
 )
 
 // OnuDeviceEvent - event of interest to Device Adapters and OpenOMCI State Machines
@@ -418,10 +419,11 @@
 	}
 
 	onuDeviceEntry.onuKVStorePath = onuDeviceEntry.deviceID
-	onuDeviceEntry.onuKVStore = onuDeviceEntry.baseDeviceHandler.setBackend(cBasePathOnuKVStore)
+	baseKvStorePath := fmt.Sprintf(cBasePathOnuKVStore, dh.pOpenOnuAc.cm.Backend.PathPrefix)
+	onuDeviceEntry.onuKVStore = onuDeviceEntry.baseDeviceHandler.setBackend(baseKvStorePath)
 	if onuDeviceEntry.onuKVStore == nil {
 		logger.Errorw("Can't access onuKVStore - no backend connection to service",
-			log.Fields{"device-id": dh.deviceID, "service": cBasePathOnuKVStore})
+			log.Fields{"device-id": dh.deviceID, "service": baseKvStorePath})
 	}
 
 	// Alarm Synchronization Database
diff --git a/internal/pkg/onuadaptercore/onu_uni_tp.go b/internal/pkg/onuadaptercore/onu_uni_tp.go
index 40bbb6b..ee52b13 100644
--- a/internal/pkg/onuadaptercore/onu_uni_tp.go
+++ b/internal/pkg/onuadaptercore/onu_uni_tp.go
@@ -31,7 +31,7 @@
 	tp "github.com/opencord/voltha-lib-go/v3/pkg/techprofile"
 )
 
-const cBasePathTechProfileKVStore = "service/voltha/technology_profiles"
+const cBasePathTechProfileKVStore = "%s/technology_profiles"
 
 //definitions for TechProfileProcessing - copied from OltAdapter:openolt_flowmgr.go
 //  could perhaps be defined more globally
@@ -114,10 +114,11 @@
 	onuTP.mapPonAniConfig = make(map[uniTP]*tcontGemList)
 	onuTP.procResult = make(map[uniTP]error)
 	onuTP.tpProfileExists = make(map[uniTP]bool)
-	onuTP.techProfileKVStore = aDeviceHandler.setBackend(cBasePathTechProfileKVStore)
+	baseKvStorePath := fmt.Sprintf(cBasePathTechProfileKVStore, aDeviceHandler.pOpenOnuAc.cm.Backend.PathPrefix)
+	onuTP.techProfileKVStore = aDeviceHandler.setBackend(baseKvStorePath)
 	if onuTP.techProfileKVStore == nil {
 		logger.Errorw("Can't access techProfileKVStore - no backend connection to service",
-			log.Fields{"device-id": aDeviceHandler.deviceID, "service": cBasePathTechProfileKVStore})
+			log.Fields{"device-id": aDeviceHandler.deviceID, "service": baseKvStorePath})
 	}
 
 	return &onuTP
diff --git a/internal/pkg/onuadaptercore/openonu.go b/internal/pkg/onuadaptercore/openonu.go
index f189d51..16ef7d7 100644
--- a/internal/pkg/onuadaptercore/openonu.go
+++ b/internal/pkg/onuadaptercore/openonu.go
@@ -21,6 +21,7 @@
 	"context"
 	"errors"
 	"fmt"
+	conf "github.com/opencord/voltha-lib-go/v3/pkg/config"
 	"sync"
 	"time"
 
@@ -47,6 +48,7 @@
 	eventProxy                  adapterif.EventProxy
 	kafkaICProxy                kafka.InterContainerProxy
 	kvClient                    kvstore.Client
+	cm                          *conf.ConfigManager
 	config                      *config.AdapterFlags
 	numOnus                     int
 	KVStoreHost                 string
@@ -67,7 +69,7 @@
 //NewOpenONUAC returns a new instance of OpenONU_AC
 func NewOpenONUAC(ctx context.Context, kafkaICProxy kafka.InterContainerProxy,
 	coreProxy adapterif.CoreProxy, adapterProxy adapterif.AdapterProxy,
-	eventProxy adapterif.EventProxy, kvClient kvstore.Client, cfg *config.AdapterFlags) *OpenONUAC {
+	eventProxy adapterif.EventProxy, kvClient kvstore.Client, cfg *config.AdapterFlags, cm *conf.ConfigManager) *OpenONUAC {
 	var openOnuAc OpenONUAC
 	openOnuAc.exitChannel = make(chan int, 1)
 	openOnuAc.deviceHandlers = make(map[string]*deviceHandler)
@@ -75,6 +77,7 @@
 	openOnuAc.lockDeviceHandlersMap = sync.RWMutex{}
 	openOnuAc.kafkaICProxy = kafkaICProxy
 	openOnuAc.config = cfg
+	openOnuAc.cm = cm
 	openOnuAc.numOnus = cfg.OnuNumber
 	openOnuAc.coreProxy = coreProxy
 	openOnuAc.adapterProxy = adapterProxy