Skip to content

Commit 31aeef2

Browse files
authored
Rollup merge of #111154 - djkoloski:use_builtin_ffx_isolation, r=tmandry
Use builtin FFX isolation for Fuchsia test runner FFX has new builtin support for isolating the daemon's environment. This switches the manual isolation originally written to that new builtin feature. r? ````@tmandry````
2 parents 48c7824 + e973836 commit 31aeef2

File tree

1 file changed

+45
-92
lines changed

1 file changed

+45
-92
lines changed

src/ci/docker/scripts/fuchsia-test-runner.py

+45-92
Original file line numberDiff line numberDiff line change
@@ -168,85 +168,17 @@ def ffx_daemon_log_path(self):
168168
def ffx_isolate_dir(self):
169169
return os.path.join(self.tmp_dir(), "ffx_isolate")
170170

171-
def ffx_home_dir(self):
172-
return os.path.join(self.ffx_isolate_dir(), "user-home")
171+
def home_dir(self):
172+
return os.path.join(self.tmp_dir(), "user-home")
173173

174-
def ffx_tmp_dir(self):
175-
return os.path.join(self.ffx_isolate_dir(), "tmp")
176-
177-
def ffx_log_dir(self):
178-
return os.path.join(self.ffx_isolate_dir(), "log")
179-
180-
def ffx_user_config_dir(self):
181-
return os.path.join(self.ffx_xdg_config_home(), "Fuchsia", "ffx", "config")
182-
183-
def ffx_user_config_path(self):
184-
return os.path.join(self.ffx_user_config_dir(), "config.json")
185-
186-
def ffx_xdg_config_home(self):
187-
if platform.system() == "Darwin":
188-
return os.path.join(self.ffx_home_dir(), "Library", "Preferences")
189-
return os.path.join(self.ffx_home_dir(), ".local", "share")
190-
191-
def ffx_ascendd_path(self):
192-
return os.path.join(self.ffx_tmp_dir(), "ascendd")
193174

194175
def start_ffx_isolation(self):
195176
# Most of this is translated directly from ffx's isolate library
196177
os.mkdir(self.ffx_isolate_dir())
197-
os.mkdir(self.ffx_home_dir())
198-
os.mkdir(self.ffx_tmp_dir())
199-
os.mkdir(self.ffx_log_dir())
200-
201-
fuchsia_dir = os.path.join(self.ffx_home_dir(), ".fuchsia")
202-
os.mkdir(fuchsia_dir)
203-
204-
fuchsia_debug_dir = os.path.join(fuchsia_dir, "debug")
205-
os.mkdir(fuchsia_debug_dir)
206-
207-
metrics_dir = os.path.join(fuchsia_dir, "metrics")
208-
os.mkdir(metrics_dir)
178+
os.mkdir(self.home_dir())
209179

210-
analytics_path = os.path.join(metrics_dir, "analytics-status")
211-
with open(analytics_path, "w", encoding="utf-8") as analytics_file:
212-
print("0", file=analytics_file)
213-
214-
ffx_path = os.path.join(metrics_dir, "ffx")
215-
with open(ffx_path, "w", encoding="utf-8") as ffx_file:
216-
print("1", file=ffx_file)
217-
218-
os.makedirs(self.ffx_user_config_dir())
219-
220-
with open(
221-
self.ffx_user_config_path(), "w", encoding="utf-8"
222-
) as config_json_file:
223-
user_config_for_test = {
224-
"log": {
225-
"enabled": True,
226-
"dir": self.ffx_log_dir(),
227-
},
228-
"overnet": {
229-
"socket": self.ffx_ascendd_path(),
230-
},
231-
"ssh": {
232-
"pub": self.ssh_authfile_path(),
233-
"priv": self.ssh_keyfile_path(),
234-
},
235-
"test": {
236-
"is_isolated": True,
237-
"experimental_structured_output": True,
238-
},
239-
}
240-
print(json.dumps(user_config_for_test), file=config_json_file)
241-
242-
ffx_env_path = os.path.join(self.ffx_user_config_dir(), ".ffx_env")
243-
with open(ffx_env_path, "w", encoding="utf-8") as ffx_env_file:
244-
ffx_env_config_for_test = {
245-
"user": self.ffx_user_config_path(),
246-
"build": None,
247-
"global": None,
248-
}
249-
print(json.dumps(ffx_env_config_for_test), file=ffx_env_file)
180+
ffx_path = self.tool_path("ffx")
181+
ffx_env = self.ffx_cmd_env()
250182

251183
# Start ffx daemon
252184
# We want this to be a long-running process that persists after the script finishes
@@ -256,38 +188,65 @@ def start_ffx_isolation(self):
256188
) as ffx_daemon_log_file:
257189
subprocess.Popen(
258190
[
259-
self.tool_path("ffx"),
260-
"--config",
261-
self.ffx_user_config_path(),
191+
ffx_path,
262192
"daemon",
263193
"start",
264194
],
265-
env=self.ffx_cmd_env(),
195+
env=ffx_env,
266196
stdout=ffx_daemon_log_file,
267197
stderr=ffx_daemon_log_file,
268198
)
269199

200+
# Disable analytics
201+
subprocess.check_call(
202+
[
203+
ffx_path,
204+
"config",
205+
"analytics",
206+
"disable",
207+
],
208+
env=ffx_env,
209+
stdout=self.subprocess_output(),
210+
stderr=self.subprocess_output(),
211+
)
212+
213+
# Set configs
214+
configs = {
215+
"log.enabled": "true",
216+
"ssh.pub": self.ssh_authfile_path(),
217+
"ssh.priv": self.ssh_keyfile_path(),
218+
"test.is_isolated": "true",
219+
"test.experimental_structured_output": "true",
220+
}
221+
for key, value in configs.items():
222+
subprocess.check_call(
223+
[
224+
self.tool_path("ffx"),
225+
"config",
226+
"set",
227+
key,
228+
value,
229+
],
230+
env=self.ffx_cmd_env(),
231+
stdout=self.subprocess_output(),
232+
stderr=self.subprocess_output(),
233+
)
234+
270235
def ffx_cmd_env(self):
271-
result = {
272-
"HOME": self.ffx_home_dir(),
273-
"XDG_CONFIG_HOME": self.ffx_xdg_config_home(),
274-
"ASCENDD": self.ffx_ascendd_path(),
275-
"FUCHSIA_SSH_KEY": self.ssh_keyfile_path(),
236+
return {
237+
"HOME": self.home_dir(),
238+
"FFX_ISOLATE_DIR": self.ffx_isolate_dir(),
276239
# We want to use our own specified temp directory
277240
"TMP": self.tmp_dir(),
278241
"TEMP": self.tmp_dir(),
279242
"TMPDIR": self.tmp_dir(),
280243
"TEMPDIR": self.tmp_dir(),
281244
}
282245

283-
return result
284-
285246
def stop_ffx_isolation(self):
286247
subprocess.check_call(
287248
[
288249
self.tool_path("ffx"),
289-
"--config",
290-
self.ffx_user_config_path(),
291250
"daemon",
292251
"stop",
293252
],
@@ -709,8 +668,6 @@ def log(msg):
709668
subprocess.run(
710669
[
711670
self.tool_path("ffx"),
712-
"--config",
713-
self.ffx_user_config_path(),
714671
"test",
715672
"run",
716673
f"fuchsia-pkg://{self.TEST_REPO_NAME}/{package_name}#meta/{package_name}.cm",
@@ -849,8 +806,6 @@ def delete_tmp(self):
849806
def debug(self, args):
850807
command = [
851808
self.tool_path("ffx"),
852-
"--config",
853-
self.ffx_user_config_path(),
854809
"debug",
855810
"connect",
856811
"--",
@@ -948,8 +903,6 @@ def syslog(self, args):
948903
subprocess.run(
949904
[
950905
self.tool_path("ffx"),
951-
"--config",
952-
self.ffx_user_config_path(),
953906
"log",
954907
"--since",
955908
"now",

0 commit comments

Comments
 (0)