[VOL-2866] Removing NNI port before ofagent disconnection

Change-Id: Icb34e1ae0fdebb3495331134e1ed3f456f3cc9f5
diff --git a/rw_core/core/device_state_transitions.go b/rw_core/core/device_state_transitions.go
index 3bf01ec..b8acafc 100644
--- a/rw_core/core/device_state_transitions.go
+++ b/rw_core/core/device_state_transitions.go
@@ -131,7 +131,7 @@
 			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.DeleteLogicalDevice, dMgr.RunPostDeviceDelete}})
+			handlers:      []TransitionHandler{dMgr.DisableAllChildDevices, dMgr.DeleteAllUNILogicalPorts, dMgr.DeleteAllChildDevices, dMgr.DeleteAllLogicalPorts, dMgr.DeleteLogicalDevice, dMgr.RunPostDeviceDelete}})
 	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 8e06cb7..f7e94fb 100644
--- a/rw_core/core/device_state_transitions_test.go
+++ b/rw_core/core/device_state_transitions_test.go
@@ -213,6 +213,7 @@
 			tdm.DisableAllChildDevices,
 			tdm.DeleteAllUNILogicalPorts,
 			tdm.DeleteAllChildDevices,
+			tdm.DeleteAllLogicalPorts,
 			tdm.DeleteLogicalDevice,
 			tdm.RunPostDeviceDelete,
 		},
@@ -230,7 +231,7 @@
 			to.Root = true
 			t.Run(testName, func(t *testing.T) {
 				handlers = transitionMap.GetTransitionHandler(from, to)
-				assert.Equal(t, 5, len(handlers))
+				assert.Equal(t, 6, 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/core/logical_device_agent.go b/rw_core/core/logical_device_agent.go
index 4208e32..64237d3 100644
--- a/rw_core/core/logical_device_agent.go
+++ b/rw_core/core/logical_device_agent.go
@@ -1449,6 +1449,7 @@
 
 // deleteLogicalPorts removes the logical ports associated with that deviceId
 func (agent *LogicalDeviceAgent) deleteLogicalPorts(ctx context.Context, deviceID string) error {
+	logger.Debugw("deleting-logical-ports", log.Fields{"device-id": deviceID})
 	if err := agent.requestQueue.WaitForGreenLight(ctx); err != nil {
 		return err
 	}
@@ -1466,9 +1467,9 @@
 	}
 	logicalDevice.Ports = lPortstoKeep
 
-	logger.Debugw("updated-logical-ports", log.Fields{"ports": lPortstoKeep})
+	logger.Debugw("deleted-logical-ports", log.Fields{"ports": lPortstoKeep})
 	if err := agent.updateLogicalDeviceWithoutLock(ctx, logicalDevice); err != nil {
-		logger.Errorw("logical-device-update-failed", log.Fields{"logicalDeviceId": agent.logicalDeviceID})
+		logger.Errorw("logical-device-update-failed", log.Fields{"logical-device-id": agent.logicalDeviceID})
 		return err
 	}
 	// Remove the port from the cached logical ports set
diff --git a/rw_core/core/logical_device_manager.go b/rw_core/core/logical_device_manager.go
index af76258..f2554d6 100644
--- a/rw_core/core/logical_device_manager.go
+++ b/rw_core/core/logical_device_manager.go
@@ -98,6 +98,7 @@
 // getLogicalDeviceAgent returns the logical device agent.  If the device is not in memory then the device will
 // be loaded from dB and a logical device agent created to managed it.
 func (ldMgr *LogicalDeviceManager) getLogicalDeviceAgent(ctx context.Context, logicalDeviceID string) *LogicalDeviceAgent {
+	logger.Debugw("get-logical-device-agent", log.Fields{"logical-device-id": logicalDeviceID})
 	agent, ok := ldMgr.logicalDeviceAgents.Load(logicalDeviceID)
 	if ok {
 		lda := agent.(*LogicalDeviceAgent)
@@ -427,7 +428,7 @@
 
 // deleteLogicalPort removes the logical port associated with a child device
 func (ldMgr *LogicalDeviceManager) deleteLogicalPorts(ctx context.Context, deviceID string) error {
-	logger.Debugw("deleting-logical-ports", log.Fields{"deviceId": deviceID})
+	logger.Debugw("deleting-logical-ports", log.Fields{"device-id": deviceID})
 	// Get logical port
 	ldID, err := ldMgr.getLogicalDeviceIDFromDeviceID(ctx, deviceID)
 	if err != nil {
@@ -435,11 +436,11 @@
 	}
 	if agent := ldMgr.getLogicalDeviceAgent(ctx, *ldID); agent != nil {
 		if err = agent.deleteLogicalPorts(ctx, deviceID); err != nil {
-			logger.Warnw("deleteLogicalPorts-failed", log.Fields{"ldeviceId": *ldID})
+			logger.Warnw("delete-logical-ports-failed", log.Fields{"logical-device-id": *ldID})
 			return err
 		}
 	}
-	logger.Debug("deleting-logical-port-ends")
+	logger.Debug("deleting-logical-ports-ends")
 	return nil
 }