X-Git-Url: https://git.arvados.org/arvados.git/blobdiff_plain/42cb6a6d7679c5dc90adc14da57bb5691930e0f0..dbbc5a9078c0fe88160729f3ca8f56673397b106:/sdk/cwl/tests/test_submit.py diff --git a/sdk/cwl/tests/test_submit.py b/sdk/cwl/tests/test_submit.py index a7a21e709e..9535f6ba20 100644 --- a/sdk/cwl/tests/test_submit.py +++ b/sdk/cwl/tests/test_submit.py @@ -2,8 +2,14 @@ # # SPDX-License-Identifier: Apache-2.0 +from future import standard_library +standard_library.install_aliases() +from builtins import object +from builtins import str +from future.utils import viewvalues + import copy -import cStringIO +import io import functools import hashlib import json @@ -12,6 +18,17 @@ import mock import sys import unittest +from io import BytesIO + +# StringIO.StringIO and io.StringIO have different behavior write() is +# called with both python2 (byte) strings and unicode strings +# (specifically there's some logging in cwltool that causes trouble). +# This isn't a problem on python3 because all string are unicode. +if sys.version_info[0] < 3: + from StringIO import StringIO +else: + from io import StringIO + import arvados import arvados.collection import arvados_cwl @@ -33,7 +50,7 @@ def stubs(func): @mock.patch("arvados.keep.KeepClient") @mock.patch("arvados.events.subscribe") def wrapped(self, events, keep_client1, keep_client2, keepdocker, *args, **kwargs): - class Stubs: + class Stubs(object): pass stubs = Stubs() stubs.events = events @@ -60,6 +77,11 @@ def stubs(func): stubs.fake_user_uuid = "zzzzz-tpzed-zzzzzzzzzzzzzzz" stubs.fake_container_uuid = "zzzzz-dz642-zzzzzzzzzzzzzzz" + if sys.version_info[0] < 3: + stubs.capture_stdout = BytesIO() + else: + stubs.capture_stdout = StringIO() + stubs.api = mock.MagicMock() stubs.api._rootDesc = get_rootDesc() @@ -78,18 +100,18 @@ def stubs(func): return self.exe def collection_createstub(created_collections, body, ensure_unique_name=None): - mt = body["manifest_text"] + mt = body["manifest_text"].encode('utf-8') uuid = "zzzzz-4zz18-zzzzzzzzzzzzzx%d" % len(created_collections) pdh = "%s+%i" % (hashlib.md5(mt).hexdigest(), len(mt)) created_collections[uuid] = { "uuid": uuid, "portable_data_hash": pdh, - "manifest_text": mt + "manifest_text": mt.decode('utf-8') } return CollectionExecute(created_collections[uuid]) def collection_getstub(created_collections, uuid): - for v in created_collections.itervalues(): + for v in viewvalues(created_collections): if uuid in (v["uuid"], v["portable_data_hash"]): return CollectionExecute(v) @@ -99,6 +121,11 @@ def stubs(func): "portable_data_hash": "99999999999999999999999999999998+99", "manifest_text": ". 99999999999999999999999999999998+99 0:0:file1.txt" }, + "99999999999999999999999999999997+99": { + "uuid": "", + "portable_data_hash": "99999999999999999999999999999997+99", + "manifest_text": ". 99999999999999999999999999999997+99 0:0:file1.txt" + }, "99999999999999999999999999999994+99": { "uuid": "", "portable_data_hash": "99999999999999999999999999999994+99", @@ -273,7 +300,7 @@ def stubs(func): 'state': 'Committed', 'command': ['arvados-cwl-runner', '--local', '--api=containers', '--no-log-timestamps', '--disable-validate', - '--eval-timeout=20', '--thread-count=4', + '--eval-timeout=20', '--thread-count=1', '--enable-reuse', "--collection-cache-size=256", '--debug', '--on-error=continue', '/var/lib/cwl/workflow.json#main', '/var/lib/cwl/cwl.input.json'], 'name': 'submit_wf.cwl', @@ -318,12 +345,10 @@ class TestSubmit(unittest.TestCase): return '999999999999999999999999999999d4+99' arvdock.side_effect = get_image - capture_stdout = cStringIO.StringIO() exited = arvados_cwl.main( ["--submit", "--no-wait", "--api=jobs", "--debug", "tests/wf/submit_wf.cwl", "tests/submit_test_job.json"], - capture_stdout, sys.stderr, api_client=stubs.api) - self.assertEqual(exited, 0) + stubs.capture_stdout, sys.stderr, api_client=stubs.api) stubs.api.collections().create.assert_has_calls([ mock.call(body=JsonDiffMatcher({ @@ -354,19 +379,17 @@ class TestSubmit(unittest.TestCase): expect_pipeline = copy.deepcopy(stubs.expect_pipeline_instance) stubs.api.pipeline_instances().create.assert_called_with( body=JsonDiffMatcher(expect_pipeline)) - self.assertEqual(capture_stdout.getvalue(), + self.assertEqual(stubs.capture_stdout.getvalue(), stubs.expect_pipeline_uuid + '\n') - + self.assertEqual(exited, 0) @mock.patch("time.sleep") @stubs def test_submit_no_reuse(self, stubs, tm): - capture_stdout = cStringIO.StringIO() exited = arvados_cwl.main( ["--submit", "--no-wait", "--api=jobs", "--debug", "--disable-reuse", "tests/wf/submit_wf.cwl", "tests/submit_test_job.json"], - capture_stdout, sys.stderr, api_client=stubs.api) - self.assertEqual(exited, 0) + stubs.capture_stdout, sys.stderr, api_client=stubs.api) expect_pipeline = copy.deepcopy(stubs.expect_pipeline_instance) expect_pipeline["components"]["cwl-runner"]["script_parameters"]["arv:enable_reuse"] = {"value": False} @@ -374,8 +397,9 @@ class TestSubmit(unittest.TestCase): stubs.api.pipeline_instances().create.assert_called_with( body=JsonDiffMatcher(expect_pipeline)) - self.assertEqual(capture_stdout.getvalue(), + self.assertEqual(stubs.capture_stdout.getvalue(), stubs.expect_pipeline_uuid + '\n') + self.assertEqual(exited, 0) @stubs def test_error_when_multiple_storage_classes_specified(self, stubs): @@ -389,49 +413,44 @@ class TestSubmit(unittest.TestCase): @mock.patch("time.sleep") @stubs def test_submit_on_error(self, stubs, tm): - capture_stdout = cStringIO.StringIO() exited = arvados_cwl.main( ["--submit", "--no-wait", "--api=jobs", "--debug", "--on-error=stop", "tests/wf/submit_wf.cwl", "tests/submit_test_job.json"], - capture_stdout, sys.stderr, api_client=stubs.api) - self.assertEqual(exited, 0) + stubs.capture_stdout, sys.stderr, api_client=stubs.api) expect_pipeline = copy.deepcopy(stubs.expect_pipeline_instance) expect_pipeline["components"]["cwl-runner"]["script_parameters"]["arv:on_error"] = "stop" stubs.api.pipeline_instances().create.assert_called_with( body=JsonDiffMatcher(expect_pipeline)) - self.assertEqual(capture_stdout.getvalue(), + self.assertEqual(stubs.capture_stdout.getvalue(), stubs.expect_pipeline_uuid + '\n') - + self.assertEqual(exited, 0) @mock.patch("time.sleep") @stubs def test_submit_runner_ram(self, stubs, tm): - capture_stdout = cStringIO.StringIO() exited = arvados_cwl.main( ["--submit", "--no-wait", "--debug", "--submit-runner-ram=2048", "tests/wf/submit_wf.cwl", "tests/submit_test_job.json"], - capture_stdout, sys.stderr, api_client=stubs.api) - self.assertEqual(exited, 0) + stubs.capture_stdout, sys.stderr, api_client=stubs.api) expect_pipeline = copy.deepcopy(stubs.expect_pipeline_instance) expect_pipeline["components"]["cwl-runner"]["runtime_constraints"]["min_ram_mb_per_node"] = 2048 stubs.api.pipeline_instances().create.assert_called_with( body=JsonDiffMatcher(expect_pipeline)) - self.assertEqual(capture_stdout.getvalue(), + self.assertEqual(stubs.capture_stdout.getvalue(), stubs.expect_pipeline_uuid + '\n') - + self.assertEqual(exited, 0) @mock.patch("time.sleep") @stubs def test_submit_invalid_runner_ram(self, stubs, tm): - capture_stdout = cStringIO.StringIO() exited = arvados_cwl.main( ["--submit", "--no-wait", "--debug", "--submit-runner-ram=-2048", "tests/wf/submit_wf.cwl", "tests/submit_test_job.json"], - capture_stdout, sys.stderr, api_client=stubs.api) + stubs.capture_stdout, sys.stderr, api_client=stubs.api) self.assertEqual(exited, 1) @mock.patch("time.sleep") @@ -439,30 +458,27 @@ class TestSubmit(unittest.TestCase): def test_submit_output_name(self, stubs, tm): output_name = "test_output_name" - capture_stdout = cStringIO.StringIO() exited = arvados_cwl.main( ["--submit", "--no-wait", "--debug", "--output-name", output_name, "tests/wf/submit_wf.cwl", "tests/submit_test_job.json"], - capture_stdout, sys.stderr, api_client=stubs.api) - self.assertEqual(exited, 0) + stubs.capture_stdout, sys.stderr, api_client=stubs.api) expect_pipeline = copy.deepcopy(stubs.expect_pipeline_instance) expect_pipeline["components"]["cwl-runner"]["script_parameters"]["arv:output_name"] = output_name stubs.api.pipeline_instances().create.assert_called_with( body=JsonDiffMatcher(expect_pipeline)) - self.assertEqual(capture_stdout.getvalue(), + self.assertEqual(stubs.capture_stdout.getvalue(), stubs.expect_pipeline_uuid + '\n') - + self.assertEqual(exited, 0) @mock.patch("time.sleep") @stubs def test_submit_pipeline_name(self, stubs, tm): - capture_stdout = cStringIO.StringIO() exited = arvados_cwl.main( ["--submit", "--no-wait", "--debug", "--name=hello job 123", "tests/wf/submit_wf.cwl", "tests/submit_test_job.json"], - capture_stdout, sys.stderr, api_client=stubs.api) + stubs.capture_stdout, sys.stderr, api_client=stubs.api) self.assertEqual(exited, 0) expect_pipeline = copy.deepcopy(stubs.expect_pipeline_instance) @@ -470,7 +486,7 @@ class TestSubmit(unittest.TestCase): stubs.api.pipeline_instances().create.assert_called_with( body=JsonDiffMatcher(expect_pipeline)) - self.assertEqual(capture_stdout.getvalue(), + self.assertEqual(stubs.capture_stdout.getvalue(), stubs.expect_pipeline_uuid + '\n') @mock.patch("time.sleep") @@ -478,11 +494,10 @@ class TestSubmit(unittest.TestCase): def test_submit_output_tags(self, stubs, tm): output_tags = "tag0,tag1,tag2" - capture_stdout = cStringIO.StringIO() exited = arvados_cwl.main( ["--submit", "--no-wait", "--debug", "--output-tags", output_tags, "tests/wf/submit_wf.cwl", "tests/submit_test_job.json"], - capture_stdout, sys.stderr, api_client=stubs.api) + stubs.capture_stdout, sys.stderr, api_client=stubs.api) self.assertEqual(exited, 0) expect_pipeline = copy.deepcopy(stubs.expect_pipeline_instance) @@ -490,7 +505,7 @@ class TestSubmit(unittest.TestCase): stubs.api.pipeline_instances().create.assert_called_with( body=JsonDiffMatcher(expect_pipeline)) - self.assertEqual(capture_stdout.getvalue(), + self.assertEqual(stubs.capture_stdout.getvalue(), stubs.expect_pipeline_uuid + '\n') @mock.patch("time.sleep") @@ -512,15 +527,10 @@ class TestSubmit(unittest.TestCase): @stubs def test_submit_container(self, stubs): - capture_stdout = cStringIO.StringIO() - try: - exited = arvados_cwl.main( - ["--submit", "--no-wait", "--api=containers", "--debug", - "tests/wf/submit_wf.cwl", "tests/submit_test_job.json"], - capture_stdout, sys.stderr, api_client=stubs.api, keep_client=stubs.keep_client) - self.assertEqual(exited, 0) - except: - logging.exception("") + exited = arvados_cwl.main( + ["--submit", "--no-wait", "--api=containers", "--debug", + "tests/wf/submit_wf.cwl", "tests/submit_test_job.json"], + stubs.capture_stdout, sys.stderr, api_client=stubs.api, keep_client=stubs.keep_client) stubs.api.collections().create.assert_has_calls([ mock.call(body=JsonDiffMatcher({ @@ -539,26 +549,22 @@ class TestSubmit(unittest.TestCase): expect_container = copy.deepcopy(stubs.expect_container_spec) stubs.api.container_requests().create.assert_called_with( body=JsonDiffMatcher(expect_container)) - self.assertEqual(capture_stdout.getvalue(), + self.assertEqual(stubs.capture_stdout.getvalue(), stubs.expect_container_request_uuid + '\n') + self.assertEqual(exited, 0) @stubs def test_submit_container_no_reuse(self, stubs): - capture_stdout = cStringIO.StringIO() - try: - exited = arvados_cwl.main( - ["--submit", "--no-wait", "--api=containers", "--debug", "--disable-reuse", - "tests/wf/submit_wf.cwl", "tests/submit_test_job.json"], - capture_stdout, sys.stderr, api_client=stubs.api, keep_client=stubs.keep_client) - self.assertEqual(exited, 0) - except: - logging.exception("") + exited = arvados_cwl.main( + ["--submit", "--no-wait", "--api=containers", "--debug", "--disable-reuse", + "tests/wf/submit_wf.cwl", "tests/submit_test_job.json"], + stubs.capture_stdout, sys.stderr, api_client=stubs.api, keep_client=stubs.keep_client) expect_container = copy.deepcopy(stubs.expect_container_spec) expect_container["command"] = [ 'arvados-cwl-runner', '--local', '--api=containers', '--no-log-timestamps', '--disable-validate', - '--eval-timeout=20', '--thread-count=4', + '--eval-timeout=20', '--thread-count=1', '--disable-reuse', "--collection-cache-size=256", '--debug', '--on-error=continue', '/var/lib/cwl/workflow.json#main', '/var/lib/cwl/cwl.input.json'] @@ -566,25 +572,23 @@ class TestSubmit(unittest.TestCase): stubs.api.container_requests().create.assert_called_with( body=JsonDiffMatcher(expect_container)) - self.assertEqual(capture_stdout.getvalue(), + self.assertEqual(stubs.capture_stdout.getvalue(), stubs.expect_container_request_uuid + '\n') - + self.assertEqual(exited, 0) @stubs def test_submit_container_reuse_disabled_by_workflow(self, stubs): - capture_stdout = cStringIO.StringIO() - exited = arvados_cwl.main( ["--submit", "--no-wait", "--api=containers", "--debug", "tests/wf/submit_wf_no_reuse.cwl", "tests/submit_test_job.json"], - capture_stdout, sys.stderr, api_client=stubs.api, keep_client=stubs.keep_client) + stubs.capture_stdout, sys.stderr, api_client=stubs.api, keep_client=stubs.keep_client) self.assertEqual(exited, 0) expect_container = copy.deepcopy(stubs.expect_container_spec) expect_container["command"] = [ 'arvados-cwl-runner', '--local', '--api=containers', '--no-log-timestamps', '--disable-validate', - '--eval-timeout=20', '--thread-count=4', + '--eval-timeout=20', '--thread-count=1', '--disable-reuse', "--collection-cache-size=256", '--debug', '--on-error=continue', '/var/lib/cwl/workflow.json#main', '/var/lib/cwl/cwl.input.json'] expect_container["use_existing"] = False @@ -602,53 +606,44 @@ class TestSubmit(unittest.TestCase): stubs.api.container_requests().create.assert_called_with( body=JsonDiffMatcher(expect_container)) - self.assertEqual(capture_stdout.getvalue(), + self.assertEqual(stubs.capture_stdout.getvalue(), stubs.expect_container_request_uuid + '\n') @stubs def test_submit_container_on_error(self, stubs): - capture_stdout = cStringIO.StringIO() - try: - exited = arvados_cwl.main( - ["--submit", "--no-wait", "--api=containers", "--debug", "--on-error=stop", - "tests/wf/submit_wf.cwl", "tests/submit_test_job.json"], - capture_stdout, sys.stderr, api_client=stubs.api, keep_client=stubs.keep_client) - self.assertEqual(exited, 0) - except: - logging.exception("") + exited = arvados_cwl.main( + ["--submit", "--no-wait", "--api=containers", "--debug", "--on-error=stop", + "tests/wf/submit_wf.cwl", "tests/submit_test_job.json"], + stubs.capture_stdout, sys.stderr, api_client=stubs.api, keep_client=stubs.keep_client) expect_container = copy.deepcopy(stubs.expect_container_spec) expect_container["command"] = ['arvados-cwl-runner', '--local', '--api=containers', '--no-log-timestamps', '--disable-validate', - '--eval-timeout=20', '--thread-count=4', + '--eval-timeout=20', '--thread-count=1', '--enable-reuse', "--collection-cache-size=256", '--debug', '--on-error=stop', '/var/lib/cwl/workflow.json#main', '/var/lib/cwl/cwl.input.json'] stubs.api.container_requests().create.assert_called_with( body=JsonDiffMatcher(expect_container)) - self.assertEqual(capture_stdout.getvalue(), + self.assertEqual(stubs.capture_stdout.getvalue(), stubs.expect_container_request_uuid + '\n') + self.assertEqual(exited, 0) @stubs def test_submit_container_output_name(self, stubs): output_name = "test_output_name" - capture_stdout = cStringIO.StringIO() - try: - exited = arvados_cwl.main( - ["--submit", "--no-wait", "--api=containers", "--debug", "--output-name", output_name, - "tests/wf/submit_wf.cwl", "tests/submit_test_job.json"], - capture_stdout, sys.stderr, api_client=stubs.api, keep_client=stubs.keep_client) - self.assertEqual(exited, 0) - except: - logging.exception("") + exited = arvados_cwl.main( + ["--submit", "--no-wait", "--api=containers", "--debug", "--output-name", output_name, + "tests/wf/submit_wf.cwl", "tests/submit_test_job.json"], + stubs.capture_stdout, sys.stderr, api_client=stubs.api, keep_client=stubs.keep_client) expect_container = copy.deepcopy(stubs.expect_container_spec) expect_container["command"] = ['arvados-cwl-runner', '--local', '--api=containers', '--no-log-timestamps', '--disable-validate', - '--eval-timeout=20', '--thread-count=4', + '--eval-timeout=20', '--thread-count=1', '--enable-reuse', "--collection-cache-size=256", "--output-name="+output_name, '--debug', '--on-error=continue', '/var/lib/cwl/workflow.json#main', '/var/lib/cwl/cwl.input.json'] @@ -656,33 +651,30 @@ class TestSubmit(unittest.TestCase): stubs.api.container_requests().create.assert_called_with( body=JsonDiffMatcher(expect_container)) - self.assertEqual(capture_stdout.getvalue(), + self.assertEqual(stubs.capture_stdout.getvalue(), stubs.expect_container_request_uuid + '\n') + self.assertEqual(exited, 0) @stubs def test_submit_storage_classes(self, stubs): - capture_stdout = cStringIO.StringIO() - try: - exited = arvados_cwl.main( - ["--debug", "--submit", "--no-wait", "--api=containers", "--storage-classes=foo", - "tests/wf/submit_wf.cwl", "tests/submit_test_job.json"], - capture_stdout, sys.stderr, api_client=stubs.api, keep_client=stubs.keep_client) - self.assertEqual(exited, 0) - except: - logging.exception("") + exited = arvados_cwl.main( + ["--debug", "--submit", "--no-wait", "--api=containers", "--storage-classes=foo", + "tests/wf/submit_wf.cwl", "tests/submit_test_job.json"], + stubs.capture_stdout, sys.stderr, api_client=stubs.api, keep_client=stubs.keep_client) expect_container = copy.deepcopy(stubs.expect_container_spec) expect_container["command"] = ['arvados-cwl-runner', '--local', '--api=containers', '--no-log-timestamps', '--disable-validate', - '--eval-timeout=20', '--thread-count=4', + '--eval-timeout=20', '--thread-count=1', '--enable-reuse', "--collection-cache-size=256", "--debug", "--storage-classes=foo", '--on-error=continue', '/var/lib/cwl/workflow.json#main', '/var/lib/cwl/cwl.input.json'] stubs.api.container_requests().create.assert_called_with( body=JsonDiffMatcher(expect_container)) - self.assertEqual(capture_stdout.getvalue(), + self.assertEqual(stubs.capture_stdout.getvalue(), stubs.expect_container_request_uuid + '\n') + self.assertEqual(exited, 0) @mock.patch("arvados_cwl.task_queue.TaskQueue") @mock.patch("arvados_cwl.arvworkflow.ArvadosWorkflow.job") @@ -694,16 +686,13 @@ class TestSubmit(unittest.TestCase): return [] job.side_effect = set_final_output - try: - exited = arvados_cwl.main( - ["--debug", "--local", "--storage-classes=foo", - "tests/wf/submit_wf.cwl", "tests/submit_test_job.json"], - sys.stdin, sys.stderr, api_client=stubs.api, keep_client=stubs.keep_client) - self.assertEqual(exited, 0) - except: - logging.exception("") + exited = arvados_cwl.main( + ["--debug", "--local", "--storage-classes=foo", + "tests/wf/submit_wf.cwl", "tests/submit_test_job.json"], + sys.stdin, sys.stderr, api_client=stubs.api, keep_client=stubs.keep_client) make_output.assert_called_with(u'Output of submit_wf.cwl', ['foo'], '', 'zzzzz-4zz18-zzzzzzzzzzzzzzzz') + self.assertEqual(exited, 0) @mock.patch("arvados_cwl.task_queue.TaskQueue") @mock.patch("arvados_cwl.arvworkflow.ArvadosWorkflow.job") @@ -715,33 +704,25 @@ class TestSubmit(unittest.TestCase): return [] job.side_effect = set_final_output - try: - exited = arvados_cwl.main( - ["--debug", "--local", - "tests/wf/submit_wf.cwl", "tests/submit_test_job.json"], - sys.stdin, sys.stderr, api_client=stubs.api, keep_client=stubs.keep_client) - self.assertEqual(exited, 0) - except: - logging.exception("") + exited = arvados_cwl.main( + ["--debug", "--local", + "tests/wf/submit_wf.cwl", "tests/submit_test_job.json"], + sys.stdin, sys.stderr, api_client=stubs.api, keep_client=stubs.keep_client) make_output.assert_called_with(u'Output of submit_wf.cwl', ['default'], '', 'zzzzz-4zz18-zzzzzzzzzzzzzzzz') + self.assertEqual(exited, 0) @stubs def test_submit_container_output_ttl(self, stubs): - capture_stdout = cStringIO.StringIO() - try: - exited = arvados_cwl.main( - ["--submit", "--no-wait", "--api=containers", "--debug", "--intermediate-output-ttl", "3600", - "tests/wf/submit_wf.cwl", "tests/submit_test_job.json"], - capture_stdout, sys.stderr, api_client=stubs.api, keep_client=stubs.keep_client) - self.assertEqual(exited, 0) - except: - logging.exception("") + exited = arvados_cwl.main( + ["--submit", "--no-wait", "--api=containers", "--debug", "--intermediate-output-ttl", "3600", + "tests/wf/submit_wf.cwl", "tests/submit_test_job.json"], + stubs.capture_stdout, sys.stderr, api_client=stubs.api, keep_client=stubs.keep_client) expect_container = copy.deepcopy(stubs.expect_container_spec) expect_container["command"] = ['arvados-cwl-runner', '--local', '--api=containers', '--no-log-timestamps', '--disable-validate', - '--eval-timeout=20', '--thread-count=4', + '--eval-timeout=20', '--thread-count=1', '--enable-reuse', "--collection-cache-size=256", '--debug', '--on-error=continue', "--intermediate-output-ttl=3600", @@ -749,25 +730,22 @@ class TestSubmit(unittest.TestCase): stubs.api.container_requests().create.assert_called_with( body=JsonDiffMatcher(expect_container)) - self.assertEqual(capture_stdout.getvalue(), + self.assertEqual(stubs.capture_stdout.getvalue(), stubs.expect_container_request_uuid + '\n') + self.assertEqual(exited, 0) @stubs def test_submit_container_trash_intermediate(self, stubs): - capture_stdout = cStringIO.StringIO() - try: - exited = arvados_cwl.main( - ["--submit", "--no-wait", "--api=containers", "--debug", "--trash-intermediate", - "tests/wf/submit_wf.cwl", "tests/submit_test_job.json"], - capture_stdout, sys.stderr, api_client=stubs.api, keep_client=stubs.keep_client) - self.assertEqual(exited, 0) - except: - logging.exception("") + exited = arvados_cwl.main( + ["--submit", "--no-wait", "--api=containers", "--debug", "--trash-intermediate", + "tests/wf/submit_wf.cwl", "tests/submit_test_job.json"], + stubs.capture_stdout, sys.stderr, api_client=stubs.api, keep_client=stubs.keep_client) + expect_container = copy.deepcopy(stubs.expect_container_spec) expect_container["command"] = ['arvados-cwl-runner', '--local', '--api=containers', '--no-log-timestamps', '--disable-validate', - '--eval-timeout=20', '--thread-count=4', + '--eval-timeout=20', '--thread-count=1', '--enable-reuse', "--collection-cache-size=256", '--debug', '--on-error=continue', "--trash-intermediate", @@ -775,83 +753,71 @@ class TestSubmit(unittest.TestCase): stubs.api.container_requests().create.assert_called_with( body=JsonDiffMatcher(expect_container)) - self.assertEqual(capture_stdout.getvalue(), + self.assertEqual(stubs.capture_stdout.getvalue(), stubs.expect_container_request_uuid + '\n') + self.assertEqual(exited, 0) @stubs def test_submit_container_output_tags(self, stubs): output_tags = "tag0,tag1,tag2" - capture_stdout = cStringIO.StringIO() - try: - exited = arvados_cwl.main( - ["--submit", "--no-wait", "--api=containers", "--debug", "--output-tags", output_tags, - "tests/wf/submit_wf.cwl", "tests/submit_test_job.json"], - capture_stdout, sys.stderr, api_client=stubs.api, keep_client=stubs.keep_client) - self.assertEqual(exited, 0) - except: - logging.exception("") + exited = arvados_cwl.main( + ["--submit", "--no-wait", "--api=containers", "--debug", "--output-tags", output_tags, + "tests/wf/submit_wf.cwl", "tests/submit_test_job.json"], + stubs.capture_stdout, sys.stderr, api_client=stubs.api, keep_client=stubs.keep_client) expect_container = copy.deepcopy(stubs.expect_container_spec) expect_container["command"] = ['arvados-cwl-runner', '--local', '--api=containers', '--no-log-timestamps', '--disable-validate', - '--eval-timeout=20', '--thread-count=4', + '--eval-timeout=20', '--thread-count=1', '--enable-reuse', "--collection-cache-size=256", "--output-tags="+output_tags, '--debug', '--on-error=continue', '/var/lib/cwl/workflow.json#main', '/var/lib/cwl/cwl.input.json'] stubs.api.container_requests().create.assert_called_with( body=JsonDiffMatcher(expect_container)) - self.assertEqual(capture_stdout.getvalue(), + self.assertEqual(stubs.capture_stdout.getvalue(), stubs.expect_container_request_uuid + '\n') + self.assertEqual(exited, 0) @stubs def test_submit_container_runner_ram(self, stubs): - capture_stdout = cStringIO.StringIO() - try: - exited = arvados_cwl.main( - ["--submit", "--no-wait", "--api=containers", "--debug", "--submit-runner-ram=2048", - "tests/wf/submit_wf.cwl", "tests/submit_test_job.json"], - capture_stdout, sys.stderr, api_client=stubs.api, keep_client=stubs.keep_client) - self.assertEqual(exited, 0) - except: - logging.exception("") + exited = arvados_cwl.main( + ["--submit", "--no-wait", "--api=containers", "--debug", "--submit-runner-ram=2048", + "tests/wf/submit_wf.cwl", "tests/submit_test_job.json"], + stubs.capture_stdout, sys.stderr, api_client=stubs.api, keep_client=stubs.keep_client) expect_container = copy.deepcopy(stubs.expect_container_spec) expect_container["runtime_constraints"]["ram"] = (2048+256)*1024*1024 stubs.api.container_requests().create.assert_called_with( body=JsonDiffMatcher(expect_container)) - self.assertEqual(capture_stdout.getvalue(), + self.assertEqual(stubs.capture_stdout.getvalue(), stubs.expect_container_request_uuid + '\n') + self.assertEqual(exited, 0) @mock.patch("arvados.collection.CollectionReader") @mock.patch("time.sleep") @stubs def test_submit_file_keepref(self, stubs, tm, collectionReader): - capture_stdout = cStringIO.StringIO() collectionReader().find.return_value = arvados.arvfile.ArvadosFile(mock.MagicMock(), "blorp.txt") exited = arvados_cwl.main( ["--submit", "--no-wait", "--api=containers", "--debug", "tests/wf/submit_keepref_wf.cwl"], - capture_stdout, sys.stderr, api_client=stubs.api) + stubs.capture_stdout, sys.stderr, api_client=stubs.api) self.assertEqual(exited, 0) - @mock.patch("arvados.collection.CollectionReader") @mock.patch("time.sleep") @stubs def test_submit_keepref(self, stubs, tm, reader): - capture_stdout = cStringIO.StringIO() - with open("tests/wf/expect_arvworkflow.cwl") as f: reader().open().__enter__().read.return_value = f.read() exited = arvados_cwl.main( ["--submit", "--no-wait", "--api=containers", "--debug", "keep:99999999999999999999999999999994+99/expect_arvworkflow.cwl#main", "-x", "XxX"], - capture_stdout, sys.stderr, api_client=stubs.api) - self.assertEqual(exited, 0) + stubs.capture_stdout, sys.stderr, api_client=stubs.api) expect_container = { 'priority': 500, @@ -880,7 +846,7 @@ class TestSubmit(unittest.TestCase): 'container_image': '999999999999999999999999999999d3+99', 'command': ['arvados-cwl-runner', '--local', '--api=containers', '--no-log-timestamps', '--disable-validate', - '--eval-timeout=20', '--thread-count=4', + '--eval-timeout=20', '--thread-count=1', '--enable-reuse', "--collection-cache-size=256", '--debug', '--on-error=continue', '/var/lib/cwl/workflow/expect_arvworkflow.cwl#main', '/var/lib/cwl/cwl.input.json'], 'cwd': '/var/spool/cwl', @@ -896,24 +862,21 @@ class TestSubmit(unittest.TestCase): stubs.api.container_requests().create.assert_called_with( body=JsonDiffMatcher(expect_container)) - self.assertEqual(capture_stdout.getvalue(), + self.assertEqual(stubs.capture_stdout.getvalue(), stubs.expect_container_request_uuid + '\n') - + self.assertEqual(exited, 0) @mock.patch("arvados.collection.CollectionReader") @mock.patch("time.sleep") @stubs def test_submit_jobs_keepref(self, stubs, tm, reader): - capture_stdout = cStringIO.StringIO() - with open("tests/wf/expect_arvworkflow.cwl") as f: reader().open().__enter__().read.return_value = f.read() exited = arvados_cwl.main( ["--submit", "--no-wait", "--api=jobs", "--debug", "keep:99999999999999999999999999999994+99/expect_arvworkflow.cwl#main", "-x", "XxX"], - capture_stdout, sys.stderr, api_client=stubs.api) - self.assertEqual(exited, 0) + stubs.capture_stdout, sys.stderr, api_client=stubs.api) expect_pipeline = copy.deepcopy(stubs.expect_pipeline_instance) expect_pipeline["components"]["cwl-runner"]["script_parameters"]["x"] = "XxX" @@ -923,20 +886,18 @@ class TestSubmit(unittest.TestCase): expect_pipeline["name"] = "expect_arvworkflow.cwl#main" stubs.api.pipeline_instances().create.assert_called_with( body=JsonDiffMatcher(expect_pipeline)) + self.assertEqual(exited, 0) @mock.patch("time.sleep") @stubs def test_submit_arvworkflow(self, stubs, tm): - capture_stdout = cStringIO.StringIO() - with open("tests/wf/expect_arvworkflow.cwl") as f: stubs.api.workflows().get().execute.return_value = {"definition": f.read(), "name": "a test workflow"} exited = arvados_cwl.main( ["--submit", "--no-wait", "--api=containers", "--debug", "962eh-7fd4e-gkbzl62qqtfig37", "-x", "XxX"], - capture_stdout, sys.stderr, api_client=stubs.api) - self.assertEqual(exited, 0) + stubs.capture_stdout, sys.stderr, api_client=stubs.api) expect_container = { 'priority': 500, @@ -1002,7 +963,7 @@ class TestSubmit(unittest.TestCase): 'container_image': "999999999999999999999999999999d3+99", 'command': ['arvados-cwl-runner', '--local', '--api=containers', '--no-log-timestamps', '--disable-validate', - '--eval-timeout=20', '--thread-count=4', + '--eval-timeout=20', '--thread-count=1', '--enable-reuse', "--collection-cache-size=256", '--debug', '--on-error=continue', '/var/lib/cwl/workflow.json#main', '/var/lib/cwl/cwl.input.json'], 'cwd': '/var/spool/cwl', @@ -1020,49 +981,53 @@ class TestSubmit(unittest.TestCase): stubs.api.container_requests().create.assert_called_with( body=JsonDiffMatcher(expect_container)) - self.assertEqual(capture_stdout.getvalue(), + self.assertEqual(stubs.capture_stdout.getvalue(), stubs.expect_container_request_uuid + '\n') - + self.assertEqual(exited, 0) @stubs def test_submit_container_name(self, stubs): - capture_stdout = cStringIO.StringIO() - try: - exited = arvados_cwl.main( - ["--submit", "--no-wait", "--api=containers", "--debug", "--name=hello container 123", - "tests/wf/submit_wf.cwl", "tests/submit_test_job.json"], - capture_stdout, sys.stderr, api_client=stubs.api, keep_client=stubs.keep_client) - self.assertEqual(exited, 0) - except: - logging.exception("") + exited = arvados_cwl.main( + ["--submit", "--no-wait", "--api=containers", "--debug", "--name=hello container 123", + "tests/wf/submit_wf.cwl", "tests/submit_test_job.json"], + stubs.capture_stdout, sys.stderr, api_client=stubs.api, keep_client=stubs.keep_client) expect_container = copy.deepcopy(stubs.expect_container_spec) expect_container["name"] = "hello container 123" stubs.api.container_requests().create.assert_called_with( body=JsonDiffMatcher(expect_container)) - self.assertEqual(capture_stdout.getvalue(), + self.assertEqual(stubs.capture_stdout.getvalue(), stubs.expect_container_request_uuid + '\n') + self.assertEqual(exited, 0) + @stubs + def test_submit_missing_input(self, stubs): + exited = arvados_cwl.main( + ["--submit", "--no-wait", "--api=containers", "--debug", + "tests/wf/submit_wf.cwl", "tests/submit_test_job.json"], + stubs.capture_stdout, sys.stderr, api_client=stubs.api, keep_client=stubs.keep_client) + self.assertEqual(exited, 0) + + exited = arvados_cwl.main( + ["--submit", "--no-wait", "--api=containers", "--debug", + "tests/wf/submit_wf.cwl", "tests/submit_test_job_missing.json"], + stubs.capture_stdout, sys.stderr, api_client=stubs.api, keep_client=stubs.keep_client) + self.assertEqual(exited, 1) @stubs def test_submit_container_project(self, stubs): project_uuid = 'zzzzz-j7d0g-zzzzzzzzzzzzzzz' - capture_stdout = cStringIO.StringIO() - try: - exited = arvados_cwl.main( - ["--submit", "--no-wait", "--api=containers", "--debug", "--project-uuid="+project_uuid, - "tests/wf/submit_wf.cwl", "tests/submit_test_job.json"], - capture_stdout, sys.stderr, api_client=stubs.api, keep_client=stubs.keep_client) - self.assertEqual(exited, 0) - except: - logging.exception("") + exited = arvados_cwl.main( + ["--submit", "--no-wait", "--api=containers", "--debug", "--project-uuid="+project_uuid, + "tests/wf/submit_wf.cwl", "tests/submit_test_job.json"], + stubs.capture_stdout, sys.stderr, api_client=stubs.api, keep_client=stubs.keep_client) expect_container = copy.deepcopy(stubs.expect_container_spec) expect_container["owner_uuid"] = project_uuid expect_container["command"] = ['arvados-cwl-runner', '--local', '--api=containers', '--no-log-timestamps', '--disable-validate', - "--eval-timeout=20", "--thread-count=4", + "--eval-timeout=20", "--thread-count=1", '--enable-reuse', "--collection-cache-size=256", '--debug', '--on-error=continue', '--project-uuid='+project_uuid, @@ -1070,74 +1035,59 @@ class TestSubmit(unittest.TestCase): stubs.api.container_requests().create.assert_called_with( body=JsonDiffMatcher(expect_container)) - self.assertEqual(capture_stdout.getvalue(), + self.assertEqual(stubs.capture_stdout.getvalue(), stubs.expect_container_request_uuid + '\n') + self.assertEqual(exited, 0) @stubs def test_submit_container_eval_timeout(self, stubs): - project_uuid = 'zzzzz-j7d0g-zzzzzzzzzzzzzzz' - capture_stdout = cStringIO.StringIO() - try: - exited = arvados_cwl.main( - ["--submit", "--no-wait", "--api=containers", "--debug", "--eval-timeout=60", - "tests/wf/submit_wf.cwl", "tests/submit_test_job.json"], - capture_stdout, sys.stderr, api_client=stubs.api, keep_client=stubs.keep_client) - self.assertEqual(exited, 0) - except: - logging.exception("") + exited = arvados_cwl.main( + ["--submit", "--no-wait", "--api=containers", "--debug", "--eval-timeout=60", + "tests/wf/submit_wf.cwl", "tests/submit_test_job.json"], + stubs.capture_stdout, sys.stderr, api_client=stubs.api, keep_client=stubs.keep_client) expect_container = copy.deepcopy(stubs.expect_container_spec) expect_container["command"] = ['arvados-cwl-runner', '--local', '--api=containers', '--no-log-timestamps', '--disable-validate', - '--eval-timeout=60.0', '--thread-count=4', + '--eval-timeout=60.0', '--thread-count=1', '--enable-reuse', "--collection-cache-size=256", '--debug', '--on-error=continue', '/var/lib/cwl/workflow.json#main', '/var/lib/cwl/cwl.input.json'] stubs.api.container_requests().create.assert_called_with( body=JsonDiffMatcher(expect_container)) - self.assertEqual(capture_stdout.getvalue(), + self.assertEqual(stubs.capture_stdout.getvalue(), stubs.expect_container_request_uuid + '\n') + self.assertEqual(exited, 0) @stubs def test_submit_container_collection_cache(self, stubs): - project_uuid = 'zzzzz-j7d0g-zzzzzzzzzzzzzzz' - capture_stdout = cStringIO.StringIO() - try: - exited = arvados_cwl.main( - ["--submit", "--no-wait", "--api=containers", "--debug", "--collection-cache-size=500", - "tests/wf/submit_wf.cwl", "tests/submit_test_job.json"], - capture_stdout, sys.stderr, api_client=stubs.api, keep_client=stubs.keep_client) - self.assertEqual(exited, 0) - except: - logging.exception("") + exited = arvados_cwl.main( + ["--submit", "--no-wait", "--api=containers", "--debug", "--collection-cache-size=500", + "tests/wf/submit_wf.cwl", "tests/submit_test_job.json"], + stubs.capture_stdout, sys.stderr, api_client=stubs.api, keep_client=stubs.keep_client) expect_container = copy.deepcopy(stubs.expect_container_spec) expect_container["command"] = ['arvados-cwl-runner', '--local', '--api=containers', '--no-log-timestamps', '--disable-validate', - '--eval-timeout=60.0', '--thread-count=4', + '--eval-timeout=20', '--thread-count=1', '--enable-reuse', "--collection-cache-size=500", '--debug', '--on-error=continue', '/var/lib/cwl/workflow.json#main', '/var/lib/cwl/cwl.input.json'] + expect_container["runtime_constraints"]["ram"] = (1024+500)*1024*1024 stubs.api.container_requests().create.assert_called_with( body=JsonDiffMatcher(expect_container)) - self.assertEqual(capture_stdout.getvalue(), + self.assertEqual(stubs.capture_stdout.getvalue(), stubs.expect_container_request_uuid + '\n') - + self.assertEqual(exited, 0) @stubs def test_submit_container_thread_count(self, stubs): - project_uuid = 'zzzzz-j7d0g-zzzzzzzzzzzzzzz' - capture_stdout = cStringIO.StringIO() - try: - exited = arvados_cwl.main( - ["--submit", "--no-wait", "--api=containers", "--debug", "--thread-count=20", - "tests/wf/submit_wf.cwl", "tests/submit_test_job.json"], - capture_stdout, sys.stderr, api_client=stubs.api, keep_client=stubs.keep_client) - self.assertEqual(exited, 0) - except: - logging.exception("") + exited = arvados_cwl.main( + ["--submit", "--no-wait", "--api=containers", "--debug", "--thread-count=20", + "tests/wf/submit_wf.cwl", "tests/submit_test_job.json"], + stubs.capture_stdout, sys.stderr, api_client=stubs.api, keep_client=stubs.keep_client) expect_container = copy.deepcopy(stubs.expect_container_spec) expect_container["command"] = ['arvados-cwl-runner', '--local', '--api=containers', @@ -1149,82 +1099,64 @@ class TestSubmit(unittest.TestCase): stubs.api.container_requests().create.assert_called_with( body=JsonDiffMatcher(expect_container)) - self.assertEqual(capture_stdout.getvalue(), + self.assertEqual(stubs.capture_stdout.getvalue(), stubs.expect_container_request_uuid + '\n') - + self.assertEqual(exited, 0) @stubs def test_submit_job_runner_image(self, stubs): - capture_stdout = cStringIO.StringIO() - try: - exited = arvados_cwl.main( - ["--submit", "--no-wait", "--api=jobs", "--debug", "--submit-runner-image=arvados/jobs:123", - "tests/wf/submit_wf.cwl", "tests/submit_test_job.json"], - capture_stdout, sys.stderr, api_client=stubs.api, keep_client=stubs.keep_client) - self.assertEqual(exited, 0) - except: - logging.exception("") + exited = arvados_cwl.main( + ["--submit", "--no-wait", "--api=jobs", "--debug", "--submit-runner-image=arvados/jobs:123", + "tests/wf/submit_wf.cwl", "tests/submit_test_job.json"], + stubs.capture_stdout, sys.stderr, api_client=stubs.api, keep_client=stubs.keep_client) stubs.expect_pipeline_instance["components"]["cwl-runner"]["runtime_constraints"]["docker_image"] = "999999999999999999999999999999d5+99" expect_pipeline = copy.deepcopy(stubs.expect_pipeline_instance) stubs.api.pipeline_instances().create.assert_called_with( body=JsonDiffMatcher(expect_pipeline)) - self.assertEqual(capture_stdout.getvalue(), + self.assertEqual(stubs.capture_stdout.getvalue(), stubs.expect_pipeline_uuid + '\n') + self.assertEqual(exited, 0) @stubs def test_submit_container_runner_image(self, stubs): - capture_stdout = cStringIO.StringIO() - try: - exited = arvados_cwl.main( - ["--submit", "--no-wait", "--api=containers", "--debug", "--submit-runner-image=arvados/jobs:123", - "tests/wf/submit_wf.cwl", "tests/submit_test_job.json"], - capture_stdout, sys.stderr, api_client=stubs.api, keep_client=stubs.keep_client) - self.assertEqual(exited, 0) - except: - logging.exception("") + exited = arvados_cwl.main( + ["--submit", "--no-wait", "--api=containers", "--debug", "--submit-runner-image=arvados/jobs:123", + "tests/wf/submit_wf.cwl", "tests/submit_test_job.json"], + stubs.capture_stdout, sys.stderr, api_client=stubs.api, keep_client=stubs.keep_client) stubs.expect_container_spec["container_image"] = "999999999999999999999999999999d5+99" expect_container = copy.deepcopy(stubs.expect_container_spec) stubs.api.container_requests().create.assert_called_with( body=JsonDiffMatcher(expect_container)) - self.assertEqual(capture_stdout.getvalue(), + self.assertEqual(stubs.capture_stdout.getvalue(), stubs.expect_container_request_uuid + '\n') + self.assertEqual(exited, 0) @stubs def test_submit_priority(self, stubs): - capture_stdout = cStringIO.StringIO() - try: - exited = arvados_cwl.main( - ["--submit", "--no-wait", "--api=containers", "--debug", "--priority=669", - "tests/wf/submit_wf.cwl", "tests/submit_test_job.json"], - capture_stdout, sys.stderr, api_client=stubs.api, keep_client=stubs.keep_client) - self.assertEqual(exited, 0) - except: - logging.exception("") + exited = arvados_cwl.main( + ["--submit", "--no-wait", "--api=containers", "--debug", "--priority=669", + "tests/wf/submit_wf.cwl", "tests/submit_test_job.json"], + stubs.capture_stdout, sys.stderr, api_client=stubs.api, keep_client=stubs.keep_client) stubs.expect_container_spec["priority"] = 669 expect_container = copy.deepcopy(stubs.expect_container_spec) stubs.api.container_requests().create.assert_called_with( body=JsonDiffMatcher(expect_container)) - self.assertEqual(capture_stdout.getvalue(), + self.assertEqual(stubs.capture_stdout.getvalue(), stubs.expect_container_request_uuid + '\n') - + self.assertEqual(exited, 0) @stubs def test_submit_wf_runner_resources(self, stubs): - capture_stdout = cStringIO.StringIO() - try: - exited = arvados_cwl.main( - ["--submit", "--no-wait", "--api=containers", "--debug", - "tests/wf/submit_wf_runner_resources.cwl", "tests/submit_test_job.json"], - capture_stdout, sys.stderr, api_client=stubs.api, keep_client=stubs.keep_client) - self.assertEqual(exited, 0) - except: - logging.exception("") + exited = arvados_cwl.main( + ["--submit", "--no-wait", "--api=containers", "--debug", + "tests/wf/submit_wf_runner_resources.cwl", "tests/submit_test_job.json"], + stubs.capture_stdout, sys.stderr, api_client=stubs.api, keep_client=stubs.keep_client) expect_container = copy.deepcopy(stubs.expect_container_spec) expect_container["runtime_constraints"] = { @@ -1246,14 +1178,15 @@ class TestSubmit(unittest.TestCase): } expect_container['command'] = ['arvados-cwl-runner', '--local', '--api=containers', '--no-log-timestamps', '--disable-validate', - '--eval-timeout=20', '--thread-count=4', + '--eval-timeout=20', '--thread-count=1', '--enable-reuse', "--collection-cache-size=512", '--debug', '--on-error=continue', '/var/lib/cwl/workflow.json#main', '/var/lib/cwl/cwl.input.json'] stubs.api.container_requests().create.assert_called_with( body=JsonDiffMatcher(expect_container)) - self.assertEqual(capture_stdout.getvalue(), + self.assertEqual(stubs.capture_stdout.getvalue(), stubs.expect_container_request_uuid + '\n') + self.assertEqual(exited, 0) def tearDown(self): arvados_cwl.arvdocker.arv_docker_clear_cache() @@ -1297,16 +1230,10 @@ class TestSubmit(unittest.TestCase): @stubs def test_submit_secrets(self, stubs): - capture_stdout = cStringIO.StringIO() - try: - exited = arvados_cwl.main( - ["--submit", "--no-wait", "--api=containers", "--debug", - "tests/wf/secret_wf.cwl", "tests/secret_test_job.yml"], - capture_stdout, sys.stderr, api_client=stubs.api, keep_client=stubs.keep_client) - self.assertEqual(exited, 0) - except: - logging.exception("") - + exited = arvados_cwl.main( + ["--submit", "--no-wait", "--api=containers", "--debug", + "tests/wf/secret_wf.cwl", "tests/secret_test_job.yml"], + stubs.capture_stdout, sys.stderr, api_client=stubs.api, keep_client=stubs.keep_client) expect_container = { "command": [ @@ -1316,7 +1243,7 @@ class TestSubmit(unittest.TestCase): "--no-log-timestamps", "--disable-validate", "--eval-timeout=20", - '--thread-count=4', + '--thread-count=1', "--enable-reuse", "--collection-cache-size=256", '--debug', @@ -1461,8 +1388,9 @@ class TestSubmit(unittest.TestCase): stubs.api.container_requests().create.assert_called_with( body=JsonDiffMatcher(expect_container)) - self.assertEqual(capture_stdout.getvalue(), + self.assertEqual(stubs.capture_stdout.getvalue(), stubs.expect_container_request_uuid + '\n') + self.assertEqual(exited, 0) @stubs def test_submit_request_uuid(self, stubs): @@ -1474,52 +1402,133 @@ class TestSubmit(unittest.TestCase): "state": "Queued" } - capture_stdout = cStringIO.StringIO() - try: - exited = arvados_cwl.main( - ["--submit", "--no-wait", "--api=containers", "--debug", "--submit-request-uuid=zzzzz-xvhdp-yyyyyyyyyyyyyyy", - "tests/wf/submit_wf.cwl", "tests/submit_test_job.json"], - capture_stdout, sys.stderr, api_client=stubs.api, keep_client=stubs.keep_client) - self.assertEqual(exited, 0) - except: - logging.exception("") + exited = arvados_cwl.main( + ["--submit", "--no-wait", "--api=containers", "--debug", "--submit-request-uuid=zzzzz-xvhdp-yyyyyyyyyyyyyyy", + "tests/wf/submit_wf.cwl", "tests/submit_test_job.json"], + stubs.capture_stdout, sys.stderr, api_client=stubs.api, keep_client=stubs.keep_client) stubs.api.container_requests().update.assert_called_with( - uuid="zzzzz-xvhdp-yyyyyyyyyyyyyyy", body=JsonDiffMatcher(stubs.expect_container_spec), cluster_id="zzzzz") - self.assertEqual(capture_stdout.getvalue(), + uuid="zzzzz-xvhdp-yyyyyyyyyyyyyyy", body=JsonDiffMatcher(stubs.expect_container_spec)) + self.assertEqual(stubs.capture_stdout.getvalue(), stubs.expect_container_request_uuid + '\n') + self.assertEqual(exited, 0) @stubs def test_submit_container_cluster_id(self, stubs): - capture_stdout = cStringIO.StringIO() stubs.api._rootDesc["remoteHosts"]["zbbbb"] = "123" - try: - exited = arvados_cwl.main( - ["--submit", "--no-wait", "--api=containers", "--debug", "--submit-runner-cluster=zbbbb", - "tests/wf/submit_wf.cwl", "tests/submit_test_job.json"], - capture_stdout, sys.stderr, api_client=stubs.api, keep_client=stubs.keep_client) - self.assertEqual(exited, 0) - except: - logging.exception("") + + exited = arvados_cwl.main( + ["--submit", "--no-wait", "--api=containers", "--debug", "--submit-runner-cluster=zbbbb", + "tests/wf/submit_wf.cwl", "tests/submit_test_job.json"], + stubs.capture_stdout, sys.stderr, api_client=stubs.api, keep_client=stubs.keep_client) expect_container = copy.deepcopy(stubs.expect_container_spec) stubs.api.container_requests().create.assert_called_with( body=JsonDiffMatcher(expect_container), cluster_id="zbbbb") - self.assertEqual(capture_stdout.getvalue(), + self.assertEqual(stubs.capture_stdout.getvalue(), stubs.expect_container_request_uuid + '\n') - + self.assertEqual(exited, 0) @stubs def test_submit_validate_cluster_id(self, stubs): - capture_stdout = cStringIO.StringIO() stubs.api._rootDesc["remoteHosts"]["zbbbb"] = "123" exited = arvados_cwl.main( ["--submit", "--no-wait", "--api=containers", "--debug", "--submit-runner-cluster=zcccc", "tests/wf/submit_wf.cwl", "tests/submit_test_job.json"], - capture_stdout, sys.stderr, api_client=stubs.api, keep_client=stubs.keep_client) + stubs.capture_stdout, sys.stderr, api_client=stubs.api, keep_client=stubs.keep_client) self.assertEqual(exited, 1) + @mock.patch("arvados.collection.CollectionReader") + @stubs + def test_submit_uuid_inputs(self, stubs, collectionReader): + collectionReader().find.return_value = arvados.arvfile.ArvadosFile(mock.MagicMock(), "file1.txt") + def list_side_effect(**kwargs): + m = mock.MagicMock() + if "count" in kwargs: + m.execute.return_value = {"items": [ + {"uuid": "zzzzz-4zz18-zzzzzzzzzzzzzzz", "portable_data_hash": "99999999999999999999999999999998+99"} + ]} + else: + m.execute.return_value = {"items": []} + return m + stubs.api.collections().list.side_effect = list_side_effect + + exited = arvados_cwl.main( + ["--submit", "--no-wait", "--api=containers", "--debug", + "tests/wf/submit_wf.cwl", "tests/submit_test_job_with_uuids.json"], + stubs.capture_stdout, sys.stderr, api_client=stubs.api, keep_client=stubs.keep_client) + + expect_container = copy.deepcopy(stubs.expect_container_spec) + expect_container['mounts']['/var/lib/cwl/cwl.input.json']['content']['y']['basename'] = 'zzzzz-4zz18-zzzzzzzzzzzzzzz' + expect_container['mounts']['/var/lib/cwl/cwl.input.json']['content']['y']['http://arvados.org/cwl#collectionUUID'] = 'zzzzz-4zz18-zzzzzzzzzzzzzzz' + expect_container['mounts']['/var/lib/cwl/cwl.input.json']['content']['z']['listing'][0]['http://arvados.org/cwl#collectionUUID'] = 'zzzzz-4zz18-zzzzzzzzzzzzzzz' + + stubs.api.collections().list.assert_has_calls([ + mock.call(count='none', + filters=[['uuid', 'in', ['zzzzz-4zz18-zzzzzzzzzzzzzzz']]], + select=['uuid', 'portable_data_hash'])]) + stubs.api.container_requests().create.assert_called_with( + body=JsonDiffMatcher(expect_container)) + self.assertEqual(stubs.capture_stdout.getvalue(), + stubs.expect_container_request_uuid + '\n') + self.assertEqual(exited, 0) + + @stubs + def test_submit_mismatched_uuid_inputs(self, stubs): + def list_side_effect(**kwargs): + m = mock.MagicMock() + if "count" in kwargs: + m.execute.return_value = {"items": [ + {"uuid": "zzzzz-4zz18-zzzzzzzzzzzzzzz", "portable_data_hash": "99999999999999999999999999999997+99"} + ]} + else: + m.execute.return_value = {"items": []} + return m + stubs.api.collections().list.side_effect = list_side_effect + + for infile in ("tests/submit_test_job_with_mismatched_uuids.json", "tests/submit_test_job_with_inconsistent_uuids.json"): + capture_stderr = StringIO() + cwltool_logger = logging.getLogger('cwltool') + stderr_logger = logging.StreamHandler(capture_stderr) + cwltool_logger.addHandler(stderr_logger) + + try: + exited = arvados_cwl.main( + ["--submit", "--no-wait", "--api=containers", "--debug", + "tests/wf/submit_wf.cwl", infile], + stubs.capture_stdout, capture_stderr, api_client=stubs.api, keep_client=stubs.keep_client) + + self.assertEqual(exited, 1) + self.assertRegexpMatches( + capture_stderr.getvalue(), + r"Expected collection uuid zzzzz-4zz18-zzzzzzzzzzzzzzz to be 99999999999999999999999999999998\+99 but API server reported 99999999999999999999999999999997\+99") + finally: + cwltool_logger.removeHandler(stderr_logger) + + @mock.patch("arvados.collection.CollectionReader") + @stubs + def test_submit_unknown_uuid_inputs(self, stubs, collectionReader): + collectionReader().find.return_value = arvados.arvfile.ArvadosFile(mock.MagicMock(), "file1.txt") + capture_stderr = StringIO() + + cwltool_logger = logging.getLogger('cwltool') + stderr_logger = logging.StreamHandler(capture_stderr) + cwltool_logger.addHandler(stderr_logger) + + exited = arvados_cwl.main( + ["--submit", "--no-wait", "--api=containers", "--debug", + "tests/wf/submit_wf.cwl", "tests/submit_test_job_with_uuids.json"], + stubs.capture_stdout, capture_stderr, api_client=stubs.api, keep_client=stubs.keep_client) + + try: + self.assertEqual(exited, 1) + self.assertRegexpMatches( + capture_stderr.getvalue(), + r"Collection uuid zzzzz-4zz18-zzzzzzzzzzzzzzz not found") + finally: + cwltool_logger.removeHandler(stderr_logger) + class TestCreateTemplate(unittest.TestCase): existing_template_uuid = "zzzzz-d1hrv-validworkfloyml" @@ -1547,15 +1556,12 @@ class TestCreateTemplate(unittest.TestCase): def test_create(self, stubs): project_uuid = 'zzzzz-j7d0g-zzzzzzzzzzzzzzz' - capture_stdout = cStringIO.StringIO() - exited = arvados_cwl.main( ["--create-workflow", "--debug", "--api=jobs", "--project-uuid", project_uuid, "tests/wf/submit_wf.cwl", "tests/submit_test_job.json"], - capture_stdout, sys.stderr, api_client=stubs.api) - self.assertEqual(exited, 0) + stubs.capture_stdout, sys.stderr, api_client=stubs.api) stubs.api.pipeline_instances().create.refute_called() stubs.api.jobs().create.refute_called() @@ -1572,24 +1578,21 @@ class TestCreateTemplate(unittest.TestCase): stubs.api.pipeline_templates().create.assert_called_with( body=JsonDiffMatcher(expect_template), ensure_unique_name=True) - self.assertEqual(capture_stdout.getvalue(), + self.assertEqual(stubs.capture_stdout.getvalue(), stubs.expect_pipeline_template_uuid + '\n') - + self.assertEqual(exited, 0) @stubs def test_create_name(self, stubs): project_uuid = 'zzzzz-j7d0g-zzzzzzzzzzzzzzz' - capture_stdout = cStringIO.StringIO() - exited = arvados_cwl.main( ["--create-workflow", "--debug", "--project-uuid", project_uuid, "--api=jobs", "--name", "testing 123", "tests/wf/submit_wf.cwl", "tests/submit_test_job.json"], - capture_stdout, sys.stderr, api_client=stubs.api) - self.assertEqual(exited, 0) + stubs.capture_stdout, sys.stderr, api_client=stubs.api) stubs.api.pipeline_instances().create.refute_called() stubs.api.jobs().create.refute_called() @@ -1606,16 +1609,14 @@ class TestCreateTemplate(unittest.TestCase): stubs.api.pipeline_templates().create.assert_called_with( body=JsonDiffMatcher(expect_template), ensure_unique_name=True) - self.assertEqual(capture_stdout.getvalue(), + self.assertEqual(stubs.capture_stdout.getvalue(), stubs.expect_pipeline_template_uuid + '\n') - + self.assertEqual(exited, 0) @stubs def test_update_name(self, stubs): project_uuid = 'zzzzz-j7d0g-zzzzzzzzzzzzzzz' - capture_stdout = cStringIO.StringIO() - exited = arvados_cwl.main( ["--update-workflow", self.existing_template_uuid, "--debug", @@ -1623,8 +1624,7 @@ class TestCreateTemplate(unittest.TestCase): "--api=jobs", "--name", "testing 123", "tests/wf/submit_wf.cwl", "tests/submit_test_job.json"], - capture_stdout, sys.stderr, api_client=stubs.api) - self.assertEqual(exited, 0) + stubs.capture_stdout, sys.stderr, api_client=stubs.api) stubs.api.pipeline_instances().create.refute_called() stubs.api.jobs().create.refute_called() @@ -1642,8 +1642,9 @@ class TestCreateTemplate(unittest.TestCase): stubs.api.pipeline_templates().update.assert_called_with( body=JsonDiffMatcher(expect_template), uuid=self.existing_template_uuid) - self.assertEqual(capture_stdout.getvalue(), + self.assertEqual(stubs.capture_stdout.getvalue(), self.existing_template_uuid + '\n') + self.assertEqual(exited, 0) class TestCreateWorkflow(unittest.TestCase): @@ -1655,15 +1656,12 @@ class TestCreateWorkflow(unittest.TestCase): def test_create(self, stubs): project_uuid = 'zzzzz-j7d0g-zzzzzzzzzzzzzzz' - capture_stdout = cStringIO.StringIO() - exited = arvados_cwl.main( ["--create-workflow", "--debug", "--api=containers", "--project-uuid", project_uuid, "tests/wf/submit_wf.cwl", "tests/submit_test_job.json"], - capture_stdout, sys.stderr, api_client=stubs.api) - self.assertEqual(exited, 0) + stubs.capture_stdout, sys.stderr, api_client=stubs.api) stubs.api.pipeline_templates().create.refute_called() stubs.api.container_requests().create.refute_called() @@ -1679,24 +1677,21 @@ class TestCreateWorkflow(unittest.TestCase): stubs.api.workflows().create.assert_called_with( body=JsonDiffMatcher(body)) - self.assertEqual(capture_stdout.getvalue(), + self.assertEqual(stubs.capture_stdout.getvalue(), stubs.expect_workflow_uuid + '\n') - + self.assertEqual(exited, 0) @stubs def test_create_name(self, stubs): project_uuid = 'zzzzz-j7d0g-zzzzzzzzzzzzzzz' - capture_stdout = cStringIO.StringIO() - exited = arvados_cwl.main( ["--create-workflow", "--debug", "--api=containers", "--project-uuid", project_uuid, "--name", "testing 123", "tests/wf/submit_wf.cwl", "tests/submit_test_job.json"], - capture_stdout, sys.stderr, api_client=stubs.api) - self.assertEqual(exited, 0) + stubs.capture_stdout, sys.stderr, api_client=stubs.api) stubs.api.pipeline_templates().create.refute_called() stubs.api.container_requests().create.refute_called() @@ -1712,36 +1707,38 @@ class TestCreateWorkflow(unittest.TestCase): stubs.api.workflows().create.assert_called_with( body=JsonDiffMatcher(body)) - self.assertEqual(capture_stdout.getvalue(), + self.assertEqual(stubs.capture_stdout.getvalue(), stubs.expect_workflow_uuid + '\n') + self.assertEqual(exited, 0) @stubs def test_incompatible_api(self, stubs): - capture_stderr = cStringIO.StringIO() - logging.getLogger('arvados.cwl-runner').addHandler( - logging.StreamHandler(capture_stderr)) + capture_stderr = StringIO() + acr_logger = logging.getLogger('arvados.cwl-runner') + stderr_logger = logging.StreamHandler(capture_stderr) + acr_logger.addHandler(stderr_logger) - exited = arvados_cwl.main( - ["--update-workflow", self.existing_workflow_uuid, - "--api=jobs", - "--debug", - "tests/wf/submit_wf.cwl", "tests/submit_test_job.json"], - sys.stderr, sys.stderr, api_client=stubs.api) - self.assertEqual(exited, 1) - self.assertRegexpMatches( - capture_stderr.getvalue(), - "--update-workflow arg '{}' uses 'containers' API, but --api='jobs' specified".format(self.existing_workflow_uuid)) + try: + exited = arvados_cwl.main( + ["--update-workflow", self.existing_workflow_uuid, + "--api=jobs", + "--debug", + "tests/wf/submit_wf.cwl", "tests/submit_test_job.json"], + sys.stderr, sys.stderr, api_client=stubs.api) + self.assertEqual(exited, 1) + self.assertRegexpMatches( + capture_stderr.getvalue(), + "--update-workflow arg '{}' uses 'containers' API, but --api='jobs' specified".format(self.existing_workflow_uuid)) + finally: + acr_logger.removeHandler(stderr_logger) @stubs def test_update(self, stubs): - capture_stdout = cStringIO.StringIO() - exited = arvados_cwl.main( ["--update-workflow", self.existing_workflow_uuid, "--debug", "tests/wf/submit_wf.cwl", "tests/submit_test_job.json"], - capture_stdout, sys.stderr, api_client=stubs.api) - self.assertEqual(exited, 0) + stubs.capture_stdout, sys.stderr, api_client=stubs.api) body = { "workflow": { @@ -1753,20 +1750,17 @@ class TestCreateWorkflow(unittest.TestCase): stubs.api.workflows().update.assert_called_with( uuid=self.existing_workflow_uuid, body=JsonDiffMatcher(body)) - self.assertEqual(capture_stdout.getvalue(), + self.assertEqual(stubs.capture_stdout.getvalue(), self.existing_workflow_uuid + '\n') - + self.assertEqual(exited, 0) @stubs def test_update_name(self, stubs): - capture_stdout = cStringIO.StringIO() - exited = arvados_cwl.main( ["--update-workflow", self.existing_workflow_uuid, "--debug", "--name", "testing 123", "tests/wf/submit_wf.cwl", "tests/submit_test_job.json"], - capture_stdout, sys.stderr, api_client=stubs.api) - self.assertEqual(exited, 0) + stubs.capture_stdout, sys.stderr, api_client=stubs.api) body = { "workflow": { @@ -1778,23 +1772,20 @@ class TestCreateWorkflow(unittest.TestCase): stubs.api.workflows().update.assert_called_with( uuid=self.existing_workflow_uuid, body=JsonDiffMatcher(body)) - self.assertEqual(capture_stdout.getvalue(), + self.assertEqual(stubs.capture_stdout.getvalue(), self.existing_workflow_uuid + '\n') - + self.assertEqual(exited, 0) @stubs def test_create_collection_per_tool(self, stubs): project_uuid = 'zzzzz-j7d0g-zzzzzzzzzzzzzzz' - capture_stdout = cStringIO.StringIO() - exited = arvados_cwl.main( ["--create-workflow", "--debug", "--api=containers", "--project-uuid", project_uuid, "tests/collection_per_tool/collection_per_tool.cwl"], - capture_stdout, sys.stderr, api_client=stubs.api) - self.assertEqual(exited, 0) + stubs.capture_stdout, sys.stderr, api_client=stubs.api) toolfile = "tests/collection_per_tool/collection_per_tool_packed.cwl" expect_workflow = StripYAMLComments(open(toolfile).read()) @@ -1810,8 +1801,9 @@ class TestCreateWorkflow(unittest.TestCase): stubs.api.workflows().create.assert_called_with( body=JsonDiffMatcher(body)) - self.assertEqual(capture_stdout.getvalue(), + self.assertEqual(stubs.capture_stdout.getvalue(), stubs.expect_workflow_uuid + '\n') + self.assertEqual(exited, 0) class TestTemplateInputs(unittest.TestCase): expect_template = { @@ -1866,19 +1858,19 @@ class TestTemplateInputs(unittest.TestCase): exited = arvados_cwl.main( ["--create-template", "tests/wf/inputs_test.cwl", "tests/order/empty_order.json"], - cStringIO.StringIO(), sys.stderr, api_client=stubs.api) - self.assertEqual(exited, 0) + stubs.capture_stdout, sys.stderr, api_client=stubs.api) stubs.api.pipeline_templates().create.assert_called_with( body=JsonDiffMatcher(self.expect_template), ensure_unique_name=True) + self.assertEqual(exited, 0) + @stubs def test_inputs(self, stubs): exited = arvados_cwl.main( ["--create-template", "tests/wf/inputs_test.cwl", "tests/order/inputs_test_order.json"], - cStringIO.StringIO(), sys.stderr, api_client=stubs.api) - self.assertEqual(exited, 0) + stubs.capture_stdout, sys.stderr, api_client=stubs.api) expect_template = copy.deepcopy(self.expect_template) params = expect_template[ @@ -1890,3 +1882,4 @@ class TestTemplateInputs(unittest.TestCase): stubs.api.pipeline_templates().create.assert_called_with( body=JsonDiffMatcher(expect_template), ensure_unique_name=True) + self.assertEqual(exited, 0)