VOL-1774 Etcd Crash Handling
Change-Id: I1eeb726654c3972fd0a4fafae134607e5a810415
diff --git a/db/model/node.go b/db/model/node.go
index 264a9dd..7e703ff 100644
--- a/db/model/node.go
+++ b/db/model/node.go
@@ -41,11 +41,11 @@
// CRUD functions
Add(ctx context.Context, path string, data interface{}, txid string, makeBranch MakeBranchFunction) Revision
- Get(ctx context.Context, path string, hash string, depth int, deep bool, txid string) interface{}
- List(ctx context.Context, path string, hash string, depth int, deep bool, txid string) interface{}
+ Get(ctx context.Context, path string, hash string, depth int, deep bool, txid string) (interface{}, error)
+ List(ctx context.Context, path string, hash string, depth int, deep bool, txid string) (interface{}, error)
Update(ctx context.Context, path string, data interface{}, strict bool, txid string, makeBranch MakeBranchFunction) Revision
Remove(ctx context.Context, path string, txid string, makeBranch MakeBranchFunction) Revision
- CreateProxy(ctx context.Context, path string, exclusive bool) *Proxy
+ CreateProxy(ctx context.Context, path string, exclusive bool) (*Proxy, error)
GetProxy() *Proxy
@@ -250,7 +250,7 @@
}
// Get retrieves the data from a node tree that resides at the specified path
-func (n *node) List(ctx context.Context, path string, hash string, depth int, deep bool, txid string) interface{} {
+func (n *node) List(ctx context.Context, path string, hash string, depth int, deep bool, txid string) (interface{}, error) {
n.mutex.Lock()
defer n.mutex.Unlock()
@@ -278,18 +278,23 @@
var result interface{}
var prList []interface{}
- if pr := rev.LoadFromPersistence(ctx, path, txid, nil); pr != nil {
+
+ pr, err := rev.LoadFromPersistence(ctx, path, txid, nil)
+ if err != nil {
+ log.Errorf("failed-to-load-from-persistence")
+ return nil, err
+ }
+ if pr != nil {
for _, revEntry := range pr {
prList = append(prList, revEntry.GetData())
}
result = prList
}
-
- return result
+ return result, nil
}
// Get retrieves the data from a node tree that resides at the specified path
-func (n *node) Get(ctx context.Context, path string, hash string, depth int, reconcile bool, txid string) interface{} {
+func (n *node) Get(ctx context.Context, path string, hash string, depth int, reconcile bool, txid string) (interface{}, error) {
n.mutex.Lock()
defer n.mutex.Unlock()
@@ -328,13 +333,13 @@
"hash": hash,
"age": entryAge,
})
- return proto.Clone(entry.(Revision).GetData().(proto.Message))
+ return proto.Clone(entry.(Revision).GetData().(proto.Message)), nil
} else {
log.Debugw("cache-entry-expired", log.Fields{"path": path, "hash": hash, "age": entryAge})
}
} else if result = n.getPath(ctx, rev.GetBranch().GetLatest(), path, depth); result != nil && reflect.ValueOf(result).IsValid() && !reflect.ValueOf(result).IsNil() {
log.Debugw("using-rev-tree-entry", log.Fields{"path": path, "hash": hash, "depth": depth, "reconcile": reconcile, "txid": txid})
- return result
+ return result, nil
} else {
log.Debugw("not-using-cache-entry", log.Fields{
"path": path,
@@ -354,7 +359,10 @@
// If we got to this point, we are either trying to reconcile with the db
// or we simply failed at getting information from memory
if n.Root.KvStore != nil {
- if pr := rev.LoadFromPersistence(ctx, path, txid, nil); pr != nil && len(pr) > 0 {
+ if pr, err := rev.LoadFromPersistence(ctx, path, txid, nil); err != nil {
+ log.Errorf("failed-to-load-from-persistence")
+ return nil, err
+ } else if len(pr) > 0 {
// Did we receive a single or multiple revisions?
if len(pr) > 1 {
var revs []interface{}
@@ -367,8 +375,7 @@
}
}
}
-
- return result
+ return result, nil
}
//getPath traverses the specified path and retrieves the data associated to it
@@ -949,11 +956,11 @@
// ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ node Proxy ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
// CreateProxy returns a reference to a sub-tree of the data model
-func (n *node) CreateProxy(ctx context.Context, path string, exclusive bool) *Proxy {
+func (n *node) CreateProxy(ctx context.Context, path string, exclusive bool) (*Proxy, error) {
return n.createProxy(ctx, path, path, n, exclusive)
}
-func (n *node) createProxy(ctx context.Context, path string, fullPath string, parentNode *node, exclusive bool) *Proxy {
+func (n *node) createProxy(ctx context.Context, path string, fullPath string, parentNode *node, exclusive bool) (*Proxy, error) {
log.Debugw("node-create-proxy", log.Fields{
"node-type": reflect.ValueOf(n.Type).Type(),
"parent-node-type": reflect.ValueOf(parentNode.Type).Type(),
@@ -965,7 +972,7 @@
path = path[1:]
}
if path == "" {
- return n.makeProxy(path, fullPath, parentNode, exclusive)
+ return n.makeProxy(path, fullPath, parentNode, exclusive), nil
}
rev := n.GetBranch(NONE).GetLatest()
@@ -998,7 +1005,7 @@
"name": name,
})
newNode := n.MakeNode(reflect.New(field.ClassType.Elem()).Interface(), "")
- return newNode.makeProxy(path, fullPath, parentNode, exclusive)
+ return newNode.makeProxy(path, fullPath, parentNode, exclusive), nil
} else if field.Key != "" {
log.Debugw("key-proxy", log.Fields{
"node-type": reflect.ValueOf(n.Type).Type(),
@@ -1026,7 +1033,10 @@
"fullPath": fullPath,
"name": name,
})
- } else if revs := n.GetBranch(NONE).GetLatest().LoadFromPersistence(ctx, fullPath, "", nil); revs != nil && len(revs) > 0 {
+ } else if revs, err := n.GetBranch(NONE).GetLatest().LoadFromPersistence(ctx, fullPath, "", nil); err != nil {
+ log.Errorf("failed-to-load-from-persistence")
+ return nil, err
+ } else if revs != nil && len(revs) > 0 {
log.Debugw("found-revision-matching-key-in-db", log.Fields{
"node-type": reflect.ValueOf(n.Type).Type(),
"parent-node-type": reflect.ValueOf(parentNode.Type).Type(),
@@ -1081,7 +1091,7 @@
"fullPath": fullPath,
"latest-rev": rev.GetHash(),
})
- return nil
+ return nil, nil
}
func (n *node) makeProxy(path string, fullPath string, parentNode *node, exclusive bool) *Proxy {
diff --git a/db/model/non_persisted_revision.go b/db/model/non_persisted_revision.go
index 384caed..c7fb6ea 100644
--- a/db/model/non_persisted_revision.go
+++ b/db/model/non_persisted_revision.go
@@ -496,9 +496,9 @@
return npr.lastUpdate
}
-func (npr *NonPersistedRevision) LoadFromPersistence(ctx context.Context, path string, txid string, blobs map[string]*kvstore.KVPair) []Revision {
+func (npr *NonPersistedRevision) LoadFromPersistence(ctx context.Context, path string, txid string, blobs map[string]*kvstore.KVPair) ([]Revision, error) {
// stub... required by interface
- return nil
+ return nil, nil
}
func (npr *NonPersistedRevision) SetupWatch(key string) {
diff --git a/db/model/persisted_revision.go b/db/model/persisted_revision.go
index b5f1d09..b9aad44 100644
--- a/db/model/persisted_revision.go
+++ b/db/model/persisted_revision.go
@@ -518,13 +518,14 @@
// LoadFromPersistence retrieves data from kv store at the specified location and refreshes the memory
// by adding missing entries, updating changed entries and ignoring unchanged ones
-func (pr *PersistedRevision) LoadFromPersistence(ctx context.Context, path string, txid string, blobs map[string]*kvstore.KVPair) []Revision {
+func (pr *PersistedRevision) LoadFromPersistence(ctx context.Context, path string, txid string, blobs map[string]*kvstore.KVPair) ([]Revision, error) {
pr.mutex.Lock()
defer pr.mutex.Unlock()
log.Debugw("loading-from-persistence", log.Fields{"path": path, "txid": txid})
var response []Revision
+ var err error
for strings.HasPrefix(path, "/") {
path = path[1:]
@@ -533,7 +534,11 @@
if pr.kvStore != nil && path != "" {
if blobs == nil || len(blobs) == 0 {
log.Debugw("retrieve-from-kv", log.Fields{"path": path, "txid": txid})
- blobs, _ = pr.kvStore.List(path)
+
+ if blobs, err = pr.kvStore.List(path); err != nil {
+ log.Errorw("failed-to-retrieve-data-from-kvstore", log.Fields{"error": err})
+ return nil, err
+ }
}
partition := strings.SplitN(path, "/", 2)
@@ -622,5 +627,5 @@
}
}
- return response
+ return response, nil
}
diff --git a/db/model/proxy.go b/db/model/proxy.go
index b5378fe..a7eedda 100644
--- a/db/model/proxy.go
+++ b/db/model/proxy.go
@@ -214,7 +214,7 @@
// List will retrieve information from the data model at the specified path location
// A list operation will force access to persistence storage
-func (p *Proxy) List(ctx context.Context, path string, depth int, deep bool, txid string) interface{} {
+func (p *Proxy) List(ctx context.Context, path string, depth int, deep bool, txid string) (interface{}, error) {
var effectivePath string
if path == "/" {
effectivePath = p.getFullPath()
@@ -234,14 +234,11 @@
"controlled": controlled,
"operation": p.GetOperation(),
})
-
- rv := p.GetRoot().List(ctx, path, "", depth, deep, txid)
-
- return rv
+ return p.GetRoot().List(ctx, path, "", depth, deep, txid)
}
// Get will retrieve information from the data model at the specified path location
-func (p *Proxy) Get(ctx context.Context, path string, depth int, deep bool, txid string) interface{} {
+func (p *Proxy) Get(ctx context.Context, path string, depth int, deep bool, txid string) (interface{}, error) {
var effectivePath string
if path == "/" {
effectivePath = p.getFullPath()
@@ -262,16 +259,14 @@
"operation": p.GetOperation(),
})
- rv := p.GetRoot().Get(ctx, path, "", depth, deep, txid)
-
- return rv
+ return p.GetRoot().Get(ctx, path, "", depth, deep, txid)
}
// Update will modify information in the data model at the specified location with the provided data
-func (p *Proxy) Update(ctx context.Context, path string, data interface{}, strict bool, txid string) interface{} {
+func (p *Proxy) Update(ctx context.Context, path string, data interface{}, strict bool, txid string) (interface{}, error) {
if !strings.HasPrefix(path, "/") {
log.Errorf("invalid path: %s", path)
- return nil
+ return nil, fmt.Errorf("invalid path: %s", path)
}
var fullPath string
var effectivePath string
@@ -298,26 +293,29 @@
})
if p.GetRoot().KvStore != nil {
- p.GetRoot().KvStore.Client.Reserve(pathLock+"_", uuid.New().String(), ReservationTTL)
+ if _, err := p.GetRoot().KvStore.Client.Reserve(pathLock+"_", uuid.New().String(), ReservationTTL); err != nil {
+ log.Errorw("unable-to-acquire-key-from-kvstore", log.Fields{"error": err})
+ return nil, err
+ }
defer p.GetRoot().KvStore.Client.ReleaseReservation(pathLock + "_")
}
result := p.GetRoot().Update(ctx, fullPath, data, strict, txid, nil)
if result != nil {
- return result.GetData()
+ return result.GetData(), nil
}
- return nil
+ return nil, nil
}
// AddWithID will insert new data at specified location.
// This method also allows the user to specify the ID of the data entry to ensure
// that access control is active while inserting the information.
-func (p *Proxy) AddWithID(ctx context.Context, path string, id string, data interface{}, txid string) interface{} {
+func (p *Proxy) AddWithID(ctx context.Context, path string, id string, data interface{}, txid string) (interface{}, error) {
if !strings.HasPrefix(path, "/") {
log.Errorf("invalid path: %s", path)
- return nil
+ return nil, fmt.Errorf("invalid path: %s", path)
}
var fullPath string
var effectivePath string
@@ -344,24 +342,27 @@
})
if p.GetRoot().KvStore != nil {
- p.GetRoot().KvStore.Client.Reserve(pathLock+"_", uuid.New().String(), ReservationTTL)
+ if _, err := p.GetRoot().KvStore.Client.Reserve(pathLock+"_", uuid.New().String(), ReservationTTL); err != nil {
+ log.Errorw("unable-to-acquire-key-from-kvstore", log.Fields{"error": err})
+ return nil, err
+ }
defer p.GetRoot().KvStore.Client.ReleaseReservation(pathLock + "_")
}
result := p.GetRoot().Add(ctx, fullPath, data, txid, nil)
if result != nil {
- return result.GetData()
+ return result.GetData(), nil
}
- return nil
+ return nil, nil
}
// Add will insert new data at specified location.
-func (p *Proxy) Add(ctx context.Context, path string, data interface{}, txid string) interface{} {
+func (p *Proxy) Add(ctx context.Context, path string, data interface{}, txid string) (interface{}, error) {
if !strings.HasPrefix(path, "/") {
log.Errorf("invalid path: %s", path)
- return nil
+ return nil, fmt.Errorf("invalid path: %s", path)
}
var fullPath string
var effectivePath string
@@ -388,24 +389,27 @@
})
if p.GetRoot().KvStore != nil {
- p.GetRoot().KvStore.Client.Reserve(pathLock+"_", uuid.New().String(), ReservationTTL)
+ if _, err := p.GetRoot().KvStore.Client.Reserve(pathLock+"_", uuid.New().String(), ReservationTTL); err != nil {
+ log.Errorw("unable-to-acquire-key-from-kvstore", log.Fields{"error": err})
+ return nil, err
+ }
defer p.GetRoot().KvStore.Client.ReleaseReservation(pathLock + "_")
}
result := p.GetRoot().Add(ctx, fullPath, data, txid, nil)
if result != nil {
- return result.GetData()
+ return result.GetData(), nil
}
- return nil
+ return nil, nil
}
// Remove will delete an entry at the specified location
-func (p *Proxy) Remove(ctx context.Context, path string, txid string) interface{} {
+func (p *Proxy) Remove(ctx context.Context, path string, txid string) (interface{}, error) {
if !strings.HasPrefix(path, "/") {
log.Errorf("invalid path: %s", path)
- return nil
+ return nil, fmt.Errorf("invalid path: %s", path)
}
var fullPath string
var effectivePath string
@@ -432,24 +436,27 @@
})
if p.GetRoot().KvStore != nil {
- p.GetRoot().KvStore.Client.Reserve(pathLock+"_", uuid.New().String(), ReservationTTL)
+ if _, err := p.GetRoot().KvStore.Client.Reserve(pathLock+"_", uuid.New().String(), ReservationTTL); err != nil {
+ log.Errorw("unable-to-acquire-key-from-kvstore", log.Fields{"error": err})
+ return nil, err
+ }
defer p.GetRoot().KvStore.Client.ReleaseReservation(pathLock + "_")
}
result := p.GetRoot().Remove(ctx, fullPath, txid, nil)
if result != nil {
- return result.GetData()
+ return result.GetData(), nil
}
- return nil
+ return nil, nil
}
// CreateProxy to interact with specific path directly
-func (p *Proxy) CreateProxy(ctx context.Context, path string, exclusive bool) *Proxy {
+func (p *Proxy) CreateProxy(ctx context.Context, path string, exclusive bool) (*Proxy, error) {
if !strings.HasPrefix(path, "/") {
log.Errorf("invalid path: %s", path)
- return nil
+ return nil, fmt.Errorf("invalid path: %s", path)
}
var fullPath string
@@ -477,10 +484,12 @@
})
if p.GetRoot().KvStore != nil {
- p.GetRoot().KvStore.Client.Reserve(pathLock+"_", uuid.New().String(), ReservationTTL)
+ if _, err := p.GetRoot().KvStore.Client.Reserve(pathLock+"_", uuid.New().String(), ReservationTTL); err != nil {
+ log.Errorw("unable-to-acquire-key-from-kvstore", log.Fields{"error": err})
+ return nil, err
+ }
defer p.GetRoot().KvStore.Client.ReleaseReservation(pathLock + "_")
}
-
return p.GetRoot().CreateProxy(ctx, fullPath, exclusive)
}
diff --git a/db/model/proxy_load_test.go b/db/model/proxy_load_test.go
index 3f3327b..e5ae1c1 100644
--- a/db/model/proxy_load_test.go
+++ b/db/model/proxy_load_test.go
@@ -23,6 +23,7 @@
"github.com/opencord/voltha-protos/v2/go/common"
"github.com/opencord/voltha-protos/v2/go/openflow_13"
"github.com/opencord/voltha-protos/v2/go/voltha"
+ "github.com/stretchr/testify/assert"
"math/rand"
"reflect"
"strconv"
@@ -81,6 +82,7 @@
}
func init() {
+ var err error
BenchmarkProxy_Root = NewRoot(&voltha.Voltha{}, nil)
BenchmarkProxy_Logger, _ = log.AddPackage(log.JSON, log.DebugLevel, log.Fields{"instanceId": "PLT"})
@@ -96,7 +98,9 @@
}
log.SetPackageLogLevel("github.com/opencord/voltha-go/db/model", log.DebugLevel)
- BenchmarkProxy_DeviceProxy = BenchmarkProxy_Root.node.CreateProxy(context.Background(), "/", false)
+ if BenchmarkProxy_DeviceProxy, err = BenchmarkProxy_Root.node.CreateProxy(context.Background(), "/", false); err != nil {
+ log.With(log.Fields{"error": err}).Fatal("Cannot create benchmark proxy")
+ }
// Register ADD instructions callbacks
BenchmarkProxy_PLT = &proxyLoadTest{}
@@ -110,6 +114,7 @@
}
func BenchmarkProxy_AddDevice(b *testing.B) {
+ var err error
defer GetProfiling().Report()
b.RunParallel(func(pb *testing.PB) {
b.Log("Started adding devices")
@@ -150,7 +155,10 @@
var added interface{}
// Add the device
- if added = BenchmarkProxy_DeviceProxy.AddWithID(context.Background(), "/devices", ltDevID, ltDevice, ""); added == nil {
+ if added, err = BenchmarkProxy_DeviceProxy.AddWithID(context.Background(), "/devices", ltDevID, ltDevice, ""); err != nil {
+ log.With(log.Fields{"error": err}).Fatal("Cannot create proxy")
+ }
+ if added == nil {
BenchmarkProxy_Logger.Errorf("Failed to add device: %+v", ltDevice)
continue
} else {
@@ -174,9 +182,17 @@
if len(BenchmarkProxy_PLT.addedDevices) > 0 {
var target interface{}
randomID := BenchmarkProxy_PLT.addedDevices[rand.Intn(len(BenchmarkProxy_PLT.addedDevices))]
- firmProxy := BenchmarkProxy_Root.node.CreateProxy(context.Background(), "/", false)
- if target = firmProxy.Get(context.Background(), "/devices/"+randomID, 0, false,
- ""); !reflect.ValueOf(target).IsValid() {
+ firmProxy, err := BenchmarkProxy_Root.node.CreateProxy(context.Background(), "/", false)
+ if err != nil {
+ log.With(log.Fields{"error": err}).Fatal("Cannot create firmware proxy")
+ }
+ target, err = firmProxy.Get(context.Background(), "/devices/"+randomID, 0, false,
+ "")
+ if err != nil {
+ BenchmarkProxy_Logger.Errorf("Failed to create target due to error %v", err)
+ assert.NotNil(b, err)
+ }
+ if !reflect.ValueOf(target).IsValid() {
BenchmarkProxy_Logger.Errorf("Failed to find device: %s %+v", randomID, target)
continue
}
@@ -200,8 +216,11 @@
after := target.(*voltha.Device).FirmwareVersion
var updated interface{}
- if updated = firmProxy.Update(context.Background(), "/devices/"+randomID, target.(*voltha.Device), false,
- ""); updated == nil {
+ if updated, err = firmProxy.Update(context.Background(), "/devices/"+randomID, target.(*voltha.Device), false, ""); err != nil {
+ BenchmarkProxy_Logger.Errorf("Failed to update firmware proxy due to error %v", err)
+ assert.NotNil(b, err)
+ }
+ if updated == nil {
BenchmarkProxy_Logger.Errorf("Failed to update device: %+v", target)
continue
} else {
@@ -209,8 +228,12 @@
}
- if d := firmProxy.Get(context.Background(), "/devices/"+randomID, 0, false,
- ""); !reflect.ValueOf(d).IsValid() {
+ d, err := firmProxy.Get(context.Background(), "/devices/"+randomID, 0, false, "")
+ if err != nil {
+ BenchmarkProxy_Logger.Errorf("Failed to get device info from firmware proxy due to error %v", err)
+ assert.NotNil(b, err)
+ }
+ if !reflect.ValueOf(d).IsValid() {
BenchmarkProxy_Logger.Errorf("Failed to get device: %s", randomID)
continue
} else if d.(*voltha.Device).FirmwareVersion == after {
@@ -264,8 +287,15 @@
if len(BenchmarkProxy_PLT.addedDevices) > 0 {
randomID := BenchmarkProxy_PLT.addedDevices[rand.Intn(len(BenchmarkProxy_PLT.addedDevices))]
- flowsProxy := BenchmarkProxy_Root.node.CreateProxy(context.Background(), "/devices/"+randomID+"/flows", false)
- flows := flowsProxy.Get(context.Background(), "/", 0, false, "")
+ flowsProxy, err := BenchmarkProxy_Root.node.CreateProxy(context.Background(), "/devices/"+randomID+"/flows", false)
+ if err != nil {
+ log.With(log.Fields{"error": err}).Fatal("Cannot create flows proxy")
+ }
+ flows, err := flowsProxy.Get(context.Background(), "/", 0, false, "")
+ if err != nil {
+ BenchmarkProxy_Logger.Errorf("Failed to get flows from flows proxy due to error: %v", err)
+ assert.NotNil(b, err)
+ }
before := flows.(*openflow_13.Flows).Items[0].TableId
flows.(*openflow_13.Flows).Items[0].TableId = uint32(rand.Intn(3000))
@@ -281,7 +311,11 @@
)
var updated interface{}
- if updated = flowsProxy.Update(context.Background(), "/", flows.(*openflow_13.Flows), false, ""); updated == nil {
+ if updated, err = flowsProxy.Update(context.Background(), "/", flows.(*openflow_13.Flows), false, ""); err != nil {
+ BenchmarkProxy_Logger.Errorf("Cannot update flows proxy due to error: %v", err)
+ assert.NotNil(b, err)
+ }
+ if updated == nil {
b.Errorf("Failed to update flows for device: %+v", flows)
} else {
BenchmarkProxy_Logger.Infof("Flows were updated : %+v", updated)
@@ -303,8 +337,12 @@
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 := BenchmarkProxy_DeviceProxy.Get(context.Background(), "/devices/"+devToGet, 0, false,
- ""); !reflect.ValueOf(d).IsValid() {
+ d, err := BenchmarkProxy_DeviceProxy.Get(context.Background(), "/devices/"+devToGet, 0, false, "")
+ if err != nil {
+ BenchmarkProxy_Logger.Errorf("Failed to get device info from device proxy due to error: %v", err)
+ assert.NotNil(b, err)
+ }
+ if !reflect.ValueOf(d).IsValid() {
BenchmarkProxy_Logger.Errorf("Failed to get device: %s", devToGet)
continue
} else {
@@ -317,8 +355,12 @@
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 := BenchmarkProxy_DeviceProxy.Get(context.Background(), "/devices/"+devToGet, 0, false,
- ""); !reflect.ValueOf(d).IsValid() {
+ d, err := BenchmarkProxy_DeviceProxy.Get(context.Background(), "/devices/"+devToGet, 0, false, "")
+ if err != nil {
+ BenchmarkProxy_Logger.Errorf("Failed to get device info from device proxy due to error: %v", err)
+ assert.NotNil(b, err)
+ }
+ if !reflect.ValueOf(d).IsValid() {
BenchmarkProxy_Logger.Errorf("Failed to get device: %s", devToGet)
continue
} else if d.(*voltha.Device).FirmwareVersion == BenchmarkProxy_PLT.updatedFirmwares[i].After.(string) {
diff --git a/db/model/proxy_test.go b/db/model/proxy_test.go
index 785c65b..0ed8af9 100644
--- a/db/model/proxy_test.go
+++ b/db/model/proxy_test.go
@@ -21,9 +21,11 @@
"encoding/json"
"github.com/golang/protobuf/proto"
"github.com/google/uuid"
+ "github.com/opencord/voltha-lib-go/v2/pkg/log"
"github.com/opencord/voltha-protos/v2/go/common"
"github.com/opencord/voltha-protos/v2/go/openflow_13"
"github.com/opencord/voltha-protos/v2/go/voltha"
+ "github.com/stretchr/testify/assert"
"math/rand"
"reflect"
"strconv"
@@ -53,10 +55,17 @@
func init() {
//log.AddPackage(log.JSON, log.InfoLevel, log.Fields{"instanceId": "DB_MODEL"})
//log.UpdateAllLoggers(log.Fields{"instanceId": "PROXY_LOAD_TEST"})
+ var err error
TestProxy_Root = NewRoot(&voltha.Voltha{}, nil)
- TestProxy_Root_LogicalDevice = TestProxy_Root.CreateProxy(context.Background(), "/", false)
- TestProxy_Root_Device = TestProxy_Root.CreateProxy(context.Background(), "/", false)
- TestProxy_Root_Adapter = TestProxy_Root.CreateProxy(context.Background(), "/", false)
+ if TestProxy_Root_LogicalDevice, err = TestProxy_Root.CreateProxy(context.Background(), "/", false); err != nil {
+ log.With(log.Fields{"error": err}).Fatal("Cannot create logical device proxy")
+ }
+ if TestProxy_Root_Device, err = TestProxy_Root.CreateProxy(context.Background(), "/", false); err != nil {
+ log.With(log.Fields{"error": err}).Fatal("Cannot create device proxy")
+ }
+ if TestProxy_Root_Adapter, err = TestProxy_Root.CreateProxy(context.Background(), "/", false); err != nil {
+ log.With(log.Fields{"error": err}).Fatal("Cannot create adapter proxy")
+ }
TestProxy_LogicalPorts = []*voltha.LogicalPort{
{
@@ -116,7 +125,10 @@
postAddExecuted := make(chan struct{})
preAddExecutedPtr, postAddExecutedPtr := preAddExecuted, postAddExecuted
- devicesProxy := TestProxy_Root.node.CreateProxy(context.Background(), "/devices", false)
+ devicesProxy, err := TestProxy_Root.node.CreateProxy(context.Background(), "/devices", false)
+ if err != nil {
+ log.With(log.Fields{"error": err}).Fatal("Cannot create devices proxy")
+ }
devicesProxy.RegisterCallback(PRE_ADD, commonCallback2, "PRE_ADD Device container changes")
devicesProxy.RegisterCallback(POST_ADD, commonCallback2, "POST_ADD Device container changes")
@@ -124,7 +136,12 @@
TestProxy_Root_Device.RegisterCallback(PRE_ADD, commonChanCallback, "PRE_ADD instructions", &preAddExecutedPtr)
TestProxy_Root_Device.RegisterCallback(POST_ADD, commonChanCallback, "POST_ADD instructions", &postAddExecutedPtr)
- if added := TestProxy_Root_Device.Add(context.Background(), "/devices", TestProxy_Device, ""); added == nil {
+ added, err := TestProxy_Root_Device.Add(context.Background(), "/devices", TestProxy_Device, "")
+ if err != nil {
+ BenchmarkProxy_Logger.Errorf("Failed to add test proxy device due to error: %v", err)
+ assert.NotNil(t, err)
+ }
+ if added == nil {
t.Error("Failed to add device")
} else {
t.Logf("Added device : %+v", added)
@@ -138,7 +155,12 @@
}
// Verify that the added device can now be retrieved
- if d := TestProxy_Root_Device.Get(context.Background(), "/devices/"+TestProxy_DeviceId, 0, false, ""); !reflect.ValueOf(d).IsValid() {
+ d, err := TestProxy_Root_Device.Get(context.Background(), "/devices/"+TestProxy_DeviceId, 0, false, "")
+ if err != nil {
+ BenchmarkProxy_Logger.Errorf("Failed get device info from test proxy due to error: %v", err)
+ assert.NotNil(t, err)
+ }
+ if !reflect.ValueOf(d).IsValid() {
t.Error("Failed to find added device")
} else {
djson, _ := json.Marshal(d)
@@ -149,7 +171,11 @@
func TestProxy_1_1_2_Add_ExistingDevice(t *testing.T) {
TestProxy_Device.Id = TestProxy_DeviceId
- added := TestProxy_Root_Device.Add(context.Background(), "/devices", TestProxy_Device, "")
+ added, err := TestProxy_Root_Device.Add(context.Background(), "/devices", TestProxy_Device, "")
+ if err != nil {
+ BenchmarkProxy_Logger.Errorf("Failed to add device to test proxy due to error: %v", err)
+ assert.NotNil(t, err)
+ }
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)
}
@@ -181,7 +207,12 @@
TestProxy_Root_Adapter.RegisterCallback(POST_ADD, commonChanCallback, "POST_ADD instructions for adapters", &postAddExecutedPtr)
// Add the adapter
- if added := TestProxy_Root_Adapter.Add(context.Background(), "/adapters", TestProxy_Adapter, ""); added == nil {
+ added, err := TestProxy_Root_Adapter.Add(context.Background(), "/adapters", TestProxy_Adapter, "")
+ if err != nil {
+ BenchmarkProxy_Logger.Errorf("Failed to add adapter to test proxy due to error: %v", err)
+ assert.NotNil(t, err)
+ }
+ if added == nil {
t.Error("Failed to add adapter")
} else {
t.Logf("Added adapter : %+v", added)
@@ -190,7 +221,12 @@
verifyGotResponse(postAddExecuted)
// Verify that the added device can now be retrieved
- if d := TestProxy_Root_Adapter.Get(context.Background(), "/adapters/"+TestProxy_AdapterId, 0, false, ""); !reflect.ValueOf(d).IsValid() {
+ d, err := TestProxy_Root_Adapter.Get(context.Background(), "/adapters/"+TestProxy_AdapterId, 0, false, "")
+ if err != nil {
+ BenchmarkProxy_Logger.Errorf("Failed to retrieve device info from test proxy due to error: %v", err)
+ assert.NotNil(t, err)
+ }
+ if !reflect.ValueOf(d).IsValid() {
t.Error("Failed to find added adapter")
} else {
djson, _ := json.Marshal(d)
@@ -206,8 +242,11 @@
}
func TestProxy_1_2_1_Get_AllDevices(t *testing.T) {
- devices := TestProxy_Root_Device.Get(context.Background(), "/devices", 1, false, "")
-
+ devices, err := TestProxy_Root_Device.Get(context.Background(), "/devices", 1, false, "")
+ if err != nil {
+ BenchmarkProxy_Logger.Errorf("Failed to get all devices info from test proxy due to error: %v", err)
+ assert.NotNil(t, err)
+ }
if len(devices.([]interface{})) == 0 {
t.Error("there are no available devices to retrieve")
} else {
@@ -218,7 +257,12 @@
}
func TestProxy_1_2_2_Get_SingleDevice(t *testing.T) {
- if d := TestProxy_Root_Device.Get(context.Background(), "/devices/"+TestProxy_TargetDeviceId, 0, false, ""); !reflect.ValueOf(d).IsValid() {
+ d, err := TestProxy_Root_Device.Get(context.Background(), "/devices/"+TestProxy_TargetDeviceId, 0, false, "")
+ if err != nil {
+ BenchmarkProxy_Logger.Errorf("Failed to get single device info from test proxy due to error: %v", err)
+ assert.NotNil(t, err)
+ }
+ if !reflect.ValueOf(d).IsValid() {
t.Errorf("Failed to find device : %s", TestProxy_TargetDeviceId)
} else {
djson, _ := json.Marshal(d)
@@ -233,7 +277,12 @@
postUpdateExecuted := make(chan struct{})
preUpdateExecutedPtr, postUpdateExecutedPtr := preUpdateExecuted, postUpdateExecuted
- if retrieved := TestProxy_Root_Device.Get(context.Background(), "/devices/"+TestProxy_TargetDeviceId, 1, false, ""); retrieved == nil {
+ retrieved, err := TestProxy_Root_Device.Get(context.Background(), "/devices/"+TestProxy_TargetDeviceId, 1, false, "")
+ if err != nil {
+ BenchmarkProxy_Logger.Errorf("Failed to get device info from test proxy due to error: %v", err)
+ assert.NotNil(t, err)
+ }
+ if retrieved == nil {
t.Error("Failed to get device")
} else {
t.Logf("Found raw device (root proxy): %+v", retrieved)
@@ -258,7 +307,12 @@
"POST_UPDATE instructions (root proxy)", &postUpdateExecutedPtr,
)
- if afterUpdate := TestProxy_Root_Device.Update(context.Background(), "/devices/"+TestProxy_TargetDeviceId, retrieved, false, ""); afterUpdate == nil {
+ afterUpdate, err := TestProxy_Root_Device.Update(context.Background(), "/devices/"+TestProxy_TargetDeviceId, retrieved, false, "")
+ if err != nil {
+ BenchmarkProxy_Logger.Errorf("Failed to update device info test proxy due to error: %v", err)
+ assert.NotNil(t, err)
+ }
+ if afterUpdate == nil {
t.Error("Failed to update device")
} else {
t.Logf("Updated device : %+v", afterUpdate)
@@ -271,7 +325,12 @@
t.Error("POST_UPDATE callback was not executed")
}
- if d := TestProxy_Root_Device.Get(context.Background(), "/devices/"+TestProxy_TargetDeviceId, 1, false, ""); !reflect.ValueOf(d).IsValid() {
+ d, err := TestProxy_Root_Device.Get(context.Background(), "/devices/"+TestProxy_TargetDeviceId, 1, false, "")
+ if err != nil {
+ BenchmarkProxy_Logger.Errorf("Failed to get device info from test proxy due to error: %v", err)
+ assert.NotNil(t, err)
+ }
+ if !reflect.ValueOf(d).IsValid() {
t.Error("Failed to find updated device (root proxy)")
} else {
djson, _ := json.Marshal(d)
@@ -282,8 +341,15 @@
func TestProxy_1_3_2_Update_DeviceFlows(t *testing.T) {
// Get a device proxy and update a specific port
- devFlowsProxy := TestProxy_Root.node.CreateProxy(context.Background(), "/devices/"+TestProxy_DeviceId+"/flows", false)
- flows := devFlowsProxy.Get(context.Background(), "/", 0, false, "")
+ devFlowsProxy, err := TestProxy_Root.node.CreateProxy(context.Background(), "/devices/"+TestProxy_DeviceId+"/flows", false)
+ if err != nil {
+ log.With(log.Fields{"error": err}).Fatal("Cannot create device flows proxy")
+ }
+ flows, err := devFlowsProxy.Get(context.Background(), "/", 0, false, "")
+ if err != nil {
+ BenchmarkProxy_Logger.Errorf("Failed to get flows from device flows proxy due to error: %v", err)
+ assert.NotNil(t, err)
+ }
flows.(*openflow_13.Flows).Items[0].TableId = 2244
preUpdateExecuted := make(chan struct{})
@@ -301,13 +367,22 @@
"POST_UPDATE instructions (flows proxy)", &postUpdateExecutedPtr,
)
- kvFlows := devFlowsProxy.Get(context.Background(), "/", 0, false, "")
+ kvFlows, err := devFlowsProxy.Get(context.Background(), "/", 0, false, "")
+ if err != nil {
+ BenchmarkProxy_Logger.Errorf("Failed to get flows from device flows proxy due to error: %v", err)
+ assert.NotNil(t, err)
+ }
if reflect.DeepEqual(flows, kvFlows) {
t.Errorf("Local changes have changed the KV store contents - local:%+v, kv: %+v", flows, kvFlows)
}
- if updated := devFlowsProxy.Update(context.Background(), "/", flows.(*openflow_13.Flows), false, ""); updated == nil {
+ updated, err := devFlowsProxy.Update(context.Background(), "/", flows.(*openflow_13.Flows), false, "")
+ if err != nil {
+ BenchmarkProxy_Logger.Errorf("Failed to update flows in device flows proxy due to error: %v", err)
+ assert.NotNil(t, err)
+ }
+ if updated == nil {
t.Error("Failed to update flow")
} else {
t.Logf("Updated flows : %+v", updated)
@@ -320,14 +395,24 @@
t.Error("POST_UPDATE callback was not executed")
}
- if d := devFlowsProxy.Get(context.Background(), "/", 0, false, ""); d == nil {
+ d, err := devFlowsProxy.Get(context.Background(), "/", 0, false, "")
+ if err != nil {
+ BenchmarkProxy_Logger.Errorf("Failed to get flows in device flows proxy due to error: %v", err)
+ assert.NotNil(t, err)
+ }
+ if 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 := TestProxy_Root_Device.Get(context.Background(), "/devices/"+TestProxy_DeviceId+"/flows", 1, false, ""); !reflect.ValueOf(d).IsValid() {
+ d, err = TestProxy_Root_Device.Get(context.Background(), "/devices/"+TestProxy_DeviceId+"/flows", 1, false, "")
+ if err != nil {
+ BenchmarkProxy_Logger.Errorf("Failed to get flows from device flows proxy due to error: %v", err)
+ assert.NotNil(t, err)
+ }
+ if !reflect.ValueOf(d).IsValid() {
t.Error("Failed to find updated flows (root proxy)")
} else {
djson, _ := json.Marshal(d)
@@ -340,9 +425,16 @@
postUpdateExecuted := make(chan struct{})
preUpdateExecutedPtr, postUpdateExecutedPtr := preUpdateExecuted, postUpdateExecuted
- adaptersProxy := TestProxy_Root.node.CreateProxy(context.Background(), "/adapters", false)
-
- if retrieved := TestProxy_Root_Adapter.Get(context.Background(), "/adapters/"+TestProxy_AdapterId, 1, false, ""); retrieved == nil {
+ adaptersProxy, err := TestProxy_Root.node.CreateProxy(context.Background(), "/adapters", false)
+ if err != nil {
+ log.With(log.Fields{"error": err}).Fatal("Cannot create adapters proxy")
+ }
+ retrieved, err := TestProxy_Root_Adapter.Get(context.Background(), "/adapters/"+TestProxy_AdapterId, 1, false, "")
+ if err != nil {
+ BenchmarkProxy_Logger.Errorf("Failed to retrieve adapter info from adapters proxy due to error: %v", err)
+ assert.NotNil(t, err)
+ }
+ if retrieved == nil {
t.Error("Failed to get adapter")
} else {
t.Logf("Found raw adapter (root proxy): %+v", retrieved)
@@ -360,7 +452,12 @@
"POST_UPDATE instructions for adapters", &postUpdateExecutedPtr,
)
- if afterUpdate := adaptersProxy.Update(context.Background(), "/"+TestProxy_AdapterId, retrieved, false, ""); afterUpdate == nil {
+ afterUpdate, err := adaptersProxy.Update(context.Background(), "/"+TestProxy_AdapterId, retrieved, false, "")
+ if err != nil {
+ BenchmarkProxy_Logger.Errorf("Failed to update adapter info in adapters proxy due to error: %v", err)
+ assert.NotNil(t, err)
+ }
+ if afterUpdate == nil {
t.Error("Failed to update adapter")
} else {
t.Logf("Updated adapter : %+v", afterUpdate)
@@ -373,7 +470,12 @@
t.Error("POST_UPDATE callback for adapter was not executed")
}
- if d := TestProxy_Root_Adapter.Get(context.Background(), "/adapters/"+TestProxy_AdapterId, 1, false, ""); !reflect.ValueOf(d).IsValid() {
+ d, err := TestProxy_Root_Adapter.Get(context.Background(), "/adapters/"+TestProxy_AdapterId, 1, false, "")
+ if err != nil {
+ BenchmarkProxy_Logger.Errorf("Failed to get updated adapter info from adapters proxy due to error: %v", err)
+ assert.NotNil(t, err)
+ }
+ if !reflect.ValueOf(d).IsValid() {
t.Error("Failed to find updated adapter (root proxy)")
} else {
djson, _ := json.Marshal(d)
@@ -398,7 +500,12 @@
"POST_REMOVE instructions (root proxy)", &postRemoveExecutedPtr,
)
- if removed := TestProxy_Root_Device.Remove(context.Background(), "/devices/"+TestProxy_DeviceId, ""); removed == nil {
+ removed, err := TestProxy_Root_Device.Remove(context.Background(), "/devices/"+TestProxy_DeviceId, "")
+ if err != nil {
+ BenchmarkProxy_Logger.Errorf("Failed to remove device from devices proxy due to error: %v", err)
+ assert.NotNil(t, err)
+ }
+ if removed == nil {
t.Error("Failed to remove device")
} else {
t.Logf("Removed device : %+v", removed)
@@ -411,7 +518,12 @@
t.Error("POST_REMOVE callback was not executed")
}
- if d := TestProxy_Root_Device.Get(context.Background(), "/devices/"+TestProxy_DeviceId, 0, false, ""); reflect.ValueOf(d).IsValid() {
+ d, err := TestProxy_Root_Device.Get(context.Background(), "/devices/"+TestProxy_DeviceId, 0, false, "")
+ if err != nil {
+ BenchmarkProxy_Logger.Errorf("Failed to get device info from devices proxy due to error: %v", err)
+ assert.NotNil(t, err)
+ }
+ if reflect.ValueOf(d).IsValid() {
djson, _ := json.Marshal(d)
t.Errorf("Device was not removed - %s", djson)
} else {
@@ -433,7 +545,12 @@
TestProxy_Root_LogicalDevice.RegisterCallback(PRE_ADD, commonChanCallback, "PRE_ADD instructions", &preAddExecutedPtr)
TestProxy_Root_LogicalDevice.RegisterCallback(POST_ADD, commonChanCallback, "POST_ADD instructions", &postAddExecutedPtr)
- if added := TestProxy_Root_LogicalDevice.Add(context.Background(), "/logical_devices", TestProxy_LogicalDevice, ""); added == nil {
+ added, err := TestProxy_Root_LogicalDevice.Add(context.Background(), "/logical_devices", TestProxy_LogicalDevice, "")
+ if err != nil {
+ BenchmarkProxy_Logger.Errorf("Failed to add new logical device into proxy due to error: %v", err)
+ assert.NotNil(t, err)
+ }
+ if added == nil {
t.Error("Failed to add logical device")
} else {
t.Logf("Added logical device : %+v", added)
@@ -441,7 +558,12 @@
verifyGotResponse(postAddExecuted)
- if ld := TestProxy_Root_LogicalDevice.Get(context.Background(), "/logical_devices/"+TestProxy_LogicalDeviceId, 0, false, ""); !reflect.ValueOf(ld).IsValid() {
+ ld, err := TestProxy_Root_LogicalDevice.Get(context.Background(), "/logical_devices/"+TestProxy_LogicalDeviceId, 0, false, "")
+ if err != nil {
+ BenchmarkProxy_Logger.Errorf("Failed to get logical device info from logical device proxy due to error: %v", err)
+ assert.NotNil(t, err)
+ }
+ if !reflect.ValueOf(ld).IsValid() {
t.Error("Failed to find added logical device")
} else {
ldJSON, _ := json.Marshal(ld)
@@ -459,15 +581,22 @@
func TestProxy_2_1_2_Add_ExistingLogicalDevice(t *testing.T) {
TestProxy_LogicalDevice.Id = TestProxy_LogicalDeviceId
- added := TestProxy_Root_LogicalDevice.Add(context.Background(), "/logical_devices", TestProxy_LogicalDevice, "")
+ added, err := TestProxy_Root_LogicalDevice.Add(context.Background(), "/logical_devices", TestProxy_LogicalDevice, "")
+ if err != nil {
+ BenchmarkProxy_Logger.Errorf("Failed to add logical device due to error: %v", err)
+ assert.NotNil(t, err)
+ }
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 TestProxy_2_2_1_Get_AllLogicalDevices(t *testing.T) {
- logicalDevices := TestProxy_Root_LogicalDevice.Get(context.Background(), "/logical_devices", 1, false, "")
-
+ logicalDevices, err := TestProxy_Root_LogicalDevice.Get(context.Background(), "/logical_devices", 1, false, "")
+ if err != nil {
+ BenchmarkProxy_Logger.Errorf("Failed to get all logical devices from proxy due to error: %v", err)
+ assert.NotNil(t, err)
+ }
if len(logicalDevices.([]interface{})) == 0 {
t.Error("there are no available logical devices to retrieve")
} else {
@@ -478,7 +607,12 @@
}
func TestProxy_2_2_2_Get_SingleLogicalDevice(t *testing.T) {
- if ld := TestProxy_Root_LogicalDevice.Get(context.Background(), "/logical_devices/"+TestProxy_TargetLogicalDeviceId, 0, false, ""); !reflect.ValueOf(ld).IsValid() {
+ ld, err := TestProxy_Root_LogicalDevice.Get(context.Background(), "/logical_devices/"+TestProxy_TargetLogicalDeviceId, 0, false, "")
+ if err != nil {
+ BenchmarkProxy_Logger.Errorf("Failed to get single logical device from proxy due to error: %v", err)
+ assert.NotNil(t, err)
+ }
+ if !reflect.ValueOf(ld).IsValid() {
t.Errorf("Failed to find logical device : %s", TestProxy_TargetLogicalDeviceId)
} else {
ldJSON, _ := json.Marshal(ld)
@@ -493,7 +627,12 @@
postUpdateExecuted := make(chan struct{})
preUpdateExecutedPtr, postUpdateExecutedPtr := preUpdateExecuted, postUpdateExecuted
- if retrieved := TestProxy_Root_LogicalDevice.Get(context.Background(), "/logical_devices/"+TestProxy_TargetLogicalDeviceId, 1, false, ""); retrieved == nil {
+ retrieved, err := TestProxy_Root_LogicalDevice.Get(context.Background(), "/logical_devices/"+TestProxy_TargetLogicalDeviceId, 1, false, "")
+ if err != nil {
+ BenchmarkProxy_Logger.Errorf("Failed to get logical devices due to error: %v", err)
+ assert.NotNil(t, err)
+ }
+ if retrieved == nil {
t.Error("Failed to get logical device")
} else {
t.Logf("Found raw logical device (root proxy): %+v", retrieved)
@@ -518,8 +657,13 @@
retrieved.(*voltha.LogicalDevice).RootDeviceId = strconv.Itoa(fwVersion)
- if afterUpdate := TestProxy_Root_LogicalDevice.Update(context.Background(), "/logical_devices/"+TestProxy_TargetLogicalDeviceId, retrieved, false,
- ""); afterUpdate == nil {
+ afterUpdate, err := TestProxy_Root_LogicalDevice.Update(context.Background(), "/logical_devices/"+TestProxy_TargetLogicalDeviceId, retrieved, false,
+ "")
+ if err != nil {
+ BenchmarkProxy_Logger.Errorf("Faield to update logical device info due to error: %v", err)
+ assert.NotNil(t, err)
+ }
+ if afterUpdate == nil {
t.Error("Failed to update logical device")
} else {
t.Logf("Updated logical device : %+v", afterUpdate)
@@ -532,7 +676,12 @@
t.Error("POST_UPDATE callback was not executed")
}
- if d := TestProxy_Root_LogicalDevice.Get(context.Background(), "/logical_devices/"+TestProxy_TargetLogicalDeviceId, 1, false, ""); !reflect.ValueOf(d).IsValid() {
+ d, err := TestProxy_Root_LogicalDevice.Get(context.Background(), "/logical_devices/"+TestProxy_TargetLogicalDeviceId, 1, false, "")
+ if err != nil {
+ BenchmarkProxy_Logger.Errorf("Failed to get logical device info due to error: %v", err)
+ assert.NotNil(t, err)
+ }
+ if !reflect.ValueOf(d).IsValid() {
t.Error("Failed to find updated logical device (root proxy)")
} else {
djson, _ := json.Marshal(d)
@@ -544,8 +693,15 @@
func TestProxy_2_3_2_Update_LogicalDeviceFlows(t *testing.T) {
// Get a device proxy and update a specific port
- ldFlowsProxy := TestProxy_Root.node.CreateProxy(context.Background(), "/logical_devices/"+TestProxy_LogicalDeviceId+"/flows", false)
- flows := ldFlowsProxy.Get(context.Background(), "/", 0, false, "")
+ ldFlowsProxy, err := TestProxy_Root.node.CreateProxy(context.Background(), "/logical_devices/"+TestProxy_LogicalDeviceId+"/flows", false)
+ if err != nil {
+ log.With(log.Fields{"error": err}).Fatal("Failed to create logical device flows proxy")
+ }
+ flows, err := ldFlowsProxy.Get(context.Background(), "/", 0, false, "")
+ if err != nil {
+ BenchmarkProxy_Logger.Errorf("Failed to get flows from logical device flows proxy due to error: %v", err)
+ assert.NotNil(t, err)
+ }
flows.(*openflow_13.Flows).Items[0].TableId = rand.Uint32()
t.Logf("before updated flows: %+v", flows)
@@ -558,27 +714,40 @@
commonCallback2,
)
- kvFlows := ldFlowsProxy.Get(context.Background(), "/", 0, false, "")
-
+ kvFlows, err := ldFlowsProxy.Get(context.Background(), "/", 0, false, "")
+ if err != nil {
+ BenchmarkProxy_Logger.Errorf("Faield to get flows from logical device flows proxy due to error: %v", err)
+ assert.NotNil(t, err)
+ }
if reflect.DeepEqual(flows, kvFlows) {
t.Errorf("Local changes have changed the KV store contents - local:%+v, kv: %+v", flows, kvFlows)
}
- if updated := ldFlowsProxy.Update(context.Background(), "/", flows.(*openflow_13.Flows), false, ""); updated == nil {
+ updated, err := ldFlowsProxy.Update(context.Background(), "/", flows.(*openflow_13.Flows), false, "")
+ if err != nil {
+ BenchmarkProxy_Logger.Errorf("Failed to update flows in logical device flows proxy due to error: %v", err)
+ assert.NotNil(t, err)
+ }
+ if updated == nil {
t.Error("Failed to update logical device flows")
} else {
t.Logf("Updated logical device flows : %+v", updated)
}
- if d := ldFlowsProxy.Get(context.Background(), "/", 0, false, ""); d == nil {
+ if d, _ := ldFlowsProxy.Get(context.Background(), "/", 0, false, ""); d == nil {
t.Error("Failed to find updated logical device flows (flows proxy)")
} else {
djson, _ := json.Marshal(d)
t.Logf("Found flows (flows proxy): %s", string(djson))
}
- if d := TestProxy_Root_LogicalDevice.Get(context.Background(), "/logical_devices/"+TestProxy_LogicalDeviceId+"/flows", 0, false,
- ""); !reflect.ValueOf(d).IsValid() {
+ d, err := TestProxy_Root_LogicalDevice.Get(context.Background(), "/logical_devices/"+TestProxy_LogicalDeviceId+"/flows", 0, false,
+ "")
+ if err != nil {
+ BenchmarkProxy_Logger.Errorf("Failed to get flows from logical device flows proxy due to error: %v", err)
+ assert.NotNil(t, err)
+ }
+ if !reflect.ValueOf(d).IsValid() {
t.Error("Failed to find updated logical device flows (root proxy)")
} else {
djson, _ := json.Marshal(d)
@@ -602,7 +771,12 @@
"POST_REMOVE instructions (root proxy)", &postRemoveExecutedPtr,
)
- if removed := TestProxy_Root_LogicalDevice.Remove(context.Background(), "/logical_devices/"+TestProxy_LogicalDeviceId, ""); removed == nil {
+ removed, err := TestProxy_Root_LogicalDevice.Remove(context.Background(), "/logical_devices/"+TestProxy_LogicalDeviceId, "")
+ if err != nil {
+ BenchmarkProxy_Logger.Errorf("Failed to remove device from logical devices proxy due to error: %v", err)
+ assert.NotNil(t, err)
+ }
+ if removed == nil {
t.Error("Failed to remove logical device")
} else {
t.Logf("Removed device : %+v", removed)
@@ -615,7 +789,12 @@
t.Error("POST_REMOVE callback was not executed")
}
- if d := TestProxy_Root_LogicalDevice.Get(context.Background(), "/logical_devices/"+TestProxy_LogicalDeviceId, 0, false, ""); reflect.ValueOf(d).IsValid() {
+ d, err := TestProxy_Root_LogicalDevice.Get(context.Background(), "/logical_devices/"+TestProxy_LogicalDeviceId, 0, false, "")
+ if err != nil {
+ BenchmarkProxy_Logger.Errorf("Failed to get logical device info due to error: %v", err)
+ assert.NotNil(t, err)
+ }
+ if reflect.ValueOf(d).IsValid() {
djson, _ := json.Marshal(d)
t.Errorf("Device was not removed - %s", djson)
} else {
diff --git a/db/model/revision.go b/db/model/revision.go
index 29fc5e9..9addad4 100644
--- a/db/model/revision.go
+++ b/db/model/revision.go
@@ -47,7 +47,7 @@
GetNode() *node
SetLastUpdate(ts ...time.Time)
GetLastUpdate() time.Time
- LoadFromPersistence(ctx context.Context, path string, txid string, blobs map[string]*kvstore.KVPair) []Revision
+ LoadFromPersistence(ctx context.Context, path string, txid string, blobs map[string]*kvstore.KVPair) ([]Revision, error)
UpdateData(ctx context.Context, data interface{}, branch *Branch) Revision
UpdateChildren(ctx context.Context, name string, children []Revision, branch *Branch) Revision
UpdateAllChildren(children map[string][]Revision, branch *Branch) Revision
diff --git a/db/model/transaction.go b/db/model/transaction.go
index d7a34e7..e10236c 100644
--- a/db/model/transaction.go
+++ b/db/model/transaction.go
@@ -17,6 +17,7 @@
import (
"context"
+ "fmt"
"github.com/opencord/voltha-lib-go/v2/pkg/log"
)
@@ -32,32 +33,32 @@
}
return tx
}
-func (t *Transaction) Get(ctx context.Context, path string, depth int, deep bool) interface{} {
+func (t *Transaction) Get(ctx context.Context, path string, depth int, deep bool) (interface{}, error) {
if t.txid == "" {
log.Errorf("closed transaction")
- return nil
+ return nil, fmt.Errorf("closed transaction")
}
// TODO: need to review the return values at the different layers!!!!!
return t.proxy.Get(ctx, path, depth, deep, t.txid)
}
-func (t *Transaction) Update(ctx context.Context, path string, data interface{}, strict bool) interface{} {
+func (t *Transaction) Update(ctx context.Context, path string, data interface{}, strict bool) (interface{}, error) {
if t.txid == "" {
log.Errorf("closed transaction")
- return nil
+ return nil, fmt.Errorf("closed transaction")
}
return t.proxy.Update(ctx, path, data, strict, t.txid)
}
-func (t *Transaction) Add(ctx context.Context, path string, data interface{}) interface{} {
+func (t *Transaction) Add(ctx context.Context, path string, data interface{}) (interface{}, error) {
if t.txid == "" {
log.Errorf("closed transaction")
- return nil
+ return nil, fmt.Errorf("closed transaction")
}
return t.proxy.Add(ctx, path, data, t.txid)
}
-func (t *Transaction) Remove(ctx context.Context, path string) interface{} {
+func (t *Transaction) Remove(ctx context.Context, path string) (interface{}, error) {
if t.txid == "" {
log.Errorf("closed transaction")
- return nil
+ return nil, fmt.Errorf("closed transaction")
}
return t.proxy.Remove(ctx, path, t.txid)
}
diff --git a/db/model/transaction_test.go b/db/model/transaction_test.go
index c33e5be..a52688a 100644
--- a/db/model/transaction_test.go
+++ b/db/model/transaction_test.go
@@ -20,8 +20,10 @@
"context"
"encoding/hex"
"github.com/google/uuid"
+ "github.com/opencord/voltha-lib-go/v2/pkg/log"
"github.com/opencord/voltha-protos/v2/go/common"
"github.com/opencord/voltha-protos/v2/go/voltha"
+ "github.com/stretchr/testify/assert"
"strconv"
"testing"
)
@@ -34,26 +36,13 @@
)
func init() {
+ var err error
TestTransaction_Root = NewRoot(&voltha.Voltha{}, nil)
- TestTransaction_RootProxy = TestTransaction_Root.node.CreateProxy(context.Background(), "/", false)
+ if TestTransaction_RootProxy, err = TestTransaction_Root.node.CreateProxy(context.Background(), "/", false); err != nil {
+ log.With(log.Fields{"error": err}).Fatal("Cannot create proxy")
+ }
}
-//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 TestTransaction_2_AddDevice(t *testing.T) {
devIDBin, _ := uuid.New().MarshalBinary()
TestTransaction_DeviceId = "0001" + hex.EncodeToString(devIDBin)[:12]
@@ -80,7 +69,12 @@
addTx := TestTransaction_RootProxy.OpenTransaction()
- if added := addTx.Add(context.Background(), "/devices", device); added == nil {
+ added, err := addTx.Add(context.Background(), "/devices", device)
+ if err != nil {
+ log.Errorf("Failed to add device due to error %v", err)
+ assert.NotNil(t, err)
+ }
+ if added == nil {
t.Error("Failed to add device")
} else {
TestTransaction_TargetDeviceId = added.(*voltha.Device).Id
@@ -94,12 +88,20 @@
basePath := "/devices/" + TestTransaction_DeviceId
getDevWithPortsTx := TestTransaction_RootProxy.OpenTransaction()
- device1 := getDevWithPortsTx.Get(context.Background(), basePath+"/ports", 1, false)
+ device1, err := getDevWithPortsTx.Get(context.Background(), basePath+"/ports", 1, false)
+ if err != nil {
+ log.Errorf("Failed to get device with ports due to error %v", err)
+ assert.NotNil(t, err)
+ }
t.Logf("retrieved device with ports: %+v", device1)
getDevWithPortsTx.Commit()
getDevTx := TestTransaction_RootProxy.OpenTransaction()
- device2 := getDevTx.Get(context.Background(), basePath, 0, false)
+ device2, err := getDevTx.Get(context.Background(), basePath, 0, false)
+ if err != nil {
+ log.Errorf("Failed to open transaction due to error %v", err)
+ assert.NotNil(t, err)
+ }
t.Logf("retrieved device: %+v", device2)
getDevTx.Commit()
@@ -107,7 +109,10 @@
func TestTransaction_4_UpdateDevice(t *testing.T) {
updateTx := TestTransaction_RootProxy.OpenTransaction()
- if retrieved := updateTx.Get(context.Background(), "/devices/"+TestTransaction_TargetDeviceId, 1, false); retrieved == nil {
+ if retrieved, err := updateTx.Get(context.Background(), "/devices/"+TestTransaction_TargetDeviceId, 1, false); err != nil {
+ log.Errorf("Failed to retrieve device info due to error %v", err)
+ assert.NotNil(t, err)
+ } else if retrieved == nil {
t.Error("Failed to get device")
} else {
var fwVersion int
@@ -123,7 +128,12 @@
t.Logf("Before update : %+v", retrieved)
// FIXME: The makeBranch passed in function is nil or not being executed properly!!!!!
- if afterUpdate := updateTx.Update(context.Background(), "/devices/"+TestTransaction_TargetDeviceId, retrieved, false); afterUpdate == nil {
+ afterUpdate, err := updateTx.Update(context.Background(), "/devices/"+TestTransaction_TargetDeviceId, retrieved, false)
+ if err != nil {
+ log.Errorf("Failed to update device info due to error %v", err)
+ assert.NotNil(t, err)
+ }
+ if afterUpdate == nil {
t.Error("Failed to update device")
} else {
t.Logf("Updated device : %+v", afterUpdate)
@@ -137,12 +147,20 @@
basePath := "/devices/" + TestTransaction_DeviceId
getDevWithPortsTx := TestTransaction_RootProxy.OpenTransaction()
- device1 := getDevWithPortsTx.Get(context.Background(), basePath+"/ports", 1, false)
+ device1, err := getDevWithPortsTx.Get(context.Background(), basePath+"/ports", 1, false)
+ if err != nil {
+ log.Errorf("Failed to device with ports info due to error %v", err)
+ assert.NotNil(t, err)
+ }
t.Logf("retrieved device with ports: %+v", device1)
getDevWithPortsTx.Commit()
getDevTx := TestTransaction_RootProxy.OpenTransaction()
- device2 := getDevTx.Get(context.Background(), basePath, 0, false)
+ device2, err := getDevTx.Get(context.Background(), basePath, 0, false)
+ if err != nil {
+ log.Errorf("Failed to get device info due to error %v", err)
+ assert.NotNil(t, err)
+ }
t.Logf("retrieved device: %+v", device2)
getDevTx.Commit()
@@ -150,7 +168,12 @@
func TestTransaction_6_RemoveDevice(t *testing.T) {
removeTx := TestTransaction_RootProxy.OpenTransaction()
- if removed := removeTx.Remove(context.Background(), "/devices/"+TestTransaction_DeviceId); removed == nil {
+ removed, err := removeTx.Remove(context.Background(), "/devices/"+TestTransaction_DeviceId)
+ if err != nil {
+ log.Errorf("Failed to remove device due to error %v", err)
+ assert.NotNil(t, err)
+ }
+ if removed == nil {
t.Error("Failed to remove device")
} else {
t.Logf("Removed device : %+v", removed)
@@ -163,7 +186,11 @@
basePath := "/devices/" + TestTransaction_DeviceId
getDevTx := TestTransaction_RootProxy.OpenTransaction()
- device := TestTransaction_RootProxy.Get(context.Background(), basePath, 0, false, "")
+ device, err := TestTransaction_RootProxy.Get(context.Background(), basePath, 0, false, "")
+ if err != nil {
+ log.Errorf("Failed to get device info post remove due to error %v", err)
+ assert.NotNil(t, err)
+ }
t.Logf("retrieved device: %+v", device)
getDevTx.Commit()
diff --git a/go.sum b/go.sum
index 00a1590..8b30a06 100644
--- a/go.sum
+++ b/go.sum
@@ -8,7 +8,9 @@
github.com/Shopify/sarama v1.23.1/go.mod h1:XLH1GYJnLVE0XCr6KdJGVJRTwY30moWNJ4sERjXX6fs=
github.com/Shopify/toxiproxy v2.1.4+incompatible h1:TKdv8HiTLgE5wdJuEML90aBgNWsokNbMijUGhmcoBJc=
github.com/Shopify/toxiproxy v2.1.4+incompatible/go.mod h1:OXgGpZ6Cli1/URJOF1DMxUHB2q5Ap20/P/eIdh4G0pI=
+github.com/alecthomas/template v0.0.0-20160405071501-a0175ee3bccc h1:cAKDfWh5VpdgMhJosfJnn5/FoN2SRZ4p7fJNX58YPaU=
github.com/alecthomas/template v0.0.0-20160405071501-a0175ee3bccc/go.mod h1:LOuyumcjzFXgccqObfd/Ljyb9UuFJ6TxHnclSeseNhc=
+github.com/alecthomas/units v0.0.0-20151022065526-2efee857e7cf h1:qet1QNfXsQxTZqLG4oE62mJzwPIB8+Tee4RNCL9ulrY=
github.com/alecthomas/units v0.0.0-20151022065526-2efee857e7cf/go.mod h1:ybxpYRFXyAe+OPACYpWeL0wqObRcbAqCMya13uyzqw0=
github.com/armon/circbuf v0.0.0-20150827004946-bbbad097214e/go.mod h1:3U/XgcO3hCbHZ8TKRvWD2dDTCfh9M9ya+I9JpbB7O8o=
github.com/armon/go-metrics v0.0.0-20180917152333-f0300d1749da/go.mod h1:Q73ZrmVTwzkszR9V5SSuryQ31EELlFMUz1kKyl939pY=
@@ -331,6 +333,7 @@
google.golang.org/grpc v1.23.1/go.mod h1:Y5yQAOtifL1yxbo5wqy6BxZv8vAUGQwXBOALyacEbxg=
google.golang.org/grpc v1.24.0 h1:vb/1TCsVn3DcJlQ0Gs1yB1pKI6Do2/QNwxdKqmc/b0s=
google.golang.org/grpc v1.24.0/go.mod h1:XDChyiUovWa60DnaeDeZmSW86xtLtjtZbwvSiRnRtcA=
+gopkg.in/alecthomas/kingpin.v2 v2.2.6 h1:jMFz6MfLP0/4fUyZle81rXUoxOBFi19VUFKVDOQfozc=
gopkg.in/alecthomas/kingpin.v2 v2.2.6/go.mod h1:FMv+mEhP44yOT+4EoQTLFTRgOQ1FBLkstjWtayDeSgw=
gopkg.in/check.v1 v0.0.0-20161208181325-20d25e280405/go.mod h1:Co6ibVJAznAaIkqp8huTwlJQCZ016jof/cbN4VW5Yz0=
gopkg.in/check.v1 v1.0.0-20180628173108-788fd7840127 h1:qIbj1fsPNlZgppZ+VLlY7N33q108Sa+fhmuc+sWQYwY=
diff --git a/ro_core/core/core.go b/ro_core/core/core.go
index da9fead..a125798 100644
--- a/ro_core/core/core.go
+++ b/ro_core/core/core.go
@@ -18,6 +18,7 @@
import (
"context"
+ "fmt"
"time"
@@ -60,7 +61,7 @@
}
// NewCore instantiates core service parameters
-func NewCore(id string, cf *config.ROCoreFlags, kvClient kvstore.Client) *Core {
+func NewCore(ctx context.Context, id string, cf *config.ROCoreFlags, kvClient kvstore.Client) *Core {
var core Core
core.instanceID = id
core.exitChannel = make(chan int, 1)
@@ -85,8 +86,7 @@
PathPrefix: "service/voltha"}
core.clusterDataRoot = model.NewRoot(&voltha.Voltha{}, &core.backend)
core.localDataRoot = model.NewRoot(&voltha.CoreInstance{}, &core.backend)
- core.clusterDataProxy = core.clusterDataRoot.CreateProxy(context.Background(), "/", false)
- core.localDataProxy = core.localDataRoot.CreateProxy(context.Background(), "/", false)
+
return &core
}
@@ -123,7 +123,8 @@
}
// Start will start core adapter services
-func (core *Core) Start(ctx context.Context) {
+func (core *Core) Start(ctx context.Context) error {
+ var err error
log.Info("starting-adaptercore", log.Fields{"coreId": core.instanceID})
// Wait until connection to KV Store is up
@@ -133,6 +134,16 @@
probe.UpdateStatusFromContext(ctx, "kv-store", probe.ServiceStatusRunning)
+ core.clusterDataProxy, err = core.clusterDataRoot.CreateProxy(context.Background(), "/", false)
+ if err != nil {
+ probe.UpdateStatusFromContext(ctx, "kv-store", probe.ServiceStatusNotReady)
+ return fmt.Errorf("Failed to create cluster data proxy")
+ }
+ core.localDataProxy, err = core.localDataRoot.CreateProxy(context.Background(), "/", false)
+ if err != nil {
+ probe.UpdateStatusFromContext(ctx, "kv-store", probe.ServiceStatusNotReady)
+ return fmt.Errorf("Failed to create local cluster data proxy")
+ }
core.genericMgr = newModelProxyManager(core.clusterDataProxy)
core.deviceMgr = newDeviceManager(core.clusterDataProxy, core.instanceID)
core.logicalDeviceMgr = newLogicalDeviceManager(core.deviceMgr, core.clusterDataProxy)
@@ -142,6 +153,7 @@
go core.monitorKvstoreLiveness(ctx)
log.Info("adaptercore-started")
+ return nil
}
// Stop will stop core services
diff --git a/ro_core/core/core_test.go b/ro_core/core/core_test.go
index d88a7de..02cdc84 100644
--- a/ro_core/core/core_test.go
+++ b/ro_core/core/core_test.go
@@ -91,10 +91,12 @@
func TestNewCore(t *testing.T) {
+ var ctx context.Context
+
roCoreFlgs, roC := makeTestNewCore()
assert.NotNil(t, roCoreFlgs)
assert.NotNil(t, roC)
- core := NewCore("ro_core", roCoreFlgs, roC.kvClient)
+ core := NewCore(ctx, "ro_core", roCoreFlgs, roC.kvClient)
assert.NotNil(t, core)
}
@@ -105,9 +107,10 @@
roCoreFlgs, roC := makeTestNewCore()
assert.NotNil(t, roCoreFlgs)
assert.NotNil(t, roC)
- core := NewCore("ro_core", roCoreFlgs, roC.kvClient)
+ core := NewCore(ctx, "ro_core", roCoreFlgs, roC.kvClient)
assert.NotNil(t, core)
- core.Start(ctx)
+ err := core.Start(ctx)
+ assert.Nil(t, err)
core.Stop(ctx)
}
diff --git a/ro_core/core/device_agent.go b/ro_core/core/device_agent.go
index 345e424..b056bec 100644
--- a/ro_core/core/device_agent.go
+++ b/ro_core/core/device_agent.go
@@ -59,7 +59,10 @@
defer agent.lockDevice.Unlock()
log.Debugw("starting-device-agent", log.Fields{"device": agent.lastData})
if loadFromDb {
- if device := agent.clusterDataProxy.Get(ctx, "/devices/"+agent.deviceID, 0, false, ""); device != nil {
+ if device, err := agent.clusterDataProxy.Get(ctx, "/devices/"+agent.deviceID, 0, false, ""); err != nil {
+ log.Errorw("failed-to-get-device", log.Fields{"error": err})
+ return err
+ } else if device != nil {
if d, ok := device.(*voltha.Device); ok {
agent.lastData = proto.Clone(d).(*voltha.Device)
}
@@ -86,7 +89,10 @@
func (agent *DeviceAgent) getDevice() (*voltha.Device, error) {
agent.lockDevice.Lock()
defer agent.lockDevice.Unlock()
- if device := agent.clusterDataProxy.Get(context.Background(), "/devices/"+agent.deviceID, 0, false, ""); device != nil {
+ if device, err := agent.clusterDataProxy.Get(context.Background(), "/devices/"+agent.deviceID, 0, false, ""); err != nil {
+ log.Errorw("failed-to-get-device", log.Fields{"error": err})
+ return nil, err
+ } else if device != nil {
if d, ok := device.(*voltha.Device); ok {
cloned := proto.Clone(d).(*voltha.Device)
return cloned, nil
diff --git a/ro_core/core/device_manager.go b/ro_core/core/device_manager.go
index 634566c..b73ec10 100644
--- a/ro_core/core/device_manager.go
+++ b/ro_core/core/device_manager.go
@@ -132,7 +132,10 @@
func (dMgr *DeviceManager) ListDevices() (*voltha.Devices, error) {
log.Debug("ListDevices")
result := &voltha.Devices{}
- if devices := dMgr.clusterDataProxy.List(context.Background(), "/devices", 0, false, ""); devices != nil {
+ if devices, err := dMgr.clusterDataProxy.List(context.Background(), "/devices", 0, false, ""); err != nil {
+ log.Errorw("failed-to-list-devices", log.Fields{"error": err})
+ return nil, err
+ } else if devices != nil {
for _, device := range devices.([]interface{}) {
// If device is not in memory then set it up
if !dMgr.IsDeviceInCache(device.(*voltha.Device).Id) {
diff --git a/ro_core/core/grpc_nbi_api_handler.go b/ro_core/core/grpc_nbi_api_handler.go
index a611337..0a73ff2 100644
--- a/ro_core/core/grpc_nbi_api_handler.go
+++ b/ro_core/core/grpc_nbi_api_handler.go
@@ -153,7 +153,12 @@
// ListDevices returns the contents of all devices known to the system
func (handler *APIHandler) ListDevices(ctx context.Context, empty *empty.Empty) (*voltha.Devices, error) {
log.Debug("ListDevices")
- return handler.deviceMgr.ListDevices()
+ devices, err := handler.deviceMgr.ListDevices()
+ if err != nil {
+ log.Errorw("failed-to-list-devices", log.Fields{"error": err})
+ return nil, err
+ }
+ return devices, nil
}
// ListDeviceIds returns the list of device ids managed by a voltha core
diff --git a/ro_core/core/grpc_nbi_api_handler_test.go b/ro_core/core/grpc_nbi_api_handler_test.go
index 3244fd3..0a95daa 100644
--- a/ro_core/core/grpc_nbi_api_handler_test.go
+++ b/ro_core/core/grpc_nbi_api_handler_test.go
@@ -29,6 +29,7 @@
)
func MakeTestGrpcNbiConfig() *Core {
+ var ctx context.Context
var core *Core
var roCoreFlgs *config.ROCoreFlags
var roC *roCore
@@ -44,7 +45,7 @@
cli, err := newKVClient("etcd", addr, 5)
if err == nil {
roC.kvClient = cli
- core = NewCore("ro_core", roCoreFlgs, roC.kvClient)
+ core = NewCore(ctx, "ro_core", roCoreFlgs, roC.kvClient)
}
}
}
diff --git a/ro_core/core/logical_device_agent.go b/ro_core/core/logical_device_agent.go
index 829aa6b..407511f 100644
--- a/ro_core/core/logical_device_agent.go
+++ b/ro_core/core/logical_device_agent.go
@@ -60,7 +60,10 @@
if loadFromDb {
// load from dB - the logical may not exist at this time. On error, just return and the calling function
// will destroy this agent.
- if logicalDevice := agent.clusterDataProxy.Get(ctx, "/logical_devices/"+agent.logicalDeviceID, 0, false, ""); logicalDevice != nil {
+ if logicalDevice, err := agent.clusterDataProxy.Get(ctx, "/logical_devices/"+agent.logicalDeviceID, 0, false, ""); err != nil {
+ log.Errorw("failed-to-get-logical-device", log.Fields{"error": err})
+ return err
+ } else if logicalDevice != nil {
if lDevice, ok := logicalDevice.(*voltha.LogicalDevice); ok {
agent.lastData = proto.Clone(lDevice).(*voltha.LogicalDevice)
}
@@ -88,7 +91,10 @@
log.Debug("GetLogicalDevice")
agent.lockLogicalDevice.Lock()
defer agent.lockLogicalDevice.Unlock()
- if logicalDevice := agent.clusterDataProxy.Get(context.Background(), "/logical_devices/"+agent.logicalDeviceID, 0, false, ""); logicalDevice != nil {
+ if logicalDevice, err := agent.clusterDataProxy.Get(context.Background(), "/logical_devices/"+agent.logicalDeviceID, 0, false, ""); err != nil {
+ log.Errorw("failed-to-get-logical-device", log.Fields{"error": err})
+ return nil, err
+ } else if logicalDevice != nil {
if lDevice, ok := logicalDevice.(*voltha.LogicalDevice); ok {
return lDevice, nil
}
diff --git a/ro_core/core/logical_device_agent_test.go b/ro_core/core/logical_device_agent_test.go
index 09de443..1685606 100644
--- a/ro_core/core/logical_device_agent_test.go
+++ b/ro_core/core/logical_device_agent_test.go
@@ -16,7 +16,9 @@
package core
import (
+ "context"
"github.com/opencord/voltha-go/ro_core/config"
+ "github.com/opencord/voltha-lib-go/v2/pkg/log"
"github.com/phayes/freeport"
"github.com/stretchr/testify/assert"
"strconv"
@@ -24,6 +26,7 @@
)
func MakeTestLogDevAgConfig() (*Core, error) {
+ var ctx context.Context
var core *Core
var roCoreFlgs *config.ROCoreFlags
var roC *roCore
@@ -34,6 +37,7 @@
roCoreFlgs = config.NewROCoreFlags()
roC = newROCore(roCoreFlgs)
+
if (roC != nil) && (roCoreFlgs != nil) {
addr := "127.0.0.1" + ":" + freePortStr
cli, err := newKVClient("etcd", addr, 5)
@@ -44,8 +48,7 @@
}
}
- core = NewCore("ro_core", roCoreFlgs, roC.kvClient)
-
+ core = NewCore(ctx, "ro_core", roCoreFlgs, roC.kvClient)
return core, nil
}
@@ -62,6 +65,12 @@
core, _ := MakeTestLogDevAgConfig()
assert.NotNil(t, core)
+ var err1 error
+ if core.clusterDataProxy, err1 = core.localDataRoot.CreateProxy(context.Background(), "/", false); err1 != nil {
+ log.Errorw("failed-to-create-cluster-proxy", log.Fields{"error": err1})
+ assert.NotNil(t, err1)
+ }
+
logDevMgr := newLogicalDeviceManager(core.deviceMgr, core.clusterDataProxy)
assert.NotNil(t, logDevMgr)
diff --git a/ro_core/core/logical_device_manager.go b/ro_core/core/logical_device_manager.go
index 97bc603..fc09f12 100644
--- a/ro_core/core/logical_device_manager.go
+++ b/ro_core/core/logical_device_manager.go
@@ -103,7 +103,11 @@
func (ldMgr *LogicalDeviceManager) listLogicalDevices() (*voltha.LogicalDevices, error) {
log.Debug("ListAllLogicalDevices")
result := &voltha.LogicalDevices{}
- if logicalDevices := ldMgr.clusterDataProxy.List(context.Background(), "/logical_devices", 0, false, ""); logicalDevices != nil {
+ if logicalDevices, err := ldMgr.clusterDataProxy.List(context.Background(), "/logical_devices", 0, false,
+ ""); err != nil {
+ log.Errorw("failed-to-list-devices", log.Fields{"error": err})
+ return nil, err
+ } else if logicalDevices != nil {
for _, logicalDevice := range logicalDevices.([]interface{}) {
result.Items = append(result.Items, logicalDevice.(*voltha.LogicalDevice))
}
diff --git a/ro_core/core/logical_device_manager_test.go b/ro_core/core/logical_device_manager_test.go
index e7b33bc..a53e4ec 100644
--- a/ro_core/core/logical_device_manager_test.go
+++ b/ro_core/core/logical_device_manager_test.go
@@ -22,6 +22,7 @@
"github.com/opencord/voltha-go/db/model"
"github.com/opencord/voltha-go/ro_core/config"
+ "github.com/opencord/voltha-lib-go/v2/pkg/log"
"github.com/opencord/voltha-protos/v2/go/openflow_13"
"github.com/opencord/voltha-protos/v2/go/voltha"
"github.com/stretchr/testify/assert"
@@ -30,9 +31,13 @@
func MakeTestNewCoreConfig() *Core {
var core Core
core.instanceID = "ro_core"
+ var err error
core.config = config.NewROCoreFlags()
core.clusterDataRoot = model.NewRoot(&voltha.Voltha{}, nil)
- core.clusterDataProxy = core.clusterDataRoot.CreateProxy(context.Background(), "/", false)
+ core.clusterDataProxy, err = core.clusterDataRoot.CreateProxy(context.Background(), "/", false)
+ if err != nil {
+ log.With(log.Fields{"error": err}).Fatal("Cannot create cluster data proxy")
+ }
core.genericMgr = newModelProxyManager(core.clusterDataProxy)
core.deviceMgr = newDeviceManager(core.clusterDataProxy, core.instanceID)
@@ -127,13 +132,18 @@
/*** Case: getLogicalDevice() is Success ***/
// Add Data
- if added := core.clusterDataProxy.Add(
+ added, err := core.clusterDataProxy.Add(
context.Background(),
"/logical_devices",
&voltha.LogicalDevice{
Id: "id",
},
- ""); added == nil {
+ "")
+ if err != nil {
+ log.Errorw("failed-to-add-logical-device", log.Fields{"error": err})
+ assert.NotNil(t, err)
+ }
+ if added == nil {
t.Error("Failed to add logical device")
}
ldAgent := newLogicalDeviceAgent("id", "device_id", ldMgr, core.deviceMgr, core.clusterDataProxy)
@@ -219,7 +229,7 @@
device := &voltha.Device{Id: "id", Root: true, ParentId: "parent_id"}
// Add Data
- if added := core.clusterDataProxy.Add(
+ added, err := core.clusterDataProxy.Add(
context.Background(),
"/logical_devices",
&voltha.LogicalDevice{
@@ -231,7 +241,12 @@
},
},
},
- ""); added == nil {
+ "")
+ if err != nil {
+ log.Errorw("failed-to-add-logical-device", log.Fields{"error": err})
+ assert.NotNil(t, err)
+ }
+ if added == nil {
t.Error("Failed to add logical device")
}
ldAgent := newLogicalDeviceAgent("parent_id", "device_id", ldMgr, core.deviceMgr, core.clusterDataProxy)
@@ -273,7 +288,7 @@
}
// Add Data
- if added := core.clusterDataProxy.Add(
+ added, err := core.clusterDataProxy.Add(
context.Background(),
"/logical_devices",
&voltha.LogicalDevice{
@@ -284,7 +299,12 @@
},
},
},
- ""); added == nil {
+ "")
+ if err != nil {
+ log.Errorw("failed-to-add-logical-device", log.Fields{"error": err})
+ assert.NotNil(t, err)
+ }
+ if added == nil {
t.Error("Failed to add logical device")
}
ldAgent := newLogicalDeviceAgent("id", "", ldMgr, core.deviceMgr, core.clusterDataProxy)
@@ -319,7 +339,7 @@
wantResult := &voltha.Flows{}
// Add Data
- if added := core.clusterDataProxy.Add(
+ added, err := core.clusterDataProxy.Add(
context.Background(),
"/logical_devices",
&voltha.LogicalDevice{
@@ -332,7 +352,12 @@
},
},
},
- ""); added == nil {
+ "")
+ if err != nil {
+ log.Errorw("failed-to-add-logical-device", log.Fields{"error": err})
+ assert.NotNil(t, err)
+ }
+ if added == nil {
t.Error("Failed to add logical device")
}
ldAgent := newLogicalDeviceAgent("id", "", ldMgr, core.deviceMgr, core.clusterDataProxy)
@@ -367,7 +392,7 @@
wantResult := &voltha.FlowGroups{}
// Add Data
- if added := core.clusterDataProxy.Add(
+ added, err := core.clusterDataProxy.Add(
context.Background(),
"/logical_devices",
&voltha.LogicalDevice{
@@ -382,7 +407,12 @@
},
},
},
- ""); added == nil {
+ "")
+ if err != nil {
+ log.Errorw("failed-to-add-logical-device", log.Fields{"error": err})
+ assert.NotNil(t, err)
+ }
+ if added == nil {
t.Error("Failed to add logical device")
}
ldAgent := newLogicalDeviceAgent("id", "", ldMgr, core.deviceMgr, core.clusterDataProxy)
@@ -417,7 +447,7 @@
wantResult := &voltha.LogicalPort{Id: "123"}
// Add Data
- if added := core.clusterDataProxy.Add(
+ added, err := core.clusterDataProxy.Add(
context.Background(),
"/logical_devices",
&voltha.LogicalDevice{
@@ -428,7 +458,12 @@
},
},
},
- ""); added == nil {
+ "")
+ if err != nil {
+ log.Errorw("failed-to-add-logical-device", log.Fields{"error": err})
+ assert.NotNil(t, err)
+ }
+ if added == nil {
t.Error("Failed to add logical device")
}
ldAgent := newLogicalDeviceAgent("id", "", ldMgr, core.deviceMgr, core.clusterDataProxy)
diff --git a/ro_core/core/model_proxy.go b/ro_core/core/model_proxy.go
index eb93e44..56233eb 100644
--- a/ro_core/core/model_proxy.go
+++ b/ro_core/core/model_proxy.go
@@ -58,7 +58,10 @@
log.Debugw("get-data", log.Fields{"path": path})
- if data := mp.rootProxy.Get(context.Background(), path, 1, false, ""); data != nil {
+ if data, err := mp.rootProxy.Get(context.Background(), path, 1, false, ""); err != nil {
+ log.Errorw("failed-to-retrieve-data-from-model-proxy", log.Fields{"error": err})
+ return nil, err
+ } else if data != nil {
return data, nil
}
return nil, status.Errorf(codes.NotFound, "data-path: %s", path)
diff --git a/ro_core/core/model_proxy_manager_test.go b/ro_core/core/model_proxy_manager_test.go
index 10411bf..c375f7d 100644
--- a/ro_core/core/model_proxy_manager_test.go
+++ b/ro_core/core/model_proxy_manager_test.go
@@ -18,6 +18,7 @@
import (
"context"
"github.com/opencord/voltha-go/db/model"
+ "github.com/opencord/voltha-lib-go/v2/pkg/log"
"github.com/opencord/voltha-protos/v2/go/voltha"
"github.com/stretchr/testify/assert"
"reflect"
@@ -26,7 +27,10 @@
func makeModelProxyManagerObj() *ModelProxyManager {
cdRoot := model.NewRoot(&voltha.Voltha{}, nil)
- cdProxy := cdRoot.CreateProxy(context.Background(), "/", false)
+ cdProxy, err := cdRoot.CreateProxy(context.Background(), "/", false)
+ if err != nil {
+ log.With(log.Fields{"error": err}).Fatal("Failed to create model proxy manager")
+ }
mpMgr := newModelProxyManager(cdProxy)
return mpMgr
}
@@ -103,7 +107,12 @@
assert.Nil(t, err0)
// Case 2: Found
- if added := mpMgr.clusterDataProxy.Add(context.Background(), "/adapters", &voltha.Adapter{Id: "id"}, ""); added == nil {
+ added, err := mpMgr.clusterDataProxy.Add(context.Background(), "/adapters", &voltha.Adapter{Id: "id"}, "")
+ if err != nil {
+ log.Errorw("failed-to-add-adapter-to-cluster-proxy", log.Fields{"error": err})
+ assert.NotNil(t, err)
+ }
+ if added == nil {
t.Error("Failed to add adapter")
}
result1, err1 := mpMgr.ListAdapters(context.Background())
@@ -135,7 +144,12 @@
assert.Nil(t, err0)
// Case 2: Found
- if added := mpMgr.clusterDataProxy.Add(context.Background(), "/device_types", &voltha.DeviceType{Id: "id"}, ""); added == nil {
+ added, err := mpMgr.clusterDataProxy.Add(context.Background(), "/device_types", &voltha.DeviceType{Id: "id"}, "")
+ if err != nil {
+ log.Errorw("failed-to-add-device-types-to-cluster-proxy", log.Fields{"error": err})
+ assert.NotNil(t, err)
+ }
+ if added == nil {
t.Error("Failed to add device type")
}
result1, err1 := mpMgr.ListDeviceTypes(context.Background())
@@ -160,7 +174,11 @@
assert.NotNil(t, err0)
// Case 2: Found
- if added := mpMgr.clusterDataProxy.Add(context.Background(), "/device_types", &voltha.DeviceType{Id: "id"}, ""); added == nil {
+ added, err := mpMgr.clusterDataProxy.Add(context.Background(), "/device_types", &voltha.DeviceType{Id: "id"}, "")
+ if err != nil {
+ log.Errorw("failed-to-add-adapter-to-device-types-proxy", log.Fields{"error": err})
+ assert.NotNil(t, err)
+ } else if added == nil {
t.Error("Failed to add device type")
}
result1, err1 := mpMgr.GetDeviceType(context.Background(), "id")
@@ -192,7 +210,12 @@
assert.Nil(t, err0)
// Case 2: Found
- if added := mpMgr.clusterDataProxy.Add(context.Background(), "/device_groups", &voltha.DeviceGroup{Id: "id"}, ""); added == nil {
+ added, err := mpMgr.clusterDataProxy.Add(context.Background(), "/device_groups", &voltha.DeviceGroup{Id: "id"}, "")
+ if err != nil {
+ log.Errorw("failed-to-add-device-groups-to-cluster-proxy", log.Fields{"error": err})
+ assert.NotNil(t, err)
+ }
+ if added == nil {
t.Error("Failed to add device group")
}
result1, err1 := mpMgr.ListDeviceGroups(context.Background())
@@ -217,7 +240,12 @@
assert.NotNil(t, err0)
// Case 2: Found
- if added := mpMgr.clusterDataProxy.Add(context.Background(), "/device_groups", &voltha.DeviceGroup{Id: "id"}, ""); added == nil {
+ added, err := mpMgr.clusterDataProxy.Add(context.Background(), "/device_groups", &voltha.DeviceGroup{Id: "id"}, "")
+ if err != nil {
+ log.Errorw("failed-to-add-device-groups-to-cluster-proxy", log.Fields{"error": err})
+ assert.NotNil(t, err)
+ }
+ if added == nil {
t.Error("Failed to add device group")
}
result1, err1 := mpMgr.GetDeviceGroup(context.Background(), "id")
@@ -249,7 +277,12 @@
assert.Nil(t, err0)
// Case 2: Found
- if added := mpMgr.clusterDataProxy.Add(context.Background(), "/event_filters", &voltha.EventFilter{Id: "id"}, ""); added == nil {
+ added, err := mpMgr.clusterDataProxy.Add(context.Background(), "/event_filters", &voltha.EventFilter{Id: "id"}, "")
+ if err != nil {
+ log.Errorw("failed-to-add-alarm-filters-to-cluster-proxy", log.Fields{"error": err})
+ assert.NotNil(t, err)
+ }
+ if added == nil {
t.Error("Failed to add event filter")
}
result1, err1 := mpMgr.ListEventFilters(context.Background())
@@ -279,7 +312,13 @@
}
assert.Nil(t, result0)
// Case 2: Found
- if added := mpMgr.clusterDataProxy.Add(context.Background(), "/event_filters", &voltha.EventFilter{Id: "id"}, ""); added == nil {
+ //added, err := mpMgr.clusterDataProxy.Add(context.Background(), "/alarm_filters", &voltha.EventFilter{Id: "id"}, "")
+ added, err := mpMgr.clusterDataProxy.Add(context.Background(), "/event_filters", &voltha.EventFilter{Id: "id"}, "")
+ if err != nil {
+ log.Errorw("failed-to-add-adapter-to-alarm-filter-to-proxy", log.Fields{"error": err})
+ assert.NotNil(t, err)
+ }
+ if added == nil {
t.Error("Failed to add event filter")
}
result1, err1 := mpMgr.ListEventFilters(context.Background())
diff --git a/ro_core/core/model_proxy_test.go b/ro_core/core/model_proxy_test.go
index a9caa00..5c26563 100644
--- a/ro_core/core/model_proxy_test.go
+++ b/ro_core/core/model_proxy_test.go
@@ -17,6 +17,8 @@
import (
"context"
+ "github.com/opencord/voltha-lib-go/v2/pkg/log"
+ "github.com/stretchr/testify/assert"
"reflect"
"testing"
@@ -31,22 +33,30 @@
basePath string
}
-func getModelProxyPathNotFound() *fields {
+func getModelProxyPathNotFound(t *testing.T) *fields {
var modelProxy fields
TestProxyRoot := model.NewRoot(&voltha.Voltha{}, nil)
- TestProxyRootProxy := TestProxyRoot.CreateProxy(context.Background(), "/", false)
+ TestProxyRootProxy, err := TestProxyRoot.CreateProxy(context.Background(), "/", false)
+ if err != nil {
+ log.Errorw("failed-to-create-test-proxy", log.Fields{"error": err})
+ assert.NotNil(t, err)
+ }
modelProxy.rootProxy = TestProxyRootProxy
modelProxy.basePath = "base_path"
return &modelProxy
}
-func getModelProxyPathFound() *fields {
+func getModelProxyPathFound(t *testing.T) *fields {
var modelProxy fields
TestProxyRoot := model.NewRoot(&voltha.Voltha{}, nil)
- TestProxyRootProxy := TestProxyRoot.CreateProxy(context.Background(), "/", false)
+ TestProxyRootProxy, err := TestProxyRoot.CreateProxy(context.Background(), "/", false)
+ if err != nil {
+ log.Errorw("failed-to-create-test-proxy", log.Fields{"error": err})
+ assert.NotNil(t, err)
+ }
modelProxy.rootProxy = TestProxyRootProxy
modelProxy.basePath = "devices"
@@ -88,8 +98,8 @@
fields *fields
wantErr error
}{
- {"Get-PathNotFound", getModelProxyPathNotFound(), status.Errorf(codes.NotFound, "data-path: base_path")},
- {"Get-PathFound", getModelProxyPathFound(), nil},
+ {"Get-PathNotFound", getModelProxyPathNotFound(t), status.Errorf(codes.NotFound, "data-path: base_path")},
+ {"Get-PathFound", getModelProxyPathFound(t), nil},
}
for _, tt := range tests {
t.Run(tt.name, func(t *testing.T) {
diff --git a/ro_core/main.go b/ro_core/main.go
index dc78302..b203bec 100644
--- a/ro_core/main.go
+++ b/ro_core/main.go
@@ -111,14 +111,16 @@
}
// Create the core service
- ro.core = c.NewCore(ro.config.InstanceID, ro.config, ro.kvClient)
+ ro.core = c.NewCore(ctx, ro.config.InstanceID, ro.config, ro.kvClient)
if p != nil {
p.UpdateStatus("kv-store", probe.ServiceStatusPrepared)
}
// start the core
- ro.core.Start(ctx)
+ if err := ro.core.Start(ctx); err != nil {
+ log.Fatalf("failed-to-start-rocore", log.Fields{"error": err})
+ }
}
func (ro *roCore) stop(ctx context.Context) {
diff --git a/rw_core/core/adapter_manager.go b/rw_core/core/adapter_manager.go
index b5f0131..3155ab8 100644
--- a/rw_core/core/adapter_manager.go
+++ b/rw_core/core/adapter_manager.go
@@ -110,42 +110,65 @@
return &adapterMgr
}
-func (aMgr *AdapterManager) start(ctx context.Context) {
+func (aMgr *AdapterManager) start(ctx context.Context) error {
log.Info("starting-adapter-manager")
// Load the existing adapterAgents and device types - this will also ensure the correct paths have been
// created if there are no data in the dB to start
- aMgr.loadAdaptersAndDevicetypesInMemory()
+ err := aMgr.loadAdaptersAndDevicetypesInMemory()
+ if err != nil {
+ log.Errorw("Failed-to-load-adapters-and-device-types-in-memeory", log.Fields{"error": err})
+ return err
+ }
//// Create the proxies
- aMgr.adapterProxy = aMgr.clusterDataProxy.CreateProxy(context.Background(), "/adapters", false)
- aMgr.deviceTypeProxy = aMgr.clusterDataProxy.CreateProxy(context.Background(), "/device_types", false)
+ aMgr.adapterProxy, err = aMgr.clusterDataProxy.CreateProxy(context.Background(), "/adapters", false)
+ if err != nil {
+ log.Errorw("Failed-to-create-adapter-proxy", log.Fields{"error": err})
+ return err
+ }
+ aMgr.deviceTypeProxy, err = aMgr.clusterDataProxy.CreateProxy(context.Background(), "/device_types", false)
+ if err != nil {
+ log.Errorw("Failed-to-create-device-proxy", log.Fields{"error": err})
+ return err
+ }
// Register the callbacks
aMgr.adapterProxy.RegisterCallback(model.POST_UPDATE, aMgr.adapterUpdated)
aMgr.deviceTypeProxy.RegisterCallback(model.POST_UPDATE, aMgr.deviceTypesUpdated)
probe.UpdateStatusFromContext(ctx, "adapter-manager", probe.ServiceStatusRunning)
log.Info("adapter-manager-started")
+ return nil
}
//loadAdaptersAndDevicetypesInMemory loads the existing set of adapters and device types in memory
-func (aMgr *AdapterManager) loadAdaptersAndDevicetypesInMemory() {
+func (aMgr *AdapterManager) loadAdaptersAndDevicetypesInMemory() error {
// Load the adapters
- if adaptersIf := aMgr.clusterDataProxy.List(context.Background(), "/adapters", 0, false, ""); adaptersIf != nil {
+ adaptersIf, err := aMgr.clusterDataProxy.List(context.Background(), "/adapters", 0, false, "")
+ if err != nil {
+ log.Errorw("Failed-to-list-adapters-from-cluster-data-proxy", log.Fields{"error": err})
+ return err
+ }
+ if adaptersIf != nil {
for _, adapterIf := range adaptersIf.([]interface{}) {
if adapter, ok := adapterIf.(*voltha.Adapter); ok {
log.Debugw("found-existing-adapter", log.Fields{"adapterId": adapter.Id})
- aMgr.addAdapter(adapter, false)
+ return aMgr.addAdapter(adapter, false)
}
}
} else {
log.Debug("no-existing-adapter-found")
// No adapter data. In order to have a proxy setup for that path let's create a fake adapter
- aMgr.addAdapter(&voltha.Adapter{Id: SentinelAdapterID}, true)
+ return aMgr.addAdapter(&voltha.Adapter{Id: SentinelAdapterID}, true)
}
// Load the device types
- if deviceTypesIf := aMgr.clusterDataProxy.List(context.Background(), "/device_types", 0, false, ""); deviceTypesIf != nil {
+ deviceTypesIf, err := aMgr.clusterDataProxy.List(context.Background(), "/device_types", 0, false, "")
+ if err != nil {
+ log.Errorw("Failed-to-list-device-types-from-cluster-data-proxy", log.Fields{"error": err})
+ return err
+ }
+ if deviceTypesIf != nil {
dTypes := &voltha.DeviceTypes{Items: []*voltha.DeviceType{}}
for _, deviceTypeIf := range deviceTypesIf.([]interface{}) {
if dType, ok := deviceTypeIf.(*voltha.DeviceType); ok {
@@ -153,12 +176,12 @@
dTypes.Items = append(dTypes.Items, dType)
}
}
- aMgr.addDeviceTypes(dTypes, false)
- } else {
- log.Debug("no-existing-device-type-found")
- // No device types data. In order to have a proxy setup for that path let's create a fake device type
- aMgr.addDeviceTypes(&voltha.DeviceTypes{Items: []*voltha.DeviceType{{Id: SentinelDevicetypeID, Adapter: SentinelAdapterID}}}, true)
+ return aMgr.addDeviceTypes(dTypes, false)
}
+
+ log.Debug("no-existing-device-type-found")
+ // No device types data. In order to have a proxy setup for that path let's create a fake device type
+ return aMgr.addDeviceTypes(&voltha.DeviceTypes{Items: []*voltha.DeviceType{{Id: SentinelDevicetypeID, Adapter: SentinelAdapterID}}}, true)
}
//updateAdaptersAndDevicetypesInMemory loads the existing set of adapters and device types in memory
@@ -180,7 +203,12 @@
}
// Update the adapters
- if adaptersIf := aMgr.clusterDataProxy.List(context.Background(), "/adapters", 0, false, ""); adaptersIf != nil {
+ adaptersIf, err := aMgr.clusterDataProxy.List(context.Background(), "/adapters", 0, false, "")
+ if err != nil {
+ log.Errorw("failed-to-list-adapters-from-cluster-proxy", log.Fields{"error": err})
+ return
+ }
+ if adaptersIf != nil {
for _, adapterIf := range adaptersIf.([]interface{}) {
if adapter, ok := adapterIf.(*voltha.Adapter); ok {
log.Debugw("found-existing-adapter", log.Fields{"adapterId": adapter.Id})
@@ -191,7 +219,12 @@
aMgr.lockdDeviceTypeToAdapterMap.Lock()
defer aMgr.lockdDeviceTypeToAdapterMap.Unlock()
// Update the device types
- if deviceTypesIf := aMgr.clusterDataProxy.List(context.Background(), "/device_types", 0, false, ""); deviceTypesIf != nil {
+ deviceTypesIf, err := aMgr.clusterDataProxy.List(context.Background(), "/device_types", 0, false, "")
+ if err != nil {
+ log.Errorw("Failed-to-list-device-types-in-cluster-data-proxy", log.Fields{"error": err})
+ return
+ }
+ if deviceTypesIf != nil {
dTypes := &voltha.DeviceTypes{Items: []*voltha.DeviceType{}}
for _, deviceTypeIf := range deviceTypesIf.([]interface{}) {
if dType, ok := deviceTypeIf.(*voltha.DeviceType); ok {
@@ -202,7 +235,7 @@
}
}
-func (aMgr *AdapterManager) addAdapter(adapter *voltha.Adapter, saveToDb bool) {
+func (aMgr *AdapterManager) addAdapter(adapter *voltha.Adapter, saveToDb bool) error {
aMgr.lockAdaptersMap.Lock()
defer aMgr.lockAdaptersMap.Unlock()
log.Debugw("adding-adapter", log.Fields{"adapter": adapter})
@@ -211,8 +244,18 @@
aMgr.adapterAgents[adapter.Id] = newAdapterAgent(clonedAdapter, nil)
if saveToDb {
// Save the adapter to the KV store - first check if it already exist
- if kvAdapter := aMgr.clusterDataProxy.Get(context.Background(), "/adapters/"+adapter.Id, 0, false, ""); kvAdapter == nil {
- if added := aMgr.clusterDataProxy.AddWithID(context.Background(), "/adapters", adapter.Id, clonedAdapter, ""); added == nil {
+ kvAdapter, err := aMgr.clusterDataProxy.Get(context.Background(), "/adapters/"+adapter.Id, 0, false, "")
+ if err != nil {
+ log.Errorw("failed-to-get-adapters-from-cluster-proxy", log.Fields{"error": err})
+ return err
+ }
+ if kvAdapter == nil {
+ added, err := aMgr.clusterDataProxy.AddWithID(context.Background(), "/adapters", adapter.Id, clonedAdapter, "")
+ if err != nil {
+ log.Errorw("failed-to-save-adapter-to-cluster-proxy", log.Fields{"error": err})
+ return err
+ }
+ if added == nil {
//TODO: Errors when saving to KV would require a separate go routine to be launched and try the saving again
log.Errorw("failed-to-save-adapter", log.Fields{"adapter": adapter})
} else {
@@ -221,11 +264,12 @@
}
}
}
+ return nil
}
-func (aMgr *AdapterManager) addDeviceTypes(deviceTypes *voltha.DeviceTypes, saveToDb bool) {
+func (aMgr *AdapterManager) addDeviceTypes(deviceTypes *voltha.DeviceTypes, saveToDb bool) error {
if deviceTypes == nil {
- return
+ return fmt.Errorf("no-device-type")
}
log.Debugw("adding-device-types", log.Fields{"deviceTypes": deviceTypes})
aMgr.lockAdaptersMap.Lock()
@@ -245,10 +289,20 @@
if saveToDb {
// Save the device types to the KV store as well
for _, deviceType := range deviceTypes.Items {
- if dType := aMgr.clusterDataProxy.Get(context.Background(), "/device_types/"+deviceType.Id, 0, false, ""); dType == nil {
+ dType, err := aMgr.clusterDataProxy.Get(context.Background(), "/device_types/"+deviceType.Id, 0, false, "")
+ if err != nil {
+ log.Errorw("Failed-to--device-types-from-cluster-data-proxy", log.Fields{"error": err})
+ return err
+ }
+ if dType == nil {
// Does not exist - save it
clonedDType := (proto.Clone(deviceType)).(*voltha.DeviceType)
- if added := aMgr.clusterDataProxy.AddWithID(context.Background(), "/device_types", deviceType.Id, clonedDType, ""); added == nil {
+ added, err := aMgr.clusterDataProxy.AddWithID(context.Background(), "/device_types", deviceType.Id, clonedDType, "")
+ if err != nil {
+ log.Errorw("Failed-to-add-device-types-to-cluster-data-proxy", log.Fields{"error": err})
+ return err
+ }
+ if added == nil {
log.Errorw("failed-to-save-deviceType", log.Fields{"deviceType": deviceType})
} else {
log.Debugw("device-type-saved-to-KV-Store", log.Fields{"deviceType": deviceType})
@@ -256,6 +310,7 @@
}
}
}
+ return nil
}
func (aMgr *AdapterManager) listAdapters(ctx context.Context) (*voltha.Adapters, error) {
@@ -315,7 +370,7 @@
aMgr.deviceTypeToAdapterMap[deviceType.Id] = deviceType.Adapter
}
-func (aMgr *AdapterManager) registerAdapter(adapter *voltha.Adapter, deviceTypes *voltha.DeviceTypes) *voltha.CoreInstance {
+func (aMgr *AdapterManager) registerAdapter(adapter *voltha.Adapter, deviceTypes *voltha.DeviceTypes) (*voltha.CoreInstance, error) {
log.Debugw("registerAdapter", log.Fields{"adapter": adapter, "deviceTypes": deviceTypes.Items})
if aMgr.getAdapter(adapter.Id) != nil {
@@ -326,15 +381,21 @@
log.Errorw("unable-to-restart-adapter", log.Fields{"error": err})
}
}()
- return &voltha.CoreInstance{InstanceId: aMgr.coreInstanceID}
+ return &voltha.CoreInstance{InstanceId: aMgr.coreInstanceID}, nil
}
// Save the adapter and the device types
- aMgr.addAdapter(adapter, true)
- aMgr.addDeviceTypes(deviceTypes, true)
+ if err := aMgr.addAdapter(adapter, true); err != nil {
+ log.Errorw("failed-to-add-adapter", log.Fields{"error": err})
+ return nil, err
+ }
+ if err := aMgr.addDeviceTypes(deviceTypes, true); err != nil {
+ log.Errorw("failed-to-add-device-types", log.Fields{"error": err})
+ return nil, err
+ }
log.Debugw("adapter-registered", log.Fields{"adapter": adapter.Id})
- return &voltha.CoreInstance{InstanceId: aMgr.coreInstanceID}
+ return &voltha.CoreInstance{InstanceId: aMgr.coreInstanceID}, nil
}
//getAdapterName returns the name of the device adapter that service this device type
diff --git a/rw_core/core/adapter_request_handler.go b/rw_core/core/adapter_request_handler.go
index 8f43643..0ffe8e1 100644
--- a/rw_core/core/adapter_request_handler.go
+++ b/rw_core/core/adapter_request_handler.go
@@ -150,7 +150,7 @@
if rhp.TestMode { // Execute only for test cases
return &voltha.CoreInstance{InstanceId: "CoreInstance"}, nil
}
- return rhp.adapterMgr.registerAdapter(adapter, deviceTypes), nil
+ return rhp.adapterMgr.registerAdapter(adapter, deviceTypes)
}
// GetDevice returns device info
diff --git a/rw_core/core/core.go b/rw_core/core/core.go
index ef08402..cb23586 100644
--- a/rw_core/core/core.go
+++ b/rw_core/core/core.go
@@ -18,6 +18,7 @@
import (
"context"
+ "fmt"
"time"
"github.com/opencord/voltha-go/db/model"
@@ -63,7 +64,7 @@
}
// NewCore creates instance of rw core
-func NewCore(id string, cf *config.RWCoreFlags, kvClient kvstore.Client, kafkaClient kafka.Client) *Core {
+func NewCore(ctx context.Context, id string, cf *config.RWCoreFlags, kvClient kvstore.Client, kafkaClient kafka.Client) *Core {
var core Core
core.instanceID = id
core.exitChannel = make(chan int, 1)
@@ -86,13 +87,11 @@
PathPrefix: cf.KVStoreDataPrefix}
core.clusterDataRoot = model.NewRoot(&voltha.Voltha{}, &core.backend)
core.localDataRoot = model.NewRoot(&voltha.CoreInstance{}, &core.backend)
- core.clusterDataProxy = core.clusterDataRoot.CreateProxy(context.Background(), "/", false)
- core.localDataProxy = core.localDataRoot.CreateProxy(context.Background(), "/", false)
return &core
}
// Start brings up core services
-func (core *Core) Start(ctx context.Context) {
+func (core *Core) Start(ctx context.Context) error {
// If the context has a probe then fetch it and register our services
var p *probe.Probe
@@ -119,6 +118,18 @@
if p != nil {
p.UpdateStatus("kv-store", probe.ServiceStatusRunning)
}
+ var err error
+
+ core.clusterDataProxy, err = core.clusterDataRoot.CreateProxy(context.Background(), "/", false)
+ if err != nil {
+ probe.UpdateStatusFromContext(ctx, "kv-store", probe.ServiceStatusNotReady)
+ return fmt.Errorf("Failed to create cluster data proxy")
+ }
+ core.localDataProxy, err = core.localDataRoot.CreateProxy(context.Background(), "/", false)
+ if err != nil {
+ probe.UpdateStatusFromContext(ctx, "kv-store", probe.ServiceStatusNotReady)
+ return fmt.Errorf("Failed to create local data proxy")
+ }
// core.kmp must be created before deviceMgr and adapterMgr, as they will make
// private copies of the poiner to core.kmp.
@@ -152,6 +163,7 @@
"service/voltha/owns_device", 10)
log.Info("core-services-started")
+ return nil
}
// Stop brings down core services
@@ -415,7 +427,10 @@
func (core *Core) startAdapterManager(ctx context.Context) {
log.Info("Adapter-Manager-Starting...")
- core.adapterMgr.start(ctx)
+ err := core.adapterMgr.start(ctx)
+ if err != nil {
+ log.Fatalf("failed-to-start-adapter-manager: error %v ", err)
+ }
log.Info("Adapter-Manager-Started")
}
diff --git a/rw_core/core/device_agent.go b/rw_core/core/device_agent.go
index ca3ffbb..8cbc63a 100755
--- a/rw_core/core/device_agent.go
+++ b/rw_core/core/device_agent.go
@@ -88,7 +88,12 @@
log.Debugw("starting-device-agent", log.Fields{"deviceId": agent.deviceID})
if deviceToCreate == nil {
// Load the existing device
- if loadedDevice := agent.clusterDataProxy.Get(ctx, "/devices/"+agent.deviceID, 1, true, ""); loadedDevice != nil {
+ loadedDevice, err := agent.clusterDataProxy.Get(ctx, "/devices/"+agent.deviceID, 1, true, "")
+ if err != nil {
+ log.Errorw("failed-to-get-from-cluster-data-proxy", log.Fields{"error": err})
+ return nil, err
+ }
+ if loadedDevice != nil {
var ok bool
if device, ok = loadedDevice.(*voltha.Device); ok {
agent.deviceType = device.Adapter
@@ -119,14 +124,22 @@
}
// Add the initial device to the local model
- if added := agent.clusterDataProxy.AddWithID(ctx, "/devices", agent.deviceID, device, ""); added == nil {
+ added, err := agent.clusterDataProxy.AddWithID(ctx, "/devices", agent.deviceID, device, "")
+ if err != nil {
+ log.Errorw("failed-to-save-devices-to-cluster-proxy", log.Fields{"error": err})
+ return nil, err
+ }
+ if added == nil {
log.Errorw("failed-to-add-device", log.Fields{"deviceId": agent.deviceID})
return nil, status.Errorf(codes.Aborted, "failed-adding-device-%s", agent.deviceID)
}
agent.device = proto.Clone(device).(*voltha.Device)
}
-
- agent.deviceProxy = agent.clusterDataProxy.CreateProxy(ctx, "/devices/"+agent.deviceID, false)
+ var err error
+ if agent.deviceProxy, err = agent.clusterDataProxy.CreateProxy(ctx, "/devices/"+agent.deviceID, false); err != nil {
+ log.Errorw("failed-to-add-devices-to-cluster-proxy", log.Fields{"error": err})
+ return nil, err
+ }
agent.deviceProxy.RegisterCallback(model.POST_UPDATE, agent.processUpdate)
log.Debugw("device-agent-started", log.Fields{"deviceId": agent.deviceID})
@@ -143,7 +156,12 @@
agent.deviceProxy.UnregisterCallback(model.POST_UPDATE, agent.processUpdate)
// Remove the device from the KV store
- if removed := agent.clusterDataProxy.Remove(ctx, "/devices/"+agent.deviceID, ""); removed == nil {
+ removed, err := agent.clusterDataProxy.Remove(ctx, "/devices/"+agent.deviceID, "")
+ if err != nil {
+ log.Errorw("Failed-to-remove-device-from-cluster-data-proxy", log.Fields{"error": err})
+ return
+ }
+ if removed == nil {
log.Debugw("device-already-removed", log.Fields{"id": agent.deviceID})
}
agent.exitChannel <- 1
@@ -157,7 +175,12 @@
defer agent.lockDevice.Unlock()
log.Debug("reconciling-device-agent-devicetype")
// TODO: context timeout
- if device := agent.clusterDataProxy.Get(context.Background(), "/devices/"+agent.deviceID, 1, true, ""); device != nil {
+ device, err := agent.clusterDataProxy.Get(context.Background(), "/devices/"+agent.deviceID, 1, true, "")
+ if err != nil {
+ log.Errorw("Failed to get device info from cluster data proxy", log.Fields{"error": err})
+ return
+ }
+ if device != nil {
if d, ok := device.(*voltha.Device); ok {
agent.deviceType = d.Adapter
agent.device = proto.Clone(d).(*voltha.Device)
@@ -743,7 +766,10 @@
cloned.PmConfigs = proto.Clone(pmConfigs).(*voltha.PmConfigs)
// Store the device
updateCtx := context.WithValue(context.Background(), model.RequestTimestamp, time.Now().UnixNano())
- afterUpdate := agent.clusterDataProxy.Update(updateCtx, "/devices/"+agent.deviceID, cloned, false, "")
+ afterUpdate, err := agent.clusterDataProxy.Update(updateCtx, "/devices/"+agent.deviceID, cloned, false, "")
+ if err != nil {
+ return status.Errorf(codes.Internal, "%s", agent.deviceID)
+ }
if afterUpdate == nil {
return status.Errorf(codes.Internal, "%s", agent.deviceID)
}
@@ -1331,7 +1357,11 @@
// It is an internal helper function.
func (agent *DeviceAgent) updateDeviceInStoreWithoutLock(device *voltha.Device, strict bool, txid string) error {
updateCtx := context.WithValue(context.Background(), model.RequestTimestamp, time.Now().UnixNano())
- if afterUpdate := agent.clusterDataProxy.Update(updateCtx, "/devices/"+agent.deviceID, device, strict, txid); afterUpdate == nil {
+ afterUpdate, err := agent.clusterDataProxy.Update(updateCtx, "/devices/"+agent.deviceID, device, strict, txid)
+ if err != nil {
+ return status.Errorf(codes.Internal, "failed-update-device:%s", agent.deviceID)
+ }
+ if afterUpdate == nil {
return status.Errorf(codes.Internal, "failed-update-device:%s", agent.deviceID)
}
log.Debugw("updated-device-in-store", log.Fields{"deviceId: ": agent.deviceID})
diff --git a/rw_core/core/device_agent_test.go b/rw_core/core/device_agent_test.go
index 8200ae7..b00c42c 100755
--- a/rw_core/core/device_agent_test.go
+++ b/rw_core/core/device_agent_test.go
@@ -112,8 +112,11 @@
cfg.GrpcHost = "127.0.0.1"
setCoreCompeteMode(inCompeteMode)
client := setupKVClient(cfg, dat.coreInstanceID)
- dat.core = NewCore(dat.coreInstanceID, cfg, client, dat.kClient)
- dat.core.Start(context.Background())
+ dat.core = NewCore(context.Background(), dat.coreInstanceID, cfg, client, dat.kClient)
+ err = dat.core.Start(context.Background())
+ if err != nil {
+ log.Fatal("Cannot start core")
+ }
}
func (dat *DATest) stopAll() {
diff --git a/rw_core/core/device_manager.go b/rw_core/core/device_manager.go
index a876bbe..7bb869f 100755
--- a/rw_core/core/device_manager.go
+++ b/rw_core/core/device_manager.go
@@ -155,7 +155,13 @@
}
func (dMgr *DeviceManager) createDevice(ctx context.Context, device *voltha.Device, ch chan interface{}) {
- if dMgr.isParentDeviceExist(device) {
+ deviceExist, err := dMgr.isParentDeviceExist(device)
+ if err != nil {
+ log.Errorf("Failed to fetch parent device info")
+ sendResponse(ctx, ch, err)
+ return
+ }
+ if deviceExist {
log.Errorf("Device is Pre-provisioned already with same IP-Port or MAC Address")
sendResponse(ctx, ch, errors.New("Device is already pre-provisioned"))
return
@@ -167,10 +173,10 @@
// Create and start a device agent for that device
agent := newDeviceAgent(dMgr.adapterProxy, device, dMgr, dMgr.clusterDataProxy, dMgr.defaultTimeout)
dMgr.addDeviceAgentToMap(agent)
- device, err := agent.start(ctx, device)
+ device, err = agent.start(ctx, device)
if err != nil {
log.Errorf("Failed to start device")
- sendResponse(ctx, ch, errors.New("Failed to start device"))
+ sendResponse(ctx, ch, err)
return
}
@@ -394,7 +400,12 @@
func (dMgr *DeviceManager) ListDevices() (*voltha.Devices, error) {
log.Debug("ListDevices")
result := &voltha.Devices{}
- if devices := dMgr.clusterDataProxy.List(context.Background(), "/devices", 0, false, ""); devices != nil {
+ devices, err := dMgr.clusterDataProxy.List(context.Background(), "/devices", 0, false, "")
+ if err != nil {
+ log.Errorw("failed-to-list-devices-from-cluster-proxy", log.Fields{"error": err})
+ return nil, err
+ }
+ if devices != nil {
for _, device := range devices.([]interface{}) {
// If device is not in memory then set it up
if !dMgr.IsDeviceInCache(device.(*voltha.Device).Id) {
@@ -415,27 +426,37 @@
}
//isParentDeviceExist checks whether device is already preprovisioned.
-func (dMgr *DeviceManager) isParentDeviceExist(newDevice *voltha.Device) bool {
+func (dMgr *DeviceManager) isParentDeviceExist(newDevice *voltha.Device) (bool, error) {
hostPort := newDevice.GetHostAndPort()
- if devices := dMgr.clusterDataProxy.List(context.Background(), "/devices", 0, false, ""); devices != nil {
+ devices, err := dMgr.clusterDataProxy.List(context.Background(), "/devices", 0, false, "")
+ if err != nil {
+ log.Errorw("Failed to list devices from cluster data proxy", log.Fields{"error": err})
+ return false, err
+ }
+ if devices != nil {
for _, device := range devices.([]interface{}) {
if !device.(*voltha.Device).Root {
continue
}
if hostPort != "" && hostPort == device.(*voltha.Device).GetHostAndPort() {
- return true
+ return true, nil
}
if newDevice.MacAddress != "" && newDevice.MacAddress == device.(*voltha.Device).MacAddress {
- return true
+ return true, nil
}
}
}
- return false
+ return false, nil
}
//getDeviceFromModelretrieves the device data from the model.
func (dMgr *DeviceManager) getDeviceFromModel(deviceID string) (*voltha.Device, error) {
- if device := dMgr.clusterDataProxy.Get(context.Background(), "/devices/"+deviceID, 0, false, ""); device != nil {
+ device, err := dMgr.clusterDataProxy.Get(context.Background(), "/devices/"+deviceID, 0, false, "")
+ if err != nil {
+ log.Errorw("failed-to-get-device-info-from-cluster-proxy", log.Fields{"error": err})
+ return nil, err
+ }
+ if device != nil {
if d, ok := device.(*voltha.Device); ok {
return d, nil
}
@@ -938,7 +959,12 @@
if deviceType == "" && vendorID != "" {
log.Debug("device-type-is-nil-fetching-device-type")
- if deviceTypesIf := dMgr.adapterMgr.clusterDataProxy.List(context.Background(), "/device_types", 0, false, ""); deviceTypesIf != nil {
+ deviceTypesIf, err := dMgr.adapterMgr.clusterDataProxy.List(context.Background(), "/device_types", 0, false, "")
+ if err != nil {
+ log.Errorw("failed-to-get-device-type-info", log.Fields{"error": err})
+ return nil, err
+ }
+ if deviceTypesIf != nil {
OLoop:
for _, deviceTypeIf := range deviceTypesIf.([]interface{}) {
if dType, ok := deviceTypeIf.(*voltha.DeviceType); ok {
diff --git a/rw_core/core/grpc_nbi_api_handler.go b/rw_core/core/grpc_nbi_api_handler.go
index 36cb647..52f8c3b 100755
--- a/rw_core/core/grpc_nbi_api_handler.go
+++ b/rw_core/core/grpc_nbi_api_handler.go
@@ -352,7 +352,12 @@
// ListDevices retrieves the latest devices from the data model
func (handler *APIHandler) ListDevices(ctx context.Context, empty *empty.Empty) (*voltha.Devices, error) {
log.Debug("ListDevices")
- return handler.deviceMgr.ListDevices()
+ devices, err := handler.deviceMgr.ListDevices()
+ if err != nil {
+ log.Errorw("Failed to list devices", log.Fields{"error": err})
+ return nil, err
+ }
+ return devices, nil
}
// ListDeviceIds returns the list of device ids managed by a voltha core
@@ -459,7 +464,7 @@
func (handler *APIHandler) CreateDevice(ctx context.Context, device *voltha.Device) (*voltha.Device, error) {
if device.MacAddress == "" && device.GetHostAndPort() == "" {
log.Errorf("No Device Info Present")
- return &voltha.Device{}, errors.New("No Device Info Present; MAC or HOSTIP&PORT")
+ return &voltha.Device{}, errors.New("no-device-info-present; MAC or HOSTIP&PORT")
}
log.Debugw("create-device", log.Fields{"device": *device})
if isTestMode(ctx) {
@@ -482,7 +487,8 @@
case res := <-ch:
if res != nil {
if err, ok := res.(error); ok {
- return &voltha.Device{}, err
+ log.Errorw("create-device-failed", log.Fields{"error": err})
+ return nil, err
}
if d, ok := res.(*voltha.Device); ok {
_, err := handler.core.deviceOwnership.OwnedByMe(&utils.DeviceID{ID: d.Id})
diff --git a/rw_core/core/grpc_nbi_api_handler_test.go b/rw_core/core/grpc_nbi_api_handler_test.go
index e9499e3..4acb8aa 100755
--- a/rw_core/core/grpc_nbi_api_handler_test.go
+++ b/rw_core/core/grpc_nbi_api_handler_test.go
@@ -69,6 +69,8 @@
}
func (nb *NBTest) startCore(inCompeteMode bool) {
+ ctx, cancel := context.WithTimeout(context.Background(), 1*time.Second)
+ defer cancel()
cfg := config.NewRWCoreFlags()
cfg.CorePairTopic = "rw_core"
cfg.DefaultRequestTimeout = nb.defaultTimeout.Nanoseconds() / 1000000 //TODO: change when Core changes to Duration
@@ -82,11 +84,14 @@
cfg.GrpcHost = "127.0.0.1"
setCoreCompeteMode(inCompeteMode)
client := setupKVClient(cfg, nb.coreInstanceID)
- nb.core = NewCore(nb.coreInstanceID, cfg, client, nb.kClient)
- nb.core.Start(context.Background())
+ nb.core = NewCore(ctx, nb.coreInstanceID, cfg, client, nb.kClient)
+ err = nb.core.Start(context.Background())
+ if err != nil {
+ log.Fatal("Cannot start core")
+ }
}
-func (nb *NBTest) createAndregisterAdapters() {
+func (nb *NBTest) createAndregisterAdapters(t *testing.T) {
// Setup the mock OLT adapter
oltAdapter, err := createMockAdapter(OltAdapter, nb.kClient, nb.coreInstanceID, coreName, nb.oltAdapterName)
if err != nil {
@@ -103,7 +108,10 @@
}
types := []*voltha.DeviceType{{Id: nb.oltAdapterName, Adapter: nb.oltAdapterName, AcceptsAddRemoveFlowUpdates: true}}
deviceTypes := &voltha.DeviceTypes{Items: types}
- nb.core.adapterMgr.registerAdapter(registrationData, deviceTypes)
+ if _, err := nb.core.adapterMgr.registerAdapter(registrationData, deviceTypes); err != nil {
+ log.Errorw("failed-to-register-adapter", log.Fields{"error": err})
+ assert.NotNil(t, err)
+ }
// Setup the mock ONU adapter
if _, err := createMockAdapter(OnuAdapter, nb.kClient, nb.coreInstanceID, coreName, nb.onuAdapterName); err != nil {
@@ -117,7 +125,10 @@
}
types = []*voltha.DeviceType{{Id: nb.onuAdapterName, Adapter: nb.onuAdapterName, AcceptsAddRemoveFlowUpdates: true}}
deviceTypes = &voltha.DeviceTypes{Items: types}
- nb.core.adapterMgr.registerAdapter(registrationData, deviceTypes)
+ if _, err := nb.core.adapterMgr.registerAdapter(registrationData, deviceTypes); err != nil {
+ log.Errorw("failed-to-register-adapter", log.Fields{"error": err})
+ assert.NotNil(t, err)
+ }
}
func (nb *NBTest) stopAll() {
@@ -314,7 +325,7 @@
// Try to create a device with invalid data
_, err = nbi.CreateDevice(getContext(), &voltha.Device{Type: nb.oltAdapterName})
assert.NotNil(t, err)
- assert.Equal(t, "No Device Info Present; MAC or HOSTIP&PORT", err.Error())
+ assert.Equal(t, "no-device-info-present; MAC or HOSTIP&PORT", err.Error())
// Ensure we only have 1 device in the Core
devices, err := nbi.ListDevices(getContext(), &empty.Empty{})
@@ -477,7 +488,7 @@
nb.testCoreWithoutData(t, nbi)
// Create/register the adapters
- nb.createAndregisterAdapters()
+ nb.createAndregisterAdapters(t)
// 2. Test adapter registration
nb.testAdapterRegistration(t, nbi)
diff --git a/rw_core/core/logical_device_agent.go b/rw_core/core/logical_device_agent.go
index e0aac9d..b85d572 100644
--- a/rw_core/core/logical_device_agent.go
+++ b/rw_core/core/logical_device_agent.go
@@ -88,6 +88,7 @@
func (agent *LogicalDeviceAgent) start(ctx context.Context, loadFromdB bool) error {
log.Infow("starting-logical_device-agent", log.Fields{"logicaldeviceId": agent.logicalDeviceID, "loadFromdB": loadFromdB})
var ld *voltha.LogicalDevice
+ var err error
if !loadFromdB {
//Build the logical device based on information retrieved from the device adapter
var switchCap *ic.SwitchCapability
@@ -113,7 +114,13 @@
agent.lockLogicalDevice.Lock()
// Save the logical device
- if added := agent.clusterDataProxy.AddWithID(ctx, "/logical_devices", ld.Id, ld, ""); added == nil {
+ added, err := agent.clusterDataProxy.AddWithID(ctx, "/logical_devices", ld.Id, ld, "")
+ if err != nil {
+ log.Errorw("failed-to-save-logical-devices-to-cluster-proxy", log.Fields{"error": err})
+ agent.lockLogicalDevice.Unlock()
+ return err
+ }
+ if added == nil {
log.Errorw("failed-to-add-logical-device", log.Fields{"logicaldeviceId": agent.logicalDeviceID})
} else {
log.Debugw("logicaldevice-created", log.Fields{"logicaldeviceId": agent.logicalDeviceID})
@@ -134,7 +141,10 @@
// load from dB - the logical may not exist at this time. On error, just return and the calling function
// will destroy this agent.
agent.lockLogicalDevice.Lock()
- logicalDevice := agent.clusterDataProxy.Get(context.Background(), "/logical_devices/"+agent.logicalDeviceID, 0, true, "")
+ logicalDevice, err := agent.clusterDataProxy.Get(context.Background(), "/logical_devices/"+agent.logicalDeviceID, 0, true, "")
+ if err != nil {
+ return status.Errorf(codes.NotFound, "logical_device-%s", agent.logicalDeviceID)
+ }
ld, ok := logicalDevice.(*voltha.LogicalDevice)
if !ok {
agent.lockLogicalDevice.Unlock()
@@ -154,23 +164,38 @@
agent.lockLogicalDevice.Lock()
defer agent.lockLogicalDevice.Unlock()
- agent.flowProxy = agent.clusterDataProxy.CreateProxy(
+ agent.flowProxy, err = agent.clusterDataProxy.CreateProxy(
ctx,
fmt.Sprintf("/logical_devices/%s/flows", agent.logicalDeviceID),
false)
- agent.meterProxy = agent.clusterDataProxy.CreateProxy(
+ if err != nil {
+ log.Errorw("failed-to-create-flow-proxy", log.Fields{"error": err})
+ return err
+ }
+ agent.meterProxy, err = agent.clusterDataProxy.CreateProxy(
ctx,
fmt.Sprintf("/logical_devices/%s/meters", agent.logicalDeviceID),
false)
- agent.groupProxy = agent.clusterDataProxy.CreateProxy(
+ if err != nil {
+ log.Errorw("failed-to-create-meter-proxy", log.Fields{"error": err})
+ return err
+ }
+ agent.groupProxy, err = agent.clusterDataProxy.CreateProxy(
ctx,
fmt.Sprintf("/logical_devices/%s/flow_groups", agent.logicalDeviceID),
false)
- agent.ldProxy = agent.clusterDataProxy.CreateProxy(
+ if err != nil {
+ log.Errorw("failed-to-create-group-proxy", log.Fields{"error": err})
+ return err
+ }
+ agent.ldProxy, err = agent.clusterDataProxy.CreateProxy(
ctx,
fmt.Sprintf("/logical_devices/%s", agent.logicalDeviceID),
false)
-
+ if err != nil {
+ log.Errorw("failed-to-create-logical-device-proxy", log.Fields{"error": err})
+ return err
+ }
// TODO: Use a port proxy once the POST_ADD is fixed
if agent.ldProxy != nil {
agent.ldProxy.RegisterCallback(model.POST_UPDATE, agent.portUpdated)
@@ -187,19 +212,23 @@
}
// stop stops the logical devuce agent. This removes the logical device from the data model.
-func (agent *LogicalDeviceAgent) stop(ctx context.Context) {
+func (agent *LogicalDeviceAgent) stop(ctx context.Context) error {
log.Info("stopping-logical_device-agent")
agent.lockLogicalDevice.Lock()
defer agent.lockLogicalDevice.Unlock()
//Remove the logical device from the model
- if removed := agent.clusterDataProxy.Remove(ctx, "/logical_devices/"+agent.logicalDeviceID, ""); removed == nil {
+ if removed, err := agent.clusterDataProxy.Remove(ctx, "/logical_devices/"+agent.logicalDeviceID, ""); err != nil {
+ log.Errorw("failed-to-remove-device", log.Fields{"error": err})
+ return err
+ } else if removed == nil {
log.Errorw("failed-to-remove-logical-device", log.Fields{"logicaldeviceId": agent.logicalDeviceID})
} else {
log.Debugw("logicaldevice-removed", log.Fields{"logicaldeviceId": agent.logicalDeviceID})
}
agent.exitChannel <- 1
log.Info("logical_device-agent-stopped")
+ return nil
}
// GetLogicalDevice returns the latest logical device data
@@ -246,7 +275,6 @@
// ListLogicalDevicePorts returns logical device ports
func (agent *LogicalDeviceAgent) ListLogicalDevicePorts() *voltha.LogicalPorts {
log.Debug("ListLogicalDevicePorts")
-
logicalDevice := agent.GetLogicalDevice()
lPorts := make([]*voltha.LogicalPort, 0)
lPorts = append(lPorts, logicalDevice.Ports...)
@@ -491,7 +519,11 @@
//updateLogicalDeviceWithoutLock updates the model with the logical device. It clones the logicaldevice before saving it
func (agent *LogicalDeviceAgent) updateLogicalDeviceWithoutLock(logicalDevice *voltha.LogicalDevice) error {
updateCtx := context.WithValue(context.Background(), model.RequestTimestamp, time.Now().UnixNano())
- afterUpdate := agent.clusterDataProxy.Update(updateCtx, "/logical_devices/"+agent.logicalDeviceID, logicalDevice, false, "")
+ afterUpdate, err := agent.clusterDataProxy.Update(updateCtx, "/logical_devices/"+agent.logicalDeviceID, logicalDevice, false, "")
+ if err != nil {
+ log.Errorw("failed-to-update-logical-devices-to-cluster-proxy", log.Fields{"error": err})
+ return err
+ }
if afterUpdate == nil {
return status.Errorf(codes.Internal, "failed-updating-logical-device:%s", agent.logicalDeviceID)
}
@@ -945,7 +977,7 @@
}
if err := agent.updateLogicalDeviceFlowsWithoutLock(&ofp.Flows{Items: toKeep}); err != nil {
- log.Errorw("Cannot-update-flows", log.Fields{"logicalDeviceId": agent.logicalDeviceID})
+ log.Errorw("cannot-update-flows", log.Fields{"logicalDeviceId": agent.logicalDeviceID})
return err
}
}
@@ -1068,7 +1100,7 @@
if changedFlow {
var flowMetadata voltha.FlowMetadata
if err := agent.GetMeterConfig(flowsToDelete, meters, &flowMetadata); err != nil {
- log.Error("Meter-referred-in-flows-not-present")
+ log.Error("meter-referred-in-flows-not-present")
return err
}
deviceRules := agent.flowDecomposer.DecomposeRules(agent, ofp.Flows{Items: flowsToDelete}, ofp.FlowGroups{})
@@ -1080,7 +1112,7 @@
}
if err := agent.updateLogicalDeviceFlowsWithoutLock(&ofp.Flows{Items: flows}); err != nil {
- log.Errorw("Cannot-update-flows", log.Fields{"logicalDeviceId": agent.logicalDeviceID})
+ log.Errorw("cannot-update-flows", log.Fields{"logicalDeviceId": agent.logicalDeviceID})
return err
}
}
@@ -1124,7 +1156,7 @@
}
if err := agent.updateLogicalDeviceFlowGroupsWithoutLock(&ofp.FlowGroups{Items: groups}); err != nil {
- log.Errorw("Cannot-update-group", log.Fields{"logicalDeviceId": agent.logicalDeviceID})
+ log.Errorw("cannot-update-group", log.Fields{"logicalDeviceId": agent.logicalDeviceID})
return err
}
} else {
@@ -1173,13 +1205,13 @@
if groupsChanged {
if err := agent.updateLogicalDeviceFlowGroupsWithoutLock(&ofp.FlowGroups{Items: groups}); err != nil {
- log.Errorw("Cannot-update-group", log.Fields{"logicalDeviceId": agent.logicalDeviceID})
+ log.Errorw("cannot-update-group", log.Fields{"logicalDeviceId": agent.logicalDeviceID})
return err
}
}
if flowsChanged {
if err := agent.updateLogicalDeviceFlowsWithoutLock(&ofp.Flows{Items: flows}); err != nil {
- log.Errorw("Cannot-update-flow", log.Fields{"logicalDeviceId": agent.logicalDeviceID})
+ log.Errorw("cannot-update-flow", log.Fields{"logicalDeviceId": agent.logicalDeviceID})
return err
}
}
diff --git a/rw_core/core/logical_device_agent_test.go b/rw_core/core/logical_device_agent_test.go
index b5789cd..f8f9348 100644
--- a/rw_core/core/logical_device_agent_test.go
+++ b/rw_core/core/logical_device_agent_test.go
@@ -446,6 +446,7 @@
}
func (lda *LDATest) startCore(inCompeteMode bool) {
+ ctx := context.Background()
cfg := config.NewRWCoreFlags()
cfg.CorePairTopic = "rw_core"
cfg.DefaultRequestTimeout = lda.defaultTimeout.Nanoseconds() / 1000000 //TODO: change when Core changes to Duration
@@ -459,8 +460,11 @@
cfg.GrpcHost = "127.0.0.1"
setCoreCompeteMode(inCompeteMode)
client := setupKVClient(cfg, lda.coreInstanceID)
- lda.core = NewCore(lda.coreInstanceID, cfg, client, lda.kClient)
- lda.core.Start(context.Background())
+ lda.core = NewCore(ctx, lda.coreInstanceID, cfg, client, lda.kClient)
+ err = lda.core.Start(ctx)
+ if err != nil {
+ log.Fatal("Cannot start core")
+ }
}
func (lda *LDATest) stopAll() {
@@ -483,7 +487,8 @@
clonedLD.DatapathId = rand.Uint64()
lDeviceAgent := newLogicalDeviceAgent(clonedLD.Id, clonedLD.RootDeviceId, lDeviceMgr, deviceMgr, lDeviceMgr.clusterDataProxy, lDeviceMgr.defaultTimeout)
lDeviceAgent.logicalDevice = clonedLD
- added := lDeviceAgent.clusterDataProxy.AddWithID(context.Background(), "/logical_devices", clonedLD.Id, clonedLD, "")
+ added, err := lDeviceAgent.clusterDataProxy.AddWithID(context.Background(), "/logical_devices", clonedLD.Id, clonedLD, "")
+ assert.Nil(t, err)
assert.NotNil(t, added)
lDeviceMgr.addLogicalDeviceAgentToMap(lDeviceAgent)
return lDeviceAgent
diff --git a/rw_core/core/logical_device_manager.go b/rw_core/core/logical_device_manager.go
index 53711d7..6f8b2fa 100644
--- a/rw_core/core/logical_device_manager.go
+++ b/rw_core/core/logical_device_manager.go
@@ -142,7 +142,12 @@
func (ldMgr *LogicalDeviceManager) listLogicalDevices() (*voltha.LogicalDevices, error) {
log.Debug("ListAllLogicalDevices")
result := &voltha.LogicalDevices{}
- if logicalDevices := ldMgr.clusterDataProxy.List(context.Background(), "/logical_devices", 0, true, ""); logicalDevices != nil {
+ logicalDevices, err := ldMgr.clusterDataProxy.List(context.Background(), "/logical_devices", 0, true, "")
+ if err != nil {
+ log.Errorw("failed-to-list-logical-devices-from-cluster-proxy", log.Fields{"error": err})
+ return nil, err
+ }
+ if logicalDevices != nil {
for _, logicalDevice := range logicalDevices.([]interface{}) {
result.Items = append(result.Items, logicalDevice.(*voltha.LogicalDevice))
}
@@ -200,7 +205,10 @@
ldAgent := value.(*LogicalDeviceAgent)
if ldAgent.rootDeviceID == id {
log.Infow("stopping-logical-device-agent", log.Fields{"lDeviceId": key})
- ldAgent.stop(context.TODO())
+ if err := ldAgent.stop(context.TODO()); err != nil {
+ log.Errorw("failed-to-stop-LDAgent", log.Fields{"error": err})
+ return false
+ }
ldID = key.(string)
ldMgr.logicalDeviceAgents.Delete(ldID)
}
@@ -211,7 +219,12 @@
//getLogicalDeviceFromModel retrieves the logical device data from the model.
func (ldMgr *LogicalDeviceManager) getLogicalDeviceFromModel(lDeviceID string) (*voltha.LogicalDevice, error) {
- if logicalDevice := ldMgr.clusterDataProxy.Get(context.Background(), "/logical_devices/"+lDeviceID, 0, false, ""); logicalDevice != nil {
+ logicalDevice, err := ldMgr.clusterDataProxy.Get(context.Background(), "/logical_devices/"+lDeviceID, 0, false, "")
+ if err != nil {
+ log.Errorw("failed-to-get-logical-devices-from-cluster-proxy", log.Fields{"error": err})
+ return nil, err
+ }
+ if logicalDevice != nil {
if lDevice, ok := logicalDevice.(*voltha.LogicalDevice); ok {
return lDevice, nil
}
@@ -234,7 +247,10 @@
log.Debugw("loading-logical-device", log.Fields{"lDeviceId": lDeviceID})
agent := newLogicalDeviceAgent(lDeviceID, "", ldMgr, ldMgr.deviceMgr, ldMgr.clusterDataProxy, ldMgr.defaultTimeout)
if err := agent.start(context.TODO(), true); err != nil {
- agent.stop(context.TODO())
+ if err := agent.stop(context.TODO()); err != nil {
+ log.Errorw("failed-to-stop-agent", log.Fields{"error": err})
+ return err
+ }
} else {
ldMgr.logicalDeviceAgents.Store(agent.logicalDeviceID, agent)
}
@@ -275,7 +291,10 @@
logDeviceID := device.ParentId
if agent := ldMgr.getLogicalDeviceAgent(logDeviceID); agent != nil {
// Stop the logical device agent
- agent.stop(ctx)
+ if err := agent.stop(ctx); err != nil {
+ log.Errorw("failed-to-stop-agent", log.Fields{"error": err})
+ return err
+ }
//Remove the logical device agent from the Map
ldMgr.deleteLogicalDeviceAgent(logDeviceID)
err := ldMgr.core.deviceOwnership.AbandonDevice(logDeviceID)
diff --git a/rw_core/main.go b/rw_core/main.go
index c066275..76d0952 100644
--- a/rw_core/main.go
+++ b/rw_core/main.go
@@ -140,10 +140,13 @@
}
// Create the core service
- rw.core = c.NewCore(instanceID, rw.config, rw.kvClient, rw.kafkaClient)
+ rw.core = c.NewCore(ctx, instanceID, rw.config, rw.kvClient, rw.kafkaClient)
// start the core
- rw.core.Start(ctx)
+ err = rw.core.Start(ctx)
+ if err != nil {
+ log.Fatalf("failed-to-start-rwcore", log.Fields{"error": err})
+ }
}
func (rw *rwCore) stop(ctx context.Context) {