Adding assert checks to Logical Device test recently added to
Olt/Onu Discovery Test Case

Add calico-node container specifier to log request for calico-node
similar to what was done to onos pod

Change-Id: I251ba94704bb7e1c9028f8d4df916db0ef2934f1
diff --git a/tests/atests/common/discovery.py b/tests/atests/common/discovery.py
index e125dcf..fb57a22 100755
--- a/tests/atests/common/discovery.py
+++ b/tests/atests/common/discovery.py
@@ -20,6 +20,7 @@
 
 import testCaseUtils
 import logging
+import os
 
 
 class Discovery(object):
@@ -60,9 +61,35 @@
         testCaseUtils.send_command_to_voltha_cli(testCaseUtils.get_dir(self, 'log'),
                                                  'voltha_logical_device.log', 'logical_device ' + self.__logicalDeviceId,
                                                  'voltha_logical_device_ports.log', 'ports', 'voltha_logical_device_flows.log', 'flows')
+        assert os.path.exists(testCaseUtils.get_dir(self, 'log') + '/voltha_logical_device.log') and \
+            (os.path.getsize(testCaseUtils.get_dir(self, 'log') + '/voltha_logical_device.log') is 0), \
+            'voltha_logical_device.log is not 0 length'
         testCaseUtils.print_log_file(self, 'voltha_logical_device_ports.log')
         testCaseUtils.print_log_file(self, 'voltha_logical_device_flows.log')
 
+    def logical_device_ports_should_exist(self):
+        statusLines = testCaseUtils.get_fields_from_grep_command(self, self.__oltDeviceId, 'voltha_logical_device_ports.log')
+        assert statusLines, 'No Olt device listed under logical device ports'
+        self.__fields = testCaseUtils.parse_fields(statusLines)
+        portType = self.__fields[1].strip()
+        assert portType == 'nni', 'Port type for %s does not match expected nni' % self.__oltDeviceId
+        for onuDeviceId in self.__onuDeviceIds:
+            statusLines = testCaseUtils.get_fields_from_grep_command(self, onuDeviceId, 'voltha_logical_device_ports.log')
+            assert statusLines, 'No Onu device %s listed under logical device ports' % onuDeviceId
+            lines = statusLines.splitlines()
+            for line in lines:
+                self.__fields = testCaseUtils.parse_fields(line)
+                portType = self.__fields[1].strip()
+                assert portType == 'uni-128', 'Port type for %s does not match expected uni-128' % onuDeviceId
+
+    def logical_device_should_have_at_least_one_flow(self):
+        statusLines = testCaseUtils.get_fields_from_grep_command(self, 'Flows', 'voltha_logical_device_flows.log')
+        assert statusLines, 'No Logical device flows listed for logical device'
+        before, flows, numFlows = statusLines.partition('Flows')
+        plainNumber = numFlows.strip().strip('():')
+        if plainNumber.isdigit():
+            assert int(plainNumber) > 0, 'Zero number of flows for logical device'
+
     def olt_discovery(self):
         logging.info('Olt Discovery')
         statusLines = testCaseUtils.get_fields_from_grep_command(self, self.__oltType, 'voltha_devices_after_enable.log')
@@ -165,6 +192,8 @@
     discovery.olt_discovery()
     discovery.onu_discovery()
     discovery.logical_device()
+    discovery.logical_device_ports_should_exist()
+    discovery.logical_device_should_have_at_least_one_flow()
     discovery.olt_ports_should_be_enabled_and_active()
     discovery.onu_ports_should_be_enabled_and_active()
     discovery.olt_should_have_at_least_one_flow()
diff --git a/tests/atests/common/volthaMngr.py b/tests/atests/common/volthaMngr.py
index 9b314c2..20b45bc 100755
--- a/tests/atests/common/volthaMngr.py
+++ b/tests/atests/common/volthaMngr.py
@@ -90,12 +90,15 @@
         for nsName in allRunningPods:
             Namespace = nsName.get('NS')
             podName = nsName.get('Name')
-            if 'onos' not in podName:
-                os.system('/usr/bin/kubectl logs -n %s -f %s > %s/%s.log 2>&1 &' %
-                          (Namespace, podName, testCaseUtils.get_dir(self, 'log'), podName))
-            else:
+            if 'onos' in podName:
                 os.system('/usr/bin/kubectl logs -n %s -f %s onos > %s/%s.log 2>&1 &' %
                           (Namespace, podName, testCaseUtils.get_dir(self, 'log'), podName))
+            elif 'calico-node' in podName:
+                    os.system('/usr/bin/kubectl logs -n %s -f %s calico-node > %s/%s.log 2>&1 &' %
+                              (Namespace, podName, testCaseUtils.get_dir(self, 'log'), podName))
+            else:
+                os.system('/usr/bin/kubectl logs -n %s -f %s > %s/%s.log 2>&1 &' %
+                          (Namespace, podName, testCaseUtils.get_dir(self, 'log'), podName))
 
         
 def get_all_running_pods():
diff --git a/tests/atests/robot/voltha_automated_test_suite.robot b/tests/atests/robot/voltha_automated_test_suite.robot
index 7779d82..9add442 100755
--- a/tests/atests/robot/voltha_automated_test_suite.robot
+++ b/tests/atests/robot/voltha_automated_test_suite.robot
@@ -70,6 +70,8 @@
     Olt Discovery
     Onu Discovery
     Logical Device
+    Logical Device Ports Should Exist
+    Logical Device Should Have At Least One Flow
     Olt Ports Should Be Enabled and Active
     Onu Ports Should Be Enabled and Active
     Olt Should Have At Least One Flow