VOL-1900 lint warning fixes ro_core
Change-Id: I5ce82f2d188d215ba9620d0923a1101ed4e5e4a8
diff --git a/ro_core/core/device_agent.go b/ro_core/core/device_agent.go
index 63af020..345e424 100644
--- a/ro_core/core/device_agent.go
+++ b/ro_core/core/device_agent.go
@@ -13,21 +13,24 @@
* See the License for the specific language governing permissions and
* limitations under the License.
*/
+
package core
import (
"context"
+ "sync"
+
"github.com/gogo/protobuf/proto"
"github.com/opencord/voltha-go/db/model"
"github.com/opencord/voltha-lib-go/v2/pkg/log"
"github.com/opencord/voltha-protos/v2/go/voltha"
"google.golang.org/grpc/codes"
"google.golang.org/grpc/status"
- "sync"
)
+// DeviceAgent holds device specific information
type DeviceAgent struct {
- deviceId string
+ deviceID string
deviceType string
lastData *voltha.Device
deviceMgr *DeviceManager
@@ -40,7 +43,7 @@
//preprovisioning
func newDeviceAgent(device *voltha.Device, deviceMgr *DeviceManager, cdProxy *model.Proxy) *DeviceAgent {
var agent DeviceAgent
- agent.deviceId = device.Id
+ agent.deviceID = device.Id
agent.deviceType = device.Type
agent.lastData = device
agent.deviceMgr = deviceMgr
@@ -56,13 +59,13 @@
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 := agent.clusterDataProxy.Get(ctx, "/devices/"+agent.deviceID, 0, false, ""); device != nil {
if d, ok := device.(*voltha.Device); ok {
agent.lastData = proto.Clone(d).(*voltha.Device)
}
} else {
- log.Errorw("failed-to-load-device", log.Fields{"deviceId": agent.deviceId})
- return status.Errorf(codes.NotFound, "device-%s", agent.deviceId)
+ log.Errorw("failed-to-load-device", log.Fields{"deviceID": agent.deviceID})
+ return status.Errorf(codes.NotFound, "device-%s", agent.deviceID)
}
log.Debugw("device-loaded-from-dB", log.Fields{"device": agent.lastData})
}
@@ -83,123 +86,95 @@
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 := agent.clusterDataProxy.Get(context.Background(), "/devices/"+agent.deviceID, 0, false, ""); device != nil {
if d, ok := device.(*voltha.Device); ok {
cloned := proto.Clone(d).(*voltha.Device)
return cloned, nil
}
}
- return nil, status.Errorf(codes.NotFound, "device-%s", agent.deviceId)
-}
-
-// getDeviceWithoutLock is a helper function to be used ONLY by any device agent function AFTER it has acquired the device lock.
-// This function is meant so that we do not have duplicate code all over the device agent functions
-func (agent *DeviceAgent) getDeviceWithoutLock() (*voltha.Device, error) {
- if device := agent.clusterDataProxy.Get(context.Background(), "/devices/"+agent.deviceId, 0, false, ""); device != nil {
- if d, ok := device.(*voltha.Device); ok {
- cloned := proto.Clone(d).(*voltha.Device)
- return cloned, nil
- }
- }
- return nil, status.Errorf(codes.NotFound, "device-%s", agent.deviceId)
-}
-
-// getPorts retrieves the ports information of the device based on the port type.
-func (agent *DeviceAgent) getPorts(ctx context.Context, portType voltha.Port_PortType) *voltha.Ports {
- log.Debugw("getPorts", log.Fields{"id": agent.deviceId, "portType": portType})
- ports := &voltha.Ports{}
- if device, _ := agent.deviceMgr.GetDevice(agent.deviceId); device != nil {
- for _, port := range device.Ports {
- if port.Type == portType {
- ports.Items = append(ports.Items, port)
- }
- }
- }
- return ports
+ return nil, status.Errorf(codes.NotFound, "device-%s", agent.deviceID)
}
// ListDevicePorts retrieves the ports information for a particular device.
func (agent *DeviceAgent) ListDevicePorts(ctx context.Context) (*voltha.Ports, error) {
- log.Debugw("ListDevicePorts", log.Fields{"id": agent.deviceId})
+ log.Debugw("ListDevicePorts", log.Fields{"id": agent.deviceID})
ports := &voltha.Ports{}
- if device, _ := agent.deviceMgr.GetDevice(agent.deviceId); device != nil {
- for _, entry := range device.GetPorts() {
- ports.Items = append(ports.Items, entry)
- }
+ if device, _ := agent.deviceMgr.GetDevice(agent.deviceID); device != nil {
+ ports.Items = append(ports.Items, device.GetPorts()...)
return ports, nil
}
- return nil, status.Errorf(codes.NotFound, "device-%s", agent.deviceId)
+ return nil, status.Errorf(codes.NotFound, "device-%s", agent.deviceID)
}
// ListDevicePmConfigs retrieves the ports information for a particular device.
func (agent *DeviceAgent) ListDevicePmConfigs(ctx context.Context) (*voltha.PmConfigs, error) {
- log.Debugw("ListDevicePmConfigs", log.Fields{"id": agent.deviceId})
- if device, _ := agent.deviceMgr.GetDevice(agent.deviceId); device != nil {
+ log.Debugw("ListDevicePmConfigs", log.Fields{"id": agent.deviceID})
+ if device, _ := agent.deviceMgr.GetDevice(agent.deviceID); device != nil {
return device.GetPmConfigs(), nil
}
- return nil, status.Errorf(codes.NotFound, "device-%s", agent.deviceId)
+ return nil, status.Errorf(codes.NotFound, "device-%s", agent.deviceID)
}
// ListDeviceFlows retrieves the ports information for a particular device.
func (agent *DeviceAgent) ListDeviceFlows(ctx context.Context) (*voltha.Flows, error) {
- log.Debugw("ListDeviceFlows", log.Fields{"id": agent.deviceId})
- if device, _ := agent.deviceMgr.GetDevice(agent.deviceId); device != nil {
+ log.Debugw("ListDeviceFlows", log.Fields{"id": agent.deviceID})
+ if device, _ := agent.deviceMgr.GetDevice(agent.deviceID); device != nil {
return device.GetFlows(), nil
}
- return nil, status.Errorf(codes.NotFound, "device-%s", agent.deviceId)
+ return nil, status.Errorf(codes.NotFound, "device-%s", agent.deviceID)
}
-// ListDeviceFlows retrieves the ports information for a particular device.
+// ListDeviceFlowGroups retrieves the ports information for a particular device.
func (agent *DeviceAgent) ListDeviceFlowGroups(ctx context.Context) (*voltha.FlowGroups, error) {
- log.Debugw("ListDeviceFlowGroups", log.Fields{"id": agent.deviceId})
- if device, _ := agent.deviceMgr.GetDevice(agent.deviceId); device != nil {
+ log.Debugw("ListDeviceFlowGroups", log.Fields{"id": agent.deviceID})
+ if device, _ := agent.deviceMgr.GetDevice(agent.deviceID); device != nil {
return device.GetFlowGroups(), nil
}
- return nil, status.Errorf(codes.NotFound, "device-%s", agent.deviceId)
+ return nil, status.Errorf(codes.NotFound, "device-%s", agent.deviceID)
}
// GetImageDownloadStatus retrieves the download status of an image of a particular device.
func (agent *DeviceAgent) GetImageDownloadStatus(ctx context.Context, imageName string) (*voltha.ImageDownload, error) {
- log.Debugw("GetImageDownloadStatus", log.Fields{"id": agent.deviceId})
- if device, _ := agent.deviceMgr.GetDevice(agent.deviceId); device != nil {
+ log.Debugw("GetImageDownloadStatus", log.Fields{"id": agent.deviceID})
+ if device, _ := agent.deviceMgr.GetDevice(agent.deviceID); device != nil {
for _, img := range device.GetImageDownloads() {
if img.GetName() == imageName {
return img, nil
}
}
- return nil, status.Errorf(codes.NotFound, "device-%s, image-%s", agent.deviceId, imageName)
+ return nil, status.Errorf(codes.NotFound, "device-%s, image-%s", agent.deviceID, imageName)
}
- return nil, status.Errorf(codes.NotFound, "device-%s", agent.deviceId)
+ return nil, status.Errorf(codes.NotFound, "device-%s", agent.deviceID)
}
// GetImageDownload retrieves the image download for a particular device.
func (agent *DeviceAgent) GetImageDownload(ctx context.Context, imageName string) (*voltha.ImageDownload, error) {
- log.Debugw("GetImageDownload", log.Fields{"id": agent.deviceId})
- if device, _ := agent.deviceMgr.GetDevice(agent.deviceId); device != nil {
+ log.Debugw("GetImageDownload", log.Fields{"id": agent.deviceID})
+ if device, _ := agent.deviceMgr.GetDevice(agent.deviceID); device != nil {
for _, img := range device.GetImageDownloads() {
if img.GetName() == imageName {
return img, nil
}
}
- return nil, status.Errorf(codes.NotFound, "device-%s, image-%s", agent.deviceId, imageName)
+ return nil, status.Errorf(codes.NotFound, "device-%s, image-%s", agent.deviceID, imageName)
}
- return nil, status.Errorf(codes.NotFound, "device-%s", agent.deviceId)
+ return nil, status.Errorf(codes.NotFound, "device-%s", agent.deviceID)
}
// ListImageDownloads retrieves the image downloads for a particular device.
func (agent *DeviceAgent) ListImageDownloads(ctx context.Context) (*voltha.ImageDownloads, error) {
- log.Debugw("ListImageDownloads", log.Fields{"id": agent.deviceId})
- if device, _ := agent.deviceMgr.GetDevice(agent.deviceId); device != nil {
+ log.Debugw("ListImageDownloads", log.Fields{"id": agent.deviceID})
+ if device, _ := agent.deviceMgr.GetDevice(agent.deviceID); device != nil {
return &voltha.ImageDownloads{Items: device.GetImageDownloads()}, nil
}
- return nil, status.Errorf(codes.NotFound, "device-%s", agent.deviceId)
+ return nil, status.Errorf(codes.NotFound, "device-%s", agent.deviceID)
}
// GetImages retrieves the list of images for a particular device.
func (agent *DeviceAgent) GetImages(ctx context.Context) (*voltha.Images, error) {
- log.Debugw("GetImages", log.Fields{"id": agent.deviceId})
- if device, _ := agent.deviceMgr.GetDevice(agent.deviceId); device != nil {
+ log.Debugw("GetImages", log.Fields{"id": agent.deviceID})
+ if device, _ := agent.deviceMgr.GetDevice(agent.deviceID); device != nil {
return device.GetImages(), nil
}
- return nil, status.Errorf(codes.NotFound, "device-%s", agent.deviceId)
+ return nil, status.Errorf(codes.NotFound, "device-%s", agent.deviceID)
}