forked from EngFlow/reclient-configs
-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathcheck_reclient_works.py
executable file
·90 lines (78 loc) · 2.78 KB
/
check_reclient_works.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
#!/usr/bin/env python3
# Copyright (c) 2023 Contributors to the reclient-configs project. All rights reserved.
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.
import argparse
import subprocess
import sys
import tempfile
from configure_reclient import Paths
DOCKER_IMAGE = 'docker://docker.io/library/debian@sha256:82bab30ed448b8e2509aabe21f40f0607d905b7fd0dec72802627a20274eba55'
def main():
Paths.init_from_args(parse_args())
return check_reclient_works()
def parse_args():
parser = argparse.ArgumentParser(
formatter_class=argparse.ArgumentDefaultsHelpFormatter)
parser.add_argument(
'--src_dir',
help='Chromium src directory.',
required=True,
default=argparse.SUPPRESS,
)
parser.add_argument(
'--reclient_cfgs_dir',
help=('Path to Chromium reclient_cfgs directory.'),
default=Paths.reclient_cfgs_dir,
)
parser.add_argument(
'--reclient_dir',
help=('Path to Chromium reclient directory.'),
default=Paths.reclient_dir,
)
return parser.parse_args()
def check_reclient_works():
print('Starting reproxy')
subprocess.check_call([
f'{Paths.reclient_dir}/bootstrap',
'--cfg',
f'{Paths.reclient_cfgs_dir}/reproxy.cfg',
])
try:
with tempfile.TemporaryDirectory() as tmp_dir:
print('Remotely executing "echo hello > hello"')
subprocess.check_call([
f'{Paths.reclient_dir}/rewrapper',
'--labels=type=tool',
f'--platform=container-image={DOCKER_IMAGE},OSFamily=linux',
'--output_files=hello',
'/bin/bash', '-c', 'echo hello > hello',
], cwd=tmp_dir)
with open(f'{tmp_dir}/hello') as f:
result = f.read()
if result == 'hello\n':
print('Received expected result')
else:
print(f'Received unexpected result: "{result}"')
return 1
return 0
finally:
print('Shutting down reproxy')
subprocess.check_call([
f'{Paths.reclient_dir}/bootstrap',
'--cfg',
f'{Paths.reclient_cfgs_dir}/reproxy.cfg',
'--shutdown',
])
if __name__ == '__main__':
sys.exit(main())