lava_wait_jobs.py: Retry only fetching LAVA jobs

Previously, the whole functions wait_for_jobs() function was wrapped in
the retry logic, but it contained not just LAVA logic, but also reporting
logic. If there was an exception in reporting logic, the whole process
of getting LAVA results was repeated, only leading to confusing output
in the logs and extra LAVA load in case of code errors. Split the
wait_for_jobs() in two functions and retry only the actual LAVA logic.

Signed-off-by: Paul Sokolovsky <paul.sokolovsky@linaro.org>
Change-Id: Iae73d3dc6947ffe1fd12791f01989b4ce44d65e1
diff --git a/lava_helper/lava_wait_jobs.py b/lava_helper/lava_wait_jobs.py
index 6847ee4..262eec2 100755
--- a/lava_helper/lava_wait_jobs.py
+++ b/lava_helper/lava_wait_jobs.py
@@ -73,13 +73,18 @@
     resubmit_jobs = resubmit_failed_jobs(finished_jobs, user_args)
     finished_resubmit_jobs = get_finished_jobs(resubmit_jobs, user_args, lava)
     finished_jobs.update(finished_resubmit_jobs)
+    return finished_jobs
+
+
+def process_finished_jobs(finished_jobs, user_args):
     print_lava_urls(finished_jobs, user_args)
     job_links(finished_jobs, user_args)
     boot_report(finished_jobs, user_args)
-    test_report(finished_jobs, user_args, lava)
+    test_report(finished_jobs, user_args)
     failure_report(finished_jobs, user_args)
     csv_report(finished_jobs)
 
+
 def get_finished_jobs(job_list, user_args, lava):
     finished_jobs = lava.block_wait_for_jobs(job_list, user_args.dispatch_timeout, 0.5)
     unfinished_jobs = [item for item in job_list if item not in finished_jobs]
@@ -212,7 +217,7 @@
                             results.remove(result)
     return(results)
 
-def test_report(jobs, user_args, lava):
+def test_report(jobs, user_args):
     # parsing of test results is WIP
     fail_j = []
     jinja_data = []
@@ -265,7 +270,7 @@
     user_args.lava_rpc = "RPC2"
     for try_time in range(3):
         try:
-            wait_for_jobs(user_args)
+            finished_jobs = wait_for_jobs(user_args)
             break
         except Exception as e:
             if try_time < 2:
@@ -273,6 +278,7 @@
                 print("Trying to get LAVA jobs again...")
             else:
                 raise e
+    process_finished_jobs(finished_jobs, user_args)
 
 def get_cmd_args():
     """ Parse command line arguments """