Skip to content

Commit bc2b9df

Browse files
some fixes
1 parent 290aad9 commit bc2b9df

3 files changed

Lines changed: 37 additions & 13 deletions

File tree

asap-tools/experiments/experiment_utils/providers/cloudlab_local.py

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -154,6 +154,10 @@ def execute_command_parallel(
154154

155155
return processes
156156

157+
def is_remote(self) -> bool:
158+
"""Commands run locally on this node (no SSH), even though paths/usernames are CloudLab-shaped."""
159+
return False
160+
157161
def get_node_address(self, node_idx: int) -> str:
158162
"""
159163
Get the network address for the local node.

asap-tools/experiments/experiment_utils/providers/local.py

Lines changed: 30 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -49,15 +49,28 @@ def execute_command(
4949
if nohup:
5050
cmd = f"nohup {cmd}"
5151

52+
# subprocess treats cwd="" as an actual (invalid) path, unlike the
53+
# CloudLab SSH path's `if cmd_dir: cd {cmd_dir}` which is falsy-safe.
54+
cmd_dir = cmd_dir or None
55+
5256
if popen:
53-
return subprocess.Popen(
54-
cmd,
55-
shell=True,
56-
cwd=cmd_dir,
57-
stdout=subprocess.PIPE,
58-
stderr=subprocess.PIPE,
59-
text=True,
60-
)
57+
try:
58+
return subprocess.Popen(
59+
cmd,
60+
shell=True,
61+
cwd=cmd_dir,
62+
stdout=subprocess.PIPE,
63+
stderr=subprocess.PIPE,
64+
text=True,
65+
)
66+
except OSError as e:
67+
# execute_command_parallel has no ignore_errors knob (see
68+
# follow-up issue), so this can't be conditional yet. Mirrors
69+
# CloudLab's SSH transport: launching `ssh` locally never
70+
# fails even if the remote cmd_dir is missing — the failure
71+
# is invisible unless something later checks output/health.
72+
print(f"Warning: failed to launch '{cmd}' in {cmd_dir!r}: {e}")
73+
return None
6174

6275
try:
6376
return subprocess.run(
@@ -68,7 +81,13 @@ def execute_command(
6881
text=True,
6982
check=not ignore_errors,
7083
)
71-
except subprocess.CalledProcessError as e:
84+
except (subprocess.CalledProcessError, OSError) as e:
85+
# Over SSH, a missing cmd_dir just makes the *remote* shell exit
86+
# nonzero, which ignore_errors already swallows via check=False.
87+
# Locally, a missing cmd_dir makes subprocess.run itself raise
88+
# OSError (e.g. FileNotFoundError) before the command ever runs —
89+
# same "best-effort cleanup, don't crash" intent, different
90+
# exception type, so it needs the same ignore_errors treatment.
7291
if ignore_errors:
7392
return e
7493
raise
@@ -97,7 +116,8 @@ def execute_command_parallel(
97116
processes = [process]
98117
if wait:
99118
for p in processes:
100-
p.wait()
119+
if p is not None:
120+
p.wait()
101121
return processes
102122

103123
def is_remote(self) -> bool:

asap-tools/experiments/experiment_utils/services/prometheus_client_service.py

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -205,7 +205,7 @@ def _stop_containerized(self):
205205
try:
206206
if self.compose_file:
207207
cmd = f"docker compose -f {self.compose_file} down"
208-
if self.provider.hostname_suffix == "localhost":
208+
if not self.provider.is_remote():
209209
utils.run_cmd(cmd, popen=False)
210210
self.compose_file = None
211211
else:
@@ -220,7 +220,7 @@ def _stop_containerized(self):
220220
else:
221221
# Fallback: stop by container name on remote node
222222
cmd = f"docker stop {self.container_name}; docker rm {self.container_name}"
223-
if self.provider.hostname_suffix == "localhost":
223+
if not self.provider.is_remote():
224224
utils.run_cmd(cmd, popen=False)
225225
else:
226226
self.provider.execute_command(
@@ -238,7 +238,7 @@ def _stop_containerized(self):
238238
def _stop_bare_metal(self):
239239
"""Kill Prometheus client processes."""
240240
cmd = "pkill -f main_prometheus_client.py"
241-
if self.provider.hostname_suffix == "localhost":
241+
if not self.provider.is_remote():
242242
# If running on localhost, use pkill to stop the process (e.g. from remote_monitor)
243243
utils.run_cmd(cmd, popen=False)
244244
else:

0 commit comments

Comments
 (0)