Beispiel #1
0
    def test_get_current_container_error(self):
        api = mock.MagicMock()
        api.containers().current().execute.side_effect = ApiError(
            httplib2.Response({"status": 300}), bytes(b""))
        logger = mock.MagicMock()

        with self.assertRaises(ApiError):
            get_current_container(api, num_retries=0, logger=logger)
Beispiel #2
0
    def test_get_current_container_404_error(self):
        api = mock.MagicMock()
        api.containers().current().execute.side_effect = ApiError(
            httplib2.Response({"status": 404}), bytes(b""))
        logger = mock.MagicMock()

        current_container = get_current_container(api,
                                                  num_retries=0,
                                                  logger=logger)
        self.assertEqual(current_container, None)
Beispiel #3
0
    def test_run(self, list_images_in_arv):
        for enable_reuse in (True, False):
            runner = mock.MagicMock()
            runner.project_uuid = "zzzzz-8i9sb-zzzzzzzzzzzzzzz"
            runner.ignore_docker_for_reuse = False
            runner.num_retries = 0
            document_loader, avsc_names, schema_metadata, metaschema_loader = cwltool.process.get_schema(
                "v1.0")

            list_images_in_arv.return_value = [["zzzzz-4zz18-zzzzzzzzzzzzzzz"]]
            runner.api.collections().get().execute.return_value = {
                "portable_data_hash": "99999999999999999999999999999993+99"
            }
            # Simulate reused job from another project so that we can check is a can_read
            # link is added.
            runner.api.jobs().create().execute.return_value = {
                'state': 'Complete' if enable_reuse else 'Queued',
                'owner_uuid': 'zzzzz-tpzed-yyyyyyyyyyyyyyy'
                if enable_reuse else 'zzzzz-8i9sb-zzzzzzzzzzzzzzz',
                'uuid': 'zzzzz-819sb-yyyyyyyyyyyyyyy',
                'output': None,
            }

            tool = cmap({
                "inputs": [],
                "outputs": [],
                "baseCommand": "ls",
                "arguments": [{
                    "valueFrom": "$(runtime.outdir)"
                }]
            })
            make_fs_access = functools.partial(
                arvados_cwl.CollectionFsAccess,
                collection_cache=arvados_cwl.CollectionCache(
                    runner.api, None, 0))
            arvtool = arvados_cwl.ArvadosCommandTool(
                runner,
                tool,
                work_api="jobs",
                avsc_names=avsc_names,
                basedir="",
                make_fs_access=make_fs_access,
                loader=Loader({}))
            arvtool.formatgraph = None
            for j in arvtool.job({},
                                 mock.MagicMock(),
                                 basedir="",
                                 make_fs_access=make_fs_access):
                j.run(enable_reuse=enable_reuse)
                runner.api.jobs().create.assert_called_with(
                    body=JsonDiffMatcher({
                        'owner_uuid': 'zzzzz-8i9sb-zzzzzzzzzzzzzzz',
                        'runtime_constraints': {},
                        'script_parameters': {
                            'tasks': [{
                                'task.env': {
                                    'HOME': '$(task.outdir)',
                                    'TMPDIR': '$(task.tmpdir)'
                                },
                                'command': ['ls', '$(task.outdir)']
                            }],
                        },
                        'script_version': 'master',
                        'minimum_script_version':
                        'a3f2cb186e437bfce0031b024b2157b73ed2717d',
                        'repository': 'arvados',
                        'script': 'crunchrunner',
                        'runtime_constraints': {
                            'docker_image': 'arvados/jobs',
                            'min_cores_per_node': 1,
                            'min_ram_mb_per_node': 1024,
                            'min_scratch_mb_per_node':
                            2048  # tmpdirSize + outdirSize
                        }
                    }),
                    find_or_create=enable_reuse,
                    filters=[['repository', '=', 'arvados'],
                             ['script', '=', 'crunchrunner'],
                             [
                                 'script_version', 'in git',
                                 'a3f2cb186e437bfce0031b024b2157b73ed2717d'
                             ],
                             [
                                 'docker_image_locator', 'in docker',
                                 'arvados/jobs'
                             ]])
                if enable_reuse:
                    runner.api.links().create.assert_called_with(
                        body=JsonDiffMatcher(
                            {
                                'link_class': 'permission',
                                'name': 'can_read',
                                "tail_uuid": "zzzzz-8i9sb-zzzzzzzzzzzzzzz",
                                "head_uuid": "zzzzz-819sb-yyyyyyyyyyyyyyy",
                            }))
                    # Simulate an API excepction when trying to create a
                    # sharing link on the job
                    runner.api.links().create.side_effect = ApiError(
                        mock.MagicMock(return_value={'status': 403}),
                        'Permission denied')
                    j.run(enable_reuse=enable_reuse)
                    j.output_callback.assert_called_with({}, 'success')
                else:
                    assert not runner.api.links().create.called