From 1bca32df3bd757da8d40a8956cac4df06e6134b4 Mon Sep 17 00:00:00 2001 From: Abhay Saxena Date: Thu, 13 Dec 2018 16:58:36 -0500 Subject: [PATCH 1/5] Report when sudo is missing rather than crashing --- telepresence/runner/runner.py | 1 + 1 file changed, 1 insertion(+) diff --git a/telepresence/runner/runner.py b/telepresence/runner/runner.py index 1ac2690a94..b79422b241 100644 --- a/telepresence/runner/runner.py +++ b/telepresence/runner/runner.py @@ -202,6 +202,7 @@ def require_sudo(self) -> None: if self.sudo_held: return + self.require(["sudo"], "Some operations require elevated privileges") try: # See whether we can grab privileges without a password self.check_call(["sudo", "-n", "echo", "-n"]) From 0b96b217dca04e1a1db8b9203bdb3b36d8b8317a Mon Sep 17 00:00:00 2001 From: Abhay Saxena Date: Thu, 13 Dec 2018 16:59:16 -0500 Subject: [PATCH 2/5] Log the paths of the binaries we check for --- telepresence/runner/runner.py | 9 ++++++++- 1 file changed, 8 insertions(+), 1 deletion(-) diff --git a/telepresence/runner/runner.py b/telepresence/runner/runner.py index b79422b241..edd5ae922c 100644 --- a/telepresence/runner/runner.py +++ b/telepresence/runner/runner.py @@ -224,7 +224,14 @@ def depend(self, commands: typing.Iterable[str]) -> typing.List[str]: """ Find unavailable commands from a set of dependencies """ - return [command for command in commands if which(command) is None] + missing = [] + for command in commands: + path = which(command) + if path: + self.write("Found {} -> {}".format(command, path)) + else: + missing.append(command) + return missing def require(self, commands: typing.Iterable[str], message: str) -> None: """ From 8787f7fa44ad62a2fe73b3b5fc61d5d3db3804e4 Mon Sep 17 00:00:00 2001 From: Abhay Saxena Date: Thu, 13 Dec 2018 17:16:16 -0500 Subject: [PATCH 3/5] Return an error if the user's command can't be launched --- telepresence/outbound/setup.py | 11 +++++++++-- 1 file changed, 9 insertions(+), 2 deletions(-) diff --git a/telepresence/outbound/setup.py b/telepresence/outbound/setup.py index 489e5b5215..4b8c833de1 100644 --- a/telepresence/outbound/setup.py +++ b/telepresence/outbound/setup.py @@ -18,7 +18,14 @@ from .local import launch_inject, launch_vpn +def check_local_command(runner: Runner, command: str) -> None: + if runner.depend([command]): + raise runner.fail("{}: command not found".format(command)) + + def setup_inject(runner: Runner, args): + command = ["torsocks"] + (args.run or ["bash", "--norc"]) + check_local_command(runner, command[1]) runner.require(["torsocks"], "Please install torsocks (v2.1 or later)") if runner.chatty: runner.show( @@ -28,7 +35,6 @@ def setup_inject(runner: Runner, args): "method limitations see " "https://telepresence.io/reference/methods.html" ) - command = ["torsocks"] + (args.run or ["bash", "--norc"]) def launch( runner_, _remote_info, env, socks_port, _ssh, _mount_dir, _pod_info @@ -39,6 +45,8 @@ def launch( def setup_vpn(runner: Runner, args): + command = args.run or ["bash", "--norc"] + check_local_command(runner, command[0]) runner.require(["sshuttle-telepresence"], "Part of the Telepresence package. Try reinstalling.") if runner.platform == "linux": @@ -57,7 +65,6 @@ def setup_vpn(runner: Runner, args): "a full list of method limitations see " "https://telepresence.io/reference/methods.html" ) - command = args.run or ["bash", "--norc"] def launch( runner_, remote_info, env, _socks_port, ssh, _mount_dir, _pod_info From 3bff6c987d78d051dafcae4bce8f8c0eb6244963 Mon Sep 17 00:00:00 2001 From: Abhay Saxena Date: Thu, 13 Dec 2018 17:36:26 -0500 Subject: [PATCH 4/5] Catch launch errors too, in case shutil.which(...) is wrong --- telepresence/outbound/local.py | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/telepresence/outbound/local.py b/telepresence/outbound/local.py index d8e571fc49..26de59ee4f 100644 --- a/telepresence/outbound/local.py +++ b/telepresence/outbound/local.py @@ -119,7 +119,10 @@ def launch_vpn( """ connect_sshuttle(runner, remote_info, also_proxy, ssh) env = get_local_env(runner, env_overrides, False) - process = Popen(command, env=env) + try: + process = Popen(command, env=env) + except OSError as exc: + raise runner.fail("Failed to launch your command: {}".format(exc)) runner.add_cleanup( "Terminate local process", terminate_local_process, runner, process ) From fb6223dd36cf667d6dfea6d696156c4b1413242c Mon Sep 17 00:00:00 2001 From: Abhay Saxena Date: Thu, 13 Dec 2018 17:36:51 -0500 Subject: [PATCH 5/5] Add news fragment --- newsfragments/869.bugfix | 1 + 1 file changed, 1 insertion(+) create mode 100644 newsfragments/869.bugfix diff --git a/newsfragments/869.bugfix b/newsfragments/869.bugfix new file mode 100644 index 0000000000..4252985ca5 --- /dev/null +++ b/newsfragments/869.bugfix @@ -0,0 +1 @@ +Telepresence now reports an error if your command cannot be launched.