core: Configurable communicator
This commit is contained in:
parent
40d89cf5ea
commit
f07ee5754a
|
@ -300,6 +300,10 @@ module Vagrant
|
|||
error_key(:command_unavailable_windows)
|
||||
end
|
||||
|
||||
class CommunicatorNotFound < VagrantError
|
||||
error_key(:communicator_not_found)
|
||||
end
|
||||
|
||||
class ConfigInvalid < VagrantError
|
||||
error_key(:config_invalid)
|
||||
end
|
||||
|
|
|
@ -173,9 +173,10 @@ module Vagrant
|
|||
# @return [Object]
|
||||
def communicate
|
||||
if !@communicator
|
||||
# For now, we always return SSH. In the future, we'll abstract
|
||||
# this and allow plugins to define new methods of communication.
|
||||
klass = Vagrant.plugin("2").manager.communicators[:ssh]
|
||||
requested = @config.vm.communicator
|
||||
requested ||= :ssh
|
||||
klass = Vagrant.plugin("2").manager.communicators[requested]
|
||||
raise Errors::CommunicatorNotFound, comm: requested.to_s if !klass
|
||||
@communicator = klass.new(self)
|
||||
end
|
||||
|
||||
|
|
|
@ -579,6 +579,9 @@ en:
|
|||
The executable '%{file}' Vagrant is trying to run was not
|
||||
found in the %PATH% variable. This is an error. Please verify
|
||||
this software is installed and on the path.
|
||||
communicator_not_found: |-
|
||||
The requested communicator '%{comm}' could not be found.
|
||||
Please verify the name is correct and try again.
|
||||
config_invalid: |-
|
||||
There are errors in the configuration of this machine. Please fix
|
||||
the following errors and try again:
|
||||
|
|
|
@ -240,14 +240,27 @@ describe Vagrant::Machine do
|
|||
end
|
||||
end
|
||||
|
||||
describe "communicator" do
|
||||
it "should always return the SSH communicator" do
|
||||
expect(instance.communicate).to be_kind_of(VagrantPlugins::CommunicatorSSH::Communicator)
|
||||
describe "#communicate" do
|
||||
it "should return the SSH communicator by default" do
|
||||
expect(subject.communicate).
|
||||
to be_kind_of(VagrantPlugins::CommunicatorSSH::Communicator)
|
||||
end
|
||||
|
||||
it "should return the specified communicator if given" do
|
||||
subject.config.vm.communicator = :winrm
|
||||
expect(subject.communicate).
|
||||
to be_kind_of(VagrantPlugins::CommunicatorWinRM::Communicator)
|
||||
end
|
||||
|
||||
it "should memoize the result" do
|
||||
obj = instance.communicate
|
||||
expect(instance.communicate).to eql(obj)
|
||||
obj = subject.communicate
|
||||
expect(subject.communicate).to equal(obj)
|
||||
end
|
||||
|
||||
it "raises an exception if an invalid communicator is given" do
|
||||
subject.config.vm.communicator = :foo
|
||||
expect { subject.communicate }.
|
||||
to raise_error(Vagrant::Errors::CommunicatorNotFound)
|
||||
end
|
||||
end
|
||||
|
||||
|
|
Loading…
Reference in New Issue