Update hyperv and docker providers to raise exception on SSH when machine is not ready

This makes the behavior of the docker and hyperv provider consistent with the
virtualbox provider by raising an error on ssh actions if the machine is not
created or not running.

Fixes #8508
This commit is contained in:
Chris Roberts 2017-05-05 13:55:59 -07:00
parent 1073aa8163
commit e5e0274ef5
4 changed files with 20 additions and 15 deletions

View File

@ -177,14 +177,12 @@ module VagrantPlugins
Vagrant::Action::Builder.new.tap do |b| Vagrant::Action::Builder.new.tap do |b|
b.use Call, IsState, :not_created do |env, b2| b.use Call, IsState, :not_created do |env, b2|
if env[:result] if env[:result]
b2.use Message, I18n.t("docker_provider.messages.not_created") raise Errors::ContainerNotCreatedError
next
end end
b2.use Call, IsState, :running do |env2, b3| b2.use Call, IsState, :running do |env2, b3|
if !env2[:result] if !env2[:result]
b3.use Message, I18n.t("docker_provider.messages.not_running") raise Errors::ContainerNotRunningError
next
end end
b3.use PrepareSSH b3.use PrepareSSH
@ -199,13 +197,12 @@ module VagrantPlugins
Vagrant::Action::Builder.new.tap do |b| Vagrant::Action::Builder.new.tap do |b|
b.use Call, IsState, :not_created do |env, b2| b.use Call, IsState, :not_created do |env, b2|
if env[:result] if env[:result]
b2.use Message, I18n.t("docker_provider.messages.not_created") raise Errors::ContainerNotCreatedError
next
end end
b2.use Call, IsState, :running do |env2, b3| b2.use Call, IsState, :running do |env2, b3|
if !env2[:result] if !env2[:result]
raise Vagrant::Errors::VMNotRunningError raise Errors::ContainerNotRunningError
end end
b3.use SSHRun b3.use SSHRun

View File

@ -9,6 +9,14 @@ module VagrantPlugins
error_key(:communicator_non_docker) error_key(:communicator_non_docker)
end end
class ContainerNotRunningError < DockerError
error_key(:not_running)
end
class ContainerNotCreatedError < DockerError
error_key(:not_created)
end
class ExecuteError < DockerError class ExecuteError < DockerError
error_key(:execute_error) error_key(:execute_error)
end end

View File

@ -178,14 +178,12 @@ module VagrantPlugins
b.use ConfigValidate b.use ConfigValidate
b.use Call, IsState, :not_created do |env, b2| b.use Call, IsState, :not_created do |env, b2|
if env[:result] if env[:result]
b2.use Message, I18n.t("vagrant_hyperv.message_not_created") raise Vagrant::Errors::VMNotCreatedError
next
end end
b2.use Call, IsState, :running do |env1, b3| b2.use Call, IsState, :running do |env1, b3|
if !env1[:result] if !env1[:result]
b3.use Message, I18n.t("vagrant_hyperv.message_not_running") raise Vagrant::Errors::VMNotRunningError
next
end end
b3.use SSHExec b3.use SSHExec
@ -199,14 +197,12 @@ module VagrantPlugins
b.use ConfigValidate b.use ConfigValidate
b.use Call, IsState, :not_created do |env, b2| b.use Call, IsState, :not_created do |env, b2|
if env[:result] if env[:result]
b2.use Message, I18n.t("vagrant_hyperv.message_not_created") raise Vagrant::Errors::VMNotCreatedError
next
end end
b2.use Call, IsState, :running do |env1, b3| b2.use Call, IsState, :running do |env1, b3|
if !env1[:result] if !env1[:result]
b3.use Message, I18n.t("vagrant_hyperv.message_not_running") raise Vagrant::Errors::VMNotRunningError
next
end end
b3.use SSHRun b3.use SSHRun

View File

@ -117,6 +117,10 @@ en:
run exits and doesn't keep running. run exits and doesn't keep running.
errors: errors:
not_created: |-
The container hasn't been created yet.
not_running: |-
The container is not currently running.
communicator_non_docker: |- communicator_non_docker: |-
The "docker_hostvm" communicator was specified on a machine that The "docker_hostvm" communicator was specified on a machine that
is not provided by the Docker provider. This is a bug with your is not provided by the Docker provider. This is a bug with your