[VOL-2865] : code changes to support uniform state transition for OLT delete

Change-Id: I2f829c23bdb39e2d91f00a849b6b965a0df9a54e
diff --git a/VERSION b/VERSION
index 005119b..d47c6fe 100644
--- a/VERSION
+++ b/VERSION
@@ -1 +1 @@
-2.4.1
+2.4.2-dev0
diff --git a/rw_core/core/device/logical_agent.go b/rw_core/core/device/logical_agent.go
index dd40863..b87b81e 100644
--- a/rw_core/core/device/logical_agent.go
+++ b/rw_core/core/device/logical_agent.go
@@ -486,34 +486,6 @@
 	return nil
 }
 
-// deleteAllUNILogicalPorts deletes all UNI logical ports associated with this parent device
-func (agent *LogicalAgent) deleteAllUNILogicalPorts(ctx context.Context, parentDevice *voltha.Device) error {
-	logger.Debugw("delete-all-uni-logical-ports", log.Fields{"logical-device-id": agent.logicalDeviceID})
-	if err := agent.requestQueue.WaitForGreenLight(ctx); err != nil {
-		return err
-	}
-	defer agent.requestQueue.RequestComplete()
-	// Get the latest logical device info
-	ld := agent.getLogicalDeviceWithoutLock()
-
-	updateLogicalPorts := []*voltha.LogicalPort{}
-	for _, lport := range ld.Ports {
-		// Save NNI ports only
-		if agent.isNNIPort(lport.DevicePortNo) {
-			updateLogicalPorts = append(updateLogicalPorts, lport)
-		}
-	}
-	if len(updateLogicalPorts) < len(ld.Ports) {
-		// Updating the logical device will trigger the port change events to be populated to the controller
-		if err := agent.updateLogicalDevicePortsWithoutLock(ctx, ld, updateLogicalPorts); err != nil {
-			return err
-		}
-	} else {
-		logger.Debugw("no-change-required", log.Fields{"logical-device-id": agent.logicalDeviceID})
-	}
-	return nil
-}
-
 func clonePorts(ports []*voltha.LogicalPort) []*voltha.LogicalPort {
 	return proto.Clone(&voltha.LogicalPorts{Items: ports}).(*voltha.LogicalPorts).Items
 }
diff --git a/rw_core/core/device/logical_manager.go b/rw_core/core/device/logical_manager.go
index 53c3759..d9b6731 100644
--- a/rw_core/core/device/logical_manager.go
+++ b/rw_core/core/device/logical_manager.go
@@ -440,23 +440,6 @@
 	return nil
 }
 
-func (ldMgr *LogicalManager) deleteAllUNILogicalPorts(ctx context.Context, parentDevice *voltha.Device) error {
-	logger.Debugw("delete-all-uni-logical-ports", log.Fields{"parent-device-id": parentDevice.Id})
-
-	var ldID *string
-	var err error
-	//Get the logical device Id for this device
-	if ldID, err = ldMgr.getLogicalDeviceID(ctx, parentDevice); err != nil {
-		return err
-	}
-	if agent := ldMgr.getLogicalDeviceAgent(ctx, *ldID); agent != nil {
-		if err := agent.deleteAllUNILogicalPorts(ctx, parentDevice); err != nil {
-			return err
-		}
-	}
-	return nil
-}
-
 func (ldMgr *LogicalManager) updatePortState(ctx context.Context, deviceID string, portNo uint32, state voltha.OperStatus_Types) error {
 	logger.Debugw("updatePortState", log.Fields{"deviceId": deviceID, "state": state, "portNo": portNo})
 
diff --git a/rw_core/core/device/manager.go b/rw_core/core/device/manager.go
index 73ab456..0c4448b 100755
--- a/rw_core/core/device/manager.go
+++ b/rw_core/core/device/manager.go
@@ -1288,16 +1288,6 @@
 	return nil
 }
 
-//DeleteAllUNILogicalPorts is invoked as a callback when the parent device is deleted
-func (dMgr *Manager) DeleteAllUNILogicalPorts(ctx context.Context, curr *voltha.Device) error {
-	logger.Debugw("delete-all-uni-logical-ports", log.Fields{"parent-device-id": curr.Id})
-	if err := dMgr.logicalDeviceMgr.deleteAllUNILogicalPorts(ctx, curr); err != nil {
-		// Just log the error and let the remaining pipeline proceed - ports may already have been deleted
-		logger.Warnw("delete-all-uni-logical-ports-failed", log.Fields{"parent-device-id": curr.Id, "error": err})
-	}
-	return nil
-}
-
 //DeleteAllLogicalPorts is invoked as a callback when the parent device's connection status moves to UNREACHABLE
 func (dMgr *Manager) DeleteAllLogicalPorts(ctx context.Context, parentDevice *voltha.Device) error {
 	logger.Debugw("delete-all-logical-ports", log.Fields{"parent-device-id": parentDevice.Id})
diff --git a/rw_core/core/device/state_transitions.go b/rw_core/core/device/state_transitions.go
index f7be154..15f4c1e 100644
--- a/rw_core/core/device/state_transitions.go
+++ b/rw_core/core/device/state_transitions.go
@@ -131,19 +131,19 @@
 			deviceType:    parent,
 			previousState: deviceState{Admin: voltha.AdminState_UNKNOWN, Connection: voltha.ConnectStatus_UNKNOWN, Operational: voltha.OperStatus_UNKNOWN},
 			currentState:  deviceState{Admin: voltha.AdminState_DELETED, Connection: voltha.ConnectStatus_UNKNOWN, Operational: voltha.OperStatus_UNKNOWN},
-			handlers:      []TransitionHandler{dMgr.DisableAllChildDevices, dMgr.DeleteAllUNILogicalPorts, dMgr.DeleteAllChildDevices, dMgr.DeleteAllLogicalPorts, dMgr.DeleteLogicalDevice, dMgr.RunPostDeviceDelete}})
+			handlers:      []TransitionHandler{dMgr.DeleteAllLogicalPorts, dMgr.DeleteAllChildDevices, dMgr.DeleteLogicalDevice, dMgr.RunPostDeviceDelete}})
 	transitionMap.transitions = append(transitionMap.transitions,
 		Transition{
 			deviceType:    parent,
 			previousState: deviceState{Admin: voltha.AdminState_ENABLED, Connection: voltha.ConnectStatus_REACHABLE, Operational: voltha.OperStatus_ACTIVE},
 			currentState:  deviceState{Admin: voltha.AdminState_ENABLED, Connection: voltha.ConnectStatus_UNREACHABLE, Operational: voltha.OperStatus_UNKNOWN},
-			handlers:      []TransitionHandler{dMgr.DeleteAllLogicalPorts, dMgr.DeleteLogicalDevice, dMgr.DeleteAllChildDevices, dMgr.DeleteAllDeviceFlows}})
+			handlers:      []TransitionHandler{dMgr.DeleteAllLogicalPorts, dMgr.DeleteAllChildDevices, dMgr.DeleteLogicalDevice, dMgr.DeleteAllDeviceFlows}})
 	transitionMap.transitions = append(transitionMap.transitions,
 		Transition{
 			deviceType:    parent,
 			previousState: deviceState{Admin: voltha.AdminState_DISABLED, Connection: voltha.ConnectStatus_REACHABLE, Operational: voltha.OperStatus_UNKNOWN},
 			currentState:  deviceState{Admin: voltha.AdminState_DISABLED, Connection: voltha.ConnectStatus_UNREACHABLE, Operational: voltha.OperStatus_UNKNOWN},
-			handlers:      []TransitionHandler{dMgr.DeleteAllLogicalPorts, dMgr.DeleteLogicalDevice, dMgr.DeleteAllChildDevices, dMgr.DeleteAllDeviceFlows}})
+			handlers:      []TransitionHandler{dMgr.DeleteAllLogicalPorts, dMgr.DeleteAllChildDevices, dMgr.DeleteLogicalDevice, dMgr.DeleteAllDeviceFlows}})
 	transitionMap.transitions = append(transitionMap.transitions,
 		Transition{
 			deviceType:    parent,
diff --git a/rw_core/core/device/state_transitions_test.go b/rw_core/core/device/state_transitions_test.go
index 0a1b43b..41d77dd 100644
--- a/rw_core/core/device/state_transitions_test.go
+++ b/rw_core/core/device/state_transitions_test.go
@@ -187,8 +187,8 @@
 	handlers = transitionMap.GetTransitionHandler(device, previousState)
 	assert.Equal(t, 4, len(handlers))
 	assert.True(t, reflect.ValueOf(tdm.DeleteAllLogicalPorts).Pointer() == reflect.ValueOf(handlers[0]).Pointer())
-	assert.True(t, reflect.ValueOf(tdm.DeleteLogicalDevice).Pointer() == reflect.ValueOf(handlers[1]).Pointer())
-	assert.True(t, reflect.ValueOf(tdm.DeleteAllChildDevices).Pointer() == reflect.ValueOf(handlers[2]).Pointer())
+	assert.True(t, reflect.ValueOf(tdm.DeleteAllChildDevices).Pointer() == reflect.ValueOf(handlers[1]).Pointer())
+	assert.True(t, reflect.ValueOf(tdm.DeleteLogicalDevice).Pointer() == reflect.ValueOf(handlers[2]).Pointer())
 	assert.True(t, reflect.ValueOf(tdm.DeleteAllDeviceFlows).Pointer() == reflect.ValueOf(handlers[3]).Pointer())
 
 	previousState = getDeviceState(voltha.AdminState_ENABLED, voltha.ConnectStatus_UNREACHABLE, voltha.OperStatus_UNKNOWN)
@@ -202,8 +202,8 @@
 	handlers = transitionMap.GetTransitionHandler(device, previousState)
 	assert.Equal(t, 4, len(handlers))
 	assert.True(t, reflect.ValueOf(tdm.DeleteAllLogicalPorts).Pointer() == reflect.ValueOf(handlers[0]).Pointer())
-	assert.True(t, reflect.ValueOf(tdm.DeleteLogicalDevice).Pointer() == reflect.ValueOf(handlers[1]).Pointer())
-	assert.True(t, reflect.ValueOf(tdm.DeleteAllChildDevices).Pointer() == reflect.ValueOf(handlers[2]).Pointer())
+	assert.True(t, reflect.ValueOf(tdm.DeleteAllChildDevices).Pointer() == reflect.ValueOf(handlers[1]).Pointer())
+	assert.True(t, reflect.ValueOf(tdm.DeleteLogicalDevice).Pointer() == reflect.ValueOf(handlers[2]).Pointer())
 	assert.True(t, reflect.ValueOf(tdm.DeleteAllDeviceFlows).Pointer() == reflect.ValueOf(handlers[3]).Pointer())
 
 	previousState = getDeviceState(voltha.AdminState_DISABLED, voltha.ConnectStatus_UNREACHABLE, voltha.OperStatus_UNKNOWN)
@@ -233,10 +233,8 @@
 			getDevice(false, voltha.AdminState_DELETED, voltha.ConnectStatus_UNREACHABLE, voltha.OperStatus_FAILED),
 		},
 		expectedParentHandlers: []TransitionHandler{
-			tdm.DisableAllChildDevices,
-			tdm.DeleteAllUNILogicalPorts,
-			tdm.DeleteAllChildDevices,
 			tdm.DeleteAllLogicalPorts,
+			tdm.DeleteAllChildDevices,
 			tdm.DeleteLogicalDevice,
 			tdm.RunPostDeviceDelete,
 		},
@@ -253,7 +251,7 @@
 			device.Root = true
 			t.Run(testName, func(t *testing.T) {
 				handlers = transitionMap.GetTransitionHandler(device, previousState)
-				assert.Equal(t, 6, len(handlers))
+				assert.Equal(t, 4, len(handlers))
 				for idx, expHandler := range deleteDeviceTest.expectedParentHandlers {
 					assert.True(t, reflect.ValueOf(expHandler).Pointer() == reflect.ValueOf(handlers[idx]).Pointer())
 				}
diff --git a/rw_core/coreif/device_manager_if.go b/rw_core/coreif/device_manager_if.go
index 0b8fc74..4d23e5c 100644
--- a/rw_core/coreif/device_manager_if.go
+++ b/rw_core/coreif/device_manager_if.go
@@ -38,7 +38,6 @@
 	DeleteAllChildDevices(ctx context.Context, curr *voltha.Device) error
 	RunPostDeviceDelete(ctx context.Context, curr *voltha.Device) error
 	ChildDeviceLost(ctx context.Context, curr *voltha.Device) error
-	DeleteAllUNILogicalPorts(ctx context.Context, curr *voltha.Device) error
 	DeleteAllLogicalPorts(ctx context.Context, curr *voltha.Device) error
 	DeleteAllDeviceFlows(ctx context.Context, curr *voltha.Device) error
 }
diff --git a/rw_core/mocks/device_manager.go b/rw_core/mocks/device_manager.go
index 6bee293..e83f935 100644
--- a/rw_core/mocks/device_manager.go
+++ b/rw_core/mocks/device_manager.go
@@ -73,11 +73,6 @@
 	return nil
 }
 
-// DeleteAllUNILogicalPorts -
-func (dm *DeviceManager) DeleteAllUNILogicalPorts(ctx context.Context, cDevice *voltha.Device) error {
-	return nil
-}
-
 // DeleteAllLogicalPorts -
 func (dm *DeviceManager) DeleteAllLogicalPorts(ctx context.Context, cDevice *voltha.Device) error {
 	return nil