示例#1
0
    def test_submit_with_project_uuid(self, events, keep, keepdocker):
        api = mock.MagicMock()

        def putstub(p, **kwargs):
            return "%s+%i" % (hashlib.md5(p).hexdigest(), len(p))

        keep().put.side_effect = putstub
        keepdocker.return_value = True
        api.users().current().execute.return_value = {
            "uuid": "zzzzz-tpzed-zzzzzzzzzzzzzzz"
        }
        api.collections().list().execute.return_value = {"items": []}
        api.collections().create().execute.side_effect = ({
            "uuid":
            "zzzzz-4zz18-zzzzzzzzzzzzzz1",
            "portable_data_hash":
            "99999999999999999999999999999991+99"
        }, {
            "uuid":
            "zzzzz-4zz18-zzzzzzzzzzzzzz2",
            "portable_data_hash":
            "99999999999999999999999999999992+99"
        })
        api.jobs().create().execute.return_value = {
            "uuid": "zzzzz-8i9sb-zzzzzzzzzzzzzzz",
            "state": "Queued"
        }
        project_uuid = 'zzzzz-j7d0g-zzzzzzzzzzzzzzz'

        arvados_cwl.main([
            "--debug", "--submit", "--project-uuid", project_uuid, "--no-wait",
            "tests/wf/submit_wf.cwl", "tests/submit_test_job.json"
        ],
                         sys.stdout,
                         sys.stderr,
                         api_client=api)

        api.jobs().create.assert_called_with(body={
            'owner_uuid': project_uuid,
            'runtime_constraints': {
                'docker_image': 'arvados/jobs'
            },
            'script_parameters': {
                'x': {
                    'path': '99999999999999999999999999999992+99/blorp.txt',
                    'class': 'File'
                },
                'cwl:tool':
                '99999999999999999999999999999991+99/wf/submit_wf.cwl'
            },
            'repository': 'arvados',
            'script_version': 'master',
            'script': 'cwl-runner'
        },
                                             find_or_create=True)
示例#2
0
    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.api.pipeline_templates().create.refute_called()
        stubs.api.container_requests().create.refute_called()

        body = {
            "workflow": {
                "owner_uuid": project_uuid,
                "name": "submit_wf.cwl",
                "description": "",
                "definition": self.expect_workflow,
            }
        }
        stubs.api.workflows().create.assert_called_with(
            body=JsonDiffMatcher(body))

        self.assertEqual(capture_stdout.getvalue(),
                         stubs.expect_workflow_uuid + '\n')
示例#3
0
    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("")

        stubs.api.collections().create.assert_has_calls([
            mock.call(),
            mock.call(body=JsonDiffMatcher({
                'manifest_text':
                '. 5bcc9fe8f8d5992e6cf418dc7ce4dbb3+16 0:16:blub.txt\n',
                'replication_desired': None,
                'name': 'submit_tool.cwl dependencies',
            }), ensure_unique_name=True),
            mock.call().execute(num_retries=4),
            mock.call(body=JsonDiffMatcher({
                'manifest_text':
                '. 979af1245a12a1fed634d4222473bfdc+16 0:16:blorp.txt\n',
                'replication_desired': None,
                'name': 'submit_wf.cwl input',
            }), ensure_unique_name=True),
            mock.call().execute(num_retries=4)])

        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(),
                         stubs.expect_container_request_uuid + '\n')
示例#4
0
 def test_submit_file_keepref(self, stubs, tm, collectionReader):
     capture_stdout = cStringIO.StringIO()
     exited = arvados_cwl.main(
         ["--submit", "--no-wait", "--api=containers", "--debug",
          "tests/wf/submit_keepref_wf.cwl"],
         capture_stdout, sys.stderr, api_client=stubs.api)
     self.assertEqual(exited, 0)
示例#5
0
    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",
             "--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.api.pipeline_instances().create.refute_called()
        stubs.api.jobs().create.refute_called()

        expect_component = copy.deepcopy(stubs.expect_job_spec)
        self._adjust_script_params(expect_component)
        expect_template = {
            "components": {
                "testing 123": expect_component,
            },
            "name": "testing 123",
            "owner_uuid": project_uuid,
        }
        stubs.api.pipeline_templates().create.refute_called()
        stubs.api.pipeline_templates().update.assert_called_with(
            body=JsonDiffMatcher(expect_template), uuid=self.existing_template_uuid)

        self.assertEqual(capture_stdout.getvalue(),
                         self.existing_template_uuid + '\n')
示例#6
0
    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",
             "--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.api.pipeline_instances().create.refute_called()
        stubs.api.jobs().create.refute_called()

        expect_component = copy.deepcopy(stubs.expect_job_spec)
        self._adjust_script_params(expect_component)
        expect_template = {
            "components": {
                "testing 123": expect_component,
            },
            "name": "testing 123",
            "owner_uuid": project_uuid,
        }
        stubs.api.pipeline_templates().create.refute_called()
        stubs.api.pipeline_templates().update.assert_called_with(
            body=JsonDiffMatcher(expect_template), uuid=self.existing_template_uuid)

        self.assertEqual(capture_stdout.getvalue(),
                         self.existing_template_uuid + '\n')
示例#7
0
 def test_submit_file_keepref(self, stubs, tm, collectionReader):
     capture_stdout = cStringIO.StringIO()
     exited = arvados_cwl.main(
         ["--submit", "--no-wait", "--api=containers", "--debug",
          "tests/wf/submit_keepref_wf.cwl"],
         capture_stdout, sys.stderr, api_client=stubs.api)
     self.assertEqual(exited, 0)
示例#8
0
    def test_create(self, stubs):
        project_uuid = 'zzzzz-j7d0g-zzzzzzzzzzzzzzz'

        capture_stdout = cStringIO.StringIO()

        exited = arvados_cwl.main(
            ["--create-template", "--no-wait",
             "--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.api.pipeline_instances().create.refute_called()
        stubs.api.jobs().create.refute_called()

        expect_component = copy.deepcopy(stubs.expect_job_spec)
        expect_component['script_parameters']['x'] = {
            'dataclass': 'File',
            'required': True,
            'type': 'File',
            'value': '99999999999999999999999999999992+99/blorp.txt',
        }
        expect_template = {
            "components": {
                "submit_wf.cwl": expect_component,
            },
            "name": "submit_wf.cwl",
            "owner_uuid": project_uuid,
        }
        stubs.api.pipeline_templates().create.assert_called_with(
            body=JsonDiffMatcher(expect_template), ensure_unique_name=True)

        self.assertEqual(capture_stdout.getvalue(),
                         stubs.expect_pipeline_template_uuid + '\n')
示例#9
0
 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)
     self.assertEqual(exited, 1)
示例#10
0
    def test_submit(self, stubs):
        capture_stdout = cStringIO.StringIO()
        exited = arvados_cwl.main(
            ["--submit", "--no-wait",
             "tests/wf/submit_wf.cwl", "tests/submit_test_job.json"],
            capture_stdout, sys.stderr, api_client=stubs.api)
        self.assertEqual(exited, 0)

        stubs.api.collections().create.assert_has_calls([
            mock.call(),
            mock.call(body={
                'manifest_text':
                './tool a3954c369b8924d40547ec8cf5f6a7f4+449 '
                '0:16:blub.txt 16:433:submit_tool.cwl\n./wf '
                'e046cace0b1a0a6ee645f6ea8688f7e2+364 0:364:submit_wf.cwl\n',
                'owner_uuid': 'zzzzz-tpzed-zzzzzzzzzzzzzzz',
                'name': 'submit_wf.cwl',
            }, ensure_unique_name=True),
            mock.call().execute(),
            mock.call(body={
                'manifest_text':
                '. 979af1245a12a1fed634d4222473bfdc+16 0:16:blorp.txt\n',
                'owner_uuid': 'zzzzz-tpzed-zzzzzzzzzzzzzzz',
                'name': '#',
            }, ensure_unique_name=True),
            mock.call().execute()])

        expect_job = copy.deepcopy(stubs.expect_job_spec)
        expect_job["owner_uuid"] = stubs.fake_user_uuid
        stubs.api.jobs().create.assert_called_with(
            body=expect_job,
            find_or_create=True)
        self.assertEqual(capture_stdout.getvalue(),
                         stubs.expect_job_uuid + '\n')
示例#11
0
 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)
     self.assertEqual(exited, 1)
示例#12
0
    def test_create(self, stubs):
        project_uuid = 'zzzzz-j7d0g-zzzzzzzzzzzzzzz'

        capture_stdout = cStringIO.StringIO()

        exited = arvados_cwl.main([
            "--create-workflow", "--debug", "--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.api.pipeline_templates().create.refute_called()
        stubs.api.container_requests().create.refute_called()

        with open("tests/wf/expect_packed.cwl") as f:
            expect_workflow = f.read()

        body = {
            "workflow": {
                "owner_uuid": project_uuid,
                "name": "submit_wf.cwl",
                "description": "",
                "definition": expect_workflow
            }
        }
        stubs.api.workflows().create.assert_called_with(
            body=JsonDiffMatcher(body))

        self.assertEqual(capture_stdout.getvalue(),
                         stubs.expect_workflow_uuid + '\n')
示例#13
0
    def test_submit(self, stubs, tm, arvdock):
        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.api.collections().create.assert_has_calls([
            mock.call(),
            mock.call(body=JsonDiffMatcher({
                'manifest_text':
                '. 5bcc9fe8f8d5992e6cf418dc7ce4dbb3+16 0:16:blub.txt\n',
                'replication_desired': None,
                'name': 'submit_tool.cwl dependencies',
            }), ensure_unique_name=True),
            mock.call().execute(num_retries=4),
            mock.call(body=JsonDiffMatcher({
                'manifest_text':
                '. 979af1245a12a1fed634d4222473bfdc+16 0:16:blorp.txt\n',
                'replication_desired': None,
                'name': 'submit_wf.cwl input',
            }), ensure_unique_name=True),
            mock.call().execute(num_retries=4)])

        arvdock.assert_has_calls([
            mock.call(stubs.api, {"class": "DockerRequirement", "dockerPull": "debian:8"}, True, None),
            mock.call(stubs.api, {'dockerPull': 'arvados/jobs:'+arvados_cwl.__version__}, True, None)
        ])

        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(),
                         stubs.expect_pipeline_uuid + '\n')
示例#14
0
    def test_inputs_empty(self, stubs):
        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.api.pipeline_templates().create.assert_called_with(
            body=JsonDiffMatcher(self.expect_template), ensure_unique_name=True)
示例#15
0
    def test_inputs_empty(self, stubs):
        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.api.pipeline_templates().create.assert_called_with(
            body=JsonDiffMatcher(self.expect_template), ensure_unique_name=True)
示例#16
0
    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)

        expect_container = {
            'priority': 1,
            'mounts': {
                '/var/spool/cwl': {
                    'writable': True,
                    'kind': 'collection'
                },
                'stdout': {
                    'path': '/var/spool/cwl/cwl.output.json',
                    'kind': 'file'
                },
                '/var/lib/cwl/workflow': {
                    'portable_data_hash': '99999999999999999999999999999994+99',
                    'kind': 'collection'
                },
                '/var/lib/cwl/cwl.input.json': {
                    'content': {
                        'x': 'XxX'
                    },
                    'kind': 'json'
                }
            }, 'state': 'Committed',
            'owner_uuid': None,
            'output_path': '/var/spool/cwl',
            'name': 'expect_arvworkflow.cwl#main',
            'container_image': 'arvados/jobs:'+arvados_cwl.__version__,
            'command': ['arvados-cwl-runner', '--local', '--api=containers', '--no-log-timestamps',
                        '--enable-reuse', '--on-error=continue',
                        '/var/lib/cwl/workflow/expect_arvworkflow.cwl#main', '/var/lib/cwl/cwl.input.json'],
            'cwd': '/var/spool/cwl',
            'runtime_constraints': {
                'API': True,
                'vcpus': 1,
                'ram': 1073741824
            },
            "properties": {}
        }

        stubs.api.container_requests().create.assert_called_with(
            body=JsonDiffMatcher(expect_container))
        self.assertEqual(capture_stdout.getvalue(),
                         stubs.expect_container_request_uuid + '\n')
示例#17
0
    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("")

        stubs.api.collections().create.assert_has_calls([
            mock.call(),
            mock.call(body={
                'manifest_text':
                './tool d51232d96b6116d964a69bfb7e0c73bf+450 '
                '0:16:blub.txt 16:434:submit_tool.cwl\n./wf '
                'cc2ffb940e60adf1b2b282c67587e43d+413 0:413:submit_wf.cwl\n',
                'owner_uuid':
                'zzzzz-tpzed-zzzzzzzzzzzzzzz',
                'name':
                'submit_wf.cwl',
            },
                      ensure_unique_name=True),
            mock.call().execute(),
            mock.call(body={
                'manifest_text': '. d41d8cd98f00b204e9800998ecf8427e+0 '
                '0:0:blub.txt 0:0:submit_tool.cwl\n',
                'owner_uuid': 'zzzzz-tpzed-zzzzzzzzzzzzzzz',
                'name': 'New collection',
                'replication_desired': None,
            },
                      ensure_unique_name=True),
            mock.call().execute(num_retries=4),
            mock.call(body={
                'manifest_text':
                '. 979af1245a12a1fed634d4222473bfdc+16 0:16:blorp.txt\n',
                'owner_uuid': 'zzzzz-tpzed-zzzzzzzzzzzzzzz',
                'name': '#',
            },
                      ensure_unique_name=True),
            mock.call().execute()
        ])

        expect_container = copy.deepcopy(stubs.expect_container_spec)
        expect_container["owner_uuid"] = stubs.fake_user_uuid
        stubs.api.container_requests().create.assert_called_with(
            body=expect_container)
        self.assertEqual(capture_stdout.getvalue(),
                         stubs.expect_container_request_uuid + '\n')
示例#18
0
    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)

        expect_container = {
            'priority': 1,
            'mounts': {
                '/var/spool/cwl': {
                    'writable': True,
                    'kind': 'collection'
                },
                'stdout': {
                    'path': '/var/spool/cwl/cwl.output.json',
                    'kind': 'file'
                },
                '/var/lib/cwl/workflow': {
                    'portable_data_hash': '99999999999999999999999999999994+99',
                    'kind': 'collection'
                },
                '/var/lib/cwl/cwl.input.json': {
                    'content': {
                        'x': 'XxX'
                    },
                    'kind': 'json'
                }
            }, 'state': 'Committed',
            'owner_uuid': None,
            'output_path': '/var/spool/cwl',
            'name': 'expect_arvworkflow.cwl#main',
            'container_image': 'arvados/jobs:'+arvados_cwl.__version__,
            'command': ['arvados-cwl-runner', '--local', '--api=containers', '--enable-reuse', '/var/lib/cwl/workflow/expect_arvworkflow.cwl#main', '/var/lib/cwl/cwl.input.json'],
            'cwd': '/var/spool/cwl',
            'runtime_constraints': {
                'API': True,
                'vcpus': 1,
                'ram': 1073741824
            },
            "properties": {}
        }

        stubs.api.container_requests().create.assert_called_with(
            body=JsonDiffMatcher(expect_container))
        self.assertEqual(capture_stdout.getvalue(),
                         stubs.expect_container_request_uuid + '\n')
示例#19
0
    def test_submit_with_project_uuid(self, stubs, tm):
        project_uuid = 'zzzzz-j7d0g-zzzzzzzzzzzzzzz'

        exited = arvados_cwl.main(
            ["--submit", "--no-wait",
             "--project-uuid", project_uuid,
             "tests/wf/submit_wf.cwl", "tests/submit_test_job.json"],
            sys.stdout, sys.stderr, api_client=stubs.api)
        self.assertEqual(exited, 0)

        expect_pipeline = copy.deepcopy(stubs.expect_pipeline_instance)
        expect_pipeline["owner_uuid"] = project_uuid
        stubs.api.pipeline_instances().create.assert_called_with(
            body=JsonDiffMatcher(expect_pipeline))
示例#20
0
    def test_submit(self, stubs):
        capture_stdout = cStringIO.StringIO()
        exited = arvados_cwl.main([
            "--submit", "--no-wait", "tests/wf/submit_wf.cwl",
            "tests/submit_test_job.json"
        ],
                                  capture_stdout,
                                  sys.stderr,
                                  api_client=stubs.api)
        self.assertEqual(exited, 0)

        stubs.api.collections().create.assert_has_calls([
            mock.call(),
            mock.call(body={
                'manifest_text':
                './tool d51232d96b6116d964a69bfb7e0c73bf+450 '
                '0:16:blub.txt 16:434:submit_tool.cwl\n./wf '
                '4d31c5fefd087faf67ca8db0111af36c+353 0:353:submit_wf.cwl\n',
                'owner_uuid':
                'zzzzz-tpzed-zzzzzzzzzzzzzzz',
                'name':
                'submit_wf.cwl',
            },
                      ensure_unique_name=True),
            mock.call().execute(),
            mock.call(body={
                'manifest_text': '. d41d8cd98f00b204e9800998ecf8427e+0 '
                '0:0:blub.txt 0:0:submit_tool.cwl\n',
                'owner_uuid': 'zzzzz-tpzed-zzzzzzzzzzzzzzz',
                'name': 'New collection',
                'replication_desired': None,
            },
                      ensure_unique_name=True),
            mock.call().execute(num_retries=4),
            mock.call(body={
                'manifest_text':
                '. 979af1245a12a1fed634d4222473bfdc+16 0:16:blorp.txt\n',
                'owner_uuid': 'zzzzz-tpzed-zzzzzzzzzzzzzzz',
                'name': '#',
            },
                      ensure_unique_name=True),
            mock.call().execute()
        ])

        expect_job = copy.deepcopy(stubs.expect_job_spec)
        expect_job["owner_uuid"] = stubs.fake_user_uuid
        stubs.api.jobs().create.assert_called_with(body=expect_job,
                                                   find_or_create=True)
        self.assertEqual(capture_stdout.getvalue(),
                         stubs.expect_job_uuid + '\n')
示例#21
0
    def test_submit_with_project_uuid(self, stubs, tm):
        project_uuid = 'zzzzz-j7d0g-zzzzzzzzzzzzzzz'

        exited = arvados_cwl.main(
            ["--submit", "--no-wait",
             "--project-uuid", project_uuid,
             "tests/wf/submit_wf.cwl", "tests/submit_test_job.json"],
            sys.stdout, sys.stderr, api_client=stubs.api)
        self.assertEqual(exited, 0)

        expect_pipeline = copy.deepcopy(stubs.expect_pipeline_instance)
        expect_pipeline["owner_uuid"] = project_uuid
        stubs.api.pipeline_instances().create.assert_called_with(
            body=JsonDiffMatcher(expect_pipeline))
示例#22
0
    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)

        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(),
                         stubs.expect_pipeline_uuid + '\n')
示例#23
0
    def test_incompatible_api(self, stubs):
        capture_stderr = cStringIO.StringIO()
        logging.getLogger('arvados.cwl-runner').addHandler(
            logging.StreamHandler(capture_stderr))

        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))
示例#24
0
    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)

        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(),
                         stubs.expect_pipeline_uuid + '\n')
示例#25
0
    def test_submit_no_reuse(self, stubs, tm):
        capture_stdout = cStringIO.StringIO()
        exited = arvados_cwl.main(
            ["--submit", "--no-wait", "--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.expect_pipeline_instance["components"]["cwl-runner"]["script_parameters"]["arv:enable_reuse"] = {"value": False}

        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(),
                         stubs.expect_pipeline_uuid + '\n')
示例#26
0
    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.expect_pipeline_instance["components"]["cwl-runner"]["runtime_constraints"]["min_ram_mb_per_node"] = 2048

        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(),
                         stubs.expect_pipeline_uuid + '\n')
示例#27
0
    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)
        self.assertEqual(exited, 0)

        stubs.expect_pipeline_instance["name"] = "hello job 123"

        expect_pipeline = copy.deepcopy(stubs.expect_pipeline_instance)
        stubs.api.pipeline_instances().create.assert_called_with(
            body=expect_pipeline)
        self.assertEqual(capture_stdout.getvalue(),
                         stubs.expect_pipeline_uuid + '\n')
示例#28
0
    def test_submit_with_project_uuid(self, stubs):
        project_uuid = 'zzzzz-j7d0g-zzzzzzzzzzzzzzz'

        exited = arvados_cwl.main(
            ["--submit", "--no-wait",
             "--project-uuid", project_uuid,
             "tests/wf/submit_wf.cwl", "tests/submit_test_job.json"],
            sys.stdout, sys.stderr, api_client=stubs.api)
        self.assertEqual(exited, 0)

        expect_body = copy.deepcopy(stubs.expect_job_spec)
        expect_body["owner_uuid"] = project_uuid
        stubs.api.jobs().create.assert_called_with(
            body=expect_body,
            find_or_create=True)
示例#29
0
    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)
        self.assertEqual(exited, 0)

        expect_pipeline = copy.deepcopy(stubs.expect_pipeline_instance)
        expect_pipeline["name"] = "hello job 123"

        stubs.api.pipeline_instances().create.assert_called_with(
            body=JsonDiffMatcher(expect_pipeline))
        self.assertEqual(capture_stdout.getvalue(),
                         stubs.expect_pipeline_uuid + '\n')
示例#30
0
    def test_incompatible_api(self, stubs):
        capture_stderr = cStringIO.StringIO()
        logging.getLogger('arvados.cwl-runner').addHandler(
            logging.StreamHandler(capture_stderr))

        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))
示例#31
0
    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)

        expect_template = copy.deepcopy(self.expect_template)
        params = expect_template[
            "components"]["inputs_test.cwl"]["script_parameters"]
        params["fileInput"]["value"] = '99999999999999999999999999999994+99/blorp.txt'
        params["floatInput"]["value"] = 1.234
        params["boolInput"]["value"] = True

        stubs.api.pipeline_templates().create.assert_called_with(
            body=JsonDiffMatcher(expect_template), ensure_unique_name=True)
示例#32
0
    def test_submit_with_project_uuid(self, stubs):
        project_uuid = 'zzzzz-j7d0g-zzzzzzzzzzzzzzz'

        exited = arvados_cwl.main([
            "--submit", "--no-wait", "--project-uuid", project_uuid,
            "tests/wf/submit_wf.cwl", "tests/submit_test_job.json"
        ],
                                  sys.stdout,
                                  sys.stderr,
                                  api_client=stubs.api)
        self.assertEqual(exited, 0)

        expect_body = copy.deepcopy(stubs.expect_job_spec)
        expect_body["owner_uuid"] = project_uuid
        stubs.api.jobs().create.assert_called_with(body=expect_body,
                                                   find_or_create=True)
示例#33
0
    def test_create(self, stubs):
        project_uuid = 'zzzzz-j7d0g-zzzzzzzzzzzzzzz'

        capture_stdout = cStringIO.StringIO()

        exited = arvados_cwl.main([
            "--create-template", "--debug", "--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.api.pipeline_instances().create.refute_called()
        stubs.api.jobs().create.refute_called()

        expect_component = copy.deepcopy(stubs.expect_job_spec)
        expect_component['script_parameters']['x'] = {
            'dataclass': 'File',
            'required': True,
            'type': 'File',
            'value': '99999999999999999999999999999994+99/blorp.txt',
        }
        expect_component['script_parameters']['y'] = {
            'dataclass': 'Collection',
            'required': True,
            'type': 'Directory',
            'value': '99999999999999999999999999999998+99',
        }
        expect_component['script_parameters']['z'] = {
            'dataclass': 'Collection',
            'required': True,
            'type': 'Directory',
        }
        expect_template = {
            "components": {
                "submit_wf.cwl": expect_component,
            },
            "name": "submit_wf.cwl",
            "owner_uuid": project_uuid,
        }
        stubs.api.pipeline_templates().create.assert_called_with(
            body=JsonDiffMatcher(expect_template), ensure_unique_name=True)

        self.assertEqual(capture_stdout.getvalue(),
                         stubs.expect_pipeline_template_uuid + '\n')
示例#34
0
    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)
        self.assertEqual(exited, 0)

        stubs.expect_pipeline_instance["components"]["cwl-runner"]["script_parameters"]["arv:output_tags"] = output_tags

        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(),
                         stubs.expect_pipeline_uuid + '\n')
示例#35
0
    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)

        expect_template = copy.deepcopy(self.expect_template)
        params = expect_template[
            "components"]["inputs_test.cwl"]["script_parameters"]
        params["fileInput"]["value"] = '99999999999999999999999999999992+99/blorp.txt'
        params["cwl:tool"] = '99999999999999999999999999999994+99/workflow.cwl#main'
        params["floatInput"]["value"] = 1.234
        params["boolInput"]["value"] = True

        stubs.api.pipeline_templates().create.assert_called_with(
            body=JsonDiffMatcher(expect_template), ensure_unique_name=True)
示例#36
0
    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("")

        stubs.expect_container_spec["container_image"] = "arvados/jobs:123"

        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(),
                         stubs.expect_container_request_uuid + '\n')
示例#37
0
    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("")

        stubs.expect_pipeline_instance["components"]["cwl-runner"]["runtime_constraints"]["docker_image"] = "arvados/jobs:123"

        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(),
                         stubs.expect_pipeline_uuid + '\n')
示例#38
0
    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("")

        stubs.expect_container_spec["command"] = ['arvados-cwl-runner', '--local', '--api=containers', '--disable-reuse', '/var/lib/cwl/workflow/submit_wf.cwl', '/var/lib/cwl/cwl.input.json']

        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(),
                         stubs.expect_container_request_uuid + '\n')
示例#39
0
    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("")

        stubs.expect_container_spec["runtime_constraints"]["ram"] = 2048*1024*1024

        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(),
                         stubs.expect_container_request_uuid + '\n')
示例#40
0
    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("")

        stubs.expect_container_spec["name"] = "hello container 123"

        expect_container = copy.deepcopy(stubs.expect_container_spec)
        stubs.api.container_requests().create.assert_called_with(
            body=expect_container)
        self.assertEqual(capture_stdout.getvalue(),
                         stubs.expect_container_request_uuid + '\n')
示例#41
0
    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)

        expect_pipeline = copy.deepcopy(stubs.expect_pipeline_instance)
        expect_pipeline["components"]["cwl-runner"]["script_parameters"]["x"] = "XxX"
        del expect_pipeline["components"]["cwl-runner"]["script_parameters"]["y"]
        del expect_pipeline["components"]["cwl-runner"]["script_parameters"]["z"]
        expect_pipeline["components"]["cwl-runner"]["script_parameters"]["cwl:tool"] = "99999999999999999999999999999994+99/expect_arvworkflow.cwl#main"
        expect_pipeline["name"] = "expect_arvworkflow.cwl#main"
        stubs.api.pipeline_instances().create.assert_called_with(
            body=JsonDiffMatcher(expect_pipeline))
示例#42
0
    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("")

        expect_container = copy.deepcopy(stubs.expect_container_spec)
        expect_container["command"] = ['arvados-cwl-runner', '--local', '--api=containers', '--no-log-timestamps',
                                                  '--enable-reuse', '--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(),
                         stubs.expect_container_request_uuid + '\n')
示例#43
0
    def test_submit(self, stubs):
        capture_stdout = cStringIO.StringIO()
        exited = arvados_cwl.main(
            ["--submit", "--no-wait",
             "tests/wf/submit_wf.cwl", "tests/submit_test_job.json"],
            capture_stdout, sys.stderr, api_client=stubs.api)
        self.assertEqual(exited, 0)

        stubs.api.collections().create.assert_has_calls([
            mock.call(),
            mock.call(body={
                'manifest_text':
                './tool d51232d96b6116d964a69bfb7e0c73bf+450 '
                '0:16:blub.txt 16:434:submit_tool.cwl\n./wf '
                '4d31c5fefd087faf67ca8db0111af36c+353 0:353:submit_wf.cwl\n',
                'owner_uuid': 'zzzzz-tpzed-zzzzzzzzzzzzzzz',
                'name': 'submit_wf.cwl',
            }, ensure_unique_name=True),
            mock.call().execute(),
            mock.call(body={'manifest_text': '. d41d8cd98f00b204e9800998ecf8427e+0 '
                            '0:0:blub.txt 0:0:submit_tool.cwl\n',
                            'owner_uuid': 'zzzzz-tpzed-zzzzzzzzzzzzzzz',
                            'name': 'New collection',
                            'replication_desired': None,
            }, ensure_unique_name=True),
            mock.call().execute(num_retries=4),
            mock.call(body={
                'manifest_text':
                '. 979af1245a12a1fed634d4222473bfdc+16 0:16:blorp.txt\n',
                'owner_uuid': 'zzzzz-tpzed-zzzzzzzzzzzzzzz',
                'name': '#',
            }, ensure_unique_name=True),
            mock.call().execute()])

        expect_job = copy.deepcopy(stubs.expect_job_spec)
        expect_job["owner_uuid"] = stubs.fake_user_uuid
        stubs.api.jobs().create.assert_called_with(
            body=expect_job,
            find_or_create=True)
        self.assertEqual(capture_stdout.getvalue(),
                         stubs.expect_job_uuid + '\n')
示例#44
0
    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)

        body = {
            "workflow": {
                "name": "testing 123",
                "description": "",
                "definition": self.expect_workflow,
            }
        }
        stubs.api.workflows().update.assert_called_with(
            uuid=self.existing_workflow_uuid,
            body=JsonDiffMatcher(body))
        self.assertEqual(capture_stdout.getvalue(),
                         self.existing_workflow_uuid + '\n')
示例#45
0
    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)

        body = {
            "workflow": {
                "name": "testing 123",
                "description": "",
                "definition": self.expect_workflow,
            }
        }
        stubs.api.workflows().update.assert_called_with(
            uuid=self.existing_workflow_uuid,
            body=JsonDiffMatcher(body))
        self.assertEqual(capture_stdout.getvalue(),
                         self.existing_workflow_uuid + '\n')
示例#46
0
    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)

        expect_container = {
            'priority': 1,
            'mounts': {
                '/var/spool/cwl': {
                    'writable': True,
                    'kind': 'collection'
                },
                'stdout': {
                    'path': '/var/spool/cwl/cwl.output.json',
                    'kind': 'file'
                },
                '/var/lib/cwl/workflow.json': {
                    'kind': 'json',
                    'content': {
                        'cwlVersion': 'v1.0',
                        '$graph': [
                            {
                                'id': '#main',
                                'inputs': [
                                    {'type': 'string', 'id': '#main/x'}
                                ],
                                'steps': [
                                    {'in': [{'source': '#main/x', 'id': '#main/step1/x'}],
                                     'run': '#submit_tool.cwl',
                                     'id': '#main/step1',
                                     'out': []}
                                ],
                                'class': 'Workflow',
                                'outputs': []
                            },
                            {
                                'inputs': [
                                    {
                                        'inputBinding': {'position': 1},
                                        'type': 'string',
                                        'id': '#submit_tool.cwl/x'}
                                ],
                                'requirements': [
                                    {'dockerPull': 'debian:8', 'class': 'DockerRequirement'}
                                ],
                                'id': '#submit_tool.cwl',
                                'outputs': [],
                                'baseCommand': 'cat',
                                'class': 'CommandLineTool'
                            }
                        ]
                    }
                },
                '/var/lib/cwl/cwl.input.json': {
                    'content': {
                        'x': 'XxX'
                    },
                    'kind': 'json'
                }
            }, 'state': 'Committed',
            'owner_uuid': None,
            'output_path': '/var/spool/cwl',
            'name': 'a test workflow',
            'container_image': 'arvados/jobs:'+arvados_cwl.__version__,
            'command': ['arvados-cwl-runner', '--local', '--api=containers', '--no-log-timestamps',
                        '--enable-reuse', '--on-error=continue',
                        '/var/lib/cwl/workflow.json#main', '/var/lib/cwl/cwl.input.json'],
            'cwd': '/var/spool/cwl',
            'runtime_constraints': {
                'API': True,
                'vcpus': 1,
                'ram': 1073741824
            },
            "properties": {
                "template_uuid": "962eh-7fd4e-gkbzl62qqtfig37"
            }
        }

        stubs.api.container_requests().create.assert_called_with(
            body=JsonDiffMatcher(expect_container))
        self.assertEqual(capture_stdout.getvalue(),
                         stubs.expect_container_request_uuid + '\n')
示例#47
0
    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)

        expect_container = {
            'priority': 1,
            'mounts': {
                '/var/spool/cwl': {
                    'writable': True,
                    'kind': 'collection'
                },
                'stdout': {
                    'path': '/var/spool/cwl/cwl.output.json',
                    'kind': 'file'
                },
                '/var/lib/cwl/workflow.json': {
                    'kind': 'json',
                    'json': {
                        'cwlVersion': 'v1.0',
                        '$graph': [
                            {
                                'inputs': [
                                    {
                                        'inputBinding': {'position': 1},
                                        'type': 'string',
                                        'id': '#submit_tool.cwl/x'}
                                ],
                                'requirements': [
                                    {'dockerPull': 'debian:8', 'class': 'DockerRequirement'}
                                ],
                                'id': '#submit_tool.cwl',
                                'outputs': [],
                                'baseCommand': 'cat',
                                'class': 'CommandLineTool'
                            }, {
                                'id': '#main',
                                'inputs': [
                                    {'type': 'string', 'id': '#main/x'}
                                ],
                                'steps': [
                                    {'in': [{'source': '#main/x', 'id': '#main/step1/x'}],
                                     'run': '#submit_tool.cwl',
                                     'id': '#main/step1',
                                     'out': []}
                                ],
                                'class': 'Workflow',
                                'outputs': []
                            }
                        ]
                    }
                },
                '/var/lib/cwl/cwl.input.json': {
                    'content': {
                        'x': 'XxX'
                    },
                    'kind': 'json'
                }
            }, 'state': 'Committed',
            'owner_uuid': None,
            'output_path': '/var/spool/cwl',
            'name': 'a test workflow',
            'container_image': 'arvados/jobs:'+arvados_cwl.__version__,
            'command': ['arvados-cwl-runner', '--local', '--api=containers', '--enable-reuse', '/var/lib/cwl/workflow.json#main', '/var/lib/cwl/cwl.input.json'],
            'cwd': '/var/spool/cwl',
            'runtime_constraints': {
                'API': True,
                'vcpus': 1,
                'ram': 1073741824
            },
            "properties": {
                "template_uuid": "962eh-7fd4e-gkbzl62qqtfig37"
            }
        }

        stubs.api.container_requests().create.assert_called_with(
            body=JsonDiffMatcher(expect_container))
        self.assertEqual(capture_stdout.getvalue(),
                         stubs.expect_container_request_uuid + '\n')
示例#48
0
    def test_submit(self, events, keep, keepdocker):
        api = mock.MagicMock()

        def putstub(p, **kwargs):
            return "%s+%i" % (hashlib.md5(p).hexdigest(), len(p))

        keep().put.side_effect = putstub
        keepdocker.return_value = True
        user_uuid = "zzzzz-tpzed-zzzzzzzzzzzzzzz"
        api.users().current().execute.return_value = {"uuid": user_uuid}
        api.collections().list().execute.return_value = {"items": []}
        api.collections().create().execute.side_effect = ({
            "uuid":
            "zzzzz-4zz18-zzzzzzzzzzzzzz1",
            "portable_data_hash":
            "99999999999999999999999999999991+99"
        }, {
            "uuid":
            "zzzzz-4zz18-zzzzzzzzzzzzzz2",
            "portable_data_hash":
            "99999999999999999999999999999992+99"
        })
        api.jobs().create().execute.return_value = {
            "uuid": "zzzzz-8i9sb-zzzzzzzzzzzzzzz",
            "state": "Queued"
        }

        arvados_cwl.main([
            "--debug", "--submit", "--no-wait", "tests/wf/submit_wf.cwl",
            "tests/submit_test_job.json"
        ],
                         sys.stdout,
                         sys.stderr,
                         api_client=api)

        api.collections().create.assert_has_calls([
            mock.call(),
            mock.call(body={
                'manifest_text':
                './tool 84ec4df683711de31b782505389a8843+429 0:16:blub.txt 16:413:submit_tool.cwl\n./wf 81d977a245a41b8e79859fbe00623fd0+344 0:344:submit_wf.cwl\n',
                'owner_uuid': 'zzzzz-tpzed-zzzzzzzzzzzzzzz',
                'name': 'submit_wf.cwl'
            },
                      ensure_unique_name=True),
            mock.call().execute(),
            mock.call(body={
                'manifest_text':
                '. 979af1245a12a1fed634d4222473bfdc+16 0:16:blorp.txt\n',
                'owner_uuid': 'zzzzz-tpzed-zzzzzzzzzzzzzzz',
                'name': '#'
            },
                      ensure_unique_name=True),
            mock.call().execute()
        ])

        api.jobs().create.assert_called_with(body={
            'owner_uuid': user_uuid,
            'runtime_constraints': {
                'docker_image': 'arvados/jobs'
            },
            'script_parameters': {
                'x': {
                    'path': '99999999999999999999999999999992+99/blorp.txt',
                    'class': 'File'
                },
                'cwl:tool':
                '99999999999999999999999999999991+99/wf/submit_wf.cwl'
            },
            'repository': 'arvados',
            'script_version': 'master',
            'script': 'cwl-runner'
        },
                                             find_or_create=True)