[VOL-3624] Parametrizing the KV-Store path
Change-Id: I44d8d72e12f83ee6c79020dd98ace4d2f1155def
diff --git a/internal/pkg/resourcemanager/resourcemanager.go b/internal/pkg/resourcemanager/resourcemanager.go
index abfb73d..612ee8c 100755
--- a/internal/pkg/resourcemanager/resourcemanager.go
+++ b/internal/pkg/resourcemanager/resourcemanager.go
@@ -40,8 +40,8 @@
const (
// KvstoreTimeout specifies the time out for KV Store Connection
KvstoreTimeout = 5 * time.Second
- // BasePathKvStore - service/voltha/openolt/<device_id>
- BasePathKvStore = "service/voltha/openolt/{%s}"
+ // BasePathKvStore - <pathPrefix>/openolt/<device_id>
+ BasePathKvStore = "%s/openolt/{%s}"
// TpIDPathSuffix - <(pon_id, onu_id, uni_id)>/tp_id
TpIDPathSuffix = "{%d,%d,%d}/tp_id"
//MeterIDPathSuffix - <(pon_id, onu_id, uni_id)>/<tp_id>/meter_id/<direction>
@@ -140,7 +140,7 @@
}
// SetKVClient sets the KV client and return a kv backend
-func SetKVClient(ctx context.Context, backend string, addr string, DeviceID string) *db.Backend {
+func SetKVClient(ctx context.Context, backend string, addr string, DeviceID string, basePathKvStore string) *db.Backend {
// TODO : Make sure direct call to NewBackend is working fine with backend , currently there is some
// issue between kv store and backend , core is not calling NewBackend directly
kvClient, err := newKVClient(ctx, backend, addr, KvstoreTimeout)
@@ -154,7 +154,7 @@
StoreType: backend,
Address: addr,
Timeout: KvstoreTimeout,
- PathPrefix: fmt.Sprintf(BasePathKvStore, DeviceID)}
+ PathPrefix: fmt.Sprintf(BasePathKvStore, basePathKvStore, DeviceID)}
return kvbackend
}
@@ -162,7 +162,7 @@
// NewResourceMgr init a New resource manager instance which in turn instantiates pon resource manager
// instances according to technology. Initializes the default resource ranges for all
// the resources.
-func NewResourceMgr(ctx context.Context, deviceID string, KVStoreAddress string, kvStoreType string, deviceType string, devInfo *openolt.DeviceInfo) *OpenOltResourceMgr {
+func NewResourceMgr(ctx context.Context, deviceID string, KVStoreAddress string, kvStoreType string, deviceType string, devInfo *openolt.DeviceInfo, basePathKvStore string) *OpenOltResourceMgr {
var ResourceMgr OpenOltResourceMgr
logger.Debugf(ctx, "Init new resource manager , address: %s, device-id: %s", KVStoreAddress, deviceID)
ResourceMgr.DeviceID = deviceID
@@ -172,7 +172,7 @@
NumPONPorts := devInfo.GetPonPorts()
Backend := kvStoreType
- ResourceMgr.KVStore = SetKVClient(ctx, Backend, ResourceMgr.Address, deviceID)
+ ResourceMgr.KVStore = SetKVClient(ctx, Backend, ResourceMgr.Address, deviceID, basePathKvStore)
if ResourceMgr.KVStore == nil {
logger.Error(ctx, "Failed to setup KV store")
}
@@ -241,7 +241,7 @@
Ranges[technology] = TechRange
RsrcMgrsByTech[technology], err = ponrmgr.NewPONResourceManager(ctx, technology, deviceType, deviceID,
- Backend, ResourceMgr.Address)
+ Backend, ResourceMgr.Address, basePathKvStore)
if err != nil {
logger.Errorf(ctx, "Failed to create pon resource manager instance for technology %s", technology)
return nil
@@ -1213,7 +1213,7 @@
//remove them one by one
for key := range value {
// Formulate the right key path suffix ti be delete
- stringToBeReplaced := fmt.Sprintf(BasePathKvStore, RsrcMgr.DeviceID) + "/"
+ stringToBeReplaced := fmt.Sprintf(BasePathKvStore, RsrcMgr.KVStore.PathPrefix, RsrcMgr.DeviceID) + "/"
replacedWith := ""
key = strings.Replace(key, stringToBeReplaced, replacedWith, 1)
diff --git a/internal/pkg/resourcemanager/resourcemanager_test.go b/internal/pkg/resourcemanager/resourcemanager_test.go
index 5901c7c..50fcf4a 100644
--- a/internal/pkg/resourcemanager/resourcemanager_test.go
+++ b/internal/pkg/resourcemanager/resourcemanager_test.go
@@ -274,6 +274,7 @@
kvStoreType string
deviceType string
devInfo *openolt.DeviceInfo
+ kvStorePrefix string
}
tests := []struct {
name string
@@ -281,15 +282,15 @@
want *OpenOltResourceMgr
}{
{"NewResourceMgr-1", args{"olt1", "1:2", "consul",
- "onu", &openolt.DeviceInfo{OnuIdStart: 1, OnuIdEnd: 1}}, &OpenOltResourceMgr{}},
+ "onu", &openolt.DeviceInfo{OnuIdStart: 1, OnuIdEnd: 1}, "service/voltha"}, &OpenOltResourceMgr{}},
{"NewResourceMgr-2", args{"olt2", "3:4", "etcd",
- "onu", &openolt.DeviceInfo{OnuIdStart: 1, OnuIdEnd: 1}}, &OpenOltResourceMgr{}},
+ "onu", &openolt.DeviceInfo{OnuIdStart: 1, OnuIdEnd: 1}, "service/voltha"}, &OpenOltResourceMgr{}},
}
for _, tt := range tests {
t.Run(tt.name, func(t *testing.T) {
ctx, cancel := context.WithTimeout(context.Background(), 5*time.Second)
defer cancel()
- if got := NewResourceMgr(ctx, tt.args.deviceID, tt.args.KVStoreAddress, tt.args.kvStoreType, tt.args.deviceType, tt.args.devInfo); reflect.TypeOf(got) != reflect.TypeOf(tt.want) {
+ if got := NewResourceMgr(ctx, tt.args.deviceID, tt.args.KVStoreAddress, tt.args.kvStoreType, tt.args.deviceType, tt.args.devInfo, tt.args.kvStorePrefix); reflect.TypeOf(got) != reflect.TypeOf(tt.want) {
t.Errorf("NewResourceMgr() = %v, want %v", got, tt.want)
}
})
@@ -827,21 +828,22 @@
func TestSetKVClient(t *testing.T) {
type args struct {
- backend string
- address string
- DeviceID string
+ backend string
+ address string
+ DeviceID string
+ kvStorePrefix string
}
tests := []struct {
name string
args args
want *db.Backend
}{
- {"setKVClient-1", args{"consul", "1.1.1.1:1", "olt1"}, &db.Backend{}},
- {"setKVClient-1", args{"etcd", "2.2.2.2:2", "olt2"}, &db.Backend{}},
+ {"setKVClient-1", args{"consul", "1.1.1.1:1", "olt1", "service/voltha"}, &db.Backend{}},
+ {"setKVClient-1", args{"etcd", "2.2.2.2:2", "olt2", "service/voltha"}, &db.Backend{}},
}
for _, tt := range tests {
t.Run(tt.name, func(t *testing.T) {
- if got := SetKVClient(context.Background(), tt.args.backend, tt.args.address, tt.args.DeviceID); reflect.TypeOf(got) != reflect.TypeOf(tt.want) {
+ if got := SetKVClient(context.Background(), tt.args.backend, tt.args.address, tt.args.DeviceID, tt.args.kvStorePrefix); reflect.TypeOf(got) != reflect.TypeOf(tt.want) {
t.Errorf("SetKVClient() = %v, want %v", got, tt.want)
}
})