[ARVADOS] updated: 72070e2405d6c3635d9e937d4faa475290c227df

git at public.curoverse.com git at public.curoverse.com
Thu Oct 8 16:17:21 EDT 2015


Summary of changes:
 sdk/python/arvados/__init__.py             | 40 ++++++++++++------------------
 sdk/python/tests/test_task_output_retry.py | 24 +++++++++++++++---
 2 files changed, 37 insertions(+), 27 deletions(-)

       via  72070e2405d6c3635d9e937d4faa475290c227df (commit)
      from  fa53e795f0d842dbbd9f861f269e5ba2913917df (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 72070e2405d6c3635d9e937d4faa475290c227df
Author: Bryan Cosca <bcosc at curoverse.com>
Date:   Thu Oct 8 16:17:15 2015 -0400

    6600: Tests work with api creation and mock_responses

diff --git a/sdk/python/arvados/__init__.py b/sdk/python/arvados/__init__.py
index 68a9578..708dbf4 100644
--- a/sdk/python/arvados/__init__.py
+++ b/sdk/python/arvados/__init__.py
@@ -43,7 +43,7 @@ def task_set_output(self,s,api_client=None,num_retries=5):
     if not api_client:
         api_client = api('v1')
 
-    for tries_left in RetryLoop(num_retries=num_retries, backoff_start=2): # change this to 2 after tests are finished
+    for tries_left in RetryLoop(num_retries=num_retries, backoff_start=0): # change this to 2 after tests are finished
         try:
             api_client.job_tasks().update(uuid=self['uuid'],
                                                  body={
@@ -67,23 +67,19 @@ def current_task(api_client=None, num_retries=5):
     if not api_client:
         api_client = api('v1')
 
-    current_task_loop = RetryLoop(num_retries=num_retries, backoff_start=0)
-    for tries_left in current_task_loop:
+    for tries_left in RetryLoop(num_retries=num_retries, backoff_start=0):
         try:
             result = api_client.job_tasks().get(uuid=os.environ['TASK_UUID']).execute()
-        except errors.HttpError as error:
-            if retry.check_http_response_success(error.status_code) is None and tries_left > 0:
+            result = UserDict.UserDict(result)
+            result.set_output = types.MethodType(task_set_output, result)
+            result.tmpdir = os.environ['TASK_WORK']
+            _current_task = result
+            return result
+        except errors.ApiError as error:
+            if retry.check_http_response_success(error.resp.status) is None and tries_left > 0:
                 logger.debug("current_task: job_tasks().get() raised {}, retrying with {} tries left".format(repr(error),tries_left))
             else:
                 raise
-        else:
-            current_task_loop.save_result(result)
-    if current_task_loop.success():
-        result = UserDict.UserDict(result)
-        result.set_output = types.MethodType(task_set_output, result)
-        result.tmpdir = os.environ['TASK_WORK']
-        _current_task = result
-        return result
 
 _current_job = None
 def current_job(api_client=None, num_retries=5):
@@ -94,22 +90,18 @@ def current_job(api_client=None, num_retries=5):
     if not api_client:
         api_client = api('v1')
 
-    current_job_loop = RetryLoop(num_retries=num_retries, backoff_start=0)
-    for tries_left in current_job_loop:
+    for tries_left in RetryLoop(num_retries=num_retries, backoff_start=0):
         try:
             result = api_client.jobs().get(uuid=os.environ['JOB_UUID']).execute()
-        except errors.HttpError as error:
-            if retry.check_http_response_success(error.status_code) is None and tries_left > 0:
+            result = UserDict.UserDict(result)
+            result.tmpdir = os.environ['JOB_WORK']
+            _current_job = result
+            return result
+        except errors.ApiError as error:
+            if retry.check_http_response_success(error.resp.status) is None and tries_left > 0:
                 logger.debug("current_job: jobs().get() raised {}, retrying with {} tries left".format(repr(error),tries_left))
             else:
                 raise
-        else:
-            current_job_loop.save_result(result)
-    if current_job_loop.success():
-        result = UserDict.UserDict(result)
-        result.tmpdir = os.environ['JOB_WORK']
-        _current_job = result
-        return result
 
 def getjobparam(*args):
     return current_job()['script_parameters'].get(*args)
diff --git a/sdk/python/tests/test_task_output_retry.py b/sdk/python/tests/test_task_output_retry.py
index 58af403..b3045d5 100644
--- a/sdk/python/tests/test_task_output_retry.py
+++ b/sdk/python/tests/test_task_output_retry.py
@@ -38,8 +38,6 @@ class ApiClientRetrytestMixin(object):
         raise NotImplementedError("test subclasses must define run_method")        
 
     def check_success(self, expected=None, *args, **kwargs):
-        if expected is None:
-            expected = self.DEFAULT_EXPECT
         try:
             self.run_method
         except: # This seems really iffy, because random exceptions can occur.
@@ -69,7 +67,7 @@ class ApiClientRetrytestMixin(object):
     def test_no_retry_after_immediate_success(self):
         with tutil.mock_responses('', 200, 400):
             self.check_success()
-
+    
 class TaskSetOutputTestCase(ApiClientRetrytestMixin, unittest.TestCase):
 
     ERROR_HEADERS = {'Content-Type': mimetypes.types_map['.json']}
@@ -77,3 +75,23 @@ class TaskSetOutputTestCase(ApiClientRetrytestMixin, unittest.TestCase):
 
     def run_method(self, locator=ApiClientRetrytestMixin.TEST_LOCATOR, api_client=None, *args, **kwargs):
         arvados.task_set_output({'uuid':self.TEST_UUID},s=locator,api_client=api_client)
+
+class CurrentJobTestCase(ApiClientRetrytestMixin, unittest.TestCase):
+
+    ERROR_HEADERS = {'Content-Type': mimetypes.types_map['.json']}
+    DEFAULT_EXCEPTION = arvados.errors.ApiError
+    os.environ['JOB_UUID'] = 'zzzzz-zzzzz-zzzzzzzzzzzzzzz'
+    os.environ['JOB_WORK'] = '.'
+
+    def run_method(self, api_client=None, *args, **kwargs):
+        arvados.current_job(api_client=api_client)
+
+class CurrentTaskTestCase(ApiClientRetrytestMixin, unittest.TestCase):
+
+    ERROR_HEADERS = {'Content-Type': mimetypes.types_map['.json']}
+    DEFAULT_EXCEPTION = arvados.errors.ApiError
+    os.environ['TASK_UUID'] = 'zzzzz-zzzzz-zzzzzzzzzzzzzzz'
+    os.environ['TASK_WORK'] = '.'
+
+    def run_method(self, api_client=None, *args, **kwargs):
+        arvados.current_task(api_client=api_client)

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


hooks/post-receive
-- 




More information about the arvados-commits mailing list