VOL-1446 : Cleanup of db/model unit tests
- Fixed issues with model components while running tests
- Removed unecessary tests
Change-Id: Ica2007b66f681d03a77144cf2e778aa5a586786a
diff --git a/db/model/backend_test.go b/db/model/backend_test.go
deleted file mode 100644
index eaa6523..0000000
--- a/db/model/backend_test.go
+++ /dev/null
@@ -1,129 +0,0 @@
-/*
- * Copyright 2018-present Open Networking Foundation
-
- * Licensed under the Apache License, Version 2.0 (the "License");
- * you may not use this file except in compliance with the License.
- * You may obtain a copy of the License at
-
- * http://www.apache.org/licenses/LICENSE-2.0
-
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- */
-package model
-
-import (
- "encoding/json"
- "fmt"
- "testing"
-)
-
-const (
- ETCD_KV = "etcd"
- CONSUL_KV = "consul"
- INVALID_KV = "invalid"
-
- etcd_host = "10.104.149.247"
- etcd_port = 2379
-
- /*
- To debug locally with the remote ETCD container
-
- ssh -f -N vagrant@10.100.198.220 -L 22379:10.104.149.247:2379
- */
- //etcd_host = "localhost"
- //etcd_port = 22379
- consul_host = "k8s-consul"
- consul_port = 30080
- timeout = 5
- prefix = "backend/test"
- key = "stephane/1"
- value = "barbarie"
-)
-
-var (
- etcd_backend *Backend
- consul_backend *Backend
-)
-
-func Test_Etcd_Backend_New(t *testing.T) {
- etcd_backend = NewBackend(ETCD_KV, etcd_host, etcd_port, timeout, prefix)
-}
-
-func Test_Etcd_Backend_Put(t *testing.T) {
- etcd_backend.Put(key, value)
-
-}
-
-func Test_Etcd_Backend_Get(t *testing.T) {
- if pair, err := etcd_backend.Client.Get("service/voltha/data/core/0001/root", timeout); err != nil {
- t.Errorf("backend get failed - %s", err.Error())
- } else {
- j, _ := json.Marshal(pair)
- t.Logf("pair: %s", string(j))
- }
-}
-
-func Test_Etcd_Backend_GetRoot(t *testing.T) {
- if pair, err := etcd_backend.Get(key); err != nil {
- t.Errorf("backend get failed - %s", err.Error())
- } else {
- j, _ := json.Marshal(pair)
- t.Logf("pair: %s", string(j))
- if pair.Key != (prefix + "/" + key) {
- t.Errorf("backend key differs - key: %s, expected: %s", pair.Key, key)
- }
-
- s := fmt.Sprintf("%s", pair.Value)
- if s != value {
- t.Errorf("backend value differs - value: %s, expected:%s", pair.Value, value)
- }
- }
-}
-
-func Test_Etcd_Backend_Delete(t *testing.T) {
- if err := etcd_backend.Delete(key); err != nil {
- t.Errorf("backend delete failed - %s", err.Error())
- }
- //if _, err := backend.Client.Get(key, Timeout); err == nil {
- // t.Errorf("backend delete failed - %s", err.Error())
- //}
-}
-
-func Test_Consul_Backend_New(t *testing.T) {
- consul_backend = NewBackend(CONSUL_KV, consul_host, consul_port, timeout, prefix)
-}
-
-func Test_Consul_Backend_Put(t *testing.T) {
- consul_backend.Put(key, value)
-
-}
-
-func Test_Consul_Backend_Get(t *testing.T) {
- if pair, err := consul_backend.Get(key); err != nil {
- t.Errorf("backend get failed - %s", err.Error())
- } else {
- j, _ := json.Marshal(pair)
- t.Logf("pair: %s", string(j))
- if pair.Key != (prefix + "/" + key) {
- t.Errorf("backend key differs - key: %s, expected: %s", pair.Key, key)
- }
-
- v := fmt.Sprintf("%s", pair.Value)
- if v != value {
- t.Errorf("backend value differs - value: %s, expected:%s", pair.Value, value)
- }
- }
-}
-
-func Test_Consul_Backend_Delete(t *testing.T) {
- if err := consul_backend.Delete(key); err != nil {
- t.Errorf("backend delete failed - %s", err.Error())
- }
- //if _, err := backend.Client.Get(key, Timeout); err == nil {
- // t.Errorf("backend delete failed - %s", err.Error())
- //}
-}
diff --git a/db/model/base_test.go b/db/model/base_test.go
index 26edce6..38f4567 100644
--- a/db/model/base_test.go
+++ b/db/model/base_test.go
@@ -17,9 +17,8 @@
import (
"github.com/opencord/voltha-go/common/log"
- "github.com/opencord/voltha-go/protos/common"
- "github.com/opencord/voltha-go/protos/openflow_13"
"github.com/opencord/voltha-go/protos/voltha"
+ "runtime/debug"
"sync"
)
@@ -34,113 +33,28 @@
DbTimeout int
}
-var (
- modelTestConfig = &ModelTestConfig{
- DbPrefix: "service/voltha",
- DbType: "etcd",
- DbHost: "localhost",
- //DbHost: "10.106.153.44",
- DbPort: 2379,
- DbTimeout: 5,
- }
-
- logports = []*voltha.LogicalPort{
- {
- Id: "123",
- DeviceId: "logicalport-0-device-id",
- DevicePortNo: 123,
- RootPort: false,
- },
- }
- ports = []*voltha.Port{
- {
- PortNo: 123,
- Label: "test-port-0",
- Type: voltha.Port_PON_OLT,
- AdminState: common.AdminState_ENABLED,
- OperStatus: common.OperStatus_ACTIVE,
- DeviceId: "etcd_port-0-device-id",
- Peers: []*voltha.Port_PeerPort{},
- },
- }
-
- stats = &openflow_13.OfpFlowStats{
- Id: 1111,
- }
- flows = &openflow_13.Flows{
- Items: []*openflow_13.OfpFlowStats{stats},
- }
- device = &voltha.Device{
- Id: devID,
- Type: "simulated_olt",
- Address: &voltha.Device_HostAndPort{HostAndPort: "1.2.3.4:5555"},
- AdminState: voltha.AdminState_PREPROVISIONED,
- Flows: flows,
- Ports: ports,
- }
-
- logicalDevice = &voltha.LogicalDevice{
- Id: devID,
- DatapathId: 0,
- Ports: logports,
- Flows: flows,
- }
-
- devID string
- ldevID string
- targetDevID string
- targetLogDevID string
-)
-
-func init() {
- log.AddPackage(log.JSON, log.WarnLevel, nil)
- log.UpdateAllLoggers(log.Fields{"instanceId": "MODEL_TEST"})
-
- defer log.CleanUp()
-
- modelTestConfig.Backend = NewBackend(
- modelTestConfig.DbType,
- modelTestConfig.DbHost,
- modelTestConfig.DbPort,
- modelTestConfig.DbTimeout,
- modelTestConfig.DbPrefix,
- )
-
- msgClass := &voltha.Voltha{}
- root := NewRoot(msgClass, modelTestConfig.Backend)
- //root := NewRoot(msgClass, nil)
-
- //if modelTestConfig.Backend != nil {
- //modelTestConfig.Root = root.Load(msgClass)
- //} else {
- modelTestConfig.Root = root
- //}
-
- GetProfiling().Report()
-
- modelTestConfig.RootProxy = modelTestConfig.Root.node.CreateProxy("/", false)
-}
-
func commonCallback(args ...interface{}) interface{} {
log.Infof("Running common callback - arg count: %s", len(args))
- for i := 0; i < len(args); i++ {
- log.Infof("ARG %d : %+v", i, args[i])
- }
+ //for i := 0; i < len(args); i++ {
+ // log.Infof("ARG %d : %+v", i, args[i])
+ //}
mutex := sync.Mutex{}
+ mutex.Lock()
+ defer mutex.Unlock()
+
execStatus := args[1].(*bool)
// Inform the caller that the callback was executed
- mutex.Lock()
*execStatus = true
- mutex.Unlock()
+ log.Infof("Changed value of exec status to true - stack:%s", string(debug.Stack()))
return nil
}
func commonCallback2(args ...interface{}) interface{} {
- log.Infof("Running common callback - arg count: %s", len(args))
+ log.Infof("Running common2 callback - arg count: %s %+v", len(args), args)
return nil
}
diff --git a/db/model/branch.go b/db/model/branch.go
index 2ad40b4..40c66ad 100644
--- a/db/model/branch.go
+++ b/db/model/branch.go
@@ -89,7 +89,7 @@
b.Lock()
defer b.Unlock()
- if revision, ok := b.Revisions[hash]; !ok {
+ if revision, ok := b.Revisions[hash]; ok {
return revision
}
diff --git a/db/model/branch_test.go b/db/model/branch_test.go
index 26129fa..cf8406c 100644
--- a/db/model/branch_test.go
+++ b/db/model/branch_test.go
@@ -22,11 +22,12 @@
)
var (
- BRANCH *Branch
- HASH string
+ TestBranch_BRANCH *Branch
+ TestBranch_HASH string
)
-func Test_ConfigBranch_New(t *testing.T) {
+// Create a new branch and ensure that fields are populated
+func TestBranch_NewBranch(t *testing.T) {
node := &node{}
hash := fmt.Sprintf("%x", md5.Sum([]byte("origin_hash")))
origin := &NonPersistedRevision{
@@ -34,38 +35,75 @@
Children: make(map[string][]Revision),
Hash: hash,
Branch: &Branch{},
- WeakRef: "need to fix this",
}
txid := fmt.Sprintf("%x", md5.Sum([]byte("branch_transaction_id")))
- BRANCH = NewBranch(node, txid, origin, true)
+ TestBranch_BRANCH = NewBranch(node, txid, origin, true)
+ t.Logf("New Branch(txid:%s) created: %+v\n", txid, TestBranch_BRANCH)
- t.Logf("New Branch created: %+v\n", BRANCH)
+ if TestBranch_BRANCH.Latest == nil {
+ t.Errorf("Branch latest pointer is nil")
+ } else if TestBranch_BRANCH.Origin == nil {
+ t.Errorf("Branch origin pointer is nil")
+ } else if TestBranch_BRANCH.Node == nil {
+ t.Errorf("Branch node pointer is nil")
+ } else if TestBranch_BRANCH.Revisions == nil {
+ t.Errorf("Branch revisions map is nil")
+ } else if TestBranch_BRANCH.Txid == "" {
+ t.Errorf("Branch transaction id is empty")
+ }
}
-func Test_ConfigBranch_AddRevision(t *testing.T) {
- HASH = fmt.Sprintf("%x", md5.Sum([]byte("revision_hash")))
+// Add a new revision to the branch
+func TestBranch_AddRevision(t *testing.T) {
+ TestBranch_HASH = fmt.Sprintf("%x", md5.Sum([]byte("revision_hash")))
rev := &NonPersistedRevision{
Config: &DataRevision{},
Children: make(map[string][]Revision),
- Hash: HASH,
+ Hash: TestBranch_HASH,
Branch: &Branch{},
- WeakRef: "need to fix this",
}
- BRANCH.Revisions[HASH] = rev
+ TestBranch_BRANCH.AddRevision(rev)
t.Logf("Added revision: %+v\n", rev)
+
+ if len(TestBranch_BRANCH.Revisions) == 0 {
+ t.Errorf("Branch revisions map is empty")
+ }
}
-func Test_ConfigBranch_GetRevision(t *testing.T) {
- rev := BRANCH.GetRevision(HASH)
- t.Logf("Got revision for hash:%s rev:%+v\n", HASH, rev)
+// Ensure that the added revision can be retrieved
+func TestBranch_GetRevision(t *testing.T) {
+ if rev := TestBranch_BRANCH.GetRevision(TestBranch_HASH); rev == nil {
+ t.Errorf("Unable to retrieve revision for hash:%s", TestBranch_HASH)
+ } else {
+ t.Logf("Got revision for hash:%s rev:%+v\n", TestBranch_HASH, rev)
+ }
}
-func Test_ConfigBranch_LatestRevision(t *testing.T) {
- rev := BRANCH.GetLatest()
- t.Logf("Got GetLatest revision:%+v\n", rev)
+
+// Set the added revision as the latest
+func TestBranch_LatestRevision(t *testing.T) {
+ addedRevision := TestBranch_BRANCH.GetRevision(TestBranch_HASH)
+ TestBranch_BRANCH.SetLatest(addedRevision)
+
+ rev := TestBranch_BRANCH.GetLatest()
+ t.Logf("Retrieved latest revision :%+v", rev)
+
+ if rev == nil {
+ t.Error("Unable to retrieve latest revision")
+ } else if rev.GetHash() != TestBranch_HASH {
+ t.Errorf("Latest revision does not match hash: %s", TestBranch_HASH)
+ }
}
-func Test_ConfigBranch_OriginRevision(t *testing.T) {
- rev := BRANCH.Origin
- t.Logf("Got Origin revision:%+v\n", rev)
+
+// Ensure that the origin revision remains and differs from subsequent revisions
+func TestBranch_OriginRevision(t *testing.T) {
+ rev := TestBranch_BRANCH.Origin
+ t.Logf("Retrieved origin revision :%+v", rev)
+
+ if rev == nil {
+ t.Error("Unable to retrieve origin revision")
+ } else if rev.GetHash() == TestBranch_HASH {
+ t.Errorf("Origin revision should differ from added revision: %s", TestBranch_HASH)
+ }
}
diff --git a/db/model/child_type_test.go b/db/model/child_type_test.go
index 1fd81bc..d604b76 100644
--- a/db/model/child_type_test.go
+++ b/db/model/child_type_test.go
@@ -17,53 +17,31 @@
import (
"github.com/opencord/voltha-go/protos/voltha"
+ "reflect"
"testing"
)
-/*
-
- */
-func Test_ChildType_01_CacheIsEmpty(t *testing.T) {
- if getChildTypeCache().Cache != nil || len(getChildTypeCache().Cache) > 0 {
- t.Errorf("getChildTypeCache().Cache should be empty: %+v\n", getChildTypeCache().Cache)
- }
- t.Logf("getChildTypeCache().Cache is empty - %+v\n", getChildTypeCache().Cache)
-}
-
-/*
-
- */
-func Test_ChildType_02_Device_Proto_ChildrenFields(t *testing.T) {
-
+// Dissect a proto message by extracting all the children fields
+func TestChildType_01_Device_Proto_ChildrenFields(t *testing.T) {
var cls *voltha.Device
- //cls = &voltha.Device{Id:"testing-Config-rev-id"}
+ t.Logf("Extracting children fields from proto type: %s", reflect.TypeOf(cls))
names := ChildrenFields(cls)
+ t.Logf("Extracting children field names: %+v", names)
- //tst := reflect.ValueOf(cls).Elem().FieldByName("ImageDownloads")
- //
- //t.Logf("############ Field by name : %+v\n", reflect.TypeOf(tst.Interface()))
-
- if names == nil || len(names) == 0 {
- t.Errorf("ChildrenFields failed to return names: %+v\n", names)
+ expectedKeys := []string{"ports", "flows", "flow_groups", "image_downloads", "pm_configs"}
+ for _, key := range expectedKeys {
+ if _, exists := names[key]; !exists {
+ t.Errorf("Missing key:%s from class type:%s", key, reflect.TypeOf(cls))
+ }
}
- t.Logf("ChildrenFields returned names: %+v\n", names)
}
-/*
-
- */
-func Test_ChildType_03_CacheHasOneEntry(t *testing.T) {
- if getChildTypeCache().Cache == nil || len(getChildTypeCache().Cache) != 1 {
- t.Errorf("getChildTypeCache().Cache should have one entry: %+v\n", getChildTypeCache().Cache)
+// Verify that the cache contains an entry for types on which ChildrenFields was performed
+func TestChildType_02_Cache_Keys(t *testing.T) {
+ if _, exists := getChildTypeCache().Cache[reflect.TypeOf(&voltha.Device{}).String()]; !exists {
+ t.Errorf("getChildTypeCache().Cache should have an entry of type: %+v\n", reflect.TypeOf(&voltha.Device{}).String())
}
- t.Logf("getChildTypeCache().Cache has one entry: %+v\n", getChildTypeCache().Cache)
-}
-
-/*
-
- */
-func Test_ChildType_04_Cache_Keys(t *testing.T) {
for k := range getChildTypeCache().Cache {
t.Logf("getChildTypeCache().Cache Key:%+v\n", k)
}
diff --git a/db/model/node.go b/db/model/node.go
index 376efca..20fd495 100644
--- a/db/model/node.go
+++ b/db/model/node.go
@@ -415,6 +415,11 @@
idx, childRev := n.findRevByKey(children, field.Key, keyValue)
childNode := childRev.GetNode()
+ // Save proxy in child node to ensure callbacks are called later on
+ if childNode.Proxy == nil {
+ childNode.Proxy = n.Proxy
+ }
+
newChildRev := childNode.Update(path, data, strict, txid, makeBranch)
if newChildRev.GetHash() == childRev.GetHash() {
@@ -439,6 +444,7 @@
children[idx] = newChildRev
updatedRev := rev.UpdateChildren(name, children, branch)
+
branch.GetLatest().Drop(txid, false)
n.makeLatest(branch, updatedRev, nil)
@@ -553,14 +559,14 @@
log.Errorf("duplicate key found: %s", key.String())
return exists
}
- childRev := n.MakeNode(data, txid).Latest(txid)
+ childRev := n.MakeNode(data, "").Latest()
// Prefix the hash with the data type (e.g. devices, logical_devices, adapters)
childRev.SetHash(name + "/" + key.String())
// Create watch for <component>/<key>
childRev.SetupWatch(childRev.GetHash())
-
+
children = append(children, childRev)
rev = rev.UpdateChildren(name, children, branch)
changes := []ChangeTuple{{POST_ADD, nil, childRev.GetData()}}
@@ -590,9 +596,12 @@
childNode := childRev.GetNode()
newChildRev := childNode.Add(path, data, txid, makeBranch)
+ // Prefix the hash with the data type (e.g. devices, logical_devices, adapters)
+ childRev.SetHash(name + "/" + keyValue.(string))
+
children[idx] = newChildRev
- rev = rev.UpdateChildren(name, branch.GetLatest().GetChildren(name), branch)
+ rev = rev.UpdateChildren(name, children, branch)
rev.Drop(txid, false)
n.makeLatest(branch, rev.GetBranch().GetLatest(), nil)
@@ -654,12 +663,15 @@
if path != "" {
idx, childRev := n.findRevByKey(children, field.Key, keyValue)
childNode := childRev.GetNode()
+ if childNode.Proxy == nil {
+ childNode.Proxy = n.Proxy
+ }
newChildRev := childNode.Remove(path, txid, makeBranch)
children[idx] = newChildRev
rev.SetChildren(name, children)
branch.GetLatest().Drop(txid, false)
n.makeLatest(branch, rev, nil)
- return rev
+ return nil
}
idx, childRev := n.findRevByKey(children, field.Key, keyValue)
if n.GetProxy() != nil {
@@ -731,7 +743,9 @@
rev, changes := Merge3Way(forkRev, srcRev, dstRev, n.mergeChild(txid, dryRun), dryRun)
if !dryRun {
- n.makeLatest(dstBranch, rev, changes)
+ if rev != nil {
+ n.makeLatest(dstBranch, rev, changes)
+ }
n.DeleteBranch(txid)
}
@@ -880,6 +894,7 @@
func (n *node) GetBranch(key string) *Branch {
n.Lock()
defer n.Unlock()
+
if n.Branches != nil {
if branch, exists := n.Branches[key]; exists {
return branch
diff --git a/db/model/node_test.go b/db/model/node_test.go
index 3b12c14..d60cc44 100644
--- a/db/model/node_test.go
+++ b/db/model/node_test.go
@@ -22,11 +22,12 @@
"github.com/opencord/voltha-go/protos/common"
"github.com/opencord/voltha-go/protos/openflow_13"
"github.com/opencord/voltha-go/protos/voltha"
+ "reflect"
"testing"
)
-func Test_Node_01_New(t *testing.T) {
- ports := []*voltha.Port{
+var (
+ TestNode_Port = []*voltha.Port{
{
PortNo: 123,
Label: "test-etcd_port-0",
@@ -37,7 +38,8 @@
Peers: []*voltha.Port_PeerPort{},
},
}
- data := &voltha.Device{
+
+ TestNode_Device = &voltha.Device{
Id: "Config-SomeNode-01-new-test",
Type: "simulated_olt",
Root: true,
@@ -60,16 +62,33 @@
Reason: "",
ConnectStatus: common.ConnectStatus_REACHABLE,
Custom: &any.Any{},
- Ports: ports,
+ Ports: TestNode_Port,
Flows: &openflow_13.Flows{},
FlowGroups: &openflow_13.FlowGroups{},
PmConfigs: &voltha.PmConfigs{},
ImageDownloads: []*voltha.ImageDownload{},
}
- root := &root{}
- txid := fmt.Sprintf("%x", md5.Sum([]byte("node_transaction_id")))
- node := NewNode(root, data, true, txid)
+ TestNode_Data = TestNode_Device
- t.Logf("new SomeNode created : %+v\n", node)
+ TestNode_Txid = fmt.Sprintf("%x", md5.Sum([]byte("node_transaction_id")))
+ TestNode_Root = &root{RevisionClass: reflect.TypeOf(NonPersistedRevision{})}
+)
+
+// Exercise node creation code
+// This test will
+func TestNode_01_NewNode(t *testing.T) {
+ node := NewNode(TestNode_Root, TestNode_Data, false, TestNode_Txid)
+
+ if reflect.ValueOf(node.Type).Type() != reflect.TypeOf(TestNode_Data) {
+ t.Errorf("Node type does not match original data type: %+v", reflect.ValueOf(node.Type).Type())
+ } else if node.GetBranch(TestNode_Txid) == nil || node.GetBranch(TestNode_Txid).Latest == nil {
+ t.Errorf("No branch associated to txid: %s", TestNode_Txid)
+ } else if node.GetBranch(TestNode_Txid).Latest == nil {
+ t.Errorf("Branch has no latest revision : %s", TestNode_Txid)
+ } else if node.GetBranch(TestNode_Txid).GetLatest().GetConfig() == nil {
+ t.Errorf("Latest revision has no assigned data: %+v", node.GetBranch(TestNode_Txid).GetLatest())
+ }
+
+ t.Logf("Created new node successfully : %+v\n", node)
}
diff --git a/db/model/non_persisted_revision.go b/db/model/non_persisted_revision.go
index 27d3d9a..cb8c9ca 100644
--- a/db/model/non_persisted_revision.go
+++ b/db/model/non_persisted_revision.go
@@ -150,8 +150,9 @@
GetRevCache().Lock()
defer GetRevCache().Unlock()
- npr.Hash = npr.hashContent()
-
+ if !skipOnExist {
+ npr.Hash = npr.hashContent()
+ }
if _, exists := GetRevCache().Cache[npr.Hash]; !exists {
GetRevCache().Cache[npr.Hash] = npr
}
diff --git a/db/model/proxy.go b/db/model/proxy.go
index 402731a..cfb2ef1 100644
--- a/db/model/proxy.go
+++ b/db/model/proxy.go
@@ -193,7 +193,7 @@
effectivePath = p.getFullPath()
} else {
fullPath = p.getPath() + path
- effectivePath = p.getFullPath()
+ effectivePath = p.getFullPath() + path
}
pathLock, controlled := p.parseForControlledPath(effectivePath)
diff --git a/db/model/proxy_concurrency_test.go b/db/model/proxy_concurrency_test.go
deleted file mode 100644
index 3ebe06a..0000000
--- a/db/model/proxy_concurrency_test.go
+++ /dev/null
@@ -1,456 +0,0 @@
-/*
- * Copyright 2018-present Open Networking Foundation
-
- * Licensed under the Apache License, Version 2.0 (the "License");
- * you may not use this file except in compliance with the License.
- * You may obtain a copy of the License at
-
- * http://www.apache.org/licenses/LICENSE-2.0
-
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- */
-package model
-
-import (
- "encoding/hex"
- "encoding/json"
- "github.com/google/uuid"
- "github.com/opencord/voltha-go/protos/voltha"
- "reflect"
- "strconv"
- "testing"
-)
-
-/*
-
-1. Add device
-2. Do parallel updates of that device
-3. Do parallel gets of that device
-4. Remove device
-
- */
-
-var (
- //pctTargetDeviceId string
- target *voltha.Device
-)
-
-func Test_ConcurrentProxy_1_1_Add_NewDevice(t *testing.T) {
- devIDBin, _ := uuid.New().MarshalBinary()
- devID = "0001" + hex.EncodeToString(devIDBin)[:12]
-
- preAddExecuted := false
- postAddExecuted := false
-
- modelTestConfig.RootProxy.RegisterCallback(PRE_ADD, commonCallback, "PRE_ADD instructions", &preAddExecuted)
- modelTestConfig.RootProxy.RegisterCallback(POST_ADD, commonCallback, "POST_ADD instructions", &postAddExecuted)
-
- device.Id = devID
- if added := modelTestConfig.RootProxy.Add("/devices", device, ""); added == nil {
- t.Error("Failed to add device")
- } else {
- t.Logf("Added device : %+v", added)
- }
-
- if d := modelTestConfig.RootProxy.Get("/devices/"+devID, 0, false, ""); !reflect.ValueOf(d).IsValid() {
- t.Error("Failed to find added device")
- } else {
- djson, _ := json.Marshal(d)
- t.Logf("Found device: %s", string(djson))
- }
-
- //if !preAddExecuted {
- // t.Error("PRE_ADD callback was not executed")
- //}
- //if !postAddExecuted {
- // t.Error("POST_ADD callback was not executed")
- //}
-}
-
-func Test_ConcurrentProxy_1_Add_ExistingDevice(t *testing.T) {
- t.Parallel()
-
- device.Id = devID
- if added := modelTestConfig.RootProxy.Add("/devices", device, ""); added == nil {
- t.Logf("Successfully detected that the device already exists: %s", devID)
- } else {
- t.Errorf("A new device should not have been created : %+v", added)
- }
-
-}
-
-func Test_ConcurrentProxy_Get_AllDevices(t *testing.T) {
- t.Parallel()
-
- devices := modelTestConfig.RootProxy.Get("/devices", 1, false, "")
-
- if len(devices.([]interface{})) == 0 {
- t.Error("there are no available devices to retrieve")
- } else {
- t.Logf("retrieved all devices: %+v", devices)
- }
-}
-
-func Test_ConcurrentProxy_Get_Update_DeviceAdminState(t *testing.T) {
- t.Parallel()
- if retrieved := modelTestConfig.RootProxy.Get("/devices/"+devID, 1, false, ""); retrieved == nil {
- t.Error("Failed to get device")
- } else {
- retrieved.(*voltha.Device).AdminState = voltha.AdminState_DISABLED
-
- preUpdateExecuted := false
- postUpdateExecuted := false
-
- modelTestConfig.RootProxy.RegisterCallback(
- PRE_UPDATE,
- commonCallback,
- "PRE_UPDATE instructions (root proxy)", &preUpdateExecuted,
- )
- modelTestConfig.RootProxy.RegisterCallback(
- POST_UPDATE,
- commonCallback,
- "POST_UPDATE instructions (root proxy)", &postUpdateExecuted,
- )
-
- if afterUpdate := modelTestConfig.RootProxy.Update("/devices/"+devID, retrieved, false, ""); afterUpdate == nil {
- t.Error("Failed to update device")
- } else {
- t.Logf("Updated device : %+v", afterUpdate.(Revision).GetData())
- }
- if d := modelTestConfig.RootProxy.Get("/devices/"+devID, 0, false, ""); !reflect.ValueOf(d).IsValid() {
- t.Error("Failed to find updated device (root proxy)")
- } else {
- djson, _ := json.Marshal(d)
- t.Logf("Found device (root proxy): %s", string(djson))
- }
-
- //if !preUpdateExecuted {
- // t.Error("PRE_UPDATE callback was not executed")
- //}
- //if !postUpdateExecuted {
- // t.Error("POST_UPDATE callback was not executed")
- //}
- }
-}
-
-func Test_ConcurrentProxy_Get_SingleDevice(t *testing.T) {
- //t.Parallel()
-
- if d := modelTestConfig.RootProxy.Get("/devices/"+devID, 0, false, ""); !reflect.ValueOf(d).IsValid() {
- t.Errorf("Failed to find device : %s", devID)
- } else {
- djson, _ := json.Marshal(d)
- t.Logf("Found device: %s", string(djson))
- }
-
-}
-
-func Test_ConcurrentProxy_Get_SingleDeviceFlows(t *testing.T) {
- t.Parallel()
-
- if d := modelTestConfig.RootProxy.Get("/devices/"+devID+"/flows", 0, false, ""); !reflect.ValueOf(d).IsValid() {
- t.Errorf("Failed to find device : %s", devID)
- } else {
- djson, _ := json.Marshal(d)
- t.Logf("Found device: %s", string(djson))
- }
-
-}
-
-func Test_ConcurrentProxy_Get_SingleDevicePorts(t *testing.T) {
- t.Parallel()
- if d := modelTestConfig.RootProxy.Get("/devices/"+devID+"/ports", 0, false, ""); !reflect.ValueOf(d).IsValid() {
- t.Errorf("Failed to find device : %s", devID)
- } else {
- djson, _ := json.Marshal(d)
- t.Logf("Found device: %s", string(djson))
- }
-
-}
-
-func Test_ConcurrentProxy_Get_Update_DeviceFirmware(t *testing.T) {
- t.Parallel()
-
- if retrieved := modelTestConfig.RootProxy.Get("/devices/"+devID, 1, false, ""); retrieved == nil {
- t.Error("Failed to get device")
- } else {
- var fwVersion int
- if retrieved.(*voltha.Device).FirmwareVersion == "n/a" {
- fwVersion = 0
- } else {
- fwVersion, _ = strconv.Atoi(retrieved.(*voltha.Device).FirmwareVersion)
- fwVersion++
- }
-
- preUpdateExecuted := false
- postUpdateExecuted := false
-
- modelTestConfig.RootProxy.RegisterCallback(
- PRE_UPDATE,
- commonCallback,
- "PRE_UPDATE instructions (root proxy)", &preUpdateExecuted,
- )
- modelTestConfig.RootProxy.RegisterCallback(
- POST_UPDATE,
- commonCallback,
- "POST_UPDATE instructions (root proxy)", &postUpdateExecuted,
- )
-
- retrieved.(*voltha.Device).FirmwareVersion = strconv.Itoa(fwVersion)
-
- if afterUpdate := modelTestConfig.RootProxy.Update("/devices/"+devID, retrieved, false, ""); afterUpdate == nil {
- t.Error("Failed to update device")
- } else {
- t.Logf("Updated device : %+v", afterUpdate.(Revision).GetData())
- }
- if d := modelTestConfig.RootProxy.Get("/devices/"+devID, 0, false, ""); !reflect.ValueOf(d).IsValid() {
- t.Error("Failed to find updated device (root proxy)")
- } else {
- djson, _ := json.Marshal(d)
- t.Logf("Found device (root proxy): %s", string(djson))
- }
-
- //if !preUpdateExecuted {
- // t.Error("PRE_UPDATE callback was not executed")
- //}
- //if !postUpdateExecuted {
- // t.Error("POST_UPDATE callback was not executed")
- //}
- }
-}
-
-//func Test_ConcurrentProxy_Get_Update_DeviceFlows(t *testing.T) {
-// t.Parallel()
-//
-// // Get a device proxy and update a specific port
-// //devflowsProxy := modelTestConfig.Root.CreateProxy("/devices/"+devID+"/flows", false)
-// flows := modelTestConfig.RootProxy.Get("/", 0, false, "")
-// flows.([]interface{})[0].(*openflow_13.Flows).Items[0].TableId = 2244
-//
-// preUpdateExecuted := false
-// postUpdateExecuted := false
-//
-// modelTestConfig.RootProxy.RegisterCallback(
-// PRE_UPDATE,
-// commonCallback,
-// "PRE_UPDATE instructions (flows proxy)", &preUpdateExecuted,
-// )
-// modelTestConfig.RootProxy.RegisterCallback(
-// POST_UPDATE,
-// commonCallback,
-// "POST_UPDATE instructions (flows proxy)", &postUpdateExecuted,
-// )
-//
-// kvFlows := modelTestConfig.RootProxy.Get("/devices/"+devID+"/flows", 0, false, "")
-//
-// if reflect.DeepEqual(flows, kvFlows) {
-// t.Errorf("Local changes have changed the KV store contents - local:%+v, kv: %+v", flows, kvFlows)
-// }
-//
-// if updated := modelTestConfig.RootProxy.Update("/devices/"+devID+"/flows", flows.([]interface{})[0], false, ""); updated == nil {
-// t.Error("Failed to update flow")
-// } else {
-// t.Logf("Updated flows : %+v", updated)
-// }
-//
-// if d := modelTestConfig.RootProxy.Get("/devices/"+devID+"/flows", 0, false, ""); d == nil {
-// t.Error("Failed to find updated flows (flows proxy)")
-// } else {
-// djson, _ := json.Marshal(d)
-// t.Logf("Found flows (flows proxy): %s", string(djson))
-// }
-//
-// if d := modelTestConfig.RootProxy.Get("/devices/"+devID+"/flows", 0, false, ""); !reflect.ValueOf(d).IsValid() {
-// t.Error("Failed to find updated flows (root proxy)")
-// } else {
-// djson, _ := json.Marshal(d)
-// t.Logf("Found flows (root proxy): %s", string(djson))
-// }
-//
-// //if !preUpdateExecuted {
-// // t.Error("PRE_UPDATE callback was not executed")
-// //}
-// //if !postUpdateExecuted {
-// // t.Error("POST_UPDATE callback was not executed")
-// //}
-//}
-
-//func Test_ConcurrentProxy_4_1_Remove_Device(t *testing.T) {
-// preRemoveExecuted := false
-// postRemoveExecuted := false
-//
-// modelTestConfig.RootProxy.RegisterCallback(
-// PRE_REMOVE,
-// commonCallback,
-// "PRE_REMOVE instructions (root proxy)", &preRemoveExecuted,
-// )
-// modelTestConfig.RootProxy.RegisterCallback(
-// POST_REMOVE,
-// commonCallback,
-// "POST_REMOVE instructions (root proxy)", &postRemoveExecuted,
-// )
-//
-// if removed := modelTestConfig.RootProxy.Remove("/devices/"+devID, ""); removed == nil {
-// t.Error("Failed to remove device")
-// } else {
-// t.Logf("Removed device : %+v", removed)
-// }
-// if d := modelTestConfig.RootProxy.Get("/devices/"+devID, 0, false, ""); reflect.ValueOf(d).IsValid() {
-// djson, _ := json.Marshal(d)
-// t.Errorf("Device was not removed - %s", djson)
-// } else {
-// t.Logf("Device was removed: %s", devID)
-// }
-//
-// if !preRemoveExecuted {
-// t.Error("PRE_UPDATE callback was not executed")
-// }
-// if !postRemoveExecuted {
-// t.Error("POST_UPDATE callback was not executed")
-// }
-//}
-
-//func Benchmark_ConcurrentProxy_UpdateFirmware(b *testing.B) {
-// //var target *voltha.Device
-// if target == nil {
-// devices := modelTestConfig.RootProxy.Get("/devices", 1, false, "")
-// if len(devices.([]interface{})) == 0 {
-// b.Error("there are no available devices to retrieve")
-// } else {
-// // Save the target device id for later tests
-// target = devices.([]interface{})[0].(*voltha.Device)
-// //b.Logf("retrieved all devices: %+v", devices)
-// }
-// }
-//
-// for n := 0; n < b.N; n++ {
-// var fwVersion int
-//
-// if target.FirmwareVersion == "n/a" {
-// fwVersion = 0
-// } else {
-// fwVersion, _ = strconv.Atoi(target.FirmwareVersion)
-// fwVersion += 1
-// }
-//
-// target.FirmwareVersion = strconv.Itoa(fwVersion)
-//
-// if afterUpdate := modelTestConfig.RootProxy.Update("/devices/"+target.Id, target, false,
-// ""); afterUpdate == nil {
-// b.Error("Failed to update device")
-// } else {
-// if d := modelTestConfig.RootProxy.Get("/devices/"+target.Id, 0, false, ""); !reflect.ValueOf(d).IsValid() {
-// b.Errorf("Failed to find device : %s", devID)
-// } else {
-// //djson, _ := json.Marshal(d)
-// //b.Logf("Checking updated device device: %s", string(djson))
-// }
-// }
-// }
-//
-//}
-//
-//func Benchmark_ConcurrentProxy_GetDevice(b *testing.B) {
-// if target == nil {
-// //var target *voltha.Device
-// devices := modelTestConfig.RootProxy.Get("/devices", 1, false, "")
-// if len(devices.([]interface{})) == 0 {
-// b.Error("there are no available devices to retrieve")
-// } else {
-// // Save the target device id for later tests
-// target = devices.([]interface{})[0].(*voltha.Device)
-// //b.Logf("retrieved all devices: %+v", devices)
-// }
-// }
-//
-// for n := 0; n < b.N; n++ {
-// if d := modelTestConfig.RootProxy.Get("/devices/"+target.Id, 0, false, ""); !reflect.ValueOf(d).IsValid() {
-// b.Errorf("Failed to find device : %s", devID)
-// } else {
-// //djson, _ := json.Marshal(d)
-// //b.Logf("Found device: %s", string(djson))
-// }
-// }
-//
-//}
-
-func Benchmark_ConcurrentProxy_UpdateFirmware(b *testing.B) {
- //GetProfiling().Reset()
- defer GetProfiling().Report()
- //b.SetParallelism(100)
- if target == nil {
- devices := modelTestConfig.RootProxy.Get("/devices", 1, false, "")
- if len(devices.([]interface{})) == 0 {
- b.Error("there are no available devices to retrieve")
- } else {
- // Save the target device id for later tests
- target = devices.([]interface{})[0].(*voltha.Device)
- //b.Logf("retrieved all devices: %+v", devices)
- }
- }
-
- b.RunParallel(func(pb *testing.PB) {
- for pb.Next() {
- var fwVersion int
-
- if target.FirmwareVersion == "n/a" {
- fwVersion = 0
- } else {
- fwVersion, _ = strconv.Atoi(target.FirmwareVersion)
- fwVersion++
- }
-
- target.FirmwareVersion = strconv.Itoa(fwVersion)
-
- if afterUpdate := modelTestConfig.RootProxy.Update("/devices/"+target.Id, target, false,
- ""); afterUpdate == nil {
- b.Error("Failed to update device")
- } else {
- if d := modelTestConfig.RootProxy.Get("/devices/"+target.Id, 0, false, ""); !reflect.ValueOf(d).IsValid() {
- b.Errorf("Failed to find device : %s", devID)
- } else if d.(*voltha.Device).FirmwareVersion != target.FirmwareVersion {
- b.Errorf("Firmware was not uptaded - expected: %s, actual: %s",
- target.FirmwareVersion,
- d.(*voltha.Device).FirmwareVersion,
- )
- } else {
- b.Logf("Firmware is now : %s", d.(*voltha.Device).FirmwareVersion)
- //djson, _ := json.Marshal(d)
- //b.Logf("Checking updated device device: %s", string(djson))
- }
- }
- }
- })
-}
-
-func Benchmark_ConcurrentProxy_GetDevice(b *testing.B) {
- //GetProfiling().Reset()
- defer GetProfiling().Report()
- //b.SetParallelism(5)
- if target == nil {
- //var target *voltha.Device
- devices := modelTestConfig.RootProxy.Get("/devices", 1, false, "")
- if len(devices.([]interface{})) == 0 {
- b.Error("there are no available devices to retrieve")
- } else {
- // Save the target device id for later tests
- target = devices.([]interface{})[0].(*voltha.Device)
- //b.Logf("retrieved all devices: %+v", devices)
- }
- }
-
- b.RunParallel(func(pb *testing.PB) {
- for pb.Next() {
- if d := modelTestConfig.RootProxy.Get("/devices/"+target.Id, 0, false, ""); !reflect.ValueOf(d).IsValid() {
- b.Errorf("Failed to find device : %s", devID)
- } else {
- //djson, _ := json.Marshal(d)
- //b.Logf("Found device: %s", string(djson))
- }
- }
- })
-}
diff --git a/db/model/proxy_load_test.go b/db/model/proxy_load_test.go
index 49443cd..23c95e2 100644
--- a/db/model/proxy_load_test.go
+++ b/db/model/proxy_load_test.go
@@ -30,9 +30,10 @@
)
var (
- ltDevProxy *Proxy
- plt *proxyLoadTest
- tlog log.Logger
+ BenchmarkProxy_Root *root
+ BenchmarkProxy_DeviceProxy *Proxy
+ BenchmarkProxy_PLT *proxyLoadTest
+ BenchmarkProxy_Logger log.Logger
)
type proxyLoadChanges struct {
@@ -71,25 +72,27 @@
defer plt.Unlock()
plt.postUpdateExecuted = status
}
+
func init() {
- tlog, _ = log.AddPackage(log.JSON, log.DebugLevel, nil)
- log.UpdateAllLoggers(log.Fields{"instanceId": "PROXY_LOAD_TEST"})
- defer log.CleanUp()
+ BenchmarkProxy_Root = NewRoot(&voltha.Voltha{}, nil)
- ltDevProxy = modelTestConfig.Root.node.CreateProxy("/", false)
+ BenchmarkProxy_Logger, _ = log.AddPackage(log.JSON, log.InfoLevel, nil)
+ //log.UpdateAllLoggers(log.Fields{"instanceId": "PROXY_LOAD_TEST"})
+
+ BenchmarkProxy_DeviceProxy = BenchmarkProxy_Root.node.CreateProxy("/", false)
// Register ADD instructions callbacks
- plt = &proxyLoadTest{}
+ BenchmarkProxy_PLT = &proxyLoadTest{}
- ltDevProxy.RegisterCallback(PRE_ADD, commonCallbackFunc, "PRE_ADD", plt.SetPreAddExecuted)
- ltDevProxy.RegisterCallback(POST_ADD, commonCallbackFunc, "POST_ADD", plt.SetPostAddExecuted)
+ BenchmarkProxy_DeviceProxy.RegisterCallback(PRE_ADD, commonCallbackFunc, "PRE_ADD", BenchmarkProxy_PLT.SetPreAddExecuted)
+ BenchmarkProxy_DeviceProxy.RegisterCallback(POST_ADD, commonCallbackFunc, "POST_ADD", BenchmarkProxy_PLT.SetPostAddExecuted)
//// Register UPDATE instructions callbacks
- ltDevProxy.RegisterCallback(PRE_UPDATE, commonCallbackFunc, "PRE_UPDATE", plt.SetPreUpdateExecuted)
- ltDevProxy.RegisterCallback(POST_UPDATE, commonCallbackFunc, "POST_UPDATE", plt.SetPostUpdateExecuted)
+ BenchmarkProxy_DeviceProxy.RegisterCallback(PRE_UPDATE, commonCallbackFunc, "PRE_UPDATE", BenchmarkProxy_PLT.SetPreUpdateExecuted)
+ BenchmarkProxy_DeviceProxy.RegisterCallback(POST_UPDATE, commonCallbackFunc, "POST_UPDATE", BenchmarkProxy_PLT.SetPostUpdateExecuted)
}
-func Benchmark_ProxyLoad_AddDevice(b *testing.B) {
+func BenchmarkProxy_AddDevice(b *testing.B) {
defer GetProfiling().Report()
b.RunParallel(func(pb *testing.PB) {
b.Log("Started adding devices")
@@ -125,46 +128,46 @@
ltDevID := "0001" + hex.EncodeToString(ltDevIDBin)[:12]
ltDevice.Id = ltDevID
- plt.SetPreAddExecuted(false)
- plt.SetPostAddExecuted(false)
+ BenchmarkProxy_PLT.SetPreAddExecuted(false)
+ BenchmarkProxy_PLT.SetPostAddExecuted(false)
var added interface{}
// Add the device
- if added = ltDevProxy.AddWithID("/devices", ltDevID, ltDevice, ""); added == nil {
- tlog.Errorf("Failed to add device: %+v", ltDevice)
+ if added = BenchmarkProxy_DeviceProxy.AddWithID("/devices", ltDevID, ltDevice, ""); added == nil {
+ BenchmarkProxy_Logger.Errorf("Failed to add device: %+v", ltDevice)
continue
} else {
- tlog.Infof("Device was added 1: %+v", added)
+ BenchmarkProxy_Logger.Infof("Device was added 1: %+v", added)
}
- plt.Lock()
- plt.addedDevices = append(plt.addedDevices, added.(*voltha.Device).Id)
- plt.Unlock()
+ BenchmarkProxy_PLT.Lock()
+ BenchmarkProxy_PLT.addedDevices = append(BenchmarkProxy_PLT.addedDevices, added.(*voltha.Device).Id)
+ BenchmarkProxy_PLT.Unlock()
}
})
- tlog.Infof("Number of added devices : %d", len(plt.addedDevices))
+ BenchmarkProxy_Logger.Infof("Number of added devices : %d", len(BenchmarkProxy_PLT.addedDevices))
}
-func Benchmark_ProxyLoad_UpdateFirmware(b *testing.B) {
+func BenchmarkProxy_UpdateFirmware(b *testing.B) {
b.RunParallel(func(pb *testing.PB) {
for pb.Next() {
//for i:=0; i < b.N; i++ {
- if len(plt.addedDevices) > 0 {
+ if len(BenchmarkProxy_PLT.addedDevices) > 0 {
var target interface{}
- randomID := plt.addedDevices[rand.Intn(len(plt.addedDevices))]
- firmProxy := modelTestConfig.Root.node.CreateProxy("/", false)
+ randomID := BenchmarkProxy_PLT.addedDevices[rand.Intn(len(BenchmarkProxy_PLT.addedDevices))]
+ firmProxy := BenchmarkProxy_Root.node.CreateProxy("/", false)
if target = firmProxy.Get("/devices/"+randomID, 0, false,
""); !reflect.ValueOf(target).IsValid() {
- tlog.Errorf("Failed to find device: %s %+v", randomID, target)
+ BenchmarkProxy_Logger.Errorf("Failed to find device: %s %+v", randomID, target)
continue
}
- plt.SetPreUpdateExecuted(false)
- plt.SetPostUpdateExecuted(false)
- firmProxy.RegisterCallback(PRE_UPDATE, commonCallbackFunc, "PRE_UPDATE", plt.SetPreUpdateExecuted)
- firmProxy.RegisterCallback(POST_UPDATE, commonCallbackFunc, "POST_UPDATE", plt.SetPostUpdateExecuted)
+ BenchmarkProxy_PLT.SetPreUpdateExecuted(false)
+ BenchmarkProxy_PLT.SetPostUpdateExecuted(false)
+ firmProxy.RegisterCallback(PRE_UPDATE, commonCallbackFunc, "PRE_UPDATE", BenchmarkProxy_PLT.SetPreUpdateExecuted)
+ firmProxy.RegisterCallback(POST_UPDATE, commonCallbackFunc, "POST_UPDATE", BenchmarkProxy_PLT.SetPostUpdateExecuted)
var fwVersion int
@@ -182,31 +185,31 @@
var updated interface{}
if updated = firmProxy.Update("/devices/"+randomID, target.(*voltha.Device), false,
""); updated == nil {
- tlog.Errorf("Failed to update device: %+v", target)
+ BenchmarkProxy_Logger.Errorf("Failed to update device: %+v", target)
continue
} else {
- tlog.Infof("Device was updated : %+v", updated)
+ BenchmarkProxy_Logger.Infof("Device was updated : %+v", updated)
}
if d := firmProxy.Get("/devices/"+randomID, 0, false,
""); !reflect.ValueOf(d).IsValid() {
- tlog.Errorf("Failed to get device: %s", randomID)
+ BenchmarkProxy_Logger.Errorf("Failed to get device: %s", randomID)
continue
} else if d.(*voltha.Device).FirmwareVersion == after {
- tlog.Infof("Imm Device was updated with new value: %s %+v", randomID, d)
+ BenchmarkProxy_Logger.Infof("Imm Device was updated with new value: %s %+v", randomID, d)
} else if d.(*voltha.Device).FirmwareVersion == before {
- tlog.Errorf("Imm Device kept old value: %s %+v %+v", randomID, d, target)
+ BenchmarkProxy_Logger.Errorf("Imm Device kept old value: %s %+v %+v", randomID, d, target)
} else {
- tlog.Errorf("Imm Device has unknown value: %s %+v %+v", randomID, d, target)
+ BenchmarkProxy_Logger.Errorf("Imm Device has unknown value: %s %+v %+v", randomID, d, target)
}
- plt.Lock()
- plt.updatedFirmwares = append(
- plt.updatedFirmwares,
+ BenchmarkProxy_PLT.Lock()
+ BenchmarkProxy_PLT.updatedFirmwares = append(
+ BenchmarkProxy_PLT.updatedFirmwares,
proxyLoadChanges{ID: randomID, Before: before, After: after},
)
- plt.Unlock()
+ BenchmarkProxy_PLT.Unlock()
}
}
})
@@ -221,14 +224,14 @@
prefix += " "
}
- tlog.Debugf("%sRevision: %s %+v", prefix, revision.GetHash(), revision.GetData())
+ BenchmarkProxy_Logger.Debugf("%sRevision: %s %+v", prefix, revision.GetHash(), revision.GetData())
//for brIdx, brRev := range revision.GetBranch().Revisions {
- // tlog.Debugf("%sbranchIndex: %s", prefix, brIdx)
+ // BenchmarkProxy_Logger.Debugf("%sbranchIndex: %s", prefix, brIdx)
// traverseBranches(brRev, depth+1)
//}
for childrenI, children := range revision.GetAllChildren() {
- tlog.Debugf("%schildrenIndex: %s, length: %d", prefix, childrenI, len(children))
+ BenchmarkProxy_Logger.Debugf("%schildrenIndex: %s, length: %d", prefix, childrenI, len(children))
for _, subrev := range children {
//subrev.GetBranch().Latest
@@ -237,13 +240,13 @@
}
}
-func Benchmark_ProxyLoad_UpdateFlows(b *testing.B) {
+func BenchmarkProxy_UpdateFlows(b *testing.B) {
b.RunParallel(func(pb *testing.PB) {
for pb.Next() {
- if len(plt.addedDevices) > 0 {
- randomID := plt.addedDevices[rand.Intn(len(plt.addedDevices))]
+ if len(BenchmarkProxy_PLT.addedDevices) > 0 {
+ randomID := BenchmarkProxy_PLT.addedDevices[rand.Intn(len(BenchmarkProxy_PLT.addedDevices))]
- flowsProxy := modelTestConfig.Root.node.CreateProxy("/devices/"+randomID+"/flows", false)
+ flowsProxy := BenchmarkProxy_Root.node.CreateProxy("/devices/"+randomID+"/flows", false)
flows := flowsProxy.Get("/", 0, false, "")
before := flows.(*openflow_13.Flows).Items[0].TableId
@@ -263,80 +266,69 @@
if updated = flowsProxy.Update("/", flows.(*openflow_13.Flows), false, ""); updated == nil {
b.Errorf("Failed to update flows for device: %+v", flows)
} else {
- tlog.Infof("Flows were updated : %+v", updated)
+ BenchmarkProxy_Logger.Infof("Flows were updated : %+v", updated)
}
- plt.Lock()
- plt.updatedFlows = append(
- plt.updatedFlows,
+ BenchmarkProxy_PLT.Lock()
+ BenchmarkProxy_PLT.updatedFlows = append(
+ BenchmarkProxy_PLT.updatedFlows,
proxyLoadChanges{ID: randomID, Before: before, After: after},
)
- plt.Unlock()
+ BenchmarkProxy_PLT.Unlock()
}
}
})
}
-func Benchmark_ProxyLoad_GetDevices(b *testing.B) {
- traverseBranches(ltDevProxy.Root.node.Branches[NONE].GetLatest(), 0)
+func BenchmarkProxy_GetDevices(b *testing.B) {
+ //traverseBranches(BenchmarkProxy_DeviceProxy.Root.node.Branches[NONE].GetLatest(), 0)
- for i := 0; i < len(plt.addedDevices); i++ {
- devToGet := plt.addedDevices[i]
+ for i := 0; i < len(BenchmarkProxy_PLT.addedDevices); i++ {
+ devToGet := BenchmarkProxy_PLT.addedDevices[i]
// Verify that the added device can now be retrieved
- if d := ltDevProxy.Get("/devices/"+devToGet, 0, false,
+ if d := BenchmarkProxy_DeviceProxy.Get("/devices/"+devToGet, 0, false,
""); !reflect.ValueOf(d).IsValid() {
- tlog.Errorf("Failed to get device: %s", devToGet)
+ BenchmarkProxy_Logger.Errorf("Failed to get device: %s", devToGet)
continue
} else {
- tlog.Infof("Got device: %s %+v", devToGet, d)
+ BenchmarkProxy_Logger.Infof("Got device: %s %+v", devToGet, d)
}
}
}
-func Benchmark_ProxyLoad_GetUpdatedFirmware(b *testing.B) {
- for i := 0; i < len(plt.updatedFirmwares); i++ {
- devToGet := plt.updatedFirmwares[i].ID
+func BenchmarkProxy_GetUpdatedFirmware(b *testing.B) {
+ for i := 0; i < len(BenchmarkProxy_PLT.updatedFirmwares); i++ {
+ devToGet := BenchmarkProxy_PLT.updatedFirmwares[i].ID
// Verify that the updated device can be retrieved and that the updates were actually applied
- if d := ltDevProxy.Get("/devices/"+devToGet, 0, false,
+ if d := BenchmarkProxy_DeviceProxy.Get("/devices/"+devToGet, 0, false,
""); !reflect.ValueOf(d).IsValid() {
- tlog.Errorf("Failed to get device: %s", devToGet)
+ BenchmarkProxy_Logger.Errorf("Failed to get device: %s", devToGet)
continue
- } else if d.(*voltha.Device).FirmwareVersion == plt.updatedFirmwares[i].After.(string) {
- tlog.Infof("Device was updated with new value: %s %+v", devToGet, d)
- } else if d.(*voltha.Device).FirmwareVersion == plt.updatedFirmwares[i].Before.(string) {
- tlog.Errorf("Device kept old value: %s %+v %+v", devToGet, d, plt.updatedFirmwares[i])
+ } else if d.(*voltha.Device).FirmwareVersion == BenchmarkProxy_PLT.updatedFirmwares[i].After.(string) {
+ BenchmarkProxy_Logger.Infof("Device was updated with new value: %s %+v", devToGet, d)
+ } else if d.(*voltha.Device).FirmwareVersion == BenchmarkProxy_PLT.updatedFirmwares[i].Before.(string) {
+ BenchmarkProxy_Logger.Errorf("Device kept old value: %s %+v %+v", devToGet, d, BenchmarkProxy_PLT.updatedFirmwares[i])
} else {
- tlog.Errorf("Device has unknown value: %s %+v %+v", devToGet, d, plt.updatedFirmwares[i])
+ BenchmarkProxy_Logger.Errorf("Device has unknown value: %s %+v %+v", devToGet, d, BenchmarkProxy_PLT.updatedFirmwares[i])
}
}
}
-func Benchmark_ProxyLoad_GetUpdatedFlows(b *testing.B) {
+func BenchmarkProxy_GetUpdatedFlows(b *testing.B) {
var d interface{}
- for i := 0; i < len(plt.updatedFlows); i++ {
- devToGet := plt.updatedFlows[i].ID
+ for i := 0; i < len(BenchmarkProxy_PLT.updatedFlows); i++ {
+ devToGet := BenchmarkProxy_PLT.updatedFlows[i].ID
// Verify that the updated device can be retrieved and that the updates were actually applied
- flowsProxy := modelTestConfig.Root.node.CreateProxy("/devices/"+devToGet+"/flows", false)
+ flowsProxy := BenchmarkProxy_Root.node.CreateProxy("/devices/"+devToGet+"/flows", false)
if d = flowsProxy.Get("/", 0, false,
""); !reflect.ValueOf(d).IsValid() {
- tlog.Errorf("Failed to get device flows: %s", devToGet)
+ BenchmarkProxy_Logger.Errorf("Failed to get device flows: %s", devToGet)
continue
- } else if d.(*openflow_13.Flows).Items[0].TableId == plt.updatedFlows[i].After.(uint32) {
- tlog.Infof("Device was updated with new flow value: %s %+v", devToGet, d)
- } else if d.(*openflow_13.Flows).Items[0].TableId == plt.updatedFlows[i].Before.(uint32) {
- tlog.Errorf("Device kept old flow value: %s %+v %+v", devToGet, d, plt.updatedFlows[i])
+ } else if d.(*openflow_13.Flows).Items[0].TableId == BenchmarkProxy_PLT.updatedFlows[i].After.(uint32) {
+ BenchmarkProxy_Logger.Infof("Device was updated with new flow value: %s %+v", devToGet, d)
+ } else if d.(*openflow_13.Flows).Items[0].TableId == BenchmarkProxy_PLT.updatedFlows[i].Before.(uint32) {
+ BenchmarkProxy_Logger.Errorf("Device kept old flow value: %s %+v %+v", devToGet, d, BenchmarkProxy_PLT.updatedFlows[i])
} else {
- tlog.Errorf("Device has unknown flow value: %s %+v %+v", devToGet, d, plt.updatedFlows[i])
+ BenchmarkProxy_Logger.Errorf("Device has unknown flow value: %s %+v %+v", devToGet, d, BenchmarkProxy_PLT.updatedFlows[i])
}
- //if d = ltDevProxy.Get("/devices/"+devToGet, 0, false,
- // ""); !reflect.ValueOf(d).IsValid() {
- // tlog.Errorf("Failed to get device: %s", devToGet)
- // continue
- //} else if d.(*voltha.Device).Flows.Items[0].TableId == plt.updatedFlows[i].After.(uint32) {
- // tlog.Infof("Device was updated with new flow value: %s %+v", devToGet, d)
- //} else if d.(*voltha.Device).Flows.Items[0].TableId == plt.updatedFlows[i].Before.(uint32) {
- // tlog.Errorf("Device kept old flow value: %s %+v %+v", devToGet, d, plt.updatedFlows[i])
- //} else {
- // tlog.Errorf("Device has unknown flow value: %s %+v %+v", devToGet, d, plt.updatedFlows[i])
- //}
}
}
diff --git a/db/model/proxy_test.go b/db/model/proxy_test.go
index 666eb3d..ea15bac 100644
--- a/db/model/proxy_test.go
+++ b/db/model/proxy_test.go
@@ -18,7 +18,9 @@
import (
"encoding/hex"
"encoding/json"
+ "github.com/golang/protobuf/proto"
"github.com/google/uuid"
+ "github.com/opencord/voltha-go/protos/common"
"github.com/opencord/voltha-go/protos/openflow_13"
"github.com/opencord/voltha-go/protos/voltha"
"math/rand"
@@ -28,37 +30,96 @@
)
var (
- ldevProxy *Proxy
- devProxy *Proxy
- flowProxy *Proxy
+ TestProxy_Root *root
+ TestProxy_Root_LogicalDevice *Proxy
+ TestProxy_Root_Device *Proxy
+ TestProxy_DeviceId string
+ TestProxy_LogicalDeviceId string
+ TestProxy_TargetDeviceId string
+ TestProxy_TargetLogicalDeviceId string
+ TestProxy_LogicalPorts []*voltha.LogicalPort
+ TestProxy_Ports []*voltha.Port
+ TestProxy_Stats *openflow_13.OfpFlowStats
+ TestProxy_Flows *openflow_13.Flows
+ TestProxy_Device *voltha.Device
+ TestProxy_LogicalDevice *voltha.LogicalDevice
)
func init() {
- ldevProxy = modelTestConfig.Root.node.CreateProxy("/", false)
- devProxy = modelTestConfig.Root.node.CreateProxy("/", false)
+ //log.AddPackage(log.JSON, log.InfoLevel, log.Fields{"instanceId": "DB_MODEL"})
+ //log.UpdateAllLoggers(log.Fields{"instanceId": "PROXY_LOAD_TEST"})
+ TestProxy_Root = NewRoot(&voltha.Voltha{}, nil)
+ TestProxy_Root_LogicalDevice = TestProxy_Root.CreateProxy("/", false)
+ TestProxy_Root_Device = TestProxy_Root.CreateProxy("/", false)
+
+ TestProxy_LogicalPorts = []*voltha.LogicalPort{
+ {
+ Id: "123",
+ DeviceId: "logicalport-0-device-id",
+ DevicePortNo: 123,
+ RootPort: false,
+ },
+ }
+ TestProxy_Ports = []*voltha.Port{
+ {
+ PortNo: 123,
+ Label: "test-port-0",
+ Type: voltha.Port_PON_OLT,
+ AdminState: common.AdminState_ENABLED,
+ OperStatus: common.OperStatus_ACTIVE,
+ DeviceId: "etcd_port-0-device-id",
+ Peers: []*voltha.Port_PeerPort{},
+ },
+ }
+
+ TestProxy_Stats = &openflow_13.OfpFlowStats{
+ Id: 1111,
+ }
+ TestProxy_Flows = &openflow_13.Flows{
+ Items: []*openflow_13.OfpFlowStats{TestProxy_Stats},
+ }
+ TestProxy_Device = &voltha.Device{
+ Id: TestProxy_DeviceId,
+ Type: "simulated_olt",
+ Address: &voltha.Device_HostAndPort{HostAndPort: "1.2.3.4:5555"},
+ AdminState: voltha.AdminState_PREPROVISIONED,
+ Flows: TestProxy_Flows,
+ Ports: TestProxy_Ports,
+ }
+
+ TestProxy_LogicalDevice = &voltha.LogicalDevice{
+ Id: TestProxy_DeviceId,
+ DatapathId: 0,
+ Ports: TestProxy_LogicalPorts,
+ Flows: TestProxy_Flows,
+ }
}
-func Test_Proxy_1_1_1_Add_NewDevice(t *testing.T) {
+func TestProxy_1_1_1_Add_NewDevice(t *testing.T) {
devIDBin, _ := uuid.New().MarshalBinary()
- devID = "0001" + hex.EncodeToString(devIDBin)[:12]
- device.Id = devID
+ TestProxy_DeviceId = "0001" + hex.EncodeToString(devIDBin)[:12]
+ TestProxy_Device.Id = TestProxy_DeviceId
preAddExecuted := false
postAddExecuted := false
+ devicesProxy := TestProxy_Root.node.CreateProxy("/devices", false)
+ devicesProxy.RegisterCallback(PRE_ADD, commonCallback2, "PRE_ADD Device container changes")
+ devicesProxy.RegisterCallback(POST_ADD, commonCallback2, "POST_ADD Device container changes")
+
// Register ADD instructions callbacks
- devProxy.RegisterCallback(PRE_ADD, commonCallback, "PRE_ADD instructions", &preAddExecuted)
- devProxy.RegisterCallback(POST_ADD, commonCallback, "POST_ADD instructions", &postAddExecuted)
+ TestProxy_Root_Device.RegisterCallback(PRE_ADD, commonCallback, "PRE_ADD instructions", &preAddExecuted)
+ TestProxy_Root_Device.RegisterCallback(POST_ADD, commonCallback, "POST_ADD instructions", &postAddExecuted)
// Add the device
- if added := devProxy.Add("/devices", device, ""); added == nil {
+ if added := TestProxy_Root_Device.Add("/devices", TestProxy_Device, ""); added == nil {
t.Error("Failed to add device")
} else {
t.Logf("Added device : %+v", added)
}
// Verify that the added device can now be retrieved
- if d := devProxy.Get("/devices/"+devID, 0, false, ""); !reflect.ValueOf(d).IsValid() {
+ if d := TestProxy_Root_Device.Get("/devices/"+TestProxy_DeviceId, 0, false, ""); !reflect.ValueOf(d).IsValid() {
t.Error("Failed to find added device")
} else {
djson, _ := json.Marshal(d)
@@ -73,45 +134,42 @@
}
}
-func Test_Proxy_1_1_2_Add_ExistingDevice(t *testing.T) {
- device.Id = devID
+func TestProxy_1_1_2_Add_ExistingDevice(t *testing.T) {
+ TestProxy_Device.Id = TestProxy_DeviceId
- if added := devProxy.Add("/devices", device, ""); added == nil {
- t.Logf("Successfully detected that the device already exists: %s", devID)
- } else {
- t.Errorf("A new device should not have been created : %+v", added)
+ added := TestProxy_Root_Device.Add("/devices", TestProxy_Device, "");
+ if added.(proto.Message).String() != reflect.ValueOf(TestProxy_Device).Interface().(proto.Message).String() {
+ t.Errorf("Devices don't match - existing: %+v returned: %+v", TestProxy_LogicalDevice, added)
}
-
}
-func Test_Proxy_1_2_1_Get_AllDevices(t *testing.T) {
- devices := devProxy.Get("/devices", 1, false, "")
+func TestProxy_1_2_1_Get_AllDevices(t *testing.T) {
+ devices := TestProxy_Root_Device.Get("/devices", 1, false, "")
if len(devices.([]interface{})) == 0 {
t.Error("there are no available devices to retrieve")
} else {
// Save the target device id for later tests
- targetDevID = devices.([]interface{})[0].(*voltha.Device).Id
+ TestProxy_TargetDeviceId = devices.([]interface{})[0].(*voltha.Device).Id
t.Logf("retrieved all devices: %+v", devices)
}
}
-func Test_Proxy_1_2_2_Get_SingleDevice(t *testing.T) {
- if d := devProxy.Get("/devices/"+targetDevID, 0, false, ""); !reflect.ValueOf(d).IsValid() {
- t.Errorf("Failed to find device : %s", targetDevID)
+func TestProxy_1_2_2_Get_SingleDevice(t *testing.T) {
+ if d := TestProxy_Root_Device.Get("/devices/"+TestProxy_TargetDeviceId, 0, false, ""); !reflect.ValueOf(d).IsValid() {
+ t.Errorf("Failed to find device : %s", TestProxy_TargetDeviceId)
} else {
djson, _ := json.Marshal(d)
t.Logf("Found device: %s", string(djson))
}
-
}
-func Test_Proxy_1_3_1_Update_Device(t *testing.T) {
+func TestProxy_1_3_1_Update_Device(t *testing.T) {
var fwVersion int
preUpdateExecuted := false
postUpdateExecuted := false
- if retrieved := devProxy.Get("/devices/"+targetDevID, 1, false, ""); retrieved == nil {
+ if retrieved := TestProxy_Root_Device.Get("/devices/"+TestProxy_TargetDeviceId, 1, false, ""); retrieved == nil {
t.Error("Failed to get device")
} else {
t.Logf("Found raw device (root proxy): %+v", retrieved)
@@ -125,24 +183,24 @@
retrieved.(*voltha.Device).FirmwareVersion = strconv.Itoa(fwVersion)
- devProxy.RegisterCallback(
+ TestProxy_Root_Device.RegisterCallback(
PRE_UPDATE,
commonCallback,
"PRE_UPDATE instructions (root proxy)", &preUpdateExecuted,
)
- devProxy.RegisterCallback(
+ TestProxy_Root_Device.RegisterCallback(
POST_UPDATE,
commonCallback,
"POST_UPDATE instructions (root proxy)", &postUpdateExecuted,
)
- if afterUpdate := devProxy.Update("/devices/"+targetDevID, retrieved, false, ""); afterUpdate == nil {
+ if afterUpdate := TestProxy_Root_Device.Update("/devices/"+TestProxy_TargetDeviceId, retrieved, false, ""); afterUpdate == nil {
t.Error("Failed to update device")
} else {
t.Logf("Updated device : %+v", afterUpdate)
}
- if d := devProxy.Get("/devices/"+targetDevID, 1, false, ""); !reflect.ValueOf(d).IsValid() {
+ if d := TestProxy_Root_Device.Get("/devices/"+TestProxy_TargetDeviceId, 1, false, ""); !reflect.ValueOf(d).IsValid() {
t.Error("Failed to find updated device (root proxy)")
} else {
djson, _ := json.Marshal(d)
@@ -158,46 +216,46 @@
}
}
-func Test_Proxy_1_3_2_Update_DeviceFlows(t *testing.T) {
+func TestProxy_1_3_2_Update_DeviceFlows(t *testing.T) {
// Get a device proxy and update a specific port
- flowProxy = modelTestConfig.Root.node.CreateProxy("/devices/"+devID+"/flows", false)
- flows := flowProxy.Get("/", 0, false, "")
+ devFlowsProxy := TestProxy_Root.node.CreateProxy("/devices/"+TestProxy_DeviceId+"/flows", false)
+ flows := devFlowsProxy.Get("/", 0, false, "")
flows.(*openflow_13.Flows).Items[0].TableId = 2244
preUpdateExecuted := false
postUpdateExecuted := false
- flowProxy.RegisterCallback(
+ devFlowsProxy.RegisterCallback(
PRE_UPDATE,
commonCallback,
"PRE_UPDATE instructions (flows proxy)", &preUpdateExecuted,
)
- flowProxy.RegisterCallback(
+ devFlowsProxy.RegisterCallback(
POST_UPDATE,
commonCallback,
"POST_UPDATE instructions (flows proxy)", &postUpdateExecuted,
)
- kvFlows := flowProxy.Get("/", 0, false, "")
+ kvFlows := devFlowsProxy.Get("/", 0, false, "")
if reflect.DeepEqual(flows, kvFlows) {
t.Errorf("Local changes have changed the KV store contents - local:%+v, kv: %+v", flows, kvFlows)
}
- if updated := flowProxy.Update("/", flows.(*openflow_13.Flows), false, ""); updated == nil {
+ if updated := devFlowsProxy.Update("/", flows.(*openflow_13.Flows), false, ""); updated == nil {
t.Error("Failed to update flow")
} else {
t.Logf("Updated flows : %+v", updated)
}
- if d := flowProxy.Get("/", 0, false, ""); d == nil {
+ if d := devFlowsProxy.Get("/", 0, false, ""); d == nil {
t.Error("Failed to find updated flows (flows proxy)")
} else {
djson, _ := json.Marshal(d)
t.Logf("Found flows (flows proxy): %s", string(djson))
}
- if d := devProxy.Get("/devices/"+devID+"/flows", 1, false, ""); !reflect.ValueOf(d).IsValid() {
+ if d := TestProxy_Root_Device.Get("/devices/"+TestProxy_DeviceId+"/flows", 1, false, ""); !reflect.ValueOf(d).IsValid() {
t.Error("Failed to find updated flows (root proxy)")
} else {
djson, _ := json.Marshal(d)
@@ -212,61 +270,61 @@
}
}
-func Test_Proxy_1_4_1_Remove_Device(t *testing.T) {
+func TestProxy_1_4_1_Remove_Device(t *testing.T) {
preRemoveExecuted := false
postRemoveExecuted := false
- modelTestConfig.RootProxy.RegisterCallback(
+ TestProxy_Root_Device.RegisterCallback(
PRE_REMOVE,
commonCallback,
"PRE_REMOVE instructions (root proxy)", &preRemoveExecuted,
)
- modelTestConfig.RootProxy.RegisterCallback(
+ TestProxy_Root_Device.RegisterCallback(
POST_REMOVE,
commonCallback,
"POST_REMOVE instructions (root proxy)", &postRemoveExecuted,
)
- if removed := modelTestConfig.RootProxy.Remove("/devices/"+devID, ""); removed == nil {
+ if removed := TestProxy_Root_Device.Remove("/devices/"+TestProxy_DeviceId, ""); removed == nil {
t.Error("Failed to remove device")
} else {
t.Logf("Removed device : %+v", removed)
}
- if d := modelTestConfig.RootProxy.Get("/devices/"+devID, 0, false, ""); reflect.ValueOf(d).IsValid() {
+ if d := TestProxy_Root_Device.Get("/devices/"+TestProxy_DeviceId, 0, false, ""); reflect.ValueOf(d).IsValid() {
djson, _ := json.Marshal(d)
t.Errorf("Device was not removed - %s", djson)
} else {
- t.Logf("Device was removed: %s", devID)
+ t.Logf("Device was removed: %s", TestProxy_DeviceId)
}
if !preRemoveExecuted {
- t.Error("PRE_UPDATE callback was not executed")
+ t.Error("PRE_REMOVE callback was not executed")
}
if !postRemoveExecuted {
- t.Error("POST_UPDATE callback was not executed")
+ t.Error("POST_REMOVE callback was not executed")
}
}
-func Test_Proxy_2_1_1_Add_NewLogicalDevice(t *testing.T) {
+func TestProxy_2_1_1_Add_NewLogicalDevice(t *testing.T) {
ldIDBin, _ := uuid.New().MarshalBinary()
- ldevID = "0001" + hex.EncodeToString(ldIDBin)[:12]
- logicalDevice.Id = ldevID
+ TestProxy_LogicalDeviceId = "0001" + hex.EncodeToString(ldIDBin)[:12]
+ TestProxy_LogicalDevice.Id = TestProxy_LogicalDeviceId
preAddExecuted := false
postAddExecuted := false
// Register
- ldevProxy.RegisterCallback(PRE_ADD, commonCallback, "PRE_ADD instructions", &preAddExecuted)
- ldevProxy.RegisterCallback(POST_ADD, commonCallback, "POST_ADD instructions", &postAddExecuted)
+ TestProxy_Root_LogicalDevice.RegisterCallback(PRE_ADD, commonCallback, "PRE_ADD instructions", &preAddExecuted)
+ TestProxy_Root_LogicalDevice.RegisterCallback(POST_ADD, commonCallback, "POST_ADD instructions", &postAddExecuted)
- if added := ldevProxy.Add("/logical_devices", logicalDevice, ""); added == nil {
+ if added := TestProxy_Root_LogicalDevice.Add("/logical_devices", TestProxy_LogicalDevice, ""); added == nil {
t.Error("Failed to add logical device")
} else {
t.Logf("Added logical device : %+v", added)
}
- if ld := ldevProxy.Get("/logical_devices/"+ldevID, 0, false, ""); !reflect.ValueOf(ld).IsValid() {
+ if ld := TestProxy_Root_LogicalDevice.Get("/logical_devices/"+TestProxy_LogicalDeviceId, 0, false, ""); !reflect.ValueOf(ld).IsValid() {
t.Error("Failed to find added logical device")
} else {
ldJSON, _ := json.Marshal(ld)
@@ -281,31 +339,30 @@
}
}
-func Test_Proxy_2_1_2_Add_ExistingLogicalDevice(t *testing.T) {
- logicalDevice.Id = ldevID
- if added := ldevProxy.Add("/logical_devices", logicalDevice, ""); added == nil {
- t.Logf("Successfully detected that the logical device already exists: %s", ldevID)
- } else {
- t.Errorf("A new logical device should not have been created : %+v", added)
- }
+func TestProxy_2_1_2_Add_ExistingLogicalDevice(t *testing.T) {
+ TestProxy_LogicalDevice.Id = TestProxy_LogicalDeviceId
+ added := TestProxy_Root_LogicalDevice.Add("/logical_devices", TestProxy_LogicalDevice, "");
+ if added.(proto.Message).String() != reflect.ValueOf(TestProxy_LogicalDevice).Interface().(proto.Message).String() {
+ t.Errorf("Logical devices don't match - existing: %+v returned: %+v", TestProxy_LogicalDevice, added)
+ }
}
-func Test_Proxy_2_2_1_Get_AllLogicalDevices(t *testing.T) {
- logicalDevices := ldevProxy.Get("/logical_devices", 1, false, "")
+func TestProxy_2_2_1_Get_AllLogicalDevices(t *testing.T) {
+ logicalDevices := TestProxy_Root_LogicalDevice.Get("/logical_devices", 1, false, "")
if len(logicalDevices.([]interface{})) == 0 {
t.Error("there are no available logical devices to retrieve")
} else {
// Save the target device id for later tests
- targetLogDevID = logicalDevices.([]interface{})[0].(*voltha.LogicalDevice).Id
+ TestProxy_TargetLogicalDeviceId = logicalDevices.([]interface{})[0].(*voltha.LogicalDevice).Id
t.Logf("retrieved all logical devices: %+v", logicalDevices)
}
}
-func Test_Proxy_2_2_2_Get_SingleLogicalDevice(t *testing.T) {
- if ld := ldevProxy.Get("/logical_devices/"+targetLogDevID, 0, false, ""); !reflect.ValueOf(ld).IsValid() {
- t.Errorf("Failed to find logical device : %s", targetLogDevID)
+func TestProxy_2_2_2_Get_SingleLogicalDevice(t *testing.T) {
+ if ld := TestProxy_Root_LogicalDevice.Get("/logical_devices/"+TestProxy_TargetLogicalDeviceId, 0, false, ""); !reflect.ValueOf(ld).IsValid() {
+ t.Errorf("Failed to find logical device : %s", TestProxy_TargetLogicalDeviceId)
} else {
ldJSON, _ := json.Marshal(ld)
t.Logf("Found logical device: %s", string(ldJSON))
@@ -313,12 +370,12 @@
}
-func Test_Proxy_2_3_1_Update_LogicalDevice(t *testing.T) {
+func TestProxy_2_3_1_Update_LogicalDevice(t *testing.T) {
var fwVersion int
preUpdateExecuted := false
postUpdateExecuted := false
- if retrieved := ldevProxy.Get("/logical_devices/"+targetLogDevID, 1, false, ""); retrieved == nil {
+ if retrieved := TestProxy_Root_LogicalDevice.Get("/logical_devices/"+TestProxy_TargetLogicalDeviceId, 1, false, ""); retrieved == nil {
t.Error("Failed to get logical device")
} else {
t.Logf("Found raw logical device (root proxy): %+v", retrieved)
@@ -330,12 +387,12 @@
fwVersion++
}
- ldevProxy.RegisterCallback(
+ TestProxy_Root_LogicalDevice.RegisterCallback(
PRE_UPDATE,
commonCallback,
"PRE_UPDATE instructions (root proxy)", &preUpdateExecuted,
)
- ldevProxy.RegisterCallback(
+ TestProxy_Root_LogicalDevice.RegisterCallback(
POST_UPDATE,
commonCallback,
"POST_UPDATE instructions (root proxy)", &postUpdateExecuted,
@@ -343,13 +400,13 @@
retrieved.(*voltha.LogicalDevice).RootDeviceId = strconv.Itoa(fwVersion)
- if afterUpdate := ldevProxy.Update("/logical_devices/"+targetLogDevID, retrieved, false,
+ if afterUpdate := TestProxy_Root_LogicalDevice.Update("/logical_devices/"+TestProxy_TargetLogicalDeviceId, retrieved, false,
""); afterUpdate == nil {
t.Error("Failed to update logical device")
} else {
t.Logf("Updated logical device : %+v", afterUpdate)
}
- if d := ldevProxy.Get("/logical_devices/"+targetLogDevID, 1, false, ""); !reflect.ValueOf(d).IsValid() {
+ if d := TestProxy_Root_LogicalDevice.Get("/logical_devices/"+TestProxy_TargetLogicalDeviceId, 1, false, ""); !reflect.ValueOf(d).IsValid() {
t.Error("Failed to find updated logical device (root proxy)")
} else {
djson, _ := json.Marshal(d)
@@ -366,9 +423,9 @@
}
}
-func Test_Proxy_2_3_2_Update_LogicalDeviceFlows(t *testing.T) {
+func TestProxy_2_3_2_Update_LogicalDeviceFlows(t *testing.T) {
// Get a device proxy and update a specific port
- ldFlowsProxy := modelTestConfig.Root.node.CreateProxy("/logical_devices/"+ldevID+"/flows", false)
+ ldFlowsProxy := TestProxy_Root.node.CreateProxy("/logical_devices/"+TestProxy_LogicalDeviceId+"/flows", false)
flows := ldFlowsProxy.Get("/", 0, false, "")
flows.(*openflow_13.Flows).Items[0].TableId = rand.Uint32()
t.Logf("before updated flows: %+v", flows)
@@ -401,7 +458,7 @@
t.Logf("Found flows (flows proxy): %s", string(djson))
}
- if d := modelTestConfig.RootProxy.Get("/logical_devices/"+ldevID+"/flows", 0, false,
+ if d := TestProxy_Root_LogicalDevice.Get("/logical_devices/"+TestProxy_LogicalDeviceId+"/flows", 0, false,
""); !reflect.ValueOf(d).IsValid() {
t.Error("Failed to find updated logical device flows (root proxy)")
} else {
@@ -410,38 +467,38 @@
}
}
-func Test_Proxy_2_4_1_Remove_Device(t *testing.T) {
+func TestProxy_2_4_1_Remove_Device(t *testing.T) {
preRemoveExecuted := false
postRemoveExecuted := false
- ldevProxy.RegisterCallback(
+ TestProxy_Root_LogicalDevice.RegisterCallback(
PRE_REMOVE,
commonCallback,
"PRE_REMOVE instructions (root proxy)", &preRemoveExecuted,
)
- ldevProxy.RegisterCallback(
+ TestProxy_Root_LogicalDevice.RegisterCallback(
POST_REMOVE,
commonCallback,
"POST_REMOVE instructions (root proxy)", &postRemoveExecuted,
)
- if removed := ldevProxy.Remove("/logical_devices/"+ldevID, ""); removed == nil {
+ if removed := TestProxy_Root_LogicalDevice.Remove("/logical_devices/"+TestProxy_LogicalDeviceId, ""); removed == nil {
t.Error("Failed to remove logical device")
} else {
t.Logf("Removed device : %+v", removed)
}
- if d := ldevProxy.Get("/logical_devices/"+ldevID, 0, false, ""); reflect.ValueOf(d).IsValid() {
+ if d := TestProxy_Root_LogicalDevice.Get("/logical_devices/"+TestProxy_LogicalDeviceId, 0, false, ""); reflect.ValueOf(d).IsValid() {
djson, _ := json.Marshal(d)
t.Errorf("Device was not removed - %s", djson)
} else {
- t.Logf("Device was removed: %s", ldevID)
+ t.Logf("Device was removed: %s", TestProxy_LogicalDeviceId)
}
if !preRemoveExecuted {
- t.Error("PRE_UPDATE callback was not executed")
+ t.Error("PRE_REMOVE callback was not executed")
}
if !postRemoveExecuted {
- t.Error("POST_UPDATE callback was not executed")
+ t.Error("POST_REMOVE callback was not executed")
}
}
@@ -449,35 +506,35 @@
// Callback tests
// -----------------------------
-func Test_Proxy_Callbacks_1_Register(t *testing.T) {
- modelTestConfig.RootProxy.RegisterCallback(PRE_ADD, firstCallback, "abcde", "12345")
+func TestProxy_Callbacks_1_Register(t *testing.T) {
+ TestProxy_Root_Device.RegisterCallback(PRE_ADD, firstCallback, "abcde", "12345")
m := make(map[string]string)
m["name"] = "fghij"
- modelTestConfig.RootProxy.RegisterCallback(PRE_ADD, secondCallback, m, 1.2345)
+ TestProxy_Root_Device.RegisterCallback(PRE_ADD, secondCallback, m, 1.2345)
d := &voltha.Device{Id: "12345"}
- modelTestConfig.RootProxy.RegisterCallback(PRE_ADD, thirdCallback, "klmno", d)
+ TestProxy_Root_Device.RegisterCallback(PRE_ADD, thirdCallback, "klmno", d)
}
-func Test_Proxy_Callbacks_2_Invoke_WithNoInterruption(t *testing.T) {
- modelTestConfig.RootProxy.InvokeCallbacks(PRE_ADD, false, nil)
+func TestProxy_Callbacks_2_Invoke_WithNoInterruption(t *testing.T) {
+ TestProxy_Root_Device.InvokeCallbacks(PRE_ADD, false, nil)
}
-func Test_Proxy_Callbacks_3_Invoke_WithInterruption(t *testing.T) {
- modelTestConfig.RootProxy.InvokeCallbacks(PRE_ADD, true, nil)
+func TestProxy_Callbacks_3_Invoke_WithInterruption(t *testing.T) {
+ TestProxy_Root_Device.InvokeCallbacks(PRE_ADD, true, nil)
}
-func Test_Proxy_Callbacks_4_Unregister(t *testing.T) {
- modelTestConfig.RootProxy.UnregisterCallback(PRE_ADD, firstCallback)
- modelTestConfig.RootProxy.UnregisterCallback(PRE_ADD, secondCallback)
- modelTestConfig.RootProxy.UnregisterCallback(PRE_ADD, thirdCallback)
+func TestProxy_Callbacks_4_Unregister(t *testing.T) {
+ TestProxy_Root_Device.UnregisterCallback(PRE_ADD, firstCallback)
+ TestProxy_Root_Device.UnregisterCallback(PRE_ADD, secondCallback)
+ TestProxy_Root_Device.UnregisterCallback(PRE_ADD, thirdCallback)
}
-//func Test_Proxy_Callbacks_5_Add(t *testing.T) {
-// modelTestConfig.RootProxy.Root.AddCallback(modelTestConfig.RootProxy.InvokeCallbacks, POST_UPDATE, false, "some data", "some new data")
+//func TestProxy_Callbacks_5_Add(t *testing.T) {
+// TestProxy_Root_Device.Root.AddCallback(TestProxy_Root_Device.InvokeCallbacks, POST_UPDATE, false, "some data", "some new data")
//}
//
-//func Test_Proxy_Callbacks_6_Execute(t *testing.T) {
-// modelTestConfig.RootProxy.Root.ExecuteCallbacks()
+//func TestProxy_Callbacks_6_Execute(t *testing.T) {
+// TestProxy_Root_Device.Root.ExecuteCallbacks()
//}
diff --git a/db/model/revision_test.go b/db/model/revision_test.go
deleted file mode 100644
index a12bf26..0000000
--- a/db/model/revision_test.go
+++ /dev/null
@@ -1,30 +0,0 @@
-/*
- * Copyright 2018-present Open Networking Foundation
-
- * Licensed under the Apache License, Version 2.0 (the "License");
- * you may not use this file except in compliance with the License.
- * You may obtain a copy of the License at
-
- * http://www.apache.org/licenses/LICENSE-2.0
-
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- */
-package model
-
-import (
- "github.com/opencord/voltha-go/protos/voltha"
- "testing"
-)
-
-func Test_Revision_01_New(t *testing.T) {
- branch := &Branch{}
- data := &voltha.Device{}
- children := make(map[string][]Revision)
- rev := NewNonPersistedRevision(nil, branch, data, children)
-
- t.Logf("New revision created: %+v\n", rev)
-}
diff --git a/db/model/root.go b/db/model/root.go
index 730cd39..0f14c7c 100644
--- a/db/model/root.go
+++ b/db/model/root.go
@@ -91,6 +91,7 @@
dirtyNode.DeleteBranch(txid)
}
delete(r.DirtyNodes, txid)
+ delete(r.node.Branches, txid)
}
// FoldTxBranch will merge the contents of a transaction branch with the root object
diff --git a/db/model/root_test.go b/db/model/root_test.go
deleted file mode 100644
index 2729de0..0000000
--- a/db/model/root_test.go
+++ /dev/null
@@ -1,51 +0,0 @@
-/*
- * Copyright 2018-present Open Networking Foundation
-
- * Licensed under the Apache License, Version 2.0 (the "License");
- * you may not use this file except in compliance with the License.
- * You may obtain a copy of the License at
-
- * http://www.apache.org/licenses/LICENSE-2.0
-
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- */
-package model
-
-var (
- backend *Backend
- rootPrefix = "service/voltha/data/core/0001"
-
- //basePrefix = "service/voltha/service/vcores/data/devices"
- deviceId = "00016f13befaedcc"
- //rootPrefix = basePrefix + "/" + deviceId
- deviceProxy = "/devices/" + deviceId
-)
-
-//func Test_NewRoot(t *testing.T) {
-// backend = NewBackend(ETCD_KV, etcd_host, etcd_port, timeout, rootPrefix)
-//
-// var msgClass *voltha.Voltha
-// //var msgClass *voltha.DeviceInstance
-// root := NewRoot(msgClass, backend)
-//
-// start := time.Now()
-//
-// //r := root.Load(msgClass)
-// afterLoad := time.Now()
-// log.Infof(">>>>>>>>>>>>> Time to Load : %f\n", afterLoad.Sub(start).Seconds())
-//
-// d := r.node.Get(deviceProxy, "", 0, false, "")
-// afterGet := time.Now()
-// log.Infof(">>>>>>>>>>>>> Time to Load and get: %f\n", afterGet.Sub(start).Seconds())
-//
-// jr, _ := json.Marshal(r)
-// log.Infof("Content of ROOT --> \n%s\n", jr)
-//
-// jd, _ := json.Marshal(d)
-// log.Infof("Content of GET --> \n%s\n", jd)
-//
-//}
diff --git a/db/model/transaction_test.go b/db/model/transaction_test.go
index 0e49f33..10ca520 100644
--- a/db/model/transaction_test.go
+++ b/db/model/transaction_test.go
@@ -21,35 +21,40 @@
"github.com/google/uuid"
"github.com/opencord/voltha-go/protos/common"
"github.com/opencord/voltha-go/protos/voltha"
- "reflect"
"strconv"
"testing"
)
var (
- txTargetDevID string
- txDevID string
+ TestTransaction_Root *root
+ TestTransaction_RootProxy *Proxy
+ TestTransaction_TargetDeviceId string
+ TestTransaction_DeviceId string
)
-func Test_Transaction_1_GetDevices(t *testing.T) {
- getTx := modelTestConfig.RootProxy.OpenTransaction()
-
- devices := getTx.Get("/devices", 1, false)
-
- if len(devices.([]interface{})) == 0 {
- t.Error("there are no available devices to retrieve")
- } else {
- // Save the target device id for later tests
- txTargetDevID = devices.([]interface{})[0].(*voltha.Device).Id
- t.Logf("retrieved devices: %+v", devices)
- }
-
- getTx.Commit()
+func init() {
+ TestTransaction_Root = NewRoot(&voltha.Voltha{}, nil)
+ TestTransaction_RootProxy = TestTransaction_Root.node.CreateProxy("/", false)
}
+//func TestTransaction_1_GetDevices(t *testing.T) {
+// getTx := TestTransaction_RootProxy.OpenTransaction()
+//
+// devices := getTx.Get("/devices", 1, false)
+//
+// if len(devices.([]interface{})) == 0 {
+// t.Error("there are no available devices to retrieve")
+// } else {
+// // Save the target device id for later tests
+// TestTransaction_TargetDeviceId = devices.([]interface{})[0].(*voltha.Device).Id
+// t.Logf("retrieved devices: %+v", devices)
+// }
+//
+// getTx.Commit()
+//}
-func Test_Transaction_2_AddDevice(t *testing.T) {
+func TestTransaction_2_AddDevice(t *testing.T) {
devIDBin, _ := uuid.New().MarshalBinary()
- txDevID = "0001" + hex.EncodeToString(devIDBin)[:12]
+ TestTransaction_DeviceId = "0001" + hex.EncodeToString(devIDBin)[:12]
ports := []*voltha.Port{
{
@@ -64,43 +69,43 @@
}
device := &voltha.Device{
- Id: txDevID,
+ Id: TestTransaction_DeviceId,
Type: "simulated_olt",
Address: &voltha.Device_HostAndPort{HostAndPort: "1.2.3.4:5555"},
AdminState: voltha.AdminState_PREPROVISIONED,
Ports: ports,
}
- addTx := modelTestConfig.RootProxy.OpenTransaction()
+ addTx := TestTransaction_RootProxy.OpenTransaction()
if added := addTx.Add("/devices", device); added == nil {
t.Error("Failed to add device")
} else {
- txTargetDevID = added.(*voltha.Device).Id
+ TestTransaction_TargetDeviceId = added.(*voltha.Device).Id
t.Logf("Added device : %+v", added)
}
addTx.Commit()
}
-func Test_Transaction_3_GetDevice_PostAdd(t *testing.T) {
+func TestTransaction_3_GetDevice_PostAdd(t *testing.T) {
- basePath := "/devices/" + txDevID
+ basePath := "/devices/" + TestTransaction_DeviceId
- getDevWithPortsTx := modelTestConfig.RootProxy.OpenTransaction()
+ getDevWithPortsTx := TestTransaction_RootProxy.OpenTransaction()
device1 := getDevWithPortsTx.Get(basePath+"/ports", 1, false)
t.Logf("retrieved device with ports: %+v", device1)
getDevWithPortsTx.Commit()
- getDevTx := modelTestConfig.RootProxy.OpenTransaction()
+ getDevTx := TestTransaction_RootProxy.OpenTransaction()
device2 := getDevTx.Get(basePath, 0, false)
t.Logf("retrieved device: %+v", device2)
getDevTx.Commit()
}
-func Test_Transaction_4_UpdateDevice(t *testing.T) {
- updateTx := modelTestConfig.RootProxy.OpenTransaction()
- if retrieved := updateTx.Get("/devices/"+txTargetDevID, 1, false); retrieved == nil {
+func TestTransaction_4_UpdateDevice(t *testing.T) {
+ updateTx := TestTransaction_RootProxy.OpenTransaction()
+ if retrieved := updateTx.Get("/devices/"+TestTransaction_TargetDeviceId, 1, false); retrieved == nil {
t.Error("Failed to get device")
} else {
var fwVersion int
@@ -111,39 +116,39 @@
fwVersion++
}
- cloned := reflect.ValueOf(retrieved).Elem().Interface().(voltha.Device)
- cloned.FirmwareVersion = strconv.Itoa(fwVersion)
- t.Logf("Before update : %+v", cloned)
+ //cloned := reflect.ValueOf(retrieved).Elem().Interface().(voltha.Device)
+ retrieved.(*voltha.Device).FirmwareVersion = strconv.Itoa(fwVersion)
+ t.Logf("Before update : %+v", retrieved)
// FIXME: The makeBranch passed in function is nil or not being executed properly!!!!!
- if afterUpdate := updateTx.Update("/devices/"+txTargetDevID, &cloned, false); afterUpdate == nil {
+ if afterUpdate := updateTx.Update("/devices/"+TestTransaction_TargetDeviceId, retrieved, false); afterUpdate == nil {
t.Error("Failed to update device")
} else {
- t.Logf("Updated device : %+v", afterUpdate.(Revision).GetData())
+ t.Logf("Updated device : %+v", afterUpdate)
}
}
updateTx.Commit()
}
-func Test_Transaction_5_GetDevice_PostUpdate(t *testing.T) {
+func TestTransaction_5_GetDevice_PostUpdate(t *testing.T) {
- basePath := "/devices/" + txDevID
+ basePath := "/devices/" + TestTransaction_DeviceId
- getDevWithPortsTx := modelTestConfig.RootProxy.OpenTransaction()
+ getDevWithPortsTx := TestTransaction_RootProxy.OpenTransaction()
device1 := getDevWithPortsTx.Get(basePath+"/ports", 1, false)
t.Logf("retrieved device with ports: %+v", device1)
getDevWithPortsTx.Commit()
- getDevTx := modelTestConfig.RootProxy.OpenTransaction()
+ getDevTx := TestTransaction_RootProxy.OpenTransaction()
device2 := getDevTx.Get(basePath, 0, false)
t.Logf("retrieved device: %+v", device2)
getDevTx.Commit()
}
-func Test_Transaction_6_RemoveDevice(t *testing.T) {
- removeTx := modelTestConfig.RootProxy.OpenTransaction()
- if removed := removeTx.Remove("/devices/" + txDevID); removed == nil {
+func TestTransaction_6_RemoveDevice(t *testing.T) {
+ removeTx := TestTransaction_RootProxy.OpenTransaction()
+ if removed := removeTx.Remove("/devices/" + TestTransaction_DeviceId); removed == nil {
t.Error("Failed to remove device")
} else {
t.Logf("Removed device : %+v", removed)
@@ -151,12 +156,12 @@
removeTx.Commit()
}
-func Test_Transaction_7_GetDevice_PostRemove(t *testing.T) {
+func TestTransaction_7_GetDevice_PostRemove(t *testing.T) {
- basePath := "/devices/" + txDevID
+ basePath := "/devices/" + TestTransaction_DeviceId
- getDevTx := modelTestConfig.RootProxy.OpenTransaction()
- device := modelTestConfig.RootProxy.Get(basePath, 0, false, "")
+ getDevTx := TestTransaction_RootProxy.OpenTransaction()
+ device := TestTransaction_RootProxy.Get(basePath, 0, false, "")
t.Logf("retrieved device: %+v", device)
getDevTx.Commit()
diff --git a/db/model/utils_test.go b/db/model/utils_test.go
deleted file mode 100644
index 618e158..0000000
--- a/db/model/utils_test.go
+++ /dev/null
@@ -1,40 +0,0 @@
-/*
- * Copyright 2018-present Open Networking Foundation
-
- * Licensed under the Apache License, Version 2.0 (the "License");
- * you may not use this file except in compliance with the License.
- * You may obtain a copy of the License at
-
- * http://www.apache.org/licenses/LICENSE-2.0
-
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- */
-package model
-
-import (
- "github.com/opencord/voltha-go/protos/voltha"
- "reflect"
- "testing"
-)
-
-func Test_Utils_Clone(t *testing.T) {
- a := &voltha.Device{
- Id: "abcde",
- FirmwareVersion: "someversion",
- }
- b := &voltha.Device{}
- clone(reflect.ValueOf(a).Interface(), b)
- t.Logf("A: %+v, B: %+v", a, b)
- b.Id = "12345"
- t.Logf("A: %+v, B: %+v", a, b)
-
- var c *voltha.Device
- c = clone2(a).(*voltha.Device)
- t.Logf("A: %+v, C: %+v", a, c)
- c.Id = "12345"
- t.Logf("A: %+v, C: %+v", a, c)
-}