SSHExec raises proper exception if SSH is not yet ready
This commit is contained in:
parent
8d50c4774e
commit
b1ced46d7c
|
@ -21,8 +21,10 @@ module Vagrant
|
||||||
def call(env)
|
def call(env)
|
||||||
# Grab the SSH info from the machine
|
# Grab the SSH info from the machine
|
||||||
info = env[:machine].ssh_info
|
info = env[:machine].ssh_info
|
||||||
# XXX: Raise an exception if info is nil, since that means that
|
|
||||||
# SSH is not ready.
|
# If the result is nil, then the machine is telling us that it is
|
||||||
|
# not yet ready for SSH, so we raise this exception.
|
||||||
|
raise Errors::SSHNotReady if info.nil?
|
||||||
|
|
||||||
# Check the SSH key permissions
|
# Check the SSH key permissions
|
||||||
SSH.check_key_permissions(info[:private_key_path])
|
SSH.check_key_permissions(info[:private_key_path])
|
||||||
|
|
|
@ -356,6 +356,10 @@ module Vagrant
|
||||||
error_key(:ssh_key_type_not_supported)
|
error_key(:ssh_key_type_not_supported)
|
||||||
end
|
end
|
||||||
|
|
||||||
|
class SSHNotReady < VagrantError
|
||||||
|
error_key(:ssh_not_ready)
|
||||||
|
end
|
||||||
|
|
||||||
class SSHPortNotDetected < VagrantError
|
class SSHPortNotDetected < VagrantError
|
||||||
status_code(50)
|
status_code(50)
|
||||||
error_key(:ssh_port_not_detected)
|
error_key(:ssh_port_not_detected)
|
||||||
|
|
|
@ -156,6 +156,12 @@ en:
|
||||||
The private key you're attempting to use with this Vagrant box uses
|
The private key you're attempting to use with this Vagrant box uses
|
||||||
an unsupported encryption type. The SSH library Vagrant uses does not support
|
an unsupported encryption type. The SSH library Vagrant uses does not support
|
||||||
this key type. Please use `ssh-rsa` or `ssh-dss` instead.
|
this key type. Please use `ssh-rsa` or `ssh-dss` instead.
|
||||||
|
ssh_not_ready: |-
|
||||||
|
The provider for this Vagrant-managed machine is reporting that it
|
||||||
|
is not yet ready for SSH. Depending on your provider this can carry
|
||||||
|
different meanings. Make sure your machine is created and running and
|
||||||
|
try again. If you continue to get this error message, please view the
|
||||||
|
documentation for the provider you're using.
|
||||||
ssh_port_not_detected: |-
|
ssh_port_not_detected: |-
|
||||||
Vagrant couldn't determine the SSH port for your VM! Vagrant attempts to
|
Vagrant couldn't determine the SSH port for your VM! Vagrant attempts to
|
||||||
automatically find a forwarded port that matches your `config.ssh.guest_port`
|
automatically find a forwarded port that matches your `config.ssh.guest_port`
|
||||||
|
|
|
@ -20,6 +20,15 @@ describe Vagrant::Action::Builtin::SSHExec do
|
||||||
ssh_klass.stub(:exec)
|
ssh_klass.stub(:exec)
|
||||||
end
|
end
|
||||||
|
|
||||||
|
it "should raise an exception if SSH is not ready" do
|
||||||
|
not_ready_machine = double("machine")
|
||||||
|
not_ready_machine.stub(:ssh_info).and_return(nil)
|
||||||
|
|
||||||
|
env[:machine] = not_ready_machine
|
||||||
|
expect { described_class.new(app, env).call(env) }.
|
||||||
|
to raise_error(Vagrant::Errors::SSHNotReady)
|
||||||
|
end
|
||||||
|
|
||||||
it "should check key permissions then exec" do
|
it "should check key permissions then exec" do
|
||||||
ssh_klass.should_receive(:check_key_permissions).
|
ssh_klass.should_receive(:check_key_permissions).
|
||||||
with(machine_ssh_info[:private_key_path]).
|
with(machine_ssh_info[:private_key_path]).
|
||||||
|
|
Loading…
Reference in New Issue