VOL-1633: Use defined proceed test instead of waiting for arbitrary time

We now test that all ONUs are ready especially in the case of BBSim
before proceeding to Discovery Test Case
Move Freeswitch setup items earlier to accomodate BBSim
- Fix unassignment issue
- Modify Robot accordingly
- Change Robot steps to hide exact method used
- Account for ipv6 DHCP detection flows in new version of onos

Change-Id: Ib0022ab13ba87071e1bf0866e9df592476447113
diff --git a/tests/atests/common/authentication.py b/tests/atests/common/authentication.py
index aedbbf2..b5196d7 100644
--- a/tests/atests/common/authentication.py
+++ b/tests/atests/common/authentication.py
@@ -19,7 +19,6 @@
 """
 
 import time
-import os
 import subprocess
 import testCaseUtils
 import logging
@@ -45,29 +44,6 @@
     def a_set_log_dirs(self, root_dir, voltha_dir, log_dir):
         testCaseUtils.config_dirs(self, log_dir, root_dir, voltha_dir)
 
-    def discover_freeradius_pod_name(self):
-        self.__radiusName = testCaseUtils.extract_pod_name('freeradius').strip()
-        logging.info('freeradius Name = %s' % self.__radiusName)
-        
-    def discover_freeradius_ip_addr(self):
-        ipAddr = testCaseUtils.extract_radius_ip_addr(self.__radiusName)
-        assert ipAddr, 'No IP address listed for freeradius'
-        self.__radiusIp = ipAddr.strip()
-        logging.info('freeradius IP = %s' % self.__radiusIp)
-        
-    def set_current_freeradius_ip_in_aaa_json(self):
-        status = testCaseUtils.modify_radius_ip_in_json_using_sed(self, self.__radiusIp)
-        assert (status == 0), 'Setting Radius Ip in Json File did not return Success'
-          
-    def alter_aaa_application_configuration_in_onos_using_aaa_json(self):
-        logging.info('Altering the Onos NetCfg AAA apps with Freeradius IP address')
-        logging.debug('curl --user karaf:karaf -X POST -H "Content-Type: application/json" '
-                      'http://localhost:30120/onos/v1/network/configuration/apps/ -d @%s/tests/atests/build/aaa_json'
-                      % testCaseUtils.get_dir(self, 'voltha'))
-        os.system('curl --user karaf:karaf -X POST -H "Content-Type: application/json" '
-                  'http://localhost:30120/onos/v1/network/configuration/apps/ -d @%s/tests/atests/build/aaa_json'
-                  % testCaseUtils.get_dir(self, 'voltha'))
-     
     def execute_authentication_on_rg(self):
         logging.info('Running Radius Authentication from RG')
         process_output = open('%s/%s' % (testCaseUtils.get_dir(self, 'log'), self.AUTHENTICATE_FILENAME), 'w')
@@ -146,10 +122,6 @@
 def run_test(root_dir, voltha_dir, log_dir):
     auth = Authentication()
     auth.a_set_log_dirs(root_dir, voltha_dir, log_dir)
-    auth.discover_freeradius_pod_name()
-    auth.discover_freeradius_ip_addr()
-    auth.set_current_freeradius_ip_in_aaa_json()
-    auth.alter_aaa_application_configuration_in_onos_using_aaa_json()
     auth.execute_authentication_on_rg()
     auth.verify_authentication_should_have_started()
     auth.verify_authentication_should_have_completed()
diff --git a/tests/atests/common/auto_test.py b/tests/atests/common/auto_test.py
index 6e21842..5182bdc 100755
--- a/tests/atests/common/auto_test.py
+++ b/tests/atests/common/auto_test.py
@@ -112,7 +112,7 @@
     volthaMngr.voltha_initialize(ROOT_DIR, VOLTHA_DIR, LOG_DIR, args.adapter)
 
     preprovisioning.run_test(OLT_HOST_IP, 50060, OLT_TYPE, ONU_TYPE, ONU_COUNT, LOG_DIR)
-    time.sleep(60)
+
     discovery.run_test(OLT_HOST_IP, OLT_TYPE, ONU_TYPE, ONU_COUNT, LOG_DIR)
     if args.adapter == 'ponsim':
         authentication.run_test(ROOT_DIR, VOLTHA_DIR, LOG_DIR)
diff --git a/tests/atests/common/dhcp.py b/tests/atests/common/dhcp.py
index a9acd8e..391c2dc 100644
--- a/tests/atests/common/dhcp.py
+++ b/tests/atests/common/dhcp.py
@@ -74,7 +74,7 @@
         statusLines = testCaseUtils.get_fields_from_grep_command(self, 'IP_PROTO:17', 'voltha_onos_flows.log')
         assert statusLines, 'No DHCP Detection flows'
         lines = statusLines.splitlines()
-        assert len(lines) == 2, 'Expected 2 DHCP Detection Flows but result was %s' % len(lines)
+        assert len(lines) >= 2, 'Expected at least 2 DHCP Detection Flows but result was %s' % len(lines)
         for line in lines:
             self.__fields = testCaseUtils.parse_fields(line, ',')
             inPortStr = self.__fields[5].strip()
diff --git a/tests/atests/common/preprovisioning.py b/tests/atests/common/preprovisioning.py
index fb68634..2b077c9 100755
--- a/tests/atests/common/preprovisioning.py
+++ b/tests/atests/common/preprovisioning.py
@@ -28,7 +28,7 @@
     """
     This class implements voltha pre-provisioning test
     """
-    
+
     def __init__(self):
         self.dirs = dict()
         self.dirs['log'] = None
@@ -99,6 +99,7 @@
         assert statusLines, 'No Olt listed under devices'
         self.__fields = testCaseUtils.parse_fields(statusLines, '|')
         assert self.check_states(self.__oltType), 'States of %s does match expected' % self.__oltType
+        hostPortCount = False
         for field in self.__fields:
             if field.strip() == self.__oltIpAddress + ':' + str(self.__oltPort):
                 hostPortCount = True
@@ -128,6 +129,23 @@
                                                  'voltha_devices_after_enable.log', 'devices')
         testCaseUtils.print_log_file(self, 'voltha_devices_after_enable.log')
 
+    def proceed(self):
+        logging.info('Pre-provisioning hold')
+        onuOnline = 0
+        portType = None
+        if self.__oltType == 'ponsim_olt':
+            portType = 'PON_OLT'
+        elif self.__oltType == 'openolt':
+            portType = 'ETHERNET_UNI'
+        while onuOnline < self.__onuCount:
+            testCaseUtils.send_command_to_voltha_cli(testCaseUtils.get_dir(self, 'log'), 'voltha_olt_device.log', 'device ' +
+                                                     self.__oltDeviceId, 'voltha_olt_ports.log', 'ports')
+            statusLines = testCaseUtils.get_fields_from_grep_command(self, portType, 'voltha_olt_ports.log')
+            lines = statusLines.splitlines()
+            onuOnline = len(lines)
+            time.sleep(5)
+        logging.info('All ONUs now Online!')
+
 
 def run_test(olt_ip_address, olt_port, olt_type, onu_type, onu_count, log_dir):
     preprovisioning = Preprovisioning()
@@ -142,3 +160,4 @@
     preprovisioning.query_devices_after_enabling()
     preprovisioning.check_olt_fields_after_enabling()
     preprovisioning.check_onu_fields_after_enabling()
+    preprovisioning.proceed()
diff --git a/tests/atests/common/volthaMngr.py b/tests/atests/common/volthaMngr.py
index 1751fa4..f94322d 100755
--- a/tests/atests/common/volthaMngr.py
+++ b/tests/atests/common/volthaMngr.py
@@ -25,7 +25,6 @@
 import logging
 
 
-
 class VolthaMngr(object):
 
     """
@@ -39,7 +38,10 @@
         self.dirs['root'] = None
         self.dirs['voltha'] = None
         self.dirs['log'] = None
-        
+
+        self.__radiusName = None
+        self.__radiusIp = None
+
     def v_set_log_dirs(self, root_dir, voltha_dir, log_dir):
         testCaseUtils.config_dirs(self, log_dir, root_dir, voltha_dir)
 
@@ -98,13 +100,36 @@
                 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))
+                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 discover_freeradius_pod_name(self):
+        self.__radiusName = testCaseUtils.extract_pod_name('freeradius').strip()
+        logging.info('freeradius Name = %s' % self.__radiusName)
+
+    def discover_freeradius_ip_addr(self):
+        ipAddr = testCaseUtils.extract_radius_ip_addr(self.__radiusName)
+        assert ipAddr, 'No IP address listed for freeradius'
+        self.__radiusIp = ipAddr.strip()
+        logging.info('freeradius IP = %s' % self.__radiusIp)
+
+    def prepare_current_freeradius_ip(self):
+        status = testCaseUtils.modify_radius_ip_in_json_using_sed(self, self.__radiusIp)
+        assert (status == 0), 'Setting Radius Ip in Json File did not return Success'
+
+    def alter_freeradius_ip_in_onos_aaa_application_configuration(self):
+        logging.info('Altering the Onos NetCfg AAA apps with Freeradius IP address')
+        logging.debug('curl --user karaf:karaf -X POST -H "Content-Type: application/json" '
+                      'http://localhost:30120/onos/v1/network/configuration/apps/ -d @%s/tests/atests/build/aaa_json'
+                      % testCaseUtils.get_dir(self, 'voltha'))
+        os.system('curl --user karaf:karaf -X POST -H "Content-Type: application/json" '
+                  'http://localhost:30120/onos/v1/network/configuration/apps/ -d @%s/tests/atests/build/aaa_json'
+                  % testCaseUtils.get_dir(self, 'voltha'))
+
+
 def get_all_running_pods():
     allRunningPods = []
     proc1 = subprocess.Popen(['/usr/bin/kubectl', 'get', 'pods', '--all-namespaces'],
@@ -135,3 +160,7 @@
     voltha.start_all_pods(adapter)
     voltha.alter_onos_net_cfg()
     voltha.collect_pod_logs()
+    voltha.discover_freeradius_pod_name()
+    voltha.discover_freeradius_ip_addr()
+    voltha.prepare_current_freeradius_ip()
+    voltha.alter_freeradius_ip_in_onos_aaa_application_configuration()
diff --git a/tests/atests/robot/voltha_automated_test_suite.robot b/tests/atests/robot/voltha_automated_test_suite.robot
index 71ec642..10a9f34 100755
--- a/tests/atests/robot/voltha_automated_test_suite.robot
+++ b/tests/atests/robot/voltha_automated_test_suite.robot
@@ -44,6 +44,8 @@
 ${ADAPTER}              ${EMPTY}
 ${RETRY_TIMEOUT_60}     60s
 ${RETRY_INTERVAL_2}     2s
+${PROCEED_TIMEOUT_180}  180s
+
 
 *** Test Cases ***
 Olt Pre Provisioning
@@ -63,7 +65,7 @@
     Status Should Be Success After Enable Command
     Check Olt Fields After Enabling
     Check Onu Fields After Enabling
-    Sleep    60
+    Wait Until Keyword Succeeds   ${PROCEED_TIMEOUT_180}  ${RETRY_INTERVAL_2}    Proceed
 
 Olt Onu Discovery
     [Documentation]     Olt Onu Discovery
@@ -92,10 +94,6 @@
     ...                 We then verify the generated log file confirming all the authentication steps
     [Tags]              ponsim
     A Set Log Dirs      ${ROOT_DIR}    ${VOLTHA_DIR}    ${LOG_DIR}
-    Discover Freeradius Pod Name
-    Discover Freeradius Ip Addr
-    Set Current Freeradius Ip In AAA Json
-    Alter AAA Application Configuration In Onos Using AAA Json
     Execute Authentication On RG
     Verify Authentication Should Have Started
     Verify Authentication Should Have Completed
@@ -160,7 +158,11 @@
     ${pod_status}       Run    kubectl get pods --all-namespaces
     Log To Console      \n${pod_status}\n
     Alter Onos Net Cfg
-    
+    Discover Freeradius Pod Name
+    Discover Freeradius Ip Addr
+    Prepare Current Freeradius Ip
+    Alter Freeradius Ip In Onos AAA Application Configuration
+
 Stop Voltha
     [Documentation]     Stop Voltha infrastructure. This includes clearing all installation milestones
     ...                 files and stopping all Kubernetes pods