21204: Merge branch '21204-stable-log-sort' from arvados-workbench2.git
[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 from __future__ import print_function
6 import arvados
7 import json
8
9 api = arvados.api()
10
11 with open("config.json") as f:
12     config = json.load(f)
13
14 scrub_collections = set(config["scrub_collections"])
15
16 for cluster_id in config["arvados_cluster_ids"]:
17     images = []
18     for scrub_image in config["scrub_images"]:
19         sp = scrub_image.split(":")
20         image_name = sp[0]
21         image_tag = sp[1] if len(sp) > 1 else "latest"
22         images.append('{}:{}'.format(image_name, image_tag))
23
24     search_links = api.links().list(
25         filters=[['link_class', '=', 'docker_image_repo+tag'],
26                  ['name', 'in', images]],
27         cluster_id=cluster_id).execute()
28
29     head_uuids = [lk["head_uuid"] for lk in search_links["items"]]
30     cols = api.collections().list(filters=[["uuid", "in", head_uuids]],
31                                   cluster_id=cluster_id).execute()
32     for c in cols["items"]:
33         scrub_collections.add(c["portable_data_hash"])
34     for lk in search_links["items"]:
35         api.links().delete(uuid=lk["uuid"]).execute()
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"]))