[VOL-2442] Fix for Core panic

The logical device agent was receiving logical ports creation
while the logical device was not ready - it was waiting for
switch capability data from the OLT device.  This was causing
a panic.  The fix prevents logical port creation to be
trigerred when the logical device is not ready.  Once the
logical device is ready it will go over the ports data from the
OLT device and automatically create the logical ports.

Change-Id: Iad62302eda80fa158e59852810ad272a8aeedb7b
diff --git a/rw_core/core/common_test.go b/rw_core/core/common_test.go
index 7f6412d..9098f0f 100644
--- a/rw_core/core/common_test.go
+++ b/rw_core/core/common_test.go
@@ -55,6 +55,7 @@
 type isLogicalDeviceConditionSatisfied func(ld *voltha.LogicalDevice) bool
 type isDeviceConditionSatisfied func(ld *voltha.Device) bool
 type isDevicesConditionSatisfied func(ds *voltha.Devices) bool
+type isLogicalDevicesConditionSatisfied func(lds *voltha.LogicalDevices) bool
 
 func init() {
 	_, err := log.AddPackage(log.JSON, logLevel, log.Fields{"instanceId": "coreTests"})
@@ -244,3 +245,31 @@
 		return fmt.Errorf("timeout-waiting-devices")
 	}
 }
+
+func waitUntilConditionForLogicalDevices(timeout time.Duration, nbi *APIHandler, verificationFunction isLogicalDevicesConditionSatisfied) error {
+	ch := make(chan int, 1)
+	done := false
+	go func() {
+		for {
+			lDevices, _ := nbi.ListLogicalDevices(getContext(), &empty.Empty{})
+			if verificationFunction(lDevices) {
+				ch <- 1
+				break
+			}
+			if done {
+				break
+			}
+
+			time.Sleep(retryInterval)
+		}
+	}()
+	timer := time.NewTimer(timeout)
+	defer timer.Stop()
+	select {
+	case <-ch:
+		return nil
+	case <-timer.C:
+		done = true
+		return fmt.Errorf("timeout-waiting-logical-devices")
+	}
+}