blob: e7268bc2d05eef2b4ae60329de165bac0a63c5be [file] [log] [blame]
Fergus Dall1cf37202020-10-09 16:09:59 +11001#!/usr/bin/env python3
2# -*- coding: utf-8 -*-
3# Copyright 2020 The Chromium OS Authors. All rights reserved.
4# 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
10import subprocess
11import shlex
12import json
13import os
14
15def update_data_file(url, filepath):
16 result = {'url': url}
17 ls = subprocess.check_output(['gsutil.py', 'ls', '-l', url])
18 result['size'] = int(ls.decode().split()[0])
19
20 sha256sum = subprocess.check_output(
21 f'gsutil.py cp {shlex.quote(url)} - | sha256sum'
22 , shell=True)
23 result['sha256sum'] = sha256sum.decode().split()[0]
24
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
42 latest_container = subprocess.check_output(
43 ['gsutil.py', 'ls', f'gs://cros-containers-staging/{milestone}'
44 '/images/debian/buster/arm64/default/']
45 ).decode().split()[-1].split('/')[-2]
Fergus Dall1cf37202020-10-09 16:09:59 +110046
47 for arch in ['amd64', 'arm64']:
48 # The container URLs use 'arm64', but the tast data files use 'arm'
49 if arch == 'arm64':
50 file_arch = 'arm'
51 else:
52 file_arch = arch
53
54 for ctype in ['test', 'app_test']:
Fergus Dall97e01202021-09-27 08:57:08 +100055 for release in ['buster', 'bullseye']:
Fergus Dall1cf37202020-10-09 16:09:59 +110056 base_url = f'gs://cros-containers-staging/{milestone}' \
57 f'/images/debian/{release}/{arch}/{ctype}/{latest_container}/'
58
59 metadata_file = f'crostini_{ctype}_container_metadata_{release}' \
60 f'_{file_arch}.tar.xz.external'
61 update_data_file(base_url + 'lxd.tar.xz',
62 os.path.join(data_dir, metadata_file))
63
64 rootfs_file = f'crostini_{ctype}_container_rootfs_{release}' \
65 f'_{file_arch}.tar.xz.external'
66 update_data_file(base_url + 'rootfs.tar.xz',
67 os.path.join(data_dir, rootfs_file))
68
Fergus Dall1cf37202020-10-09 16:09:59 +110069 print('Tast data dependencies updated')
70 print(f'Go to {data_dir} and create a CL')
71
72if __name__ == '__main__':
73 main()