[VOL-2500] Fix panic in Core
Change-Id: Icab88ac08048bcc334a311ff4c47615baf099d05
diff --git a/rw_core/core/adapter_manager.go b/rw_core/core/adapter_manager.go
index e502ff1..96fceb3 100644
--- a/rw_core/core/adapter_manager.go
+++ b/rw_core/core/adapter_manager.go
@@ -152,8 +152,11 @@
if adaptersIf != nil {
for _, adapterIf := range adaptersIf.([]interface{}) {
if adapter, ok := adapterIf.(*voltha.Adapter); ok {
- log.Debugw("found-existing-adapter", log.Fields{"adapterId": adapter.Id})
- return aMgr.addAdapter(adapter, false)
+ if err := aMgr.addAdapter(adapter, false); err != nil {
+ log.Errorw("failed to add adapter", log.Fields{"adapterId": adapter.Id})
+ } else {
+ log.Debugw("adapter added successfully", log.Fields{"adapterId": adapter.Id})
+ }
}
}
} else {
@@ -174,6 +177,8 @@
if dType, ok := deviceTypeIf.(*voltha.DeviceType); ok {
log.Debugw("found-existing-device-types", log.Fields{"deviceTypes": dTypes})
dTypes.Items = append(dTypes.Items, dType)
+ } else {
+ log.Errorw("not an voltha device type", log.Fields{"interface": deviceTypeIf})
}
}
return aMgr.addDeviceTypes(dTypes, false)
diff --git a/rw_core/core/device_agent.go b/rw_core/core/device_agent.go
index a97e12a..4053b46 100755
--- a/rw_core/core/device_agent.go
+++ b/rw_core/core/device_agent.go
@@ -367,6 +367,10 @@
// received
response := coreutils.NewResponse()
dType := agent.adapterMgr.getDeviceType(device.Type)
+ if dType == nil {
+ log.Errorw("non-existent device type", log.Fields{"deviceType": device.Type})
+ return coreutils.DoneResponse(), status.Errorf(codes.FailedPrecondition, "non-existent device type %s", device.Type)
+ }
if !dType.AcceptsAddRemoveFlowUpdates {
if len(updatedAllGroups) != 0 && reflect.DeepEqual(existingGroups.Items, updatedAllGroups) && len(updatedAllFlows) != 0 && reflect.DeepEqual(existingFlows.Items, updatedAllFlows) {
@@ -463,6 +467,10 @@
// Send update to adapters
response := coreutils.NewResponse()
dType := agent.adapterMgr.getDeviceType(device.Type)
+ if dType == nil {
+ log.Errorw("non-existent device type", log.Fields{"deviceType": device.Type})
+ return coreutils.DoneResponse(), status.Errorf(codes.FailedPrecondition, "non-existent device type %s", device.Type)
+ }
if !dType.AcceptsAddRemoveFlowUpdates {
if len(groupsToKeep) != 0 && reflect.DeepEqual(existingGroups.Items, groupsToKeep) && len(flowsToKeep) != 0 && reflect.DeepEqual(existingFlows.Items, flowsToKeep) {
log.Debugw("nothing-to-update", log.Fields{"deviceId": agent.deviceID, "flowsToDel": flowsToDel, "groupsToDel": groupsToDel})
@@ -536,6 +544,10 @@
response := coreutils.NewResponse()
dType := agent.adapterMgr.getDeviceType(device.Type)
+ if dType == nil {
+ log.Errorw("non-existent device type", log.Fields{"deviceType": device.Type})
+ return coreutils.DoneResponse(), status.Errorf(codes.FailedPrecondition, "non-existent device type %s", device.Type)
+ }
// Process bulk flow update differently than incremental update
if !dType.AcceptsAddRemoveFlowUpdates {