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

Fix for windows guests running on non-windows hosts. #67

Merged
merged 3 commits into from
Apr 27, 2014

Conversation

thematthopkins
Copy link
Contributor

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.

@pbitty
Copy link
Contributor

pbitty commented Feb 22, 2014

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 machine.communicate methods will work via the SSH communicator, right?

@thematthopkins
Copy link
Contributor Author

@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.

@pbitty
Copy link
Contributor

pbitty commented Mar 18, 2014

@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' if branch.

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"))
Copy link
Contributor

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?

Copy link
Contributor

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
   # ...

Copy link
Contributor Author

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.

@pbitty
Copy link
Contributor

pbitty commented Mar 18, 2014

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 config.vm.guest = :windows for vagrant-windows to work.

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", '')
Copy link
Contributor

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.

Copy link
Contributor Author

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

pbitty added a commit that referenced this pull request Apr 27, 2014
Fix for windows guests running on non-windows hosts.
@pbitty pbitty merged commit ae7ac77 into devopsgroup-io:master Apr 27, 2014
@pbitty
Copy link
Contributor

pbitty commented Apr 27, 2014

Thanks @thematthopkins, sorry for the delay in merging it!

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

Successfully merging this pull request may close these issues.

None yet

2 participants