14198: Federation feature and testing
[arvados.git] / sdk / cwl / tests / federation / framework / prepare.py
1 # Copyright (C) The Arvados Authors. All rights reserved.
2 #
3 # SPDX-License-Identifier: Apache-2.0
4
5 import arvados
6 import json
7
8 api = arvados.api()
9
10 with open("config.json") as f:
11     config = json.load(f)
12
13 scrub_collections = set(config["scrub_collections"])
14
15 for cluster_id in config["arvados_cluster_ids"]:
16     images = []
17     for scrub_image in config["scrub_images"]:
18         sp = scrub_image.split(":")
19         image_name = sp[0]
20         image_tag = sp[1] if len(sp) > 1 else "latest"
21         images.append('{}:{}'.format(image_name, image_tag))
22
23     search_links = api.links().list(
24         filters=[['link_class', '=', 'docker_image_repo+tag'],
25                  ['name', 'in', images]],
26         cluster_id=cluster_id).execute()
27
28     head_uuids = [lk["head_uuid"] for lk in search_links["items"]]
29     cols = api.collections().list(filters=[["uuid", "in", head_uuids]],
30                                   cluster_id=cluster_id).execute()
31     for c in cols["items"]:
32         scrub_collections.add(c["portable_data_hash"])
33     for lk in search_links["items"]:
34         api.links().delete(uuid=lk["uuid"]).execute()
35
36
37 for cluster_id in config["arvados_cluster_ids"]:
38     matches = api.collections().list(filters=[["portable_data_hash", "in", list(scrub_collections)]],
39                                      select=["uuid", "portable_data_hash"], cluster_id=cluster_id).execute()
40     for m in matches["items"]:
41         api.collections().delete(uuid=m["uuid"]).execute()
42         print("Scrubbed %s (%s)" % (m["uuid"], m["portable_data_hash"]))