1 # Copyright (C) The Arvados Authors. All rights reserved.
3 # SPDX-License-Identifier: Apache-2.0
6 import arvados.collection
12 workflow_content = """{
15 "baseCommand": "echo",
16 "class": "CommandLineTool",
20 "class": "http://arvados.org/cwl#WorkflowRunnerResources"
29 "location": "keep:d7514270f356df848477718d58308cc4+94/b",
34 "id": "#main/message",
47 def check_workflow_content(uuid):
48 c = arvados.collection.Collection(uuid)
50 j = json.load(c.open("workflow.json"))
53 # The value of "acrContainerImage" is tied to the specific version
54 # of arvados-cwl-runner so we can't just compare PDH of the whole
55 # workflow collection, it changes with every version.
56 del j["$graph"][0]["hints"][0]["acrContainerImage"]
58 return json.dumps(j, sort_keys=True, indent=4, separators=(',',': ')) == workflow_content
60 def check_contents(group, wf_uuid):
61 contents = api.groups().contents(uuid=group["uuid"]).execute()
62 if len(contents["items"]) != 4:
63 raise Exception("Expected 4 items in "+group["uuid"]+" was "+str(len(contents["items"])))
66 for c in contents["items"]:
67 if c["kind"] == "arvados#workflow" and c["uuid"] == wf_uuid:
70 raise Exception("Couldn't find workflow in "+group["uuid"])
73 for c in contents["items"]:
74 if c["kind"] == "arvados#collection" and c["portable_data_hash"] == "d7514270f356df848477718d58308cc4+94":
77 raise Exception("Couldn't find collection dependency")
80 for c in contents["items"]:
81 if c["kind"] == "arvados#collection" and c["name"].startswith("Docker image arvados jobs"):
84 raise Exception("Couldn't find jobs image dependency")
87 for c in contents["items"]:
88 if c["kind"] == "arvados#collection" and check_workflow_content(c["portable_data_hash"]):
91 raise Exception("Couldn't find collection containing expected workflow.json")
95 group = api.groups().create(body={"group": {"name": "test-19070-project-1", "group_class": "project"}}, ensure_unique_name=True).execute()
97 contents = api.groups().contents(uuid=group["uuid"]).execute()
98 if len(contents["items"]) != 0:
99 raise Exception("Expected 0 items")
101 # Create workflow, by default should also copy dependencies
102 cmd = ["arvados-cwl-runner", "--disable-git", "--create-workflow", "--project-uuid", group["uuid"], "19070-copy-deps.cwl"]
104 wf_uuid = subprocess.check_output(cmd)
105 wf_uuid = wf_uuid.decode("utf-8").strip()
106 check_contents(group, wf_uuid)
108 api.groups().delete(uuid=group["uuid"]).execute()
112 group = api.groups().create(body={"group": {"name": "test-19070-project-2", "group_class": "project"}}, ensure_unique_name=True).execute()
114 contents = api.groups().contents(uuid=group["uuid"]).execute()
115 if len(contents["items"]) != 0:
116 raise Exception("Expected 0 items")
118 # Create workflow, but with --no-copy-deps it shouldn't copy anything
119 cmd = ["arvados-cwl-runner", "--disable-git", "--no-copy-deps", "--create-workflow", "--project-uuid", group["uuid"], "19070-copy-deps.cwl"]
121 wf_uuid = subprocess.check_output(cmd)
122 wf_uuid = wf_uuid.decode("utf-8").strip()
124 contents = api.groups().contents(uuid=group["uuid"]).execute()
125 if len(contents["items"]) != 2:
126 raise Exception("Expected 2 items")
129 for c in contents["items"]:
130 if c["kind"] == "arvados#workflow" and c["uuid"] == wf_uuid:
133 raise Exception("Couldn't find workflow")
136 for c in contents["items"]:
137 if c["kind"] == "arvados#collection" and check_workflow_content(c["portable_data_hash"]):
140 raise Exception("Couldn't find collection containing expected workflow.json")
142 # Updating by default will copy missing items
143 cmd = ["arvados-cwl-runner", "--disable-git", "--update-workflow", wf_uuid, "19070-copy-deps.cwl"]
145 wf_uuid = subprocess.check_output(cmd)
146 wf_uuid = wf_uuid.decode("utf-8").strip()
147 check_contents(group, wf_uuid)
150 api.groups().delete(uuid=group["uuid"]).execute()
154 group = api.groups().create(body={"group": {"name": "test-19070-project-3", "group_class": "project"}}, ensure_unique_name=True).execute()
156 contents = api.groups().contents(uuid=group["uuid"]).execute()
157 if len(contents["items"]) != 0:
158 raise Exception("Expected 0 items")
160 # Execute workflow, shouldn't copy anything.
161 cmd = ["arvados-cwl-runner", "--disable-git", "--project-uuid", group["uuid"], "19070-copy-deps.cwl"]
163 wf_uuid = subprocess.check_output(cmd)
164 wf_uuid = wf_uuid.decode("utf-8").strip()
166 contents = api.groups().contents(uuid=group["uuid"]).execute()
168 # final output collection
170 # step output collection
171 # container request log
172 if len(contents["items"]) != 5:
173 raise Exception("Expected 5 items")
176 for c in contents["items"]:
177 if c["kind"] == "arvados#collection" and c["portable_data_hash"] == "d7514270f356df848477718d58308cc4+94":
180 raise Exception("Didn't expect to find collection dependency")
183 for c in contents["items"]:
184 if c["kind"] == "arvados#collection" and c["name"].startswith("Docker image arvados jobs"):
187 raise Exception("Didn't expect to find jobs image dependency")
189 # Execute workflow with --copy-deps
190 cmd = ["arvados-cwl-runner", "--disable-git", "--project-uuid", group["uuid"], "--copy-deps", "19070-copy-deps.cwl"]
192 wf_uuid = subprocess.check_output(cmd)
193 wf_uuid = wf_uuid.decode("utf-8").strip()
195 contents = api.groups().contents(uuid=group["uuid"]).execute()
197 for c in contents["items"]:
198 if c["kind"] == "arvados#collection" and c["portable_data_hash"] == "d7514270f356df848477718d58308cc4+94":
201 raise Exception("Couldn't find collection dependency")
204 for c in contents["items"]:
205 if c["kind"] == "arvados#collection" and c["name"].startswith("Docker image arvados jobs"):
208 raise Exception("Couldn't find jobs image dependency")
211 api.groups().delete(uuid=group["uuid"]).execute()
213 if __name__ == '__main__':