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

Modification of remote environment doesn't seem to be working #120

Closed
drennalls opened this issue Apr 28, 2014 · 4 comments
Closed

Modification of remote environment doesn't seem to be working #120

drennalls opened this issue Apr 28, 2014 · 4 comments

Comments

@drennalls
Copy link
Contributor

The docs give the impression that modifications of the remote environment work in the same way as modifications to the local environment. However that doesn't seem to be the case. For e.g. below is an example of where I added /tmp/bin/ to the remote env.path however the new env doesn't seem to get used.

>>> remote =  ParamikoMachine("192.168.0.1", port=2222, user="root", password="password", missing_host_policy=paramiko.AutoAddPolicy())
>>> r_ls = remote["ls"]
>>> print r_ls["-la", "/tmp/bin"]()
total 112
drwxr-xr-x 2 root root  4096 Apr 28 09:30 .
drwxrwxrwt 6 root root  4096 Apr 28 09:41 ..
-rwxr-xr-x 1 root root 95116 Apr 28 09:30 ls

>>> remote.which("ls")
<RemotePath /bin/ls>
>>>
>>> remote.env.path.insert(0, "/tmp/bin")
>>>
>>> remote.which("ls")
<RemotePath /bin/ls>
>>>
>>> remote.env.path
[<RemotePath /tmp/bin>, <RemotePath /usr/kerberos/sbin>, <RemotePath /usr/kerberos/bin>, <RemotePath /usr/local/sbin>, 
<RemotePath /usr/local/bin>, <RemotePath /sbin>, <RemotePath /bin>, <RemotePath /usr/sbin>, <RemotePath /usr/bin>, 
<RemotePath /usr/local/bin>]
>>>
@tomerfiliba
Copy link
Owner

that's a bug: https://github.com/tomerfiliba/plumbum/blob/master/plumbum/machines/remote.py#L185

when you which() a command, it uses the session to run which on the remote machine. the fact you update the environment doesn't affect the existing session. you can try to set the session's environment before the which. but a better solution would be to copy which from LocalMachine:

https://github.com/tomerfiliba/plumbum/blob/master/plumbum/machines/local.py#L141

which uses the env.path for that. could you try it out and submit a pull request? thanks

@drennalls
Copy link
Contributor Author

Copying the which from LocalMachine fixes the command resolution but there's still an issue with running commands with an updated environment. The RemoteEnv.getdelta method is only considering keys when comparing the current vs original environment. So if an existing env variable is modified it won't be used when executing commands (example below).

>>> remote.env["MAIL"]
u'/var/spool/mail/root'
>>> remote.env["MAIL"] = "/var/mail/bogus"
>>>
>>> remote.env["MAIL"]
'/var/mail/bogus'
>>> print remote["printenv"]()
MAIL=/var/mail/root

What's the reason for not simply using the current environment when running commands vs just the deltas with "env delta1=sds etc..".. efficiency ?

@drennalls
Copy link
Contributor Author

..I clued in after my last comment. I guess you need to check for the case where env vars have been removed. So simply using the current evironment is not sufficient.. but still need to check for modified env vars as well I guess.

@tomerfiliba
Copy link
Owner

IIRC, this issue is fixed already. closing.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants