From 4df4f77bf6a7489be3f79ff2fc9e52270acc2178 Mon Sep 17 00:00:00 2001 From: Chris Roberts Date: Mon, 8 May 2017 10:06:27 -0700 Subject: [PATCH] Match WSL installed Vagrant with Windows installed Vagrant --- lib/vagrant/errors.rb | 4 ++++ lib/vagrant/util/platform.rb | 19 +++++++++++++++++++ templates/locales/en.yml | 10 ++++++++++ 3 files changed, 33 insertions(+) diff --git a/lib/vagrant/errors.rb b/lib/vagrant/errors.rb index 6fb07803b..b822644ea 100644 --- a/lib/vagrant/errors.rb +++ b/lib/vagrant/errors.rb @@ -891,5 +891,9 @@ module Vagrant class VMPowerOffToPackage < VagrantError error_key(:power_off, "vagrant.actions.vm.export") end + + class WSLVagrantVersionMismatch < VagrantError + error_key(:wsl_vagrant_version_mismatch) + end end end diff --git a/lib/vagrant/util/platform.rb b/lib/vagrant/util/platform.rb index 24b315987..4b744c3e7 100644 --- a/lib/vagrant/util/platform.rb +++ b/lib/vagrant/util/platform.rb @@ -293,6 +293,7 @@ module Vagrant # @param [Logger] logger Optional logger to display information def wsl_init(logger=nil) if wsl? && ENV["VAGRANT_WSL_ACCESS_WINDOWS_USER"] + wsl_validate_matching_vagrant_versions! shared_user = ENV["VAGRANT_WSL_ACCESS_WINDOWS_USER"] if logger logger.warn("Windows Subsystem for Linux detected. Allowing access to user: #{shared_user}") @@ -310,6 +311,24 @@ module Vagrant end end + # Confirm Vagrant versions installed within the WSL and the Windows system + # are the same. Raise error if they do not match. + def wsl_validate_matching_vagrant_versions! + valid = false + result = Util::Subprocess.execute("vagrant.exe", "version") + if result.exit_code == 0 + windows_version = result.stdout.match(/Installed Version: (?.+$)/) + if windows_version + valid = windows_version[:version] == Vagrant::VERSION + end + end + if !valid + raise Vagrant::Errors::WSLVagrantVersionMismatch, + wsl_version: Vagrant::VERSION, + windows_version: windows_version ? windows_version[:version] : "unknown" + end + end + # @private # Reset the cached values for platform. This is not considered a public # API and should only be used for testing. diff --git a/templates/locales/en.yml b/templates/locales/en.yml index 00ba09371..8c08135f9 100644 --- a/templates/locales/en.yml +++ b/templates/locales/en.yml @@ -1520,6 +1520,16 @@ en: VM must be running to open SSH connection. Run `vagrant up` to start the virtual machine. test_key: "test value" + wsl_vagrant_version_mismatch: |- + Vagrant cannot currently enable access to manage machines within the Windows + environment because the version of Vagrant installed on Windows does not + match this version of Vagrant running within the Windows Subsystem for Linux. + Please ensure both installation of Vagrant are the same. If you do not want + update your Vagrant installations you can disable Windows access by unsetting + the `VAGRANT_WSL_ACCESS_WINDOWS_USER` environment variable. + + Windows Vagrant version: %{windows_version} + Windows Subsystem for Linux Vagrant version: %{wsl_version} #------------------------------------------------------------------------------- # Translations for config validation errors