-
Notifications
You must be signed in to change notification settings - Fork 148
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
Fix for windows guests running on non-windows hosts. #67
Conversation
HI @thematthopkins, sorry for the delay in getting to this. I haven't been able to test this (I need to get my hands on a Windows vagrant box), but it looks good to me. It doesn't make sense to ask the host OS for a path that is on the guest OS. I'm wondering, will this also work without vagrant-windows? That is, if a person has a Windows guest with cygwin sshd, all the |
@pbitty No problem at all. Thanks for getting too it! Great question. I don't have a windows guest running via the SSH communicator, but can confirm that the machine.communicate.execute function is defined, and that when launching cmd from the cygwin prompt, echo %SYSTEMROOT% behaves as it should. |
@thematthopkins I've been having trouble testing this. I built a windows 7 box with veewee, but when hostmanager tries to update the hosts file, it doesn't fall into the 'windows' I'll put the comments on the lines I'm talking about. |
@@ -10,7 +10,13 @@ def update_guest(machine) | |||
realhostfile = '/etc/inet/hosts' | |||
move_cmd = 'mv' | |||
elsif (machine.communicate.test("test -d $Env:SystemRoot")) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
It seems it's not going into this if branch.
When I run test -d $Env:SystemRoot
in the machine's shell I get exit status 1 (ie: fail). When I run test -d $SystemRoot
it works fine.
Is this working fine for you?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I wonder if we should just do a straight guest check. ie:
elsif machine.guest.name = :windows
# ...
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I tested this on my vm, and it succeeds with test -d $Env:SystemRoot
, but fails on test -d $SystemRoot
By default, vagrant-windows uses powershell as its shell. So, test -d $Env:SystemRoot
will work only from the powershell within Windows. It's a bit confusing that test -d $SystemRoot
works though, because using the Windows cmd shell, you'd need to reference it like
test -d %SystemRoot%
It seems like maybe the guest is using cygwin's shell? Is it possible your VM is communicating via ssh rather than winrm?
Branching on machine.guest.name == :windows
seems like a good idea, and worked on my test. It would also handle that case where the windows guest is communicating via ssh.
I also noticed that vagrant-windows does the same test to detect a Windows guest, but that test doesn't seem to work either. I believe that's why you have to set I want to ask the vagrant-windows folks, but I wanted to see how you have this working in the first place. |
windir = nil | ||
machine.communicate.execute("echo %SYSTEMROOT%", {:shell => :cmd}) do |type, contents| | ||
if type == :stdout | ||
windir = contents.gsub("\r\n", '') |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think instead of assigning to windir, we should be appending to it. ie:
windir << contents.gsub("\r\n", '')
I think the idea with the execute
blocks is that the data can arrive in chunks. Although the result of this call is really short and will probably always work, we might as well follow the general pattern.
Check out how it's used in the vagrant core code.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
great catch! This is now updated
Fix for windows guests running on non-windows hosts.
Thanks @thematthopkins, sorry for the delay in merging it! |
Pending WinRb/vagrant-windows#169, this will get windows guests fully operational on non-windows hosts. ENV['WINDIR'] will only be present if the host machine is Windows. This retrieves the environment variable from the guest.