Skip to content

Commit 2982869

Browse files
Merge pull request #49 from achave11/tests-fixes
Tests fixes for #48, includes #48 changes and fixes for #48
2 parents 585e878 + 56c8582 commit 2982869

File tree

7 files changed

+42
-37
lines changed

7 files changed

+42
-37
lines changed

test/test_integration.py

Lines changed: 27 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,7 @@
1515

1616
class IntegrationTest(unittest.TestCase):
1717
"""A baseclass that's inherited for use with different cwl backends."""
18+
1819
def setUp(self):
1920
"""Start a (local) wes-service server to make requests against."""
2021
raise NotImplementedError
@@ -43,31 +44,53 @@ def test_dockstore_md5sum(self):
4344
def test_local_md5sum(self):
4445
"""Pass a local md5sum cwl to the wes-service server, and check for the correct output."""
4546
cwl_local_path = os.path.abspath('testdata/md5sum.cwl')
46-
output_filepath, _ = run_cwl_md5sum(cwl_input='file://' + cwl_local_path)
47+
workflow_attachment_path = os.path.abspath('testdata/dockstore-tool-md5sum.cwl')
48+
output_filepath, _ = run_cwl_md5sum(cwl_input='file://' + cwl_local_path,
49+
workflow_attachment='file://' + workflow_attachment_path)
4750

4851
self.assertTrue(check_for_file(output_filepath), 'Output file was not found: ' + str(output_filepath))
4952

5053
def test_multipart_upload(self):
5154
"""Pass a local md5sum cwl to the wes-service server, and check for uploaded file in service."""
5255
cwl_local_path = os.path.abspath('testdata/md5sum.cwl')
53-
_, run_id = run_cwl_md5sum(cwl_input='file://' + cwl_local_path)
56+
workflow_attachment_path = os.path.abspath('testdata/dockstore-tool-md5sum.cwl')
57+
out_file_path, run_id = run_cwl_md5sum(cwl_input='file://' + cwl_local_path,
58+
workflow_attachment='file://' + workflow_attachment_path)
5459

5560
get_response = get_log_request(run_id)["request"]
5661

62+
self.assertTrue(check_for_file(out_file_path), 'Output file was not found: '
63+
+ get_response["workflow_attachment"])
5764
self.assertTrue(check_for_file(get_response["workflow_url"][7:]), 'Output file was not found: '
5865
+ get_response["workflow_url"][:7])
5966

67+
def test_run_attachments(self):
68+
"""Pass a local md5sum cwl to the wes-service server, check for attachments."""
69+
cwl_local_path = os.path.abspath('testdata/md5sum.cwl')
70+
workflow_attachment_path = os.path.abspath('testdata/dockstore-tool-md5sum.cwl')
71+
out_file_path, run_id = run_cwl_md5sum(cwl_input='file://' + cwl_local_path,
72+
workflow_attachment='file://' + workflow_attachment_path)
73+
74+
get_response = get_log_request(run_id)["request"]
75+
attachment_tool_path = get_response["workflow_attachment"][7:] + "/dockstore-tool-md5sum.cwl"
76+
self.assertTrue(check_for_file(out_file_path), 'Output file was not found: '
77+
+ get_response["workflow_attachment"])
78+
self.assertTrue(check_for_file(attachment_tool_path), 'Attachment file was not found: '
79+
+ get_response["workflow_attachment"])
80+
6081

61-
def run_cwl_md5sum(cwl_input):
82+
def run_cwl_md5sum(cwl_input, workflow_attachment=None):
6283
"""Pass a local md5sum cwl to the wes-service server, and return the path of the output file that was created."""
6384
endpoint = 'http://localhost:8080/ga4gh/wes/v1/runs'
6485
params = {'output_file': {'path': '/tmp/md5sum.txt', 'class': 'File'},
6586
'input_file': {'path': os.path.abspath('testdata/md5sum.input'), 'class': 'File'}}
6687

6788
parts = [("workflow_params", json.dumps(params)), ("workflow_type", "CWL"), ("workflow_type_version", "v1.0")]
6889
if cwl_input.startswith("file://"):
69-
parts.append(("workflow_descriptor", ("md5sum.cwl", open(cwl_input[7:], "rb"))))
90+
parts.append(("workflow_attachment", ("md5sum.cwl", open(cwl_input[7:], "rb"))))
7091
parts.append(("workflow_url", os.path.basename(cwl_input[7:])))
92+
if workflow_attachment:
93+
parts.append(("workflow_attachment", ("dockstore-tool-md5sum.cwl", open(workflow_attachment[7:], "rb"))))
7194
else:
7295
parts.append(("workflow_url", cwl_input))
7396
response = requests.post(endpoint, files=parts).json()

testdata/md5sum.cwl

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -11,8 +11,7 @@ outputs:
1111

1212
steps:
1313
md5sum:
14-
run: https://raw.githubusercontent.com/common-workflow-language/workflow-service/master/testdata/dockstore-tool-md5sum.cwl
14+
run: dockstore-tool-md5sum.cwl
1515
in:
1616
input_file: input_file
1717
out: [output_file]
18-

wes_client/wes_client_main.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -128,7 +128,7 @@ def fixpaths(d):
128128
]
129129
if workflow_url.startswith("file://"):
130130
# with open(workflow_url[7:], "rb") as f:
131-
# body["workflow_descriptor"] = f.read()
131+
# body["workflow_attachment"] = f.read()
132132
rootdir = os.path.dirname(workflow_url[7:])
133133
dirpath = rootdir
134134
# for dirpath, dirnames, filenames in os.walk(rootdir):
@@ -137,7 +137,7 @@ def fixpaths(d):
137137
continue
138138
fn = os.path.join(dirpath, f)
139139
if os.path.isfile(fn):
140-
parts.append(('workflow_descriptor', (fn[len(rootdir)+1:], open(fn, "rb"))))
140+
parts.append(('workflow_attachment', (fn[len(rootdir)+1:], open(fn, "rb"))))
141141
parts.append(("workflow_url", os.path.basename(workflow_url[7:])))
142142
else:
143143
parts.append(("workflow_url", workflow_url))

wes_service/arvados_wes.py

Lines changed: 1 addition & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -109,7 +109,7 @@ def ListRuns(self, page_size=None, page_token=None, state_search=None):
109109
}
110110

111111
def invoke_cwl_runner(self, cr_uuid, workflow_url, workflow_params,
112-
env, workflow_descriptor_file, project_uuid,
112+
env, project_uuid,
113113
tempdir):
114114
api = arvados.api_from_config(version="v1", apiconfig={
115115
"ARVADOS_API_HOST": env["ARVADOS_API_HOST"],
@@ -150,9 +150,6 @@ def invoke_cwl_runner(self, cr_uuid, workflow_url, workflow_params,
150150
except subprocess.CalledProcessError as e:
151151
api.container_requests().update(uuid=cr_uuid, body={"priority": 0,
152152
"properties": {"arvados-cwl-runner-log": str(e)}}).execute()
153-
finally:
154-
if workflow_descriptor_file is not None:
155-
workflow_descriptor_file.close()
156153

157154
@catch_exceptions
158155
def RunWorkflow(self, **args):
@@ -184,20 +181,13 @@ def RunWorkflow(self, **args):
184181
"priority": 500}}).execute()
185182

186183
workflow_url = body.get("workflow_url")
187-
workflow_descriptor_file = None
188-
if body.get("workflow_descriptor"):
189-
workflow_descriptor_file = tempfile.NamedTemporaryFile()
190-
workflow_descriptor_file.write(body.get('workflow_descriptor'))
191-
workflow_descriptor_file.flush()
192-
workflow_url = workflow_descriptor_file.name
193184

194185
project_uuid = body.get("workflow_engine_parameters", {}).get("project_uuid")
195186

196187
threading.Thread(target=self.invoke_cwl_runner, args=(cr["uuid"],
197188
workflow_url,
198189
body["workflow_params"],
199190
env,
200-
workflow_descriptor_file,
201191
project_uuid,
202192
tempdir)).start()
203193

wes_service/cwl_runner.py

Lines changed: 2 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,6 @@
22
import json
33
import os
44
import subprocess
5-
import urllib
65
import uuid
76

87
from wes_service.util import WESBackend
@@ -25,7 +24,7 @@ def run(self, request, opts):
2524
CWL (url):
2625
request["workflow_url"] == a url to a cwl file
2726
or
28-
request["workflow_descriptor"] == input cwl text (written to a file and a url constructed for that file)
27+
request["workflow_attachment"] == input cwl text (written to a file and a url constructed for that file)
2928
3029
JSON File:
3130
request["workflow_params"] == input json text (to be written to a file)
@@ -46,13 +45,7 @@ def run(self, request, opts):
4645
self.workdir, "cwl.input.json"), "w") as inputtemp:
4746
json.dump(request["workflow_params"], inputtemp)
4847

49-
if request.get("workflow_descriptor"):
50-
workflow_descriptor = request.get('workflow_descriptor')
51-
with open(os.path.join(self.workdir, "workflow.cwl"), "w") as f:
52-
f.write(workflow_descriptor)
53-
workflow_url = urllib.pathname2url(os.path.join(self.workdir, "workflow.cwl"))
54-
else:
55-
workflow_url = request.get("workflow_url")
48+
workflow_url = request.get("workflow_url") # Will always be local path to descriptor cwl, or url.
5649

5750
output = open(os.path.join(self.workdir, "cwl.output.json"), "w")
5851
stderr = open(os.path.join(self.workdir, "stderr"), "w")

wes_service/toil_wes.py

Lines changed: 7 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,6 @@
44
import subprocess
55
import time
66
import logging
7-
import urllib
87
import uuid
98

109
from multiprocessing import Process
@@ -38,13 +37,13 @@ def write_workflow(self, request, opts, wftype='cwl'):
3837
"""Writes a cwl, wdl, or python file as appropriate from the request dictionary."""
3938
self.input_wf_filename = os.path.join(self.workdir, 'workflow.' + wftype)
4039

41-
if request.get("workflow_descriptor"):
42-
workflow_descriptor = request.get('workflow_descriptor')
40+
if request.get("workflow_attachment"):
41+
workflow_attachment = request.get('workflow_attachment')
4342
with open(self.input_wf_filename, "w") as f:
44-
f.write(workflow_descriptor)
45-
workflow_url = urllib.pathname2url(self.input_wf_filename)
46-
else:
47-
workflow_url = request.get("workflow_url")
43+
f.write(workflow_attachment)
44+
# workflow_url = urllib.pathname2url(self.input_wf_filename)
45+
46+
workflow_url = request.get("workflow_url")
4847

4948
extra = opts.getoptlist("extra")
5049
if wftype == 'cwl':
@@ -147,7 +146,7 @@ def run(self, request, opts):
147146
CWL (url):
148147
request["workflow_url"] == a url to a cwl file
149148
or
150-
request["workflow_descriptor"] == input cwl text (written to a file and a url constructed for that file)
149+
request["workflow_attachment"] == input cwl text (written to a file and a url constructed for that file)
151150
152151
JSON File:
153152
request["workflow_params"] == input json text (to be written to a file)

wes_service/util.py

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -47,9 +47,10 @@ def collect_attachments(self):
4747
body = {}
4848
for k, ls in connexion.request.files.iterlists():
4949
for v in ls:
50-
if k == "workflow_descriptor":
50+
if k == "workflow_attachment":
5151
filename = secure_filename(v.filename)
5252
v.save(os.path.join(tempdir, filename))
53+
body[k] = "file://%s" % os.path.join(tempdir) # Reference to tem working dir.
5354
elif k in ("workflow_params", "tags", "workflow_engine_parameters"):
5455
body[k] = json.loads(v.read())
5556
else:

0 commit comments

Comments
 (0)