Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Make PATH and dependency fixes #870

Merged
merged 5 commits into from Dec 13, 2018
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
1 change: 1 addition & 0 deletions newsfragments/869.bugfix
@@ -0,0 +1 @@
Telepresence now reports an error if your command cannot be launched.
5 changes: 4 additions & 1 deletion telepresence/outbound/local.py
Expand Up @@ -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
)
Expand Down
11 changes: 9 additions & 2 deletions telepresence/outbound/setup.py
Expand Up @@ -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(
Expand All @@ -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
Expand All @@ -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":
Expand All @@ -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
Expand Down
10 changes: 9 additions & 1 deletion telepresence/runner/runner.py
Expand Up @@ -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"])
Expand All @@ -223,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:
"""
Expand Down