[VOL-3187]Pass Context down the execution call hierarchy across ofagent codebase

Change-Id: Ia5f2fa1509beefe0ddc427b83e39d2702782db8f
diff --git a/vendor/github.com/opencord/voltha-lib-go/v3/pkg/db/backend.go b/vendor/github.com/opencord/voltha-lib-go/v3/pkg/db/backend.go
index 1e23a0f..f595dc1 100644
--- a/vendor/github.com/opencord/voltha-lib-go/v3/pkg/db/backend.go
+++ b/vendor/github.com/opencord/voltha-lib-go/v3/pkg/db/backend.go
@@ -47,7 +47,7 @@
 }
 
 // NewBackend creates a new instance of a Backend structure
-func NewBackend(storeType string, address string, timeout time.Duration, pathPrefix string) *Backend {
+func NewBackend(ctx context.Context, storeType string, address string, timeout time.Duration, pathPrefix string) *Backend {
 	var err error
 
 	b := &Backend{
@@ -59,8 +59,8 @@
 		alive:                   false, // connection considered down at start
 	}
 
-	if b.Client, err = b.newClient(address, timeout); err != nil {
-		logger.Errorw("failed-to-create-kv-client",
+	if b.Client, err = b.newClient(ctx, address, timeout); err != nil {
+		logger.Errorw(ctx, "failed-to-create-kv-client",
 			log.Fields{
 				"type": storeType, "address": address,
 				"timeout": timeout, "prefix": pathPrefix,
@@ -71,22 +71,22 @@
 	return b
 }
 
-func (b *Backend) newClient(address string, timeout time.Duration) (kvstore.Client, error) {
+func (b *Backend) newClient(ctx context.Context, address string, timeout time.Duration) (kvstore.Client, error) {
 	switch b.StoreType {
 	case "consul":
-		return kvstore.NewConsulClient(address, timeout)
+		return kvstore.NewConsulClient(ctx, address, timeout)
 	case "etcd":
-		return kvstore.NewEtcdClient(address, timeout, log.WarnLevel)
+		return kvstore.NewEtcdClient(ctx, address, timeout, log.WarnLevel)
 	}
 	return nil, errors.New("unsupported-kv-store")
 }
 
-func (b *Backend) makePath(key string) string {
+func (b *Backend) makePath(ctx context.Context, key string) string {
 	path := fmt.Sprintf("%s/%s", b.PathPrefix, key)
 	return path
 }
 
-func (b *Backend) updateLiveness(alive bool) {
+func (b *Backend) updateLiveness(ctx context.Context, alive bool) {
 	// Periodically push stream of liveness data to the channel,
 	// so that in a live state, the core does not timeout and
 	// send a forced liveness message. Push alive state if the
@@ -94,11 +94,11 @@
 	if b.liveness != nil {
 
 		if b.alive != alive {
-			logger.Debug("update-liveness-channel-reason-change")
+			logger.Debug(ctx, "update-liveness-channel-reason-change")
 			b.liveness <- alive
 			b.lastLivenessTime = time.Now()
 		} else if time.Since(b.lastLivenessTime) > b.LivenessChannelInterval {
-			logger.Debug("update-liveness-channel-reason-interval")
+			logger.Debug(ctx, "update-liveness-channel-reason-interval")
 			b.liveness <- alive
 			b.lastLivenessTime = time.Now()
 		}
@@ -106,7 +106,7 @@
 
 	// Emit log message only for alive state change
 	if b.alive != alive {
-		logger.Debugw("change-kvstore-alive-status", log.Fields{"alive": alive})
+		logger.Debugw(ctx, "change-kvstore-alive-status", log.Fields{"alive": alive})
 		b.alive = alive
 	}
 }
@@ -115,9 +115,9 @@
 // post on Liveness channel
 func (b *Backend) PerformLivenessCheck(ctx context.Context) bool {
 	alive := b.Client.IsConnectionUp(ctx)
-	logger.Debugw("kvstore-liveness-check-result", log.Fields{"alive": alive})
+	logger.Debugw(ctx, "kvstore-liveness-check-result", log.Fields{"alive": alive})
 
-	b.updateLiveness(alive)
+	b.updateLiveness(ctx, alive)
 	return alive
 }
 
@@ -126,11 +126,11 @@
 // or not the connection is still Live. This channel is then picked up
 // by the service (i.e. rw_core / ro_core) to update readiness status
 // and/or take other actions.
-func (b *Backend) EnableLivenessChannel() chan bool {
-	logger.Debug("enable-kvstore-liveness-channel")
+func (b *Backend) EnableLivenessChannel(ctx context.Context) chan bool {
+	logger.Debug(ctx, "enable-kvstore-liveness-channel")
 
 	if b.liveness == nil {
-		logger.Debug("create-kvstore-liveness-channel")
+		logger.Debug(ctx, "create-kvstore-liveness-channel")
 
 		// Channel size of 10 to avoid any possibility of blocking in Load conditions
 		b.liveness = make(chan bool, 10)
@@ -144,7 +144,7 @@
 }
 
 // Extract Alive status of Kvstore based on type of error
-func (b *Backend) isErrorIndicatingAliveKvstore(err error) bool {
+func (b *Backend) isErrorIndicatingAliveKvstore(ctx context.Context, err error) bool {
 	// Alive unless observed an error indicating so
 	alive := true
 
@@ -182,64 +182,64 @@
 
 // List retrieves one or more items that match the specified key
 func (b *Backend) List(ctx context.Context, key string) (map[string]*kvstore.KVPair, error) {
-	formattedPath := b.makePath(key)
-	logger.Debugw("listing-key", log.Fields{"key": key, "path": formattedPath})
+	formattedPath := b.makePath(ctx, key)
+	logger.Debugw(ctx, "listing-key", log.Fields{"key": key, "path": formattedPath})
 
 	pair, err := b.Client.List(ctx, formattedPath)
 
-	b.updateLiveness(b.isErrorIndicatingAliveKvstore(err))
+	b.updateLiveness(ctx, b.isErrorIndicatingAliveKvstore(ctx, err))
 
 	return pair, err
 }
 
 // Get retrieves an item that matches the specified key
 func (b *Backend) Get(ctx context.Context, key string) (*kvstore.KVPair, error) {
-	formattedPath := b.makePath(key)
-	logger.Debugw("getting-key", log.Fields{"key": key, "path": formattedPath})
+	formattedPath := b.makePath(ctx, key)
+	logger.Debugw(ctx, "getting-key", log.Fields{"key": key, "path": formattedPath})
 
 	pair, err := b.Client.Get(ctx, formattedPath)
 
-	b.updateLiveness(b.isErrorIndicatingAliveKvstore(err))
+	b.updateLiveness(ctx, b.isErrorIndicatingAliveKvstore(ctx, err))
 
 	return pair, err
 }
 
 // Put stores an item value under the specifed key
 func (b *Backend) Put(ctx context.Context, key string, value interface{}) error {
-	formattedPath := b.makePath(key)
-	logger.Debugw("putting-key", log.Fields{"key": key, "path": formattedPath})
+	formattedPath := b.makePath(ctx, key)
+	logger.Debugw(ctx, "putting-key", log.Fields{"key": key, "path": formattedPath})
 
 	err := b.Client.Put(ctx, formattedPath, value)
 
-	b.updateLiveness(b.isErrorIndicatingAliveKvstore(err))
+	b.updateLiveness(ctx, b.isErrorIndicatingAliveKvstore(ctx, err))
 
 	return err
 }
 
 // Delete removes an item under the specified key
 func (b *Backend) Delete(ctx context.Context, key string) error {
-	formattedPath := b.makePath(key)
-	logger.Debugw("deleting-key", log.Fields{"key": key, "path": formattedPath})
+	formattedPath := b.makePath(ctx, key)
+	logger.Debugw(ctx, "deleting-key", log.Fields{"key": key, "path": formattedPath})
 
 	err := b.Client.Delete(ctx, formattedPath)
 
-	b.updateLiveness(b.isErrorIndicatingAliveKvstore(err))
+	b.updateLiveness(ctx, b.isErrorIndicatingAliveKvstore(ctx, err))
 
 	return err
 }
 
 // CreateWatch starts watching events for the specified key
 func (b *Backend) CreateWatch(ctx context.Context, key string, withPrefix bool) chan *kvstore.Event {
-	formattedPath := b.makePath(key)
-	logger.Debugw("creating-key-watch", log.Fields{"key": key, "path": formattedPath})
+	formattedPath := b.makePath(ctx, key)
+	logger.Debugw(ctx, "creating-key-watch", log.Fields{"key": key, "path": formattedPath})
 
 	return b.Client.Watch(ctx, formattedPath, withPrefix)
 }
 
 // DeleteWatch stops watching events for the specified key
-func (b *Backend) DeleteWatch(key string, ch chan *kvstore.Event) {
-	formattedPath := b.makePath(key)
-	logger.Debugw("deleting-key-watch", log.Fields{"key": key, "path": formattedPath})
+func (b *Backend) DeleteWatch(ctx context.Context, key string, ch chan *kvstore.Event) {
+	formattedPath := b.makePath(ctx, key)
+	logger.Debugw(ctx, "deleting-key-watch", log.Fields{"key": key, "path": formattedPath})
 
-	b.Client.CloseWatch(formattedPath, ch)
+	b.Client.CloseWatch(ctx, formattedPath, ch)
 }