예제 #1
0
 def test_prepare_workflow_manifest_raises_an_error_for_dependencies_file_with_filepath_not_pointing_to_zip(
     self
 ):
     with self.assertRaises(ValueError):
         utils.prepare_workflow_manifest(
             wdl_file=self.wdl_file_path, dependencies="data/fake_test_deps.wdl"
         )
예제 #2
0
 def test_prepare_workflow_manifest_works_for_wdl_file_with_filepath(self):
     manifest = utils.prepare_workflow_manifest(wdl_file=self.wdl_file_path)
     expected_manifest = {
         'workflowSource': self.wdl_file_BytesIO,
         'workflowOnHold': 'false',
     }
     assert (manifest['workflowSource'].getvalue() ==
             expected_manifest['workflowSource'].getvalue())
예제 #3
0
 def test_prepare_workflow_manifest_works_for_label_file_with_BytesIO(self):
     manifest = utils.prepare_workflow_manifest(
         wdl_file=self.wdl_file_path, label_file=self.label_file_BytesIO)
     expected_manifest = {
         'workflowSource': self.wdl_file_BytesIO,
         'labels': self.label_file_BytesIO,
         'workflowOnHold': 'false',
     }
     assert manifest['labels'].getvalue(
     ) == expected_manifest['labels'].getvalue()
예제 #4
0
 def test_prepare_workflow_manifest_works_for_on_hold(self):
     manifest = utils.prepare_workflow_manifest(wdl_file=self.wdl_file_path,
                                                on_hold=True)
     expected_manifest = {
         'workflowSource': self.wdl_file_BytesIO,
         'workflowOnHold': 'true',
     }
     assert (manifest['workflowSource'].getvalue() ==
             expected_manifest['workflowSource'].getvalue())
     assert manifest['workflowOnHold'] == expected_manifest[
         'workflowOnHold']
예제 #5
0
 def test_prepare_workflow_manifest_works_for_one_inputs_file_with_BytesIO(
         self):
     manifest = utils.prepare_workflow_manifest(
         wdl_file=self.wdl_file_path, inputs_files=self.inputs_file_BytesIO)
     expected_manifest = {
         'workflowSource': self.wdl_file_BytesIO,
         'workflowInputs': self.inputs_file_BytesIO,
         'workflowOnHold': 'false',
     }
     assert (manifest['workflowInputs'].getvalue() ==
             expected_manifest['workflowInputs'].getvalue())
예제 #6
0
 def test_prepare_workflow_manifest_works_for_collection_name(self):
     manifest = utils.prepare_workflow_manifest(
         wdl_file=self.wdl_file_path, collection_name='test_collection')
     expected_manifest = {
         'workflowSource': self.wdl_file_BytesIO,
         'collectionName': 'test_collection',
         'workflowOnHold': 'false',
     }
     assert (manifest['workflowSource'].getvalue() ==
             expected_manifest['workflowSource'].getvalue())
     assert manifest['collectionName'] == expected_manifest[
         'collectionName']
예제 #7
0
 def test_prepare_workflow_manifest_works_for_dependencies_file_with_BytesIO(
         self):
     manifest = utils.prepare_workflow_manifest(
         wdl_file=self.wdl_file_path,
         dependencies=self.deps_zip_file_BytesIO)
     expected_manifest = {
         'workflowSource': self.wdl_file_BytesIO,
         'workflowDependencies': self.deps_zip_file_BytesIO,
         'workflowOnHold': 'false',
     }
     assert (manifest['workflowDependencies'].getvalue() ==
             expected_manifest['workflowDependencies'].getvalue())
예제 #8
0
 def test_prepare_workflow_manifest_works_for_multiple_inputs_files_with_filepath(
     self, ):
     manifest = utils.prepare_workflow_manifest(
         wdl_file=self.wdl_file_path,
         inputs_files=self.inputs_file_path_list)
     expected_manifest = {
         'workflowSource': self.wdl_file_BytesIO,
         'workflowInputs': self.inputs_file_BytesIO_list[0],
         'workflowInputs_2': self.inputs_file_BytesIO_list[1],
         'workflowOnHold': 'false',
     }
     assert (manifest['workflowInputs'].getvalue() ==
             expected_manifest['workflowInputs'].getvalue())
     assert (manifest['workflowInputs_2'].getvalue() ==
             expected_manifest['workflowInputs_2'].getvalue())
예제 #9
0
    def test_prepare_workflow_manifest_works_for_dependencies_file_with_list_of_files(
        self, ):
        manifest = utils.prepare_workflow_manifest(
            wdl_file=self.wdl_file_path,
            dependencies=self.deps_files_paths_list)
        expected_manifest = {
            'workflowSource': self.wdl_file_BytesIO,
            'workflowDependencies': self.deps_zip_file_BytesIO,
            'workflowOnHold': 'false',
        }
        with zipfile.ZipFile(manifest['workflowDependencies'], 'r') as zf:
            with zf.open('test_task.wdl') as dep_file:
                contents = io.BytesIO(dep_file.read())

        with zipfile.ZipFile(expected_manifest['workflowDependencies'],
                             'r') as zf:
            with zf.open('test_task.wdl') as dep_file:
                expected_contents = io.BytesIO(dep_file.read())

        # we have to unzip both of them to get the proper comparison during the test
        assert contents.getvalue() == expected_contents.getvalue()
예제 #10
0
    def submit(
        cls: 'CromwellAPI',
        auth: CromwellAuth,
        wdl_file: Union[str, io.BytesIO],
        inputs_files: Union[List[Union[str, io.BytesIO]], str,
                            io.BytesIO] = None,
        options_file: Union[str, io.BytesIO] = None,
        dependencies: Union[str, List[str], io.BytesIO] = None,
        label_file: Union[str, io.BytesIO] = None,
        collection_name: str = None,
        on_hold: bool = False,
        validate_labels: bool = False,
        raise_for_status: bool = False,
    ) -> requests.Response:
        """ Submits a workflow to Cromwell.

        Args:
            auth: authentication class holding auth information to a
                Cromwell server.
            wdl_file: The workflow source file to submit for execution. Could be either the
                path to the file (str) or the file content in io.BytesIO.
            inputs_files: The input data in JSON
                format. Could be either the path to the file (str) or the file content in io.BytesIO. This could also
                be a list of unlimited input file paths/contents, each of them should have a type of
                Union[str, io.BytesIO].
            options_file: The Cromwell options file for workflows. Could be either
                the path to the file (str) or the file content in io.BytesIO.
            dependencies: Workflow dependency files. Could be the path to
                the zipped file (str) containing dependencies, a list of paths(List[str]) to all dependency files to be
                zipped or a zipped file in io.BytesIO.
            label_file: A collection of key/value pairs for workflow labels in JSON
                format, could be either the path to the JSON file (str) or the file content in io.BytesIO.
            collection_name: Collection in SAM that the workflow should belong to, if use CaaS.
            on_hold: Whether to submit the workflow in "On Hold" status.
            validate_labels: If True, validate cromwell labels.
            raise_for_status: Whether to check and raise for status based on the response.

        Raises:
            requests.exceptions.HTTPError: This will be raised when raise_for_status is True and Cromwell returns
                a response that satisfies 400 <= response.status_code < 600.

        Returns:
            HTTP response from Cromwell.
        """
        submission_manifest = utilities.prepare_workflow_manifest(
            wdl_file=wdl_file,
            inputs_files=inputs_files,
            options_file=options_file,
            dependencies=dependencies,
            label_file=label_file,
            collection_name=collection_name,
            on_hold=on_hold,
        )

        if auth.service_key_content:
            submission_manifest[
                'workflowOptions'] = utilities.compose_oauth_options_for_jes_backend_cromwell(
                    auth, submission_manifest.get('workflowOptions'))

        if validate_labels and label_file is not None:
            validate_cromwell_label(submission_manifest['labels'])

        response = requests.post(
            auth.url + cls._submit_endpoint,
            files=submission_manifest,
            auth=auth.auth,
            headers=auth.header,
        )

        if raise_for_status:
            cls._check_and_raise_status(response)
        return response