[ARVADOS] updated: 516265572e7ace05a8f4720761dd3ab31c468ae4
git at public.curoverse.com
git at public.curoverse.com
Fri Aug 28 17:05:50 EDT 2015
Summary of changes:
sdk/python/arvados/__init__.py | 103 +++++++++++++++++----
sdk/python/tests/test_one_task_per_input_retry.py | 47 +++++++---
..._retry.py => test_one_task_per_stream_retry.py} | 0
3 files changed, 119 insertions(+), 31 deletions(-)
copy sdk/python/tests/{test_task_output_retry.py => test_one_task_per_stream_retry.py} (100%)
via 516265572e7ace05a8f4720761dd3ab31c468ae4 (commit)
from 863d2d4c2bfb9139f7b224d85a85b3416bc943c5 (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 516265572e7ace05a8f4720761dd3ab31c468ae4
Author: Bryan Cosca <bcosc at curoverse.com>
Date: Fri Aug 28 17:05:44 2015 -0400
6600: Added test scaffold for test_one_task_per_input/stream_retry
diff --git a/sdk/python/arvados/__init__.py b/sdk/python/arvados/__init__.py
index a028992..1cfd1c9 100644
--- a/sdk/python/arvados/__init__.py
+++ b/sdk/python/arvados/__init__.py
@@ -220,11 +220,8 @@ class JobTask(object):
print "init jobtask %s %s" % (parameters, runtime_constraints)
class job_setup():
- def __init__(self, num_retries=2):
- self.num_retries = num_retries if num_retries is not None else 0
@staticmethod
- @retry_method
def one_task_per_input_file(if_sequence=0, and_end_task=True, input_as_path=False, api_client=None, num_retries=None):
if if_sequence != current_task()['sequence']:
return
@@ -232,9 +229,8 @@ class job_setup():
if not api_client:
api_client = api('v1')
-# if not num_retries:
-# num_retries = 2
-# print num_retries
+ if not num_retries:
+ num_retries = 2
job_input = current_job()['script_parameters']['input']
cr = CollectionReader(job_input, api_client=api_client)
@@ -253,18 +249,55 @@ class job_setup():
'input':task_input
}
}
- api_client.job_tasks().create(body=new_task_attrs).execute(num_retries=num_retries)
+ api_client.job_tasks().create(body=new_task_attrs).execute()
if and_end_task:
- api_client.job_tasks().update(uuid=current_task()['uuid'],
- body={'success':True}
- ).execute(num_retries=num_retries)
- exit(0)
+ one_task_per_file_retry_loop = RetryLoop(num_retries=num_retries, backoff_start=0)
+ for tries_left in one_task_per_file_retry_loop:
+ try:
+ result = api_client.job_tasks().update(uuid=current_task()['uuid'],
+ body={'success':True}
+ ).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
+ current_task_retry_loop.save_result(error)
+ else:
+ if tries_left > 0:
+ print "Retrying with {} tries left".format(tries_left)
+ else:
+ print "No more retries left (api)"
+ 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"
+ current_task_retry_loop.save_result(error)
+ else:
+ if tries_left > 0:
+ print "Retrying with {} tries left".format(tries_left+1)
+ else:
+ print "No more retries left (http)"
+ raise
+ else:
+ exit(0)
+ if one_task_per_file_retry_loop.sucess():
+ exit(0)
+ else:
+ print "one_task_per_input_file failed."
+ raise
@staticmethod
- @retry_method
- def one_task_per_input_stream(if_sequence=0, and_end_task=True, num_retries=None):
+ def one_task_per_input_stream(if_sequence=0, and_end_task=True, api_client=None, num_retries=None):
if if_sequence != current_task()['sequence']:
return
+ if not api_client:
+ api_client = api('v1')
+ if not num_retries:
+ num_retries = 2
job_input = current_job()['script_parameters']['input']
cr = CollectionReader(job_input)
for s in cr.all_streams():
@@ -277,9 +310,43 @@ class job_setup():
'input':task_input
}
}
- api('v1').job_tasks().create(body=new_task_attrs).execute(num_retries)
+ api_client.job_tasks().create(body=new_task_attrs).execute()
if and_end_task:
- api('v1').job_tasks().update(uuid=current_task()['uuid'],
- body={'success':True}
- ).execute(num_retries)
- exit(0)
+ one_task_per_stream_retry_loop = RetryLoop(num_retries=num_retries, backoff_start=0)
+ for tries_left in one_task_per_stream_retry_loop:
+ try:
+ api_client.job_tasks().update(uuid=current_task()['uuid'],
+ body={'success':True}
+ ).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
+ one_task_per_stream_retry_loop.save_result(error)
+ else:
+ if tries_left > 0:
+ print "Retrying with {} tries left".format(tries_left)
+ else:
+ print "No more retries left (api)"
+ 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"
+ one_task_per_stream_retry_loop.save_result(error)
+ else:
+ if tries_left > 0:
+ print "Retrying with {} tries left".format(tries_left+1)
+ else:
+ print "No more retries left (http)"
+ raise
+ else:
+ exit(0)
+ if one_task_per_file_retry_loop.success():
+ exit(0)
+ else:
+ print "one_task_per_input_file failed."
+ raise
diff --git a/sdk/python/tests/test_one_task_per_input_retry.py b/sdk/python/tests/test_one_task_per_input_retry.py
index ddb723e..2f7760c 100644
--- a/sdk/python/tests/test_one_task_per_input_retry.py
+++ b/sdk/python/tests/test_one_task_per_input_retry.py
@@ -7,22 +7,43 @@ import hashlib
import arvados
import arvados_testutil as tutil
-from arvados import job_setup
@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)
+class OneTaskPerInputTestCase(unittest.TestCase, tutil.ApiClientMock):
+ os.environ['TASK_UUID'] = 'zzzzz-zzzzz-zzzzzzzzzzzzzzz'
+ os.environ['TASK_WORK'] = '.'
+ os.environ['JOB_UUID'] = 'zzzzz-zzzzz-zzzzzzzzzzzzzzz'
+ os.environ['JOB_WORK'] = '.'
- 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
+ def setUp(self):
+ super(OneTaskPerInputTestCase,self).setUp()
+ try:
+ api_client = mock.MagicMock()
+ api_client.job_tasks().get().execute.side_effect = [tutil.fake_httplib2_response(200)]
+ api_client.jobs().get().execute.side_effect = [tutil.fake_httplib2_response(200)]
+ arvados.current_task(api_client)['sequence'] = 0
+ except:
+ raise
- api_client = mock.MagicMock()
+ def tearDown(self):
+ super(OneTaskPerInputTestCase,self).tearDown()
+ try:
+ arvados._current_job = None
+ except:
+ raise
+
+ def tearDown(self):
+ super(OneTaskPerInputTestCase,self).tearDown()
+ try:
+ arvados._current_task = None
+ except:
+ raise
- def test_mock_retry_until_break(self,code=500):
- j = job_setup()
- api_client = self.api_client_mock(code)
+
+ def test_mock_retry_until_break(self):
+ api_client = mock.MagicMock()
+ api_client.job_tasks().create().execute.side_effect = [tutil.fake_httplib2_response(200)]
+ api_client.job_tasks().get().execute.side_effect = [tutil.fake_httplib2_response(200)]
+ api_client.jobs().get().execute.side_effect = [arvados.errors.ApiError(tutil.fake_httplib2_response(200), "{}")]
with self.assertRaises(arvados.errors.ApiError) as err_check:
- j.one_task_per_input_file(api_client=api_client,num_retries=1)
+ arvados.current_job(api_client=api_client,num_retries=0)
diff --git a/sdk/python/tests/test_one_task_per_stream_retry.py b/sdk/python/tests/test_one_task_per_stream_retry.py
new file mode 100644
index 0000000..ae02403
--- /dev/null
+++ b/sdk/python/tests/test_one_task_per_stream_retry.py
@@ -0,0 +1,84 @@
+#!/usr/bin/env python
+
+import mock
+import os
+import unittest
+import hashlib
+
+import arvados
+import arvados_testutil as tutil
+
+ at 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)
+ 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)
+ 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)
+ 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)]
+ 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):
+ 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):
+ api_client.job_tasks().update().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.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):
+ 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):
+ 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), "{}")]
+ 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):
+ 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.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):
+ 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.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):
+ 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), "{}")]
+ 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