[ARVADOS] updated: c45afe0bb9b7edcfb09f2ef75097159e63a08251

git at public.curoverse.com git at public.curoverse.com
Thu Sep 3 11:38:54 EDT 2015


Summary of changes:
 sdk/python/arvados/__init__.py             | 70 +++++++++++++++-------------
 sdk/python/tests/test_crunch_job_retry.py  |  5 +-
 sdk/python/tests/test_crunch_task_retry.py |  7 +--
 sdk/python/tests/test_task_output_retry.py | 73 ++++++++++++++++--------------
 4 files changed, 84 insertions(+), 71 deletions(-)

       via  c45afe0bb9b7edcfb09f2ef75097159e63a08251 (commit)
      from  27928441e62c9c58115a3e1cf26aba8393a65f18 (commit)

Those revisions listed above that are new to this repository have
not appeared on any other notification email; so we list those
revisions in full, below.


commit c45afe0bb9b7edcfb09f2ef75097159e63a08251
Author: Bryan Cosca <bcosc at curoverse.com>
Date:   Thu Sep 3 11:38:48 2015 -0400

    6600: Cleaned up logging and exceptions, as well as fixed unit tests

diff --git a/sdk/python/arvados/__init__.py b/sdk/python/arvados/__init__.py
index bb73453..f5797c0 100644
--- a/sdk/python/arvados/__init__.py
+++ b/sdk/python/arvados/__init__.py
@@ -23,6 +23,7 @@ from collection import CollectionReader, CollectionWriter, ResumableCollectionWr
 from keep import *
 from stream import *
 from arvfile import StreamFileReader
+from retry import RetryLoop
 import errors
 import util
 
@@ -59,79 +60,86 @@ def task_set_output(self,s,api_client=None,num_retries=None):
                 if retry.check_http_response_success(error.resp.status) == False:
                     logger.debug("Non-retryable ApiError raised, logging error: {}".format(error))
                     output_retry_loop.save_result(error)
+                    raise
                 else:
                     if tries_left > 0:
-                        logger.debug("Retrying with {} tries left".format(tries_left))
+                        logger.debug("ApiError returned {}, retrying with {} tries left".format(error.resp.status,tries_left))
+                    else:
+                        logger.debug("No more retries left, logging error: {}".format(error))
+                        output_retry_loop.save_result(error)
+                        raise
         except errors.HttpError as error:
             if not retry.check_http_response_success(error.status_code):
                 if retry.check_http_response_success(error.status_code) == False:
-                    logger.debug("HttpError returned {}, saving error and not retrying.".format(error.status_code))
+                    logger.debug("Non-retryable HttpError raised, logging error: {}".format(error.status_code))
                     output_retry_loop.save_result(error)
                 else:
                     if tries_left > 0:
-                        logger.debug("HttpError returned {}, retrying with {} tries left".format(error.status_code,tries_left+1))
+                        logger.debug("HttpError returned {}, retrying with {} tries left".format(error.status_code,tries_left))
+                    else:
+                        logger.debug("No more retries left, logging error: {}".format(error))
+                        output_retry_loop.save_result(error)
+                        raise
         else:
             output_retry_loop.save_result(result)
     if output_retry_loop.success():
         logger.debug("task_set_output is successful")
         return output_retry_loop.last_result()
     else:
-        logger.debug("task_set_output has failed.")
         raise
+        
 
 _current_task = None
 def current_task(api_client=None, num_retries=None):
+
     global _current_task
     if _current_task:
         return _current_task
+
     if not api_client:
         api_client = api('v1')
+
     if not num_retries:
         num_retries = 5
 
     current_task_retry_loop = RetryLoop(num_retries=num_retries, backoff_start=0)
     for tries_left in current_task_retry_loop:
         try:
-            print "Trying api call"
             result = api_client.job_tasks().get(uuid=os.environ['TASK_UUID']).execute()
-            print result
         except errors.ApiError as error:
-            print error
             if not retry.check_http_response_success(error.resp.status):
                 if retry.check_http_response_success(error.resp.status) == False:
-                    print "Non-retryable ApiError raised, logging error: {}".format(error)
-                    raise
+                    logger.debug("Non-retryable ApiError raised, logging error: {}".format(error))
                     current_task_retry_loop.save_result(error)
+                    raise
                 else:
                     if tries_left > 0:
-                        print "Retrying with {} tries left".format(tries_left)
+                        logger.debug("ApiError returned {}, retrying with {} tries left".format(error.resp.status,tries_left))
                     else:
-                        print "No more retries left (api)"
+                        logger.debug("No more retries left, logging error: {}".format(error))
+                        current_task_retry_loop.save_result(error)
                         raise
         except errors.HttpError as error:
-            print "HttpError raised"
             if not retry.check_http_response_success(error.status_code):
                 if retry.check_http_response_success(error.status_code) == False:
-                    print "False retry code"
+                    logger.debug("Non-retryable HttpError raised, logging error: {}".format(error))
                     current_task_retry_loop.save_result(error)
                 else:
                     if tries_left > 0:
-                        print "Retrying with {} tries left".format(tries_left+1)
+                        logger.debug("HttpError returned {}, retrying with {} tries left".format(error.status_code,tries_left))
                     else:
-                        print "No more retries left (http)"
+                        logger.debug("No more retries left, logging error: {}".format(error))
+                        current_job_retry_loop.save_result(error)
                         raise
         else:
-            print "Task_set_output saved?"
             current_task_retry_loop.save_result(result)
     if current_task_retry_loop.success():
-        print "Current_task_retry_loop succeeded"
         result = UserDict.UserDict(current_task_retry_loop.last_result())
         result.set_output = types.MethodType(task_set_output, result)
         result.tmpdir = os.environ['TASK_WORK']
         _current_task = result
         return result
     else:
-        print "current_task failed."
         raise
 
 _current_job = None
@@ -144,39 +152,39 @@ def current_job(api_client=None, num_retries=None):
         api_client = api('v1')
 
     if not num_retries:
-        num_retries = 0
+        num_retries = 5
 
     current_job_retry_loop = RetryLoop(num_retries=num_retries, backoff_start=0)
     for tries_left in current_job_retry_loop:
         try:
             result = api_client.jobs().get(uuid=os.environ['JOB_UUID']).execute()
         except errors.ApiError as error:
-            print error
             if not retry.check_http_response_success(error.resp.status):
                 if retry.check_http_response_success(error.resp.status) == False:
-                    print "Non-retryable ApiError raised, logging error: {}".format(error)
-                    raise
+                    logger.debug("Non-retryable ApiError raised, logging error: {}".format(error))
                     current_job_retry_loop.save_result(error)
+                    raise
                 else:
                     if tries_left > 0:
-                        print "Retrying with {} tries left".format(tries_left)
+                        logger.debug("ApiError returned {}, retrying with {} tries left".format(error.resp.status,tries_left))
                     else:
-                        print "No more retries left (api)"
+                        logger.debug("No more retries left, logging error: {}".format(error))
+                        current_job_retry_loop.save_result(error)
                         raise
         except errors.HttpError as error:
-            print "HttpError raised"
             if not retry.check_http_response_success(error.status_code):
                 if retry.check_http_response_success(error.status_code) == False:
-                    print "False retry code"
+                    logger.debug("Non-retryable HttpError raised, logging error: {}".format(error))
                     current_job_retry_loop.save_result(error)
+                    raise
                 else:
                     if tries_left > 0:
-                        print "Retrying with {} tries left".format(tries_left+1)
+                        logger.debug("HttpError returned {}, retrying with {} tries left".format(error.status_code,tries_left))
                     else:
-                        print "No more retries left (http)"
-                        raise
+                        logger.debug("No more retries left, logging error: {}".format(error))
+                        current_job_retry_loop.save_result(error)
+                        raise 
         else:
-            print "Task_set_output saved?"
             current_job_retry_loop.save_result(result)
     if current_job_retry_loop.success():
         result = UserDict.UserDict(current_job_retry_loop.last_result())
@@ -184,10 +192,8 @@ def current_job(api_client=None, num_retries=None):
         _current_job = result
         return result
     else:
-        print "current_job failed."
         raise
 
-
 def getjobparam(*args):
     return current_job()['script_parameters'].get(*args)
 
diff --git a/sdk/python/tests/test_crunch_job_retry.py b/sdk/python/tests/test_crunch_job_retry.py
index ccd26c7..51c2f97 100644
--- a/sdk/python/tests/test_crunch_job_retry.py
+++ b/sdk/python/tests/test_crunch_job_retry.py
@@ -24,9 +24,10 @@ class CurrentJobTestCase(unittest.TestCase, tutil.ApiClientMock):
 
     def test_mock_retry_until_break(self):
         api_client = mock.MagicMock()
-        api_client.jobs().get().execute.side_effect = [arvados.errors.ApiError(tutil.fake_httplib2_response(500), "{}")]
+        api_client.jobs().get().execute.side_effect = [arvados.errors.ApiError(tutil.fake_httplib2_response(500), "{}"),
+                                                       arvados.errors.ApiError(tutil.fake_httplib2_response(500), "{}")]
         with self.assertRaises(arvados.errors.ApiError) as err_check:
-            arvados.current_job(api_client=api_client,num_retries=0)
+            arvados.current_job(api_client=api_client,num_retries=1)
 
     def test_mock_success(self):
         api_client = mock.MagicMock()
diff --git a/sdk/python/tests/test_crunch_task_retry.py b/sdk/python/tests/test_crunch_task_retry.py
index b203ea7..2c87c72 100644
--- a/sdk/python/tests/test_crunch_task_retry.py
+++ b/sdk/python/tests/test_crunch_task_retry.py
@@ -1,4 +1,3 @@
-
 #!/usr/bin/env python
 
 import mock
@@ -24,9 +23,11 @@ class CurrentTaskTestCase(unittest.TestCase, tutil.ApiClientMock):
 
     def test_mock_retry_until_break(self):
         api_client = mock.MagicMock()
-        api_client.job_tasks().get().execute.side_effect = [arvados.errors.ApiError(tutil.fake_httplib2_response(500), "{}")]
+        api_client.job_tasks().get().execute.side_effect = [arvados.errors.ApiError(tutil.fake_httplib2_response(500), "{}"),
+                                                            arvados.errors.ApiError(tutil.fake_httplib2_response(500), "{}"),
+                                                            arvados.errors.ApiError(tutil.fake_httplib2_response(500), "{}")]
         with self.assertRaises(arvados.errors.ApiError) as err_check:
-            arvados.current_task(api_client=api_client,num_retries=0)
+            arvados.current_task(api_client=api_client,num_retries=1)
 
     def test_mock_success(self):
         api_client = mock.MagicMock()
diff --git a/sdk/python/tests/test_task_output_retry.py b/sdk/python/tests/test_task_output_retry.py
index ae02403..4a0b5b8 100644
--- a/sdk/python/tests/test_task_output_retry.py
+++ b/sdk/python/tests/test_task_output_retry.py
@@ -10,75 +10,80 @@ import arvados_testutil as tutil
 
 @tutil.skip_sleep
 class TaskSetOutputTestCase(unittest.TestCase, tutil.ApiClientMock):
-    def mock_call_update(self, api_mock, code, body):
-        self._mock_api_call(api_mock, code, body)
 
-    def api_client_mock(self, status=200):
-        api_client = super(TaskSetOutputTestCase, self).api_client_mock()
-        self.mock_call_update(api_client.job_tasks().update, status, 'foo_file')
-        return api_client
-
-    api_client = mock.MagicMock()
-
-    def test_mock_retry_until_break(self,code=500):
-        api_client = self.api_client_mock(code)
+    def test_mock_retry_until_break(self):
+        api_client = mock.MagicMock()
+        api_client.job_tasks().update().execute.side_effect = [arvados.errors.ApiError(tutil.fake_httplib2_response(500), "{}"),
+                                                               arvados.errors.ApiError(tutil.fake_httplib2_response(500), "{}"),
+                                                               arvados.errors.ApiError(tutil.fake_httplib2_response(500), "{}")]
         with self.assertRaises(arvados.errors.ApiError) as err_check:
             arvados.task_set_output({'uuid':'zzzzz-zzzzz-zzzzzzzzzzzzzzz'},s='d41d8cd98f00b204e9800998ecf8427e+0',api_client=api_client,num_retries=1)
 
-    def test_mock_success(self,code=200):
-        api_client = self.api_client_mock(code)
+    def test_mock_success(self):
+        api_client = mock.MagicMock()
+        api_client.job_tasks().update().execute.side_effect = [tutil.fake_httplib2_response(200)]
         arvados.task_set_output({'uuid':'zzzzz-zzzzz-zzzzzzzzzzzzzzz'},s='d41d8cd98f00b204e9800998ecf8427e+0',api_client=api_client,num_retries=1)
 
-    def test_mock_fail(self,code=400):
-        api_client = self.api_client_mock(code)
+    def test_mock_fail(self):
+        api_client = mock.MagicMock()
+        api_client.job_tasks().update().execute.side_effect = [arvados.errors.ApiError(tutil.fake_httplib2_response(400), "{}")]
         with self.assertRaises(arvados.errors.ApiError) as err_check:
             arvados.task_set_output({'uuid':'zzzzz-zzzzz-zzzzzzzzzzzzzzz'},s='d41d8cd98f00b204e9800998ecf8427e+0',api_client=api_client,num_retries=1)
 
-    def test_mock_retry_success(self,api_client=api_client):
-        api_client.job_tasks().update().execute.side_effect = [arvados.errors.ApiError(tutil.fake_httplib2_response(500), "{}"), 
-                                                               tutil.fake_httplib2_response(200)]
+    def test_mock_retry_success(self):
+        api_client = mock.MagicMock()
+        api_client.job_tasks().update().execute.side_effect = [arvados.errors.ApiError(tutil.fake_httplib2_response(500), "{}"),
+                                                            tutil.fake_httplib2_response(200)]
         arvados.task_set_output({'uuid':'zzzzz-zzzzz-zzzzzzzzzzzzzzz'},s='d41d8cd98f00b204e9800998ecf8427e+0',api_client=api_client,num_retries=1)
 
-    def test_mock_retry_fail(self,api_client=api_client):
+    def test_mock_retry_fail(self):
+        api_client = mock.MagicMock()
         api_client.job_tasks().update().execute.side_effect = [arvados.errors.ApiError(tutil.fake_httplib2_response(500), "{}"),
                                                                arvados.errors.ApiError(tutil.fake_httplib2_response(404), "{}")]
         with self.assertRaises(arvados.errors.ApiError) as err_check:
             arvados.task_set_output({'uuid':'zzzzz-zzzzz-zzzzzzzzzzzzzzz'},s='d41d8cd98f00b204e9800998ecf8427e+0',api_client=api_client,num_retries=1)
 
-    def test_mock_retry_retry(self,api_client=api_client):
+    def test_mock_retry_retry(self):
+        api_client = mock.MagicMock()
         api_client.job_tasks().update().execute.side_effect = [arvados.errors.ApiError(tutil.fake_httplib2_response(500), "{}"),
-                                                               arvados.errors.ApiError(tutil.fake_httplib2_response(500), "{}")]
+                                                            arvados.errors.ApiError(tutil.fake_httplib2_response(500), "{}"),
+                                                            arvados.errors.ApiError(tutil.fake_httplib2_response(500), "{}")]
         with self.assertRaises(arvados.errors.ApiError) as err_check:
             arvados.task_set_output({'uuid':'zzzzz-zzzzz-zzzzzzzzzzzzzzz'},s='d41d8cd98f00b204e9800998ecf8427e+0',api_client=api_client,num_retries=1)
 
-    def test_mock_retry_success_retry(self,api_client=api_client):
+    def test_mock_retry_success_retry(self):
+        api_client = mock.MagicMock()
         api_client.job_tasks().update().execute.side_effect = [arvados.errors.ApiError(tutil.fake_httplib2_response(500), "{}"),
                                                                tutil.fake_httplib2_response(200),
                                                                arvados.errors.ApiError(tutil.fake_httplib2_response(500), "{}")]
         arvados.task_set_output({'uuid':'zzzzz-zzzzz-zzzzzzzzzzzzzzz'},s='d41d8cd98f00b204e9800998ecf8427e+0',api_client=api_client,num_retries=2)
 
-    def test_mock_retry_fail_retry(self,api_client=api_client):
+    def test_mock_retry_fail_retry(self):
+        api_client = mock.MagicMock()
         api_client.job_tasks().update().execute.side_effect = [arvados.errors.ApiError(tutil.fake_httplib2_response(500), "{}"),
-                                                               arvados.errors.ApiError(tutil.fake_httplib2_response(400), "{}"),
-                                                               arvados.errors.ApiError(tutil.fake_httplib2_response(500), "{}")]
+                                                            arvados.errors.ApiError(tutil.fake_httplib2_response(400), "{}"),
+                                                            arvados.errors.ApiError(tutil.fake_httplib2_response(500), "{}")]
         with self.assertRaises(arvados.errors.ApiError) as err_check:
             arvados.task_set_output({'uuid':'zzzzz-zzzzz-zzzzzzzzzzzzzzz'},s='d41d8cd98f00b204e9800998ecf8427e+0',api_client=api_client,num_retries=2)
 
-    def test_mock_success_retry_retry(self,api_client=api_client):
+    def test_mock_success_retry_retry(self):
+        api_client = mock.MagicMock()
         api_client.job_tasks().update().execute.side_effect = [tutil.fake_httplib2_response(200),
-                                                               arvados.errors.ApiError(tutil.fake_httplib2_response(500), "{}"),
-                                                               arvados.errors.ApiError(tutil.fake_httplib2_response(500), "{}")]
+                                                            arvados.errors.ApiError(tutil.fake_httplib2_response(500), "{}"),
+                                                            arvados.errors.ApiError(tutil.fake_httplib2_response(500), "{}")]
         arvados.task_set_output({'uuid':'zzzzz-zzzzz-zzzzzzzzzzzzzzz'},s='d41d8cd98f00b204e9800998ecf8427e+0',api_client=api_client,num_retries=2)
 
-    def test_mock_retry_retry_success(self,api_client=api_client):
+    def test_mock_retry_retry_success(self):
+        api_client = mock.MagicMock()
         api_client.job_tasks().update().execute.side_effect = [arvados.errors.ApiError(tutil.fake_httplib2_response(500), "{}"),
-                                                               arvados.errors.ApiError(tutil.fake_httplib2_response(500), "{}"),
-                                                               tutil.fake_httplib2_response(200)]
+                                                            arvados.errors.ApiError(tutil.fake_httplib2_response(500), "{}"),
+                                                            tutil.fake_httplib2_response(200)]
         arvados.task_set_output({'uuid':'zzzzz-zzzzz-zzzzzzzzzzzzzzz'},s='d41d8cd98f00b204e9800998ecf8427e+0',api_client=api_client,num_retries=2)
 
-    def test_mock_retry_retry_fail(self,api_client=api_client):
+    def test_mock_retry_retry_fail(self):
+        api_client = mock.MagicMock()
         api_client.job_tasks().update().execute.side_effect = [arvados.errors.ApiError(tutil.fake_httplib2_response(500), "{}"),
-                                                               arvados.errors.ApiError(tutil.fake_httplib2_response(500), "{}"),
-                                                               arvados.errors.ApiError(tutil.fake_httplib2_response(400), "{}")]
+                                                            arvados.errors.ApiError(tutil.fake_httplib2_response(500), "{}"),
+                                                            arvados.errors.ApiError(tutil.fake_httplib2_response(400), "{}")]
         with self.assertRaises(arvados.errors.ApiError) as err_check:
             arvados.task_set_output({'uuid':'zzzzz-zzzzz-zzzzzzzzzzzzzzz'},s='d41d8cd98f00b204e9800998ecf8427e+0',api_client=api_client,num_retries=2)

-----------------------------------------------------------------------


hooks/post-receive
-- 




More information about the arvados-commits mailing list