Wait for ONOS to start by checking ONOS logs instead of a static delay.
Enable exception logs in onos log.

Change-Id: Iff967d1daab63e2d3d8f7ac90fe76e2cd7abfa39
diff --git a/src/test/utils/OnosLog.py b/src/test/utils/OnosLog.py
index e876c67..6bdef9f 100644
--- a/src/test/utils/OnosLog.py
+++ b/src/test/utils/OnosLog.py
@@ -1,4 +1,5 @@
 import os
+import re
 from SSHTestAgent import SSHTestAgent
 
 class OnosLog(object):
@@ -28,19 +29,22 @@
     def update_last_snapshot(cls, host, res):
         cls.last_snapshot_map[host] = res
 
-    def get_log(self, search_terms = None):
+    def get_log(self, search_terms = None, exception = True):
         """Run the command on the test host"""
         cmd = 'cat /root/onos/apache-karaf-3.0.5/data/log/karaf.log'
         st, output = self.ssh_agent.run_cmd(cmd)
         if st is False:
             return output
+        exception_map = {'Exception' : [] }
         last_snapshot = self.get_last_snapshot(self.ssh_agent.host)
         lines = output.splitlines()
         if search_terms:
             if type(search_terms) is str:
                 terms = [ search_terms ]
             else:
-                terms = search_terms
+                terms = list(search_terms)
+            if exception is True and 'Exception' not in terms:
+                terms.append('Exception')
             match_lines = []
             last_len = len(last_snapshot)
             for i in xrange(0, len(lines)):
@@ -50,13 +54,23 @@
                 for t in terms:
                     if lines[i].find(t) >= 0:
                         match_lines.append(lines[i])
-
+                        if t == 'Exception':
+                            exception_map[t] = lines[i+1:i+1+10]
             output = '\n'.join(match_lines)
+            output += '\n'.join(exception_map['Exception'])
 
         #update the last snapshot
         self.update_last_snapshot(self.ssh_agent.host, lines)
         return st, output
 
+    def search_log_pattern(self, pattern):
+        r_pat = re.compile(pattern)
+        cmd = 'cat /root/onos/apache-karaf-3.0.5/data/log/karaf.log'
+        st, output = self.ssh_agent.run_cmd(cmd)
+        if st is False:
+            return None
+        return r_pat.findall(output)
+
 if __name__ == '__main__':
     onos = os.getenv('ONOS_CONTROLLER_IP', '172.17.0.2')
     onos_log = OnosLog(host = onos)
@@ -70,3 +84,8 @@
     st, output = onos_log.get_log(('ERROR', 'INFO'))
     print(st, output)
     onos_log.close()
+    pat = onos_log.search_log_pattern('ApplicationManager .* Started')
+    if pat:
+        print(pat)
+    else:
+        print('Onos did not start')