[VOL-3187]Pass Context down the execution call hierarchy across voltha-go codebase
Change-Id: I6bc2a0f7226c1beed4ae01a15d7b5c4dc04358d8
diff --git a/rw_core/mocks/adapter.go b/rw_core/mocks/adapter.go
index 7509f1f..ccbeea4 100644
--- a/rw_core/mocks/adapter.go
+++ b/rw_core/mocks/adapter.go
@@ -17,6 +17,7 @@
package mocks
import (
+ "context"
"fmt"
"strconv"
"strings"
@@ -81,72 +82,72 @@
}
// 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,56 +210,56 @@
}
// 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
}
diff --git a/rw_core/mocks/adapter_olt.go b/rw_core/mocks/adapter_olt.go
index c567e40..d040f64 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),
}
}
// 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
@@ -58,7 +58,7 @@
d.MacAddress = strings.ToUpper(com.GetRandomMacAddress())
oltA.storeDevice(d)
if res := oltA.coreProxy.DeviceUpdate(context.TODO(), d); res != nil {
- logger.Fatalf("deviceUpdate-failed-%s", res)
+ logger.Fatalf(ctx, "deviceUpdate-failed-%s", res)
}
capability := uint32(of.OfpPortFeatures_OFPPF_1GB_FD | of.OfpPortFeatures_OFPPF_FIBER)
nniPort := &voltha.Port{
@@ -79,7 +79,7 @@
}
var err error
if err = oltA.coreProxy.PortCreated(context.TODO(), d.Id, nniPort); err != nil {
- logger.Fatalf("PortCreated-failed-%s", err)
+ logger.Fatalf(ctx, "PortCreated-failed-%s", err)
}
ponPort := &voltha.Port{
@@ -89,19 +89,19 @@
OperStatus: voltha.OperStatus_ACTIVE,
}
if err = oltA.coreProxy.PortCreated(context.TODO(), d.Id, ponPort); err != nil {
- logger.Fatalf("PortCreated-failed-%s", err)
+ logger.Fatalf(ctx, "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 {
- logger.Fatalf("Device-state-update-failed-%s", err)
+ logger.Fatalf(ctx, "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 {
- logger.Fatalf("getting-device-failed-%s", err)
+ logger.Fatalf(ctx, "getting-device-failed-%s", err)
}
oltA.updateDevice(d)
@@ -119,7 +119,7 @@
"onu_adapter_mock",
com.GetRandomSerialNumber(),
int64(seqNo)); err != nil {
- logger.Fatalf("failure-sending-child-device-%s", err)
+ logger.Fatalf(ctx, "failure-sending-child-device-%s", err)
}
}(i)
}
@@ -128,9 +128,9 @@
}
// Get_ofp_device_info returns ofp device info
-func (oltA *OLTAdapter) Get_ofp_device_info(device *voltha.Device) (*ic.SwitchCapability, error) { // nolint
+func (oltA *OLTAdapter) Get_ofp_device_info(ctx context.Context, device *voltha.Device) (*ic.SwitchCapability, error) { // nolint
if d := oltA.getDevice(device.Id); d == nil {
- logger.Fatalf("device-not-found-%s", device.Id)
+ logger.Fatalf(ctx, "device-not-found-%s", device.Id)
}
return &ic.SwitchCapability{
Desc: &of.OfpDesc{
@@ -160,16 +160,16 @@
}
// 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 {
- logger.Fatalf("device-not-found-%s", device.Id)
+ logger.Fatalf(ctx, "device-not-found-%s", device.Id)
}
cloned := proto.Clone(device).(*voltha.Device)
// Update the all ports state on that device to disable
if err := oltA.coreProxy.PortsStateUpdate(context.TODO(), cloned.Id, voltha.OperStatus_UNKNOWN); err != nil {
- logger.Warnw("updating-ports-failed", log.Fields{"deviceId": device.Id, "error": err})
+ logger.Warnw(ctx, "updating-ports-failed", log.Fields{"deviceId": device.Id, "error": err})
}
//Update the device operational state
@@ -178,7 +178,7 @@
if err := oltA.coreProxy.DeviceStateUpdate(context.TODO(), cloned.Id, cloned.ConnectStatus, cloned.OperStatus); err != nil {
// Device may already have been deleted in the core
- logger.Warnw("device-state-update-failed", log.Fields{"deviceId": device.Id, "error": err})
+ logger.Warnw(ctx, "device-state-update-failed", log.Fields{"deviceId": device.Id, "error": err})
return
}
@@ -187,47 +187,47 @@
// 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 {
// Device may already have been deleted in the core
- logger.Warnw("lost-notif-of-child-devices-failed", log.Fields{"deviceId": device.Id, "error": err})
+ logger.Warnw(ctx, "lost-notif-of-child-devices-failed", log.Fields{"deviceId": device.Id, "error": err})
}
}()
return nil
}
// 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 {
- logger.Fatalf("device-not-found-%s", device.Id)
+ logger.Fatalf(ctx, "device-not-found-%s", device.Id)
}
cloned := proto.Clone(device).(*voltha.Device)
// Update the all ports state on that device to enable
if err := oltA.coreProxy.PortsStateUpdate(context.TODO(), cloned.Id, voltha.OperStatus_ACTIVE); err != nil {
- logger.Fatalf("updating-ports-failed", log.Fields{"deviceId": device.Id, "error": err})
+ logger.Fatalf(ctx, "updating-ports-failed", log.Fields{"deviceId": device.Id, "error": err})
}
//Update the device state
cloned.OperStatus = voltha.OperStatus_ACTIVE
if err := oltA.coreProxy.DeviceStateUpdate(context.TODO(), cloned.Id, cloned.ConnectStatus, cloned.OperStatus); err != nil {
- logger.Fatalf("device-state-update-failed", log.Fields{"deviceId": device.Id, "error": err})
+ logger.Fatalf(ctx, "device-state-update-failed", log.Fields{"deviceId": device.Id, "error": err})
}
// Tell the Core that all child devices have been enabled
if err := oltA.coreProxy.ChildDevicesDetected(context.TODO(), cloned.Id); err != nil {
- logger.Fatalf("detection-notif-of-child-devices-failed", log.Fields{"deviceId": device.Id, "error": err})
+ logger.Fatalf(ctx, "detection-notif-of-child-devices-failed", log.Fields{"deviceId": device.Id, "error": err})
}
}()
return nil
}
// 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 {
if err := oltA.coreProxy.PortStateUpdate(context.TODO(), deviceId, voltha.Port_PON_OLT, Port.PortNo, voltha.OperStatus_ACTIVE); err != nil {
- logger.Fatalf("updating-ports-failed", log.Fields{"device-id": deviceId, "error": err})
+ logger.Fatalf(ctx, "updating-ports-failed", log.Fields{"device-id": deviceId, "error": err})
}
}
@@ -236,13 +236,13 @@
}
// 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 {
if err := oltA.coreProxy.PortStateUpdate(context.TODO(), deviceId, voltha.Port_PON_OLT, Port.PortNo, voltha.OperStatus_DISCOVERED); err != nil {
// Corresponding device may have been deleted
- logger.Warnw("updating-ports-failed", log.Fields{"device-id": deviceId, "error": err})
+ logger.Warnw(ctx, "updating-ports-failed", log.Fields{"device-id": deviceId, "error": err})
}
}
}()
@@ -250,33 +250,33 @@
}
// 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
- logger.Infow("reboot-device", log.Fields{"deviceId": device.Id})
+func (oltA *OLTAdapter) Reboot_device(ctx context.Context, device *voltha.Device) error { // nolint
+ logger.Infow(ctx, "reboot-device", log.Fields{"deviceId": device.Id})
go func() {
if err := oltA.coreProxy.DeviceStateUpdate(context.TODO(), device.Id, voltha.ConnectStatus_UNREACHABLE, voltha.OperStatus_UNKNOWN); err != nil {
- logger.Fatalf("device-state-update-failed", log.Fields{"device-id": device.Id, "error": err})
+ logger.Fatalf(ctx, "device-state-update-failed", log.Fields{"device-id": device.Id, "error": err})
}
if err := oltA.coreProxy.PortsStateUpdate(context.TODO(), device.Id, voltha.OperStatus_UNKNOWN); err != nil {
// Not an error as the previous command will start the process of clearing the OLT
- logger.Infow("port-update-failed", log.Fields{"device-id": device.Id, "error": err})
+ logger.Infow(ctx, "port-update-failed", log.Fields{"device-id": device.Id, "error": err})
}
}()
return nil
}
// 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..082c12e 100644
--- a/rw_core/mocks/adapter_olt_test.go
+++ b/rw_core/mocks/adapter_olt_test.go
@@ -17,13 +17,14 @@
package mocks
import (
+ "context"
"testing"
"github.com/opencord/voltha-lib-go/v3/pkg/adapters"
)
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 02c885e..8e7b867 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),
}
}
// 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
@@ -53,14 +53,14 @@
d.MacAddress = strings.ToUpper(com.GetRandomMacAddress())
onuA.storeDevice(d)
if res := onuA.coreProxy.DeviceUpdate(context.TODO(), d); res != nil {
- logger.Fatalf("deviceUpdate-failed-%s", res)
+ logger.Fatalf(ctx, "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 {
- logger.Fatalf("device-state-update-failed-%s", err)
+ logger.Fatalf(ctx, "device-state-update-failed-%s", err)
}
uniPortNo := uint32(2)
@@ -90,7 +90,7 @@
var err error
if err = onuA.coreProxy.PortCreated(context.TODO(), d.Id, uniPort); err != nil {
- logger.Fatalf("PortCreated-failed-%s", err)
+ logger.Fatalf(ctx, "PortCreated-failed-%s", err)
}
ponPortNo := uint32(1)
@@ -107,18 +107,18 @@
PortNo: device.ParentPortNo}}, // Peer port is parent's port number
}
if err = onuA.coreProxy.PortCreated(context.TODO(), d.Id, ponPort); err != nil {
- logger.Fatalf("PortCreated-failed-%s", err)
+ logger.Fatalf(ctx, "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 {
- logger.Fatalf("device-state-update-failed-%s", err)
+ logger.Fatalf(ctx, "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 {
- logger.Fatalf("getting-device-failed-%s", err)
+ logger.Fatalf(ctx, "getting-device-failed-%s", err)
}
onuA.updateDevice(d)
@@ -127,16 +127,16 @@
}
// 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 {
- logger.Fatalf("device-not-found-%s", device.Id)
+ logger.Fatalf(ctx, "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 {
// Device may also have been deleted in the Core
- logger.Warnw("updating-ports-failed", log.Fields{"deviceId": device.Id, "error": err})
+ logger.Warnw(ctx, "updating-ports-failed", log.Fields{"deviceId": device.Id, "error": err})
return
}
//Update the device state
@@ -144,7 +144,7 @@
cloned.OperStatus = voltha.OperStatus_UNKNOWN
if err := onuA.coreProxy.DeviceStateUpdate(context.TODO(), cloned.Id, cloned.ConnectStatus, cloned.OperStatus); err != nil {
- logger.Warnw("device-state-update-failed", log.Fields{"deviceId": device.Id, "error": err})
+ logger.Warnw(ctx, "device-state-update-failed", log.Fields{"deviceId": device.Id, "error": err})
return
}
onuA.updateDevice(cloned)
@@ -153,16 +153,16 @@
}
// 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 {
- logger.Fatalf("device-not-found-%s", device.Id)
+ logger.Fatalf(ctx, "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 {
- logger.Fatalf("updating-ports-failed", log.Fields{"deviceId": device.Id, "error": err})
+ logger.Fatalf(ctx, "updating-ports-failed", log.Fields{"deviceId": device.Id, "error": err})
}
//Update the device state
@@ -170,7 +170,7 @@
cloned.OperStatus = voltha.OperStatus_ACTIVE
if err := onuA.coreProxy.DeviceStateUpdate(context.TODO(), cloned.Id, cloned.ConnectStatus, cloned.OperStatus); err != nil {
- logger.Fatalf("device-state-update-failed", log.Fields{"deviceId": device.Id, "error": err})
+ logger.Fatalf(ctx, "device-state-update-failed", log.Fields{"deviceId": device.Id, "error": err})
}
onuA.updateDevice(cloned)
@@ -179,12 +179,12 @@
}
// 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/common.go b/rw_core/mocks/common.go
index 3b2df29..836770c 100644
--- a/rw_core/mocks/common.go
+++ b/rw_core/mocks/common.go
@@ -21,12 +21,12 @@
"github.com/opencord/voltha-lib-go/v3/pkg/log"
)
-var logger log.Logger
+var logger log.CLogger
func init() {
// Setup this package so that it's log level can be modified at run time
var err error
- logger, err = log.AddPackage(log.JSON, log.ErrorLevel, log.Fields{"pkg": "mocks"})
+ logger, err = log.RegisterPackage(log.JSON, log.ErrorLevel, log.Fields{"pkg": "mocks"})
if err != nil {
panic(err)
}