Skip to content

Commit 9ae3528

Browse files
author
Peter Amstutz
committed
Improve integration tests, fix some py3 errors.
1 parent b6c0c17 commit 9ae3528

File tree

8 files changed

+44
-18
lines changed

8 files changed

+44
-18
lines changed

setup.py

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@
1111
long_description = readmeFile.read()
1212

1313
setup(name='wes-service',
14-
version='2.9',
14+
version='3.0',
1515
description='GA4GH Workflow Execution Service reference implementation',
1616
long_description=long_description,
1717
author='GA4GH Containers and Workflows task team',
@@ -25,9 +25,9 @@
2525
install_requires=[
2626
'future',
2727
'connexion==1.4.2',
28-
'ruamel.yaml >= 0.12.4, < 0.15',
28+
'ruamel.yaml >= 0.12.4, <= 0.15.77',
2929
'cwlref-runner==1.0',
30-
'schema-salad>=2.6, <3',
30+
'schema-salad >= 3.0, < 3.1',
3131
'subprocess32==3.5.2'
3232
],
3333
entry_points={

test/test_integration.py

Lines changed: 27 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,7 @@ class IntegrationTest(unittest.TestCase):
2323
def setUpClass(cls):
2424
# cwl
2525
cls.cwl_dockstore_url = 'https://dockstore.org:8443/api/ga4gh/v2/tools/quay.io%2Fbriandoconnor%2Fdockstore-tool-md5sum/versions/master/plain-CWL/descriptor/%2FDockstore.cwl'
26-
cls.cwl_local_path = os.path.abspath('testdata/md5sum.cwl')
26+
cls.cwl_local_path = "file://" + os.path.abspath('testdata/md5sum.cwl')
2727
cls.cwl_json_input = "file://" + os.path.abspath('testdata/md5sum.json')
2828
cls.cwl_attachments = ['file://' + os.path.abspath('testdata/md5sum.input'),
2929
'file://' + os.path.abspath('testdata/dockstore-tool-md5sum.cwl')]
@@ -52,22 +52,24 @@ def tearDown(self):
5252
time.sleep(3)
5353
except OSError as e:
5454
print(e)
55-
if os.path.exists('workflows'):
56-
shutil.rmtree('workflows')
5755
unittest.TestCase.tearDown(self)
5856

5957
def test_dockstore_md5sum(self):
6058
"""HTTP md5sum cwl (dockstore), run it on the wes-service server, and check for the correct output."""
61-
outfile_path, _ = self.run_md5sum(wf_input=self.cwl_dockstore_url,
59+
outfile_path, run_id = self.run_md5sum(wf_input=self.cwl_dockstore_url,
6260
json_input=self.cwl_json_input,
6361
workflow_attachment=self.cwl_attachments)
62+
state = self.wait_for_finish(run_id)
63+
assert state == "COMPLETE"
6464
self.assertTrue(check_for_file(outfile_path), 'Output file was not found: ' + str(outfile_path))
6565

6666
def test_local_md5sum(self):
6767
"""LOCAL md5sum cwl to the wes-service server, and check for the correct output."""
6868
outfile_path, run_id = self.run_md5sum(wf_input=self.cwl_local_path,
6969
json_input=self.cwl_json_input,
7070
workflow_attachment=self.cwl_attachments)
71+
state = self.wait_for_finish(run_id)
72+
assert state == "COMPLETE"
7173
self.assertTrue(check_for_file(outfile_path), 'Output file was not found: ' + str(outfile_path))
7274

7375
def test_run_attachments(self):
@@ -76,6 +78,8 @@ def test_run_attachments(self):
7678
json_input=self.cwl_json_input,
7779
workflow_attachment=self.cwl_attachments)
7880
get_response = self.client.get_run_log(run_id)["request"]
81+
state = self.wait_for_finish(run_id)
82+
assert state == "COMPLETE"
7983
self.assertTrue(check_for_file(outfile_path), 'Output file was not found: ' + get_response["workflow_attachment"])
8084
attachment_tool_path = get_response["workflow_attachment"][7:] + "/dockstore-tool-md5sum.cwl"
8185
self.assertTrue(check_for_file(attachment_tool_path), 'Attachment file was not found: ' + get_response["workflow_attachment"])
@@ -90,7 +94,7 @@ def test_get_service_info(self):
9094
assert 'workflow_type_versions' in r
9195
assert 'supported_wes_versions' in r
9296
assert 'supported_filesystem_protocols' in r
93-
assert 'engine_versions' in r
97+
assert 'workflow_engine_versions' in r
9498

9599
def test_list_runs(self):
96100
"""
@@ -121,6 +125,18 @@ def run_md5sum(self, wf_input, json_input, workflow_attachment=None):
121125
output_dir = os.path.abspath(os.path.join('workflows', response['run_id'], 'outdir'))
122126
return os.path.join(output_dir, 'md5sum.txt'), response['run_id']
123127

128+
def wait_for_finish(self, run_id, seconds=120):
129+
"""Return True if a file exists within a certain amount of time."""
130+
wait_counter = 0
131+
r = self.client.get_run_status(run_id)
132+
while r["state"] in ("QUEUED", "INITIALIZING", "RUNNING"):
133+
time.sleep(1)
134+
wait_counter += 1
135+
if wait_counter > seconds:
136+
return None
137+
r = self.client.get_run_status(run_id)
138+
return r["state"]
139+
124140

125141
def get_server_pids():
126142
try:
@@ -149,9 +165,13 @@ def setUp(self):
149165
Start a (local) wes-service server to make requests against.
150166
Use cwltool as the wes-service server 'backend'.
151167
"""
168+
if os.path.exists('workflows'):
169+
shutil.rmtree('workflows')
152170
self.wes_server_process = subprocess.Popen(
153-
'python {}'.format(os.path.abspath('wes_service/wes_service_main.py')),
154-
shell=True)
171+
['python', os.path.abspath('wes_service/wes_service_main.py'),
172+
'--backend=wes_service.cwl_runner',
173+
'--port=8080',
174+
'--debug'])
155175
time.sleep(5)
156176

157177

testdata/md5sum.json

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,2 +1 @@
1-
{"output_file": {"path": "/tmp/md5sum.txt", "class": "File"},
2-
"input_file": {"path": "md5sum.input", "class": "File"}}
1+
{"input_file": {"path": "md5sum.input", "class": "File"}}

wes_client/util.py

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -107,7 +107,9 @@ def build_wes_request(workflow_file, json_path, attachments=None):
107107
:return: A list of tuples formatted to be sent in a post to the wes-server (Swagger API).
108108
"""
109109
workflow_file = "file://" + workflow_file if ":" not in workflow_file else workflow_file
110+
wfbase = None
110111
if json_path.startswith("file://"):
112+
wfbase = os.path.dirname(json_path[7:])
111113
json_path = json_path[7:]
112114
with open(json_path) as f:
113115
wf_params = json.dumps(json.load(f))
@@ -122,17 +124,21 @@ def build_wes_request(workflow_file, json_path, attachments=None):
122124
("workflow_type_version", wf_version)]
123125

124126
if workflow_file.startswith("file://"):
127+
if wfbase is None:
128+
wfbase = os.path.dirname(workflow_file[7:])
125129
parts.append(("workflow_attachment", (os.path.basename(workflow_file[7:]), open(workflow_file[7:], "rb"))))
126130
parts.append(("workflow_url", os.path.basename(workflow_file[7:])))
127131
else:
128132
parts.append(("workflow_url", workflow_file))
129133

134+
if wfbase is None:
135+
wfbase = os.getcwd()
130136
if attachments:
131137
for attachment in attachments:
132138
if attachment.startswith("file://"):
133139
attachment = attachment[7:]
134140
attach_f = open(attachment, "rb")
135-
relpath = os.path.relpath(attachment, os.getcwd())
141+
relpath = os.path.relpath(attachment, wfbase)
136142
elif attachment.startswith("http"):
137143
attach_f = urlopen(attachment)
138144
relpath = os.path.basename(attach_f)

wes_service/arvados_wes.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -75,7 +75,7 @@ def GetServiceInfo(self):
7575
"supported_wes_versions": ["0.3.0", "1.0.0"],
7676
"supported_filesystem_protocols": ["http", "https", "keep"],
7777
"workflow_engine_versions": {
78-
"arvados-cwl-runner": stderr
78+
"arvados-cwl-runner": str(stderr)
7979
},
8080
"default_workflow_engine_parameters": [],
8181
"system_state_counts": {},

wes_service/cwl_runner.py

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -162,18 +162,19 @@ class CWLRunnerBackend(WESBackend):
162162
def GetServiceInfo(self):
163163
runner = self.getopt("runner", default="cwl-runner")
164164
stdout, stderr = subprocess.Popen([runner, "--version"], stderr=subprocess.PIPE).communicate()
165-
return {
165+
r = {
166166
"workflow_type_versions": {
167167
"CWL": {"workflow_type_version": ["v1.0"]}
168168
},
169169
"supported_wes_versions": ["0.3.0", "1.0.0"],
170170
"supported_filesystem_protocols": ["file", "http", "https"],
171171
"workflow_engine_versions": {
172-
"cwl-runner": stderr
172+
"cwl-runner": str(stderr)
173173
},
174174
"system_state_counts": {},
175175
"tags": {}
176176
}
177+
return r
177178

178179
def ListRuns(self, page_size=None, page_token=None, state_search=None):
179180
# FIXME #15 results don't page

wes_service/toil_wes.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -291,7 +291,7 @@ def GetServiceInfo(self):
291291
},
292292
'supported_wes_versions': ['0.3.0', '1.0.0'],
293293
'supported_filesystem_protocols': ['file', 'http', 'https'],
294-
'engine_versions': ['3.16.0'],
294+
'workflow_engine_versions': ['3.16.0'],
295295
'system_state_counts': {},
296296
'key_values': {}
297297
}

wes_service/util.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -65,7 +65,7 @@ def collect_attachments(self, run_id=None):
6565
body[k] = "file://%s" % tempdir # Reference to temp working dir.
6666
elif k in ("workflow_params", "tags", "workflow_engine_parameters"):
6767
content = v.read()
68-
body[k] = json.loads(content)
68+
body[k] = json.loads(content.decode("utf-8"))
6969
else:
7070
body[k] = v.read().decode()
7171

0 commit comments

Comments
 (0)