Revert "[VOL-1385] : code changes to support ONU delete"
This reverts commit e935b33392e67708b83292c27480ae5258c37724.
Change-Id: Ibd10b43d8d6264a7b0b12386eb9833b5a4864ffd
diff --git a/rw_core/core/device_agent.go b/rw_core/core/device_agent.go
index 22ca6ca..d20874a 100755
--- a/rw_core/core/device_agent.go
+++ b/rw_core/core/device_agent.go
@@ -705,19 +705,35 @@
log.Debugw("device-already-in-deleted-state", log.Fields{"id": agent.deviceID})
return nil
}
+ if (cloned.AdminState != voltha.AdminState_DISABLED) &&
+ (cloned.AdminState != voltha.AdminState_PREPROVISIONED) {
+ log.Debugw("device-not-disabled", log.Fields{"id": agent.deviceID})
+ //TODO: Needs customized error message
+ return status.Errorf(codes.FailedPrecondition, "deviceId:%s, expected-admin-state:%s", agent.deviceID, voltha.AdminState_DISABLED)
+ }
if cloned.AdminState != voltha.AdminState_PREPROVISIONED {
+ // Send the request to an Adapter only if the device is not in poreporovision state and wait for a response
if err := agent.adapterProxy.DeleteDevice(ctx, cloned); err != nil {
log.Debugw("deleteDevice-error", log.Fields{"id": agent.deviceID, "error": err})
return err
}
}
- //Set the state to deleted - this will trigger some background process to invoke parent adapter to delete child
- //device and clean up the device as well as its association with the logical device
+ // Set the state to deleted after we receive an Ack - this will trigger some background process to clean up
+ // the device as well as its association with the logical device
cloned.AdminState = voltha.AdminState_DELETED
-
if err := agent.updateDeviceInStoreWithoutLock(ctx, cloned, false, ""); err != nil {
return err
}
+ // If this is a child device then remove the associated peer ports on the parent device
+ if !cloned.Root {
+ go func() {
+ // since the caller does not wait for this for complete, use background context
+ err := agent.deviceMgr.deletePeerPorts(context.Background(), cloned.ParentId, cloned.Id)
+ if err != nil {
+ log.Errorw("unable-to-delete-peer-ports", log.Fields{"error": err})
+ }
+ }()
+ }
return nil
}
@@ -1280,6 +1296,8 @@
}
func (agent *DeviceAgent) deletePeerPorts(ctx context.Context, deviceID string) error {
+ agent.lockDevice.Lock()
+ defer agent.lockDevice.Unlock()
log.Debug("deletePeerPorts")
cloned := agent.getDeviceWithoutLock()
@@ -1448,21 +1466,3 @@
}
return nil
}
-
-func (agent *DeviceAgent) ChildDeviceLost(ctx context.Context, device *voltha.Device) error {
-
- agent.lockDevice.Lock()
- defer agent.lockDevice.Unlock()
- log.Debugw("ChildDeviceLost", log.Fields{"id": device.Id})
-
- //Remove the associated peer ports on the parent device
- if err := agent.deviceMgr.deletePeerPorts(ctx, device.ParentId, device.Id); err != nil {
- return err
- }
-
- if err := agent.adapterProxy.ChildDeviceLost(ctx, agent.deviceType, agent.deviceID, device.ParentPortNo, device.ProxyAddress.OnuId); err != nil {
- return err
- }
- return nil
-
-}