VOL-2180 code changes for context addition
Integrating InterContainerProxy interface changes

Change-Id: Ia20c5ac3093b7845acf80cce801ec0c1d90c125f
diff --git a/vendor/github.com/opencord/voltha-lib-go/v3/pkg/db/kvstore/client.go b/vendor/github.com/opencord/voltha-lib-go/v3/pkg/db/kvstore/client.go
index 088593a..d30e049 100644
--- a/vendor/github.com/opencord/voltha-lib-go/v3/pkg/db/kvstore/client.go
+++ b/vendor/github.com/opencord/voltha-lib-go/v3/pkg/db/kvstore/client.go
@@ -15,6 +15,8 @@
  */
 package kvstore
 
+import "context"
+
 const (
 	// Default timeout in seconds when making a kvstore request
 	defaultKVGetTimeout = 5
@@ -71,18 +73,18 @@
 
 // Client represents the set of APIs a KV Client must implement
 type Client interface {
-	List(key string, timeout int) (map[string]*KVPair, error)
-	Get(key string, timeout int) (*KVPair, error)
-	Put(key string, value interface{}, timeout int) error
-	Delete(key string, timeout int) error
-	Reserve(key string, value interface{}, ttl int64) (interface{}, error)
-	ReleaseReservation(key string) error
-	ReleaseAllReservations() error
-	RenewReservation(key string) error
-	Watch(key string) chan *Event
-	AcquireLock(lockName string, timeout int) error
+	List(ctx context.Context, key string) (map[string]*KVPair, error)
+	Get(ctx context.Context, key string) (*KVPair, error)
+	Put(ctx context.Context, key string, value interface{}) error
+	Delete(ctx context.Context, key string) error
+	Reserve(ctx context.Context, key string, value interface{}, ttl int64) (interface{}, error)
+	ReleaseReservation(ctx context.Context, key string) error
+	ReleaseAllReservations(ctx context.Context) error
+	RenewReservation(ctx context.Context, key string) error
+	Watch(ctx context.Context, key string) chan *Event
+	AcquireLock(ctx context.Context, lockName string, timeout int) error
 	ReleaseLock(lockName string) error
-	IsConnectionUp(timeout int) bool // timeout in second
+	IsConnectionUp(ctx context.Context) bool // timeout in second
 	CloseWatch(key string, ch chan *Event)
 	Close()
 }
diff --git a/vendor/github.com/opencord/voltha-lib-go/v3/pkg/db/kvstore/consulclient.go b/vendor/github.com/opencord/voltha-lib-go/v3/pkg/db/kvstore/consulclient.go
index e391293..fdf39be 100644
--- a/vendor/github.com/opencord/voltha-lib-go/v3/pkg/db/kvstore/consulclient.go
+++ b/vendor/github.com/opencord/voltha-lib-go/v3/pkg/db/kvstore/consulclient.go
@@ -64,19 +64,19 @@
 }
 
 // IsConnectionUp returns whether the connection to the Consul KV store is up
-func (c *ConsulClient) IsConnectionUp(timeout int) bool {
+func (c *ConsulClient) IsConnectionUp(ctx context.Context) bool {
 	logger.Error("Unimplemented function")
 	return false
 }
 
 // List returns an array of key-value pairs with key as a prefix.  Timeout defines how long the function will
 // wait for a response
-func (c *ConsulClient) List(key string, timeout int) (map[string]*KVPair, error) {
-	duration := GetDuration(timeout)
+func (c *ConsulClient) List(ctx context.Context, key string) (map[string]*KVPair, error) {
 
+	deadline, _ := ctx.Deadline()
 	kv := c.consul.KV()
 	var queryOptions consulapi.QueryOptions
-	queryOptions.WaitTime = duration
+	queryOptions.WaitTime = GetDuration(deadline.Second())
 	// For now we ignore meta data
 	kvps, _, err := kv.List(key, &queryOptions)
 	if err != nil {
@@ -92,13 +92,12 @@
 
 // Get returns a key-value pair for a given key. Timeout defines how long the function will
 // wait for a response
-func (c *ConsulClient) Get(key string, timeout int) (*KVPair, error) {
+func (c *ConsulClient) Get(ctx context.Context, key string) (*KVPair, error) {
 
-	duration := GetDuration(timeout)
-
+	deadline, _ := ctx.Deadline()
 	kv := c.consul.KV()
 	var queryOptions consulapi.QueryOptions
-	queryOptions.WaitTime = duration
+	queryOptions.WaitTime = GetDuration(deadline.Second())
 	// For now we ignore meta data
 	kvp, _, err := kv.Get(key, &queryOptions)
 	if err != nil {
@@ -115,7 +114,7 @@
 // Put writes a key-value pair to the KV store.  Value can only be a string or []byte since the consul API
 // accepts only a []byte as a value for a put operation. Timeout defines how long the function will
 // wait for a response
-func (c *ConsulClient) Put(key string, value interface{}, timeout int) error {
+func (c *ConsulClient) Put(ctx context.Context, key string, value interface{}) error {
 
 	// Validate that we can create a byte array from the value as consul API expects a byte array
 	var val []byte
@@ -141,7 +140,7 @@
 
 // Delete removes a key from the KV store. Timeout defines how long the function will
 // wait for a response
-func (c *ConsulClient) Delete(key string, timeout int) error {
+func (c *ConsulClient) Delete(ctx context.Context, key string) error {
 	kv := c.consul.KV()
 	var writeOptions consulapi.WriteOptions
 	c.writeLock.Lock()
@@ -219,7 +218,7 @@
 // defines how long that reservation is valid.  When TTL expires the key is unreserved by the KV store itself.
 // If the key is acquired then the value returned will be the value passed in.  If the key is already acquired
 // then the value assigned to that key will be returned.
-func (c *ConsulClient) Reserve(key string, value interface{}, ttl int64) (interface{}, error) {
+func (c *ConsulClient) Reserve(ctx context.Context, key string, value interface{}, ttl int64) (interface{}, error) {
 
 	// Validate that we can create a byte array from the value as consul API expects a byte array
 	var val []byte
@@ -264,7 +263,7 @@
 	logger.Debugw("key-acquired", log.Fields{"key": key, "status": result})
 
 	// Irrespective whether we were successful in acquiring the key, let's read it back and see if it's us.
-	m, err := c.Get(key, defaultKVGetTimeout)
+	m, err := c.Get(ctx, key)
 	if err != nil {
 		return nil, err
 	}
@@ -286,7 +285,7 @@
 }
 
 // ReleaseAllReservations releases all key reservations previously made (using Reserve API)
-func (c *ConsulClient) ReleaseAllReservations() error {
+func (c *ConsulClient) ReleaseAllReservations(ctx context.Context) error {
 	kv := c.consul.KV()
 	var kvp consulapi.KVPair
 	var result bool
@@ -311,7 +310,7 @@
 }
 
 // ReleaseReservation releases reservation for a specific key.
-func (c *ConsulClient) ReleaseReservation(key string) error {
+func (c *ConsulClient) ReleaseReservation(ctx context.Context, key string) error {
 	var ok bool
 	var reservedValue interface{}
 	c.writeLock.Lock()
@@ -337,7 +336,7 @@
 
 // RenewReservation renews a reservation.  A reservation will go stale after the specified TTL (Time To Live)
 // period specified when reserving the key
-func (c *ConsulClient) RenewReservation(key string) error {
+func (c *ConsulClient) RenewReservation(ctx context.Context, key string) error {
 	// In the case of Consul, renew reservation of a reserve key only require renewing the client session.
 
 	c.writeLock.Lock()
@@ -361,7 +360,7 @@
 
 // Watch provides the watch capability on a given key.  It returns a channel onto which the callee needs to
 // listen to receive Events.
-func (c *ConsulClient) Watch(key string) chan *Event {
+func (c *ConsulClient) Watch(ctx context.Context, key string) chan *Event {
 
 	// Create a new channel
 	ch := make(chan *Event, maxClientChannelBufferSize)
@@ -504,7 +503,7 @@
 	}
 }
 
-func (c *ConsulClient) AcquireLock(lockName string, timeout int) error {
+func (c *ConsulClient) AcquireLock(ctx context.Context, lockName string, timeout int) error {
 	return nil
 }
 
diff --git a/vendor/github.com/opencord/voltha-lib-go/v3/pkg/db/kvstore/etcdclient.go b/vendor/github.com/opencord/voltha-lib-go/v3/pkg/db/kvstore/etcdclient.go
index 7096748..a0f39cd 100644
--- a/vendor/github.com/opencord/voltha-lib-go/v3/pkg/db/kvstore/etcdclient.go
+++ b/vendor/github.com/opencord/voltha-lib-go/v3/pkg/db/kvstore/etcdclient.go
@@ -19,11 +19,12 @@
 	"context"
 	"errors"
 	"fmt"
+	"sync"
+
 	"github.com/opencord/voltha-lib-go/v3/pkg/log"
 	v3Client "go.etcd.io/etcd/clientv3"
 	v3Concurrency "go.etcd.io/etcd/clientv3/concurrency"
 	v3rpcTypes "go.etcd.io/etcd/etcdserver/api/v3rpc/rpctypes"
-	"sync"
 )
 
 // EtcdClient represents the Etcd KV store client
@@ -64,23 +65,19 @@
 
 // IsConnectionUp returns whether the connection to the Etcd KV store is up.  If a timeout occurs then
 // it is assumed the connection is down or unreachable.
-func (c *EtcdClient) IsConnectionUp(timeout int) bool {
+func (c *EtcdClient) IsConnectionUp(ctx context.Context) bool {
 	// Let's try to get a non existent key.  If the connection is up then there will be no error returned.
-	if _, err := c.Get("non-existent-key", timeout); err != nil {
+	if _, err := c.Get(ctx, "non-existent-key"); err != nil {
 		return false
 	}
+	//cancel()
 	return true
 }
 
 // List returns an array of key-value pairs with key as a prefix.  Timeout defines how long the function will
 // wait for a response
-func (c *EtcdClient) List(key string, timeout int) (map[string]*KVPair, error) {
-	duration := GetDuration(timeout)
-
-	ctx, cancel := context.WithTimeout(context.Background(), duration)
-
+func (c *EtcdClient) List(ctx context.Context, key string) (map[string]*KVPair, error) {
 	resp, err := c.ectdAPI.Get(ctx, key, v3Client.WithPrefix())
-	cancel()
 	if err != nil {
 		logger.Error(err)
 		return nil, err
@@ -94,13 +91,10 @@
 
 // Get returns a key-value pair for a given key. Timeout defines how long the function will
 // wait for a response
-func (c *EtcdClient) Get(key string, timeout int) (*KVPair, error) {
-	duration := GetDuration(timeout)
-
-	ctx, cancel := context.WithTimeout(context.Background(), duration)
+func (c *EtcdClient) Get(ctx context.Context, key string) (*KVPair, error) {
 
 	resp, err := c.ectdAPI.Get(ctx, key)
-	cancel()
+
 	if err != nil {
 		logger.Error(err)
 		return nil, err
@@ -115,7 +109,7 @@
 // Put writes a key-value pair to the KV store.  Value can only be a string or []byte since the etcd API
 // accepts only a string as a value for a put operation. Timeout defines how long the function will
 // wait for a response
-func (c *EtcdClient) Put(key string, value interface{}, timeout int) error {
+func (c *EtcdClient) Put(ctx context.Context, key string, value interface{}) error {
 
 	// Validate that we can convert value to a string as etcd API expects a string
 	var val string
@@ -124,10 +118,6 @@
 		return fmt.Errorf("unexpected-type-%T", value)
 	}
 
-	duration := GetDuration(timeout)
-
-	ctx, cancel := context.WithTimeout(context.Background(), duration)
-
 	c.writeLock.Lock()
 	defer c.writeLock.Unlock()
 
@@ -139,7 +129,7 @@
 	} else {
 		_, err = c.ectdAPI.Put(ctx, key, val)
 	}
-	cancel()
+
 	if err != nil {
 		switch err {
 		case context.Canceled:
@@ -158,13 +148,7 @@
 
 // Delete removes a key from the KV store. Timeout defines how long the function will
 // wait for a response
-func (c *EtcdClient) Delete(key string, timeout int) error {
-
-	duration := GetDuration(timeout)
-
-	ctx, cancel := context.WithTimeout(context.Background(), duration)
-
-	defer cancel()
+func (c *EtcdClient) Delete(ctx context.Context, key string) error {
 
 	c.writeLock.Lock()
 	defer c.writeLock.Unlock()
@@ -183,7 +167,7 @@
 // defines how long that reservation is valid.  When TTL expires the key is unreserved by the KV store itself.
 // If the key is acquired then the value returned will be the value passed in.  If the key is already acquired
 // then the value assigned to that key will be returned.
-func (c *EtcdClient) Reserve(key string, value interface{}, ttl int64) (interface{}, error) {
+func (c *EtcdClient) Reserve(ctx context.Context, key string, value interface{}, ttl int64) (interface{}, error) {
 	// Validate that we can convert value to a string as etcd API expects a string
 	var val string
 	var er error
@@ -191,12 +175,6 @@
 		return nil, fmt.Errorf("unexpected-type%T", value)
 	}
 
-	duration := GetDuration(connTimeout)
-
-	// Create a lease
-	ctx, cancel := context.WithTimeout(context.Background(), duration)
-	defer cancel()
-
 	resp, err := c.ectdAPI.Grant(ctx, ttl)
 	if err != nil {
 		logger.Error(err)
@@ -211,7 +189,7 @@
 	reservationSuccessful := false
 	defer func() {
 		if !reservationSuccessful {
-			if err = c.ReleaseReservation(key); err != nil {
+			if err = c.ReleaseReservation(context.Background(), key); err != nil {
 				logger.Error("cannot-release-lease")
 			}
 		}
@@ -241,7 +219,7 @@
 		}
 	} else {
 		// Read the Key to ensure this is our Key
-		m, err := c.Get(key, defaultKVGetTimeout)
+		m, err := c.Get(ctx, key)
 		if err != nil {
 			return nil, err
 		}
@@ -260,12 +238,9 @@
 }
 
 // ReleaseAllReservations releases all key reservations previously made (using Reserve API)
-func (c *EtcdClient) ReleaseAllReservations() error {
+func (c *EtcdClient) ReleaseAllReservations(ctx context.Context) error {
 	c.writeLock.Lock()
 	defer c.writeLock.Unlock()
-	duration := GetDuration(connTimeout)
-	ctx, cancel := context.WithTimeout(context.Background(), duration)
-	defer cancel()
 
 	for key, leaseID := range c.keyReservations {
 		_, err := c.ectdAPI.Revoke(ctx, *leaseID)
@@ -279,7 +254,7 @@
 }
 
 // ReleaseReservation releases reservation for a specific key.
-func (c *EtcdClient) ReleaseReservation(key string) error {
+func (c *EtcdClient) ReleaseReservation(ctx context.Context, key string) error {
 	// Get the leaseid using the key
 	logger.Debugw("Release-reservation", log.Fields{"key": key})
 	var ok bool
@@ -289,9 +264,6 @@
 	if leaseID, ok = c.keyReservations[key]; !ok {
 		return nil
 	}
-	duration := GetDuration(connTimeout)
-	ctx, cancel := context.WithTimeout(context.Background(), duration)
-	defer cancel()
 
 	if leaseID != nil {
 		_, err := c.ectdAPI.Revoke(ctx, *leaseID)
@@ -306,7 +278,7 @@
 
 // RenewReservation renews a reservation.  A reservation will go stale after the specified TTL (Time To Live)
 // period specified when reserving the key
-func (c *EtcdClient) RenewReservation(key string) error {
+func (c *EtcdClient) RenewReservation(ctx context.Context, key string) error {
 	// Get the leaseid using the key
 	var ok bool
 	var leaseID *v3Client.LeaseID
@@ -315,9 +287,6 @@
 	if leaseID, ok = c.keyReservations[key]; !ok {
 		return errors.New("key-not-reserved")
 	}
-	duration := GetDuration(connTimeout)
-	ctx, cancel := context.WithTimeout(context.Background(), duration)
-	defer cancel()
 
 	if leaseID != nil {
 		_, err := c.ectdAPI.KeepAliveOnce(ctx, *leaseID)
@@ -333,9 +302,9 @@
 
 // Watch provides the watch capability on a given key.  It returns a channel onto which the callee needs to
 // listen to receive Events.
-func (c *EtcdClient) Watch(key string) chan *Event {
+func (c *EtcdClient) Watch(ctx context.Context, key string) chan *Event {
 	w := v3Client.NewWatcher(c.ectdAPI)
-	ctx, cancel := context.WithCancel(context.Background())
+	ctx, cancel := context.WithCancel(ctx)
 	channel := w.Watch(ctx, key)
 
 	// Create a new channel
@@ -490,14 +459,11 @@
 	return lock, session
 }
 
-func (c *EtcdClient) AcquireLock(lockName string, timeout int) error {
-	duration := GetDuration(timeout)
-	ctx, cancel := context.WithTimeout(context.Background(), duration)
-	defer cancel()
+func (c *EtcdClient) AcquireLock(ctx context.Context, lockName string, timeout int) error {
 	session, _ := v3Concurrency.NewSession(c.ectdAPI, v3Concurrency.WithContext(ctx))
 	mu := v3Concurrency.NewMutex(session, "/devicelock_"+lockName)
 	if err := mu.Lock(context.Background()); err != nil {
-		cancel()
+		//cancel()
 		return err
 	}
 	c.addLockName(lockName, mu, session)