From 1c203405d2a488b6c5d5f689f2a90ae0156434bc Mon Sep 17 00:00:00 2001 From: Mitchell Hashimoto Date: Wed, 8 Jul 2015 12:31:24 -0600 Subject: [PATCH] providers/docker: fix crash if host VM file can't be foundJ:wq gs --- CHANGELOG.md | 2 ++ plugins/providers/docker/errors.rb | 4 ++++ plugins/providers/docker/provider.rb | 14 ++++++++++++-- templates/locales/providers_docker.yml | 4 ++++ 4 files changed, 22 insertions(+), 2 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index f79218d8b..fa4e9d7d5 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -88,6 +88,8 @@ BUG FIXES: - plugins/login: allow users to login with a token [GH-5145] - providers/docker: Build image from `/var/lib/docker` for more disk space on some systems. [GH-5302] + - providers/docker: Fix crash that could occur in some scenarios when + the host VM path changed. - providers/hyperv: allow users to configure memory, cpu count, and vmname [GH-5183] - providers/hyperv: import respects secure boot. [GH-5209] - providers/hyperv: only set EFI secure boot for gen 2 machines [GH-5538] diff --git a/plugins/providers/docker/errors.rb b/plugins/providers/docker/errors.rb index 677b7be84..4b3e71d64 100644 --- a/plugins/providers/docker/errors.rb +++ b/plugins/providers/docker/errors.rb @@ -44,6 +44,10 @@ module VagrantPlugins class SyncedFolderNonDocker < DockerError error_key(:synced_folder_non_docker) end + + class VagrantfileNotFound < DockerError + error_key(:vagrantfile_not_found) + end end end end diff --git a/plugins/providers/docker/provider.rb b/plugins/providers/docker/provider.rb index 79265b9d6..f30f32d41 100644 --- a/plugins/providers/docker/provider.rb +++ b/plugins/providers/docker/provider.rb @@ -89,6 +89,10 @@ module VagrantPlugins vagrantfile_name: vf_file, ) + # If there is no root path, then the Vagrantfile wasn't found + # and it is an error... + raise Errors::VagrantfileNotFound if !host_env.root_path + host_env.machine( host_machine_name, host_env.default_provider( @@ -149,8 +153,14 @@ module VagrantPlugins def state state_id = nil state_id = :not_created if !@machine.id - state_id = :host_state_unknown if !state_id && \ - host_vm? && !host_vm.communicate.ready? + + begin + state_id = :host_state_unknown if !state_id && \ + host_vm? && !host_vm.communicate.ready? + rescue Errors::VagrantfileNotFound + state_id = :host_state_unknown + end + state_id = :not_created if !state_id && \ (!@machine.id || !driver.created?(@machine.id)) state_id = driver.state(@machine.id) if @machine.id && !state_id diff --git a/templates/locales/providers_docker.yml b/templates/locales/providers_docker.yml index f642c8624..443649956 100644 --- a/templates/locales/providers_docker.yml +++ b/templates/locales/providers_docker.yml @@ -196,3 +196,7 @@ en: The "docker" synced folder type can't be used because the provider in use is not Docker. This synced folder type only works with the Docker provider. The provider this machine is using is: %{provider} + vagrantfile_not_found: |- + The configured host VM Vagrantfile could not be found. Please fix + the Vagrantfile for this Docker environment to point to a valid + host VM.