[VOL-3069]Pass Context down the execution call hierarchy across voltha codebase
Change-Id: I97a2630d9a4fe5dc3161113539edda476534f186
diff --git a/rw_core/mocks/adapter.go b/rw_core/mocks/adapter.go
index 3c29a01..b27c606 100644
--- a/rw_core/mocks/adapter.go
+++ b/rw_core/mocks/adapter.go
@@ -17,6 +17,7 @@
package mocks
import (
+ "context"
"fmt"
"strconv"
"strings"
@@ -28,7 +29,7 @@
"github.com/opencord/voltha-protos/v3/go/voltha"
)
-func macAddressToUint32Array(mac string) []uint32 {
+func macAddressToUint32Array(ctx context.Context, mac string) []uint32 {
slist := strings.Split(mac, ":")
result := make([]uint32, len(slist))
var err error
@@ -54,7 +55,7 @@
}
// NewAdapter creates adapter instance
-func NewAdapter(cp adapterif.CoreProxy) *Adapter {
+func NewAdapter(ctx context.Context, cp adapterif.CoreProxy) *Adapter {
return &Adapter{
flows: map[uint64]*voltha.OfpFlowStats{},
devices: map[string]*voltha.Device{},
@@ -62,7 +63,7 @@
}
}
-func (ta *Adapter) storeDevice(d *voltha.Device) {
+func (ta *Adapter) storeDevice(ctx context.Context, d *voltha.Device) {
ta.deviceLock.Lock()
defer ta.deviceLock.Unlock()
if d != nil {
@@ -70,83 +71,83 @@
}
}
-func (ta *Adapter) getDevice(id string) *voltha.Device {
+func (ta *Adapter) getDevice(ctx context.Context, id string) *voltha.Device {
ta.deviceLock.RLock()
defer ta.deviceLock.RUnlock()
return ta.devices[id]
}
-func (ta *Adapter) updateDevice(d *voltha.Device) {
- ta.storeDevice(d)
+func (ta *Adapter) updateDevice(ctx context.Context, d *voltha.Device) {
+ ta.storeDevice(ctx, d)
}
// Adapter_descriptor -
-func (ta *Adapter) Adapter_descriptor() error { // nolint
+func (ta *Adapter) Adapter_descriptor(ctx context.Context) error { // nolint
return nil
}
// Device_types -
-func (ta *Adapter) Device_types() (*voltha.DeviceTypes, error) { // nolint
+func (ta *Adapter) Device_types(ctx context.Context) (*voltha.DeviceTypes, error) { // nolint
return nil, nil
}
// Health -
-func (ta *Adapter) Health() (*voltha.HealthStatus, error) {
+func (ta *Adapter) Health(ctx context.Context) (*voltha.HealthStatus, error) {
return nil, nil
}
// Adopt_device -
-func (ta *Adapter) Adopt_device(device *voltha.Device) error { // nolint
+func (ta *Adapter) Adopt_device(ctx context.Context, device *voltha.Device) error { // nolint
return nil
}
// Reconcile_device -
-func (ta *Adapter) Reconcile_device(device *voltha.Device) error { // nolint
+func (ta *Adapter) Reconcile_device(ctx context.Context, device *voltha.Device) error { // nolint
return nil
}
// Abandon_device -
-func (ta *Adapter) Abandon_device(device *voltha.Device) error { // nolint
+func (ta *Adapter) Abandon_device(ctx context.Context, device *voltha.Device) error { // nolint
return nil
}
// Disable_device -
-func (ta *Adapter) Disable_device(device *voltha.Device) error { // nolint
+func (ta *Adapter) Disable_device(ctx context.Context, device *voltha.Device) error { // nolint
return nil
}
// Reenable_device -
-func (ta *Adapter) Reenable_device(device *voltha.Device) error { // nolint
+func (ta *Adapter) Reenable_device(ctx context.Context, device *voltha.Device) error { // nolint
return nil
}
// Reboot_device -
-func (ta *Adapter) Reboot_device(device *voltha.Device) error { // nolint
+func (ta *Adapter) Reboot_device(ctx context.Context, device *voltha.Device) error { // nolint
return nil
}
// Self_test_device -
-func (ta *Adapter) Self_test_device(device *voltha.Device) error { // nolint
+func (ta *Adapter) Self_test_device(ctx context.Context, device *voltha.Device) error { // nolint
return nil
}
// Delete_device -
-func (ta *Adapter) Delete_device(device *voltha.Device) error { // nolint
+func (ta *Adapter) Delete_device(ctx context.Context, device *voltha.Device) error { // nolint
return nil
}
// Get_device_details -
-func (ta *Adapter) Get_device_details(device *voltha.Device) error { // nolint
+func (ta *Adapter) Get_device_details(ctx context.Context, device *voltha.Device) error { // nolint
return nil
}
// Update_flows_bulk -
-func (ta *Adapter) Update_flows_bulk(device *voltha.Device, flows *voltha.Flows, groups *voltha.FlowGroups, flowMetadata *voltha.FlowMetadata) error { // nolint
+func (ta *Adapter) Update_flows_bulk(ctx context.Context, device *voltha.Device, flows *voltha.Flows, groups *voltha.FlowGroups, flowMetadata *voltha.FlowMetadata) error { // nolint
return nil
}
// Update_flows_incrementally mocks the incremental flow update
-func (ta *Adapter) Update_flows_incrementally(device *voltha.Device, flows *of.FlowChanges, groups *of.FlowGroupChanges, flowMetadata *voltha.FlowMetadata) error { // nolint
+func (ta *Adapter) Update_flows_incrementally(ctx context.Context, device *voltha.Device, flows *of.FlowChanges, groups *of.FlowGroupChanges, flowMetadata *voltha.FlowMetadata) error { // nolint
ta.flowLock.Lock()
defer ta.flowLock.Unlock()
@@ -170,27 +171,27 @@
}
// Update_pm_config -
-func (ta *Adapter) Update_pm_config(device *voltha.Device, pmConfigs *voltha.PmConfigs) error { // nolint
+func (ta *Adapter) Update_pm_config(ctx context.Context, device *voltha.Device, pmConfigs *voltha.PmConfigs) error { // nolint
return nil
}
// Receive_packet_out -
-func (ta *Adapter) Receive_packet_out(deviceID string, egressPortNo int, msg *of.OfpPacketOut) error { // nolint
+func (ta *Adapter) Receive_packet_out(ctx context.Context, deviceID string, egressPortNo int, msg *of.OfpPacketOut) error { // nolint
return nil
}
// Suppress_event -
-func (ta *Adapter) Suppress_event(filter *voltha.EventFilter) error { // nolint
+func (ta *Adapter) Suppress_event(ctx context.Context, filter *voltha.EventFilter) error { // nolint
return nil
}
// Unsuppress_event -
-func (ta *Adapter) Unsuppress_event(filter *voltha.EventFilter) error { // nolint
+func (ta *Adapter) Unsuppress_event(ctx context.Context, filter *voltha.EventFilter) error { // nolint
return nil
}
// Get_ofp_device_info -
-func (ta *Adapter) Get_ofp_device_info(device *voltha.Device) (*ic.SwitchCapability, error) { // nolint
+func (ta *Adapter) Get_ofp_device_info(ctx context.Context, device *voltha.Device) (*ic.SwitchCapability, error) { // nolint
return &ic.SwitchCapability{
Desc: &of.OfpDesc{
HwDesc: "adapter_mock",
@@ -209,12 +210,12 @@
}
// Get_ofp_port_info -
-func (ta *Adapter) Get_ofp_port_info(device *voltha.Device, portNo int64) (*ic.PortCapability, error) { // nolint
+func (ta *Adapter) Get_ofp_port_info(ctx context.Context, device *voltha.Device, portNo int64) (*ic.PortCapability, error) { // nolint
capability := uint32(of.OfpPortFeatures_OFPPF_1GB_FD | of.OfpPortFeatures_OFPPF_FIBER)
return &ic.PortCapability{
Port: &voltha.LogicalPort{
OfpPort: &of.OfpPort{
- HwAddr: macAddressToUint32Array("11:11:33:44:55:66"),
+ HwAddr: macAddressToUint32Array(ctx, "11:11:33:44:55:66"),
Config: 0,
State: uint32(of.OfpPortState_OFPPS_LIVE),
Curr: capability,
@@ -230,61 +231,61 @@
}
// Process_inter_adapter_message -
-func (ta *Adapter) Process_inter_adapter_message(msg *ic.InterAdapterMessage) error { // nolint
+func (ta *Adapter) Process_inter_adapter_message(ctx context.Context, msg *ic.InterAdapterMessage) error { // nolint
return nil
}
// Download_image -
-func (ta *Adapter) Download_image(device *voltha.Device, request *voltha.ImageDownload) (*voltha.ImageDownload, error) { // nolint
+func (ta *Adapter) Download_image(ctx context.Context, device *voltha.Device, request *voltha.ImageDownload) (*voltha.ImageDownload, error) { // nolint
return nil, nil
}
// Get_image_download_status -
-func (ta *Adapter) Get_image_download_status(device *voltha.Device, request *voltha.ImageDownload) (*voltha.ImageDownload, error) { // nolint
+func (ta *Adapter) Get_image_download_status(ctx context.Context, device *voltha.Device, request *voltha.ImageDownload) (*voltha.ImageDownload, error) { // nolint
return nil, nil
}
// Cancel_image_download -
-func (ta *Adapter) Cancel_image_download(device *voltha.Device, request *voltha.ImageDownload) (*voltha.ImageDownload, error) { // nolint
+func (ta *Adapter) Cancel_image_download(ctx context.Context, device *voltha.Device, request *voltha.ImageDownload) (*voltha.ImageDownload, error) { // nolint
return nil, nil
}
// Activate_image_update -
-func (ta *Adapter) Activate_image_update(device *voltha.Device, request *voltha.ImageDownload) (*voltha.ImageDownload, error) { // nolint
+func (ta *Adapter) Activate_image_update(ctx context.Context, device *voltha.Device, request *voltha.ImageDownload) (*voltha.ImageDownload, error) { // nolint
return nil, nil
}
// Revert_image_update -
-func (ta *Adapter) Revert_image_update(device *voltha.Device, request *voltha.ImageDownload) (*voltha.ImageDownload, error) { // nolint
+func (ta *Adapter) Revert_image_update(ctx context.Context, device *voltha.Device, request *voltha.ImageDownload) (*voltha.ImageDownload, error) { // nolint
return nil, nil
}
// Enable_port -
-func (ta *Adapter) Enable_port(deviceId string, port *voltha.Port) error { //nolint
+func (ta *Adapter) Enable_port(ctx context.Context, deviceId string, port *voltha.Port) error { //nolint
return nil
}
// Disable_port -
-func (ta *Adapter) Disable_port(deviceId string, port *voltha.Port) error { //nolint
+func (ta *Adapter) Disable_port(ctx context.Context, deviceId string, port *voltha.Port) error { //nolint
return nil
}
// Child_device_lost -
-func (ta *Adapter) Child_device_lost(pDeviceID string, pPortNo uint32, onuID uint32) error { //nolint
+func (ta *Adapter) Child_device_lost(ctx context.Context, pDeviceID string, pPortNo uint32, onuID uint32) error { //nolint
return nil
}
// Start_omci_test
-func (ta *Adapter) Start_omci_test(device *voltha.Device, request *voltha.OmciTestRequest) (*voltha.TestResponse, error) { //nolint
+func (ta *Adapter) Start_omci_test(ctx context.Context, device *voltha.Device, request *voltha.OmciTestRequest) (*voltha.TestResponse, error) { //nolint
return nil, nil
}
-func (ta *Adapter) Get_ext_value(deviceId string, device *voltha.Device, valueflag voltha.ValueType_Type) (*voltha.ReturnValues, error) { //nolint
+func (ta *Adapter) Get_ext_value(ctx context.Context, deviceId string, device *voltha.Device, valueflag voltha.ValueType_Type) (*voltha.ReturnValues, error) { //nolint
return nil, nil
}
// GetFlowCount returns the total number of flows presently under this adapter
-func (ta *Adapter) GetFlowCount() int {
+func (ta *Adapter) GetFlowCount(ctx context.Context) int {
ta.flowLock.RLock()
defer ta.flowLock.RUnlock()
@@ -292,7 +293,7 @@
}
// ClearFlows removes all flows in this adapter
-func (ta *Adapter) ClearFlows() {
+func (ta *Adapter) ClearFlows(ctx context.Context) {
ta.flowLock.Lock()
defer ta.flowLock.Unlock()
@@ -300,7 +301,7 @@
}
// SetFlowAction sets the adapter action on addition and deletion of flows
-func (ta *Adapter) SetFlowAction(failFlowAdd, failFlowDelete bool) {
+func (ta *Adapter) SetFlowAction(ctx context.Context, failFlowAdd, failFlowDelete bool) {
ta.failFlowAdd = failFlowAdd
ta.failFlowDelete = failFlowDelete
}
diff --git a/rw_core/mocks/adapter_olt.go b/rw_core/mocks/adapter_olt.go
index 61f431a..fc284ab 100644
--- a/rw_core/mocks/adapter_olt.go
+++ b/rw_core/mocks/adapter_olt.go
@@ -41,14 +41,14 @@
}
// NewOLTAdapter - creates OLT adapter instance
-func NewOLTAdapter(cp adapterif.CoreProxy) *OLTAdapter {
+func NewOLTAdapter(ctx context.Context, cp adapterif.CoreProxy) *OLTAdapter {
return &OLTAdapter{
- Adapter: NewAdapter(cp),
+ Adapter: NewAdapter(ctx, cp),
}
}
// Adopt_device creates new handler for added device
-func (oltA *OLTAdapter) Adopt_device(device *voltha.Device) error { // nolint
+func (oltA *OLTAdapter) Adopt_device(ctx context.Context, device *voltha.Device) error { // nolint
go func() {
d := proto.Clone(device).(*voltha.Device)
d.Root = true
@@ -56,8 +56,8 @@
d.Model = "go-mock"
d.SerialNumber = com.GetRandomSerialNumber()
d.MacAddress = strings.ToUpper(com.GetRandomMacAddress())
- oltA.storeDevice(d)
- if res := oltA.coreProxy.DeviceUpdate(context.TODO(), d); res != nil {
+ oltA.storeDevice(ctx, d)
+ if res := oltA.coreProxy.DeviceUpdate(ctx, d); res != nil {
logger.Fatalf("deviceUpdate-failed-%s", res)
}
nniPort := &voltha.Port{
@@ -67,7 +67,7 @@
OperStatus: voltha.OperStatus_ACTIVE,
}
var err error
- if err = oltA.coreProxy.PortCreated(context.TODO(), d.Id, nniPort); err != nil {
+ if err = oltA.coreProxy.PortCreated(ctx, d.Id, nniPort); err != nil {
logger.Fatalf("PortCreated-failed-%s", err)
}
@@ -77,30 +77,30 @@
Type: voltha.Port_PON_OLT,
OperStatus: voltha.OperStatus_ACTIVE,
}
- if err = oltA.coreProxy.PortCreated(context.TODO(), d.Id, ponPort); err != nil {
+ if err = oltA.coreProxy.PortCreated(ctx, d.Id, ponPort); err != nil {
logger.Fatalf("PortCreated-failed-%s", err)
}
d.ConnectStatus = voltha.ConnectStatus_REACHABLE
d.OperStatus = voltha.OperStatus_ACTIVE
- if err = oltA.coreProxy.DeviceStateUpdate(context.TODO(), d.Id, d.ConnectStatus, d.OperStatus); err != nil {
+ if err = oltA.coreProxy.DeviceStateUpdate(ctx, d.Id, d.ConnectStatus, d.OperStatus); err != nil {
logger.Fatalf("Device-state-update-failed-%s", err)
}
//Get the latest device data from the Core
- if d, err = oltA.coreProxy.GetDevice(context.TODO(), d.Id, d.Id); err != nil {
+ if d, err = oltA.coreProxy.GetDevice(ctx, d.Id, d.Id); err != nil {
logger.Fatalf("getting-device-failed-%s", err)
}
- oltA.updateDevice(d)
+ oltA.updateDevice(ctx, d)
// Register Child devices
initialUniPortNo := startingUNIPortNo
for i := 0; i < numONUPerOLT; i++ {
go func(seqNo int) {
if _, err := oltA.coreProxy.ChildDeviceDetected(
- context.TODO(),
+ ctx,
d.Id,
1,
"onu_adapter_mock",
@@ -117,8 +117,8 @@
}
// Get_ofp_device_info returns ofp device info
-func (oltA *OLTAdapter) Get_ofp_device_info(device *voltha.Device) (*ic.SwitchCapability, error) { // nolint
- if d := oltA.getDevice(device.Id); d == nil {
+func (oltA *OLTAdapter) Get_ofp_device_info(ctx context.Context, device *voltha.Device) (*ic.SwitchCapability, error) { // nolint
+ if d := oltA.getDevice(ctx, device.Id); d == nil {
logger.Fatalf("device-not-found-%s", device.Id)
}
return &ic.SwitchCapability{
@@ -139,15 +139,15 @@
}
// Get_ofp_port_info returns ofp port info
-func (oltA *OLTAdapter) Get_ofp_port_info(device *voltha.Device, portNo int64) (*ic.PortCapability, error) { // nolint
- if d := oltA.getDevice(device.Id); d == nil {
+func (oltA *OLTAdapter) Get_ofp_port_info(ctx context.Context, device *voltha.Device, portNo int64) (*ic.PortCapability, error) { // nolint
+ if d := oltA.getDevice(ctx, device.Id); d == nil {
logger.Fatalf("device-not-found-%s", device.Id)
}
capability := uint32(of.OfpPortFeatures_OFPPF_1GB_FD | of.OfpPortFeatures_OFPPF_FIBER)
return &ic.PortCapability{
Port: &voltha.LogicalPort{
OfpPort: &of.OfpPort{
- HwAddr: macAddressToUint32Array("11:22:33:44:55:66"),
+ HwAddr: macAddressToUint32Array(ctx, "11:22:33:44:55:66"),
Config: 0,
State: uint32(of.OfpPortState_OFPPS_LIVE),
Curr: capability,
@@ -163,19 +163,19 @@
}
// GetNumONUPerOLT returns number of ONUs per OLT
-func (oltA *OLTAdapter) GetNumONUPerOLT() int {
+func (oltA *OLTAdapter) GetNumONUPerOLT(ctx context.Context) int {
return numONUPerOLT
}
// Returns the starting UNI port number
-func (oltA *OLTAdapter) GetStartingUNIPortNo() int {
+func (oltA *OLTAdapter) GetStartingUNIPortNo(ctx context.Context) int {
return startingUNIPortNo
}
// Disable_device disables device
-func (oltA *OLTAdapter) Disable_device(device *voltha.Device) error { // nolint
+func (oltA *OLTAdapter) Disable_device(ctx context.Context, device *voltha.Device) error { // nolint
go func() {
- if d := oltA.getDevice(device.Id); d == nil {
+ if d := oltA.getDevice(ctx, device.Id); d == nil {
logger.Fatalf("device-not-found-%s", device.Id)
}
@@ -195,7 +195,7 @@
return
}
- oltA.updateDevice(cloned)
+ oltA.updateDevice(ctx, cloned)
// Tell the Core that all child devices have been disabled (by default it's an action already taken by the Core
if err := oltA.coreProxy.ChildDevicesLost(context.TODO(), cloned.Id); err != nil {
@@ -207,9 +207,9 @@
}
// Reenable_device reenables device
-func (oltA *OLTAdapter) Reenable_device(device *voltha.Device) error { // nolint
+func (oltA *OLTAdapter) Reenable_device(ctx context.Context, device *voltha.Device) error { // nolint
go func() {
- if d := oltA.getDevice(device.Id); d == nil {
+ if d := oltA.getDevice(ctx, device.Id); d == nil {
logger.Fatalf("device-not-found-%s", device.Id)
}
@@ -235,7 +235,7 @@
}
// Enable_port -
-func (oltA *OLTAdapter) Enable_port(deviceId string, Port *voltha.Port) error { //nolint
+func (oltA *OLTAdapter) Enable_port(ctx context.Context, deviceId string, Port *voltha.Port) error { //nolint
go func() {
if Port.Type == voltha.Port_PON_OLT {
@@ -249,7 +249,7 @@
}
// Disable_port -
-func (oltA *OLTAdapter) Disable_port(deviceId string, Port *voltha.Port) error { //nolint
+func (oltA *OLTAdapter) Disable_port(ctx context.Context, deviceId string, Port *voltha.Port) error { //nolint
go func() {
if Port.Type == voltha.Port_PON_OLT {
@@ -263,12 +263,12 @@
}
// Child_device_lost deletes ONU and its references
-func (oltA *OLTAdapter) Child_device_lost(deviceID string, pPortNo uint32, onuID uint32) error { // nolint
+func (oltA *OLTAdapter) Child_device_lost(ctx context.Context, deviceID string, pPortNo uint32, onuID uint32) error { // nolint
return nil
}
// Reboot_device -
-func (oltA *OLTAdapter) Reboot_device(device *voltha.Device) error { // nolint
+func (oltA *OLTAdapter) Reboot_device(ctx context.Context, device *voltha.Device) error { // nolint
logger.Infow("reboot-device", log.Fields{"deviceId": device.Id})
go func() {
@@ -284,12 +284,12 @@
}
// TODO: REMOVE Start_omci_test begins an omci self-test
-func (oltA *OLTAdapter) Start_omci_test(device *voltha.Device, request *voltha.OmciTestRequest) (*ic.TestResponse, error) { // nolint
+func (oltA *OLTAdapter) Start_omci_test(ctx context.Context, device *voltha.Device, request *voltha.OmciTestRequest) (*ic.TestResponse, error) { // nolint
_ = device
return nil, errors.New("start-omci-test-not-implemented")
}
-func (oltA *OLTAdapter) Get_ext_value(deviceId string, device *voltha.Device, valueflag voltha.ValueType_Type) (*voltha.ReturnValues, error) { // nolint
+func (oltA *OLTAdapter) Get_ext_value(ctx context.Context, deviceId string, device *voltha.Device, valueflag voltha.ValueType_Type) (*voltha.ReturnValues, error) { // nolint
_ = deviceId
_ = device
_ = valueflag
diff --git a/rw_core/mocks/adapter_olt_test.go b/rw_core/mocks/adapter_olt_test.go
index 036d612..1409b2b 100644
--- a/rw_core/mocks/adapter_olt_test.go
+++ b/rw_core/mocks/adapter_olt_test.go
@@ -17,13 +17,13 @@
package mocks
import (
- "testing"
-
+ "context"
"github.com/opencord/voltha-lib-go/v3/pkg/adapters"
+ "testing"
)
func TestOLTAdapterImplementsIAdapter(t *testing.T) {
- adapter := NewOLTAdapter(nil)
+ adapter := NewOLTAdapter(context.Background(), nil)
if _, ok := interface{}(adapter).(adapters.IAdapter); !ok {
t.Error("OLT adapter does not implement voltha-lib-go/v2/pkg/adapters/IAdapter interface")
diff --git a/rw_core/mocks/adapter_onu.go b/rw_core/mocks/adapter_onu.go
index 217f01d..f467456 100644
--- a/rw_core/mocks/adapter_onu.go
+++ b/rw_core/mocks/adapter_onu.go
@@ -36,14 +36,14 @@
}
// NewONUAdapter creates ONU adapter
-func NewONUAdapter(cp adapterif.CoreProxy) *ONUAdapter {
+func NewONUAdapter(ctx context.Context, cp adapterif.CoreProxy) *ONUAdapter {
return &ONUAdapter{
- Adapter: NewAdapter(cp),
+ Adapter: NewAdapter(ctx, cp),
}
}
// Adopt_device creates new handler for added device
-func (onuA *ONUAdapter) Adopt_device(device *voltha.Device) error { // nolint
+func (onuA *ONUAdapter) Adopt_device(ctx context.Context, device *voltha.Device) error { // nolint
go func() {
d := proto.Clone(device).(*voltha.Device)
d.Root = false
@@ -51,15 +51,15 @@
d.Model = "go-mock"
d.SerialNumber = com.GetRandomSerialNumber()
d.MacAddress = strings.ToUpper(com.GetRandomMacAddress())
- onuA.storeDevice(d)
- if res := onuA.coreProxy.DeviceUpdate(context.TODO(), d); res != nil {
+ onuA.storeDevice(ctx, d)
+ if res := onuA.coreProxy.DeviceUpdate(ctx, d); res != nil {
logger.Fatalf("deviceUpdate-failed-%s", res)
}
d.ConnectStatus = voltha.ConnectStatus_REACHABLE
d.OperStatus = voltha.OperStatus_DISCOVERED
- if err := onuA.coreProxy.DeviceStateUpdate(context.TODO(), d.Id, d.ConnectStatus, d.OperStatus); err != nil {
+ if err := onuA.coreProxy.DeviceStateUpdate(ctx, d.Id, d.ConnectStatus, d.OperStatus); err != nil {
logger.Fatalf("device-state-update-failed-%s", err)
}
@@ -77,7 +77,7 @@
OperStatus: voltha.OperStatus_ACTIVE,
}
var err error
- if err = onuA.coreProxy.PortCreated(context.TODO(), d.Id, uniPort); err != nil {
+ if err = onuA.coreProxy.PortCreated(ctx, d.Id, uniPort); err != nil {
logger.Fatalf("PortCreated-failed-%s", err)
}
@@ -94,36 +94,36 @@
Peers: []*voltha.Port_PeerPort{{DeviceId: d.ParentId, // Peer device is OLT
PortNo: device.ParentPortNo}}, // Peer port is parent's port number
}
- if err = onuA.coreProxy.PortCreated(context.TODO(), d.Id, ponPort); err != nil {
+ if err = onuA.coreProxy.PortCreated(ctx, d.Id, ponPort); err != nil {
logger.Fatalf("PortCreated-failed-%s", err)
}
d.ConnectStatus = voltha.ConnectStatus_REACHABLE
d.OperStatus = voltha.OperStatus_ACTIVE
- if err = onuA.coreProxy.DeviceStateUpdate(context.TODO(), d.Id, d.ConnectStatus, d.OperStatus); err != nil {
+ if err = onuA.coreProxy.DeviceStateUpdate(ctx, d.Id, d.ConnectStatus, d.OperStatus); err != nil {
logger.Fatalf("device-state-update-failed-%s", err)
}
//Get the latest device data from the Core
- if d, err = onuA.coreProxy.GetDevice(context.TODO(), d.Id, d.Id); err != nil {
+ if d, err = onuA.coreProxy.GetDevice(ctx, d.Id, d.Id); err != nil {
logger.Fatalf("getting-device-failed-%s", err)
}
- onuA.updateDevice(d)
+ onuA.updateDevice(ctx, d)
}()
return nil
}
// Get_ofp_port_info returns ofp device info
-func (onuA *ONUAdapter) Get_ofp_port_info(device *voltha.Device, portNo int64) (*ic.PortCapability, error) { // nolint
- if d := onuA.getDevice(device.Id); d == nil {
+func (onuA *ONUAdapter) Get_ofp_port_info(ctx context.Context, device *voltha.Device, portNo int64) (*ic.PortCapability, error) { // nolint
+ if d := onuA.getDevice(ctx, device.Id); d == nil {
logger.Fatalf("device-not-found-%s", device.Id)
}
capability := uint32(of.OfpPortFeatures_OFPPF_1GB_FD | of.OfpPortFeatures_OFPPF_FIBER)
return &ic.PortCapability{
Port: &voltha.LogicalPort{
OfpPort: &of.OfpPort{
- HwAddr: macAddressToUint32Array("12:12:12:12:12:12"),
+ HwAddr: macAddressToUint32Array(ctx, "12:12:12:12:12:12"),
Config: 0,
State: uint32(of.OfpPortState_OFPPS_LIVE),
Curr: capability,
@@ -139,14 +139,14 @@
}
// Disable_device disables device
-func (onuA *ONUAdapter) Disable_device(device *voltha.Device) error { // nolint
+func (onuA *ONUAdapter) Disable_device(ctx context.Context, device *voltha.Device) error { // nolint
go func() {
- if d := onuA.getDevice(device.Id); d == nil {
+ if d := onuA.getDevice(ctx, device.Id); d == nil {
logger.Fatalf("device-not-found-%s", device.Id)
}
cloned := proto.Clone(device).(*voltha.Device)
// Update the all ports state on that device to disable
- if err := onuA.coreProxy.PortsStateUpdate(context.TODO(), cloned.Id, voltha.OperStatus_UNKNOWN); err != nil {
+ if err := onuA.coreProxy.PortsStateUpdate(ctx, cloned.Id, voltha.OperStatus_UNKNOWN); err != nil {
// Device may also have been deleted in the Core
logger.Warnw("updating-ports-failed", log.Fields{"deviceId": device.Id, "error": err})
return
@@ -155,25 +155,25 @@
cloned.ConnectStatus = voltha.ConnectStatus_UNREACHABLE
cloned.OperStatus = voltha.OperStatus_UNKNOWN
- if err := onuA.coreProxy.DeviceStateUpdate(context.TODO(), cloned.Id, cloned.ConnectStatus, cloned.OperStatus); err != nil {
+ if err := onuA.coreProxy.DeviceStateUpdate(ctx, cloned.Id, cloned.ConnectStatus, cloned.OperStatus); err != nil {
logger.Warnw("device-state-update-failed", log.Fields{"deviceId": device.Id, "error": err})
return
}
- onuA.updateDevice(cloned)
+ onuA.updateDevice(ctx, cloned)
}()
return nil
}
// Reenable_device reenables device
-func (onuA *ONUAdapter) Reenable_device(device *voltha.Device) error { // nolint
+func (onuA *ONUAdapter) Reenable_device(ctx context.Context, device *voltha.Device) error { // nolint
go func() {
- if d := onuA.getDevice(device.Id); d == nil {
+ if d := onuA.getDevice(ctx, device.Id); d == nil {
logger.Fatalf("device-not-found-%s", device.Id)
}
cloned := proto.Clone(device).(*voltha.Device)
// Update the all ports state on that device to enable
- if err := onuA.coreProxy.PortsStateUpdate(context.TODO(), cloned.Id, voltha.OperStatus_ACTIVE); err != nil {
+ if err := onuA.coreProxy.PortsStateUpdate(ctx, cloned.Id, voltha.OperStatus_ACTIVE); err != nil {
logger.Fatalf("updating-ports-failed", log.Fields{"deviceId": device.Id, "error": err})
}
@@ -181,22 +181,22 @@
cloned.ConnectStatus = voltha.ConnectStatus_REACHABLE
cloned.OperStatus = voltha.OperStatus_ACTIVE
- if err := onuA.coreProxy.DeviceStateUpdate(context.TODO(), cloned.Id, cloned.ConnectStatus, cloned.OperStatus); err != nil {
+ if err := onuA.coreProxy.DeviceStateUpdate(ctx, cloned.Id, cloned.ConnectStatus, cloned.OperStatus); err != nil {
logger.Fatalf("device-state-update-failed", log.Fields{"deviceId": device.Id, "error": err})
}
- onuA.updateDevice(cloned)
+ onuA.updateDevice(ctx, cloned)
}()
return nil
}
// Start_omci_test begins an omci self-test
-func (onuA *ONUAdapter) Start_omci_test(device *voltha.Device, request *voltha.OmciTestRequest) (*ic.TestResponse, error) { // nolint
+func (onuA *ONUAdapter) Start_omci_test(ctx context.Context, device *voltha.Device, request *voltha.OmciTestRequest) (*ic.TestResponse, error) { // nolint
_ = device
return &ic.TestResponse{Result: ic.TestResponse_SUCCESS}, nil
}
-func (onuA *ONUAdapter) Get_ext_value(deviceId string, device *voltha.Device, valueflag voltha.ValueType_Type) (*voltha.ReturnValues, error) { // nolint
+func (onuA *ONUAdapter) Get_ext_value(ctx context.Context, deviceId string, device *voltha.Device, valueflag voltha.ValueType_Type) (*voltha.ReturnValues, error) { // nolint
_ = deviceId
_ = device
_ = valueflag
diff --git a/rw_core/mocks/adapter_onu_test.go b/rw_core/mocks/adapter_onu_test.go
index ff4ed32..6940ee6 100644
--- a/rw_core/mocks/adapter_onu_test.go
+++ b/rw_core/mocks/adapter_onu_test.go
@@ -17,12 +17,13 @@
package mocks
import (
+ "context"
"github.com/opencord/voltha-lib-go/v3/pkg/adapters"
"testing"
)
func TestONUAdapterImplementsIAdapter(t *testing.T) {
- adapter := NewONUAdapter(nil)
+ adapter := NewONUAdapter(context.Background(), nil)
if _, ok := interface{}(adapter).(adapters.IAdapter); !ok {
t.Error("ONU adapter does not implement voltha-lib-go/v2/pkg/adapters/IAdapter interface")
diff --git a/rw_core/mocks/adapter_test.go b/rw_core/mocks/adapter_test.go
index f748ea9..1850e81 100644
--- a/rw_core/mocks/adapter_test.go
+++ b/rw_core/mocks/adapter_test.go
@@ -17,12 +17,13 @@
package mocks
import (
+ "context"
"github.com/opencord/voltha-lib-go/v3/pkg/adapters"
"testing"
)
func TestAdapterImplementsIAdapter(t *testing.T) {
- adapter := NewAdapter(nil)
+ adapter := NewAdapter(context.Background(), nil)
if _, ok := interface{}(adapter).(adapters.IAdapter); !ok {
t.Error("adapter does not implement voltha-lib-go/v2/pkg/adapters/IAdapter interface")
diff --git a/rw_core/mocks/device_manager.go b/rw_core/mocks/device_manager.go
index e83f935..194b18d 100644
--- a/rw_core/mocks/device_manager.go
+++ b/rw_core/mocks/device_manager.go
@@ -34,7 +34,7 @@
}
// IsRootDevice -
-func (dm *DeviceManager) IsRootDevice(deviceID string) (bool, error) {
+func (dm *DeviceManager) IsRootDevice(ctx context.Context, deviceID string) (bool, error) {
return false, nil
}