blob: c6906dcc9ea92b459f9eb71834b04d3ce50f74bc [file] [log] [blame]
Fergus Dall1cf37202020-10-09 16:09:59 +11001#!/usr/bin/env python3
2# -*- coding: utf-8 -*-
Mike Frysingerdceb3e42022-09-13 05:35:25 -04003# Copyright 2020 The ChromiumOS Authors
Fergus Dall1cf37202020-10-09 16:09:59 +11004# Use of this source code is governed by a BSD-style license that can be
5# found in the LICENSE file.
6
7"""Uprev crostini tast data dependencies"""
8
9import argparse
James Yed0714022022-04-05 17:57:42 +100010import itertools
Fergus Dall1cf37202020-10-09 16:09:59 +110011import json
12import os
James Yed0714022022-04-05 17:57:42 +100013import subprocess
14import urllib.request
Fergus Dall1cf37202020-10-09 16:09:59 +110015
James Yed0714022022-04-05 17:57:42 +100016BUCKET_NAME = 'cros-containers-staging'
17ARCHES = ['amd64', 'arm64']
18CONTAINER_TYPES = ['test', 'app_test']
19RELEASES = ['buster', 'bullseye']
Fergus Dall1cf37202020-10-09 16:09:59 +110020
James Yed0714022022-04-05 17:57:42 +100021
22def update_data_file(url, filepath, size, sha256sum):
23 result = {'url': url, 'size': size, 'sha256sum': sha256sum}
Fergus Dall1cf37202020-10-09 16:09:59 +110024
25 print(f'Updated {os.path.basename(filepath)}')
26 with open(filepath, 'w') as f:
27 json.dump(result, f, indent=4, sort_keys=True)
28
29def main():
30 parser = argparse.ArgumentParser(description=__doc__)
31 parser.add_argument(
32 'milestone', help='milestone number, e.g. 78')
33 args = parser.parse_args()
34 milestone = args.milestone
35
36 tast_tests = subprocess.check_output(
37 ['repo', 'list', '-pf', 'chromiumos/platform/tast-tests']
38 ).decode().strip()
39 data_dir = os.path.join(tast_tests,
40 'src/chromiumos/tast/local/crostini/data')
41
James Yed0714022022-04-05 17:57:42 +100042 images = json.loads(urllib.request.urlopen(
43 f'https://storage.googleapis.com/{BUCKET_NAME}/{milestone}/streams/v1/images.json'
44 ).read())
Fergus Dall1cf37202020-10-09 16:09:59 +110045
James Yed0714022022-04-05 17:57:42 +100046 for arch, ctype, release in itertools.product(ARCHES, CONTAINER_TYPES, RELEASES):
Fergus Dall1cf37202020-10-09 16:09:59 +110047 # The container URLs use 'arm64', but the tast data files use 'arm'
48 if arch == 'arm64':
49 file_arch = 'arm'
50 else:
51 file_arch = arch
52
James Yed0714022022-04-05 17:57:42 +100053 product = images['products'][f'debian:{release}:{arch}:{ctype}']
54 latest_container = max(product['versions'].keys())
55 items = product['versions'][latest_container]['items']
Fergus Dall1cf37202020-10-09 16:09:59 +110056
James Yed0714022022-04-05 17:57:42 +100057 base_url = f'gs://{BUCKET_NAME}/{milestone}/'
Fergus Dall1cf37202020-10-09 16:09:59 +110058
James Yed0714022022-04-05 17:57:42 +100059 metadata_item = items['lxd.tar.xz']
60 metadata_file = f'crostini_{ctype}_container_metadata_{release}_{file_arch}.tar.xz.external'
61 update_data_file(
62 base_url + metadata_item['path'],
63 os.path.join(data_dir, metadata_file),
64 metadata_item['size'],
65 metadata_item['sha256'],
66 )
67
68 rootfs_item = items['rootfs.squashfs']
69 rootfs_file = f'crostini_{ctype}_container_rootfs_{release}_{file_arch}.squashfs.external'
70 update_data_file(
71 base_url + rootfs_item['path'],
72 os.path.join(data_dir, rootfs_file),
73 rootfs_item['size'],
74 rootfs_item['sha256'],
75 )
Fergus Dall1cf37202020-10-09 16:09:59 +110076
Fergus Dall1cf37202020-10-09 16:09:59 +110077 print('Tast data dependencies updated')
78 print(f'Go to {data_dir} and create a CL')
79
80if __name__ == '__main__':
81 main()