def test_short_workflow_failure_content(self, mock_request):
        """
        Test case for get_job

        Parsing should succeed even if the failure content is one-level deep.
        """
        workflow_id = 'id'
        subworkflow_id = 'subworkflow_id'
        workflow_name = 'test'
        status = 'Failed'
        timestamp = '2017-11-08T05:06:41.424Z'
        response_timestamp = '2017-11-08T05:06:41.424000+00:00'
        inputs = {'test.inputs': 'gs://project-bucket/test/inputs.txt'}
        outputs = {
            'test.analysis.outputs': 'gs://project-bucket/test/outputs.txt'
        }
        labels = {'cromwell-workflow-id': 'cromwell-12345'}
        backend_log = '/cromwell/cromwell-executions/id/call-analysis/call-analysis-log'
        attempts = 1
        return_code = 0

        def _request_callback(request, context):
            context.status_code = 200
            return {
                'workflowName': workflow_name,
                'id': workflow_id,
                'status': status,
                'calls': { },
                'inputs': inputs,
                'labels': labels,
                'outputs': outputs,
                'submission': timestamp,
                'end': timestamp,
                'start': timestamp,
                'failures': [
                    {'causedBy': [],
                     'message': 'Something failed'}
                ]
            }  # yapf: disable

        cromwell_url = self.base_url + '/{id}/metadata'.format(id=workflow_id)
        mock_request.get(cromwell_url, json=_request_callback)

        response = self.client.open('/jobs/{id}'.format(id=workflow_id),
                                    method='GET')
        self.assertStatus(response, 200)
        response_data = json.loads(response.data)
        expected_data = {
            'name': workflow_name,
            'id': workflow_id,
            'status': status,
            'submission': response_timestamp,
            'start': response_timestamp,
            'end': response_timestamp,
            'inputs': jobs_controller.update_key_names(inputs),
            'outputs': jobs_controller.update_key_names(outputs),
            'labels': labels,
            'extensions':{
                'tasks': []
            },
            'failures': [{
                'failure': 'Something failed',
                'taskName': 'Workflow Error'
            }]
        }  # yapf: disable
        self.assertDictEqual(response_data, expected_data)
    def test_get_scattered_job_returns_200(self, mock_request):
        """
        Test case for get_job

        Query for job and task-level metadata for a specified job
        """
        workflow_id = 'id'
        workflow_name = 'test'
        status = 'Failed'
        timestamp = '2017-11-08T05:06:41.424Z'
        response_timestamp = '2017-11-08T05:06:41.424000+00:00'
        inputs = {'test.inputs': 'gs://project-bucket/test/inputs.txt'}
        outputs = {
            'test.analysis.outputs': 'gs://project-bucket/test/outputs.txt'
        }
        labels = {'cromwell-workflow-id': 'cromwell-12345'}
        call_root = '/cromwell/cromwell-executions/id/call-analysis'
        backend_log = '/cromwell/cromwell-executions/id/call-analysis/call-analysis-log'
        attempts = 2
        return_code = 0

        def _request_callback(request, context):
            context.status_code = 200
            return {
                'workflowName': workflow_name,
                'id': workflow_id,
                'status': status,
                'calls': {
                    'test.analysis': [{
                        'executionStatus': 'Failed',
                        'shardIndex': 0,
                        'start': timestamp,
                        'end': timestamp,
                        'backendLogs': {
                            'log': backend_log},
                        'callRoot': call_root,
                        'returnCode': return_code,
                        'inputs': inputs,
                        'attempt': attempts,
                        'failures': [
                            {
                                'causedBy': [],
                                'message': 'test.analysis shard 0 failed'
                            }
                        ],
                    },{
                        'executionStatus': 'Failed',
                        'shardIndex': 1,
                        'start': timestamp,
                        'end': timestamp,
                        'backendLogs': {
                            'log': backend_log},
                        'callRoot': call_root,
                        'returnCode': return_code,
                        'inputs': inputs,
                        'attempt': attempts,
                        'failures': [
                            {
                                'causedBy': [],
                                'message': 'test.analysis shard 1 failed'
                            }
                        ],
                    }]
                },
                'inputs': inputs,
                'labels': labels,
                'outputs': outputs,
                'submission': timestamp,
                'end': timestamp,
                'start': timestamp,
                'failures': [
                    {
                        'causedBy': [
                            {
                                'causedBy': [],
                                'message': 'test.analysis shard 0 failed'
                            },{
                                'causedBy': [],
                                'message': 'test.analysis shard 1 failed'
                            }
                        ],
                        'message': 'Workflow failed'
                    }
                ]
            }  # yapf: disable

        cromwell_url = self.base_url + '/{id}/metadata'.format(id=workflow_id)
        mock_request.get(cromwell_url, json=_request_callback)

        response = self.client.open('/jobs/{id}'.format(id=workflow_id),
                                    method='GET')
        self.assertStatus(response, 200)
        response_data = json.loads(response.data)
        expected_data = {
            'name': workflow_name,
            'id': workflow_id,
            'status': status,
            'submission': response_timestamp,
            'start': response_timestamp,
            'end': response_timestamp,
            'inputs': jobs_controller.update_key_names(inputs),
            'outputs': jobs_controller.update_key_names(outputs),
            'labels': labels,
            'failures': [{
                'callRoot': call_root,
                'failure': 'test.analysis shard 0 failed',
                'backendLog': backend_log,
                'shardIndex': 0,
                'taskName': 'analysis',
                'timestamp': response_timestamp
            },{
                'callRoot': call_root,
                'failure': 'test.analysis shard 1 failed',
                'backendLog': backend_log,
                'shardIndex': 1,
                'taskName': 'analysis',
                'timestamp': response_timestamp
            }],
            'extensions':{
                'tasks': [{
                    'name': 'analysis',
                    'executionStatus': 'Failed',
                    'executionEvents': [],
                    'callRoot': call_root,
                    'callCached': False,
                    'attempts': attempts,
                    'start': response_timestamp,
                    'end': response_timestamp,
                    'shards': [{
                        'attempts': attempts,
                        'end': response_timestamp,
                        'callRoot': call_root,
                        'backendLog': backend_log,
                        'executionStatus': 'Failed',
                        'failureMessages': ['test.analysis shard 0 failed'],
                        'shardIndex': 0,
                        'start': response_timestamp
                    },{
                        'attempts': attempts,
                        'end': response_timestamp,
                        'callRoot': call_root,
                        'backendLog': backend_log,
                        'executionStatus': 'Failed',
                        'failureMessages': ['test.analysis shard 1 failed'],
                        'shardIndex': 1,
                        'start': response_timestamp
                    }]
                }]
            }
        }  # yapf: disable
        self.assertDictEqual(response_data, expected_data)
Example #3
0
    def test_get_job_returns_200(self, mock_request):
        """
        Test case for get_job

        Query for job and task-level metadata for a specified job
        """
        workflow_id = 'id'
        subworkflow_id = 'subworkflow_id'
        workflow_name = 'test'
        status = 'Succeeded'
        timestamp = '2017-11-08T05:06:41.424Z'
        response_timestamp = '2017-11-08T05:06:41.424000+00:00'
        inputs = {'test.inputs': 'gs://project-bucket/test/inputs.txt'}
        outputs = {
            'test.analysis.outputs': 'gs://project-bucket/test/outputs.txt'
        }
        labels = {'cromwell-workflow-id': 'cromwell-12345'}
        std_err = '/cromwell/cromwell-executions/id/call-analysis/stderr'
        std_out = '/cromwell/cromwell-executions/id/call-analysis/stdout'
        attempts = 1
        return_code = 0

        def _request_callback(request, context):
            context.status_code = 200
            return {
                'workflowName': workflow_name,
                'id': workflow_id,
                'status': status,
                'calls': {
                    'test.analysis': [{
                        'executionStatus': 'Done',
                        'shardIndex': -1,
                        'start': timestamp,
                        'end': timestamp,
                        'stderr': std_err,
                        'stdout': std_out,
                        'returnCode': return_code,
                        'inputs': inputs,
                        'outputs': outputs,
                        'attempt': attempts,
                        'subWorkflowId': subworkflow_id
                    }]
                },
                'inputs': inputs,
                'labels': labels,
                'outputs': outputs,
                'submission': timestamp,
                'end': timestamp,
                'start': timestamp,
                'failures': [
                    {'causedBy': [
                        {
                            'causedBy': [],
                            'message': 'Task test.analysis failed'
                        }
                    ],
                        'message': 'Workflow failed'}
                ]
            }  # yapf: disable

        cromwell_url = self.base_url + '/{id}/metadata'.format(id=workflow_id)
        mock_request.get(cromwell_url, json=_request_callback)

        response = self.client.open('/jobs/{id}'.format(id=workflow_id),
                                    method='GET')
        self.assertStatus(response, 200)
        response_data = json.loads(response.data)
        expected_data = {
            'name': workflow_name,
            'id': workflow_id,
            'status': status,
            'submission': response_timestamp,
            'start': response_timestamp,
            'end': response_timestamp,
            'inputs': jobs_controller.update_key_names(inputs),
            'outputs': jobs_controller.update_key_names(outputs),
            'labels': labels,
            'extensions':{
                'tasks': [{
                    'name': 'analysis',
                    'executionStatus': 'Succeeded',
                    'start': response_timestamp,
                    'end': response_timestamp,
                    'stderr': std_err,
                    'stdout': std_out,
                    'callCached': False,
                    'inputs': jobs_controller.update_key_names(inputs),
                    'outputs': jobs_controller.update_key_names(outputs),
                    'returnCode': return_code,
                    'attempts': attempts,
                    'jobId': subworkflow_id
                }]
            },
            'failures': [{
                'failure': 'Task test.analysis failed',
                'taskName': 'Workflow Error'
            }]
        }  # yapf: disable
        self.assertDictEqual(response_data, expected_data)