Remove SSH object from environment

This commit is contained in:
Mitchell Hashimoto 2010-05-07 21:45:40 -07:00
parent 2e547bda26
commit b1b4ae2077
11 changed files with 20 additions and 40 deletions

View File

@ -17,7 +17,7 @@ module Vagrant
def after_boot
logger.info "Mounting shared folders..."
@runner.env.ssh.execute do |ssh|
@runner.ssh.execute do |ssh|
shared_folders.each do |name, hostpath, guestpath|
logger.info "-- #{name}: #{guestpath}"
@runner.system.mount_shared_folder(ssh, name, guestpath)

View File

@ -11,7 +11,7 @@ module Vagrant
def execute(args=[])
env.require_persisted_vm
env.ssh.connect
env.vm.ssh.connect
end
def options_spec(opts)

View File

@ -13,7 +13,6 @@ module Vagrant
attr_reader :config
attr_reader :box
attr_accessor :vm
attr_reader :ssh
attr_reader :active_list
attr_reader :commands
@ -95,7 +94,6 @@ module Vagrant
load_config!
self.class.check_virtualbox!
load_vm!
load_ssh!
load_active_list!
load_commands!
self
@ -180,11 +178,6 @@ module Vagrant
@vm = nil
end
# Loads/initializes the SSH object
def load_ssh!
@ssh = SSH.new(self)
end
# Loads the activelist for this environment
def load_active_list!
@active_list = ActiveList.new(self)

View File

@ -28,14 +28,14 @@ module Vagrant
logger.info "Creating folder to hold client key..."
path = Pathname.new(env.config.chef.client_key_path)
env.ssh.execute do |ssh|
vm.ssh.execute do |ssh|
ssh.exec!("sudo mkdir -p #{path.dirname}")
end
end
def upload_validation_key
logger.info "Uploading chef client validation key..."
env.ssh.upload!(validation_key_path, guest_validation_key_path)
vm.ssh.upload!(validation_key_path, guest_validation_key_path)
end
def setup_server_config
@ -50,7 +50,7 @@ module Vagrant
def run_chef_client
logger.info "Running chef-client..."
env.ssh.execute do |ssh|
vm.ssh.execute do |ssh|
ssh.exec!("cd #{env.config.chef.provisioning_path} && sudo chef-client -c client.rb -j dna.json") do |channel, data, stream|
# TODO: Very verbose. It would be easier to save the data and only show it during
# an error, or when verbosity level is set high

View File

@ -36,7 +36,7 @@ module Vagrant
def run_chef_solo
logger.info "Running chef-solo..."
env.ssh.execute do |ssh|
vm.ssh.execute do |ssh|
ssh.exec!("cd #{env.config.chef.provisioning_path} && sudo chef-solo -c solo.rb -j dna.json") do |channel, data, stream|
# TODO: Very verbose. It would be easier to save the data and only show it during
# an error, or when verbosity level is set high

View File

@ -74,9 +74,10 @@ class Test::Unit::TestCase
end
# Sets up the mocks for a VM
def mock_vm
def mock_vm(env=nil)
env ||= mock_environment
vm = Vagrant::VM.new(nil, nil)
vm.stubs(:env).returns(mock_environment)
vm.stubs(:env).returns(env)
vm.stubs(:ssh).returns(Vagrant::SSH.new(vm.env))
vm
end

View File

@ -99,7 +99,7 @@ class SharedFoldersActionTest < Test::Unit::TestCase
@folders.each do |name, hostpath, guestpath|
@runner.system.expects(:mount_shared_folder).with(ssh, name, guestpath).in_sequence(mount_seq)
end
@runner.env.ssh.expects(:execute).yields(ssh)
@runner.ssh.expects(:execute).yields(ssh)
@action.after_boot
end

View File

@ -4,11 +4,11 @@ class CommandsSSHTest < Test::Unit::TestCase
setup do
@klass = Vagrant::Commands::SSH
@persisted_vm = mock("persisted_vm")
@persisted_vm.stubs(:execute!)
@env = mock_environment
@env.stubs(:require_persisted_vm)
@persisted_vm = mock_vm(@env)
@persisted_vm.stubs(:execute!)
@env.stubs(:vm).returns(@persisted_vm)
@instance = @klass.new(@env)
@ -16,7 +16,7 @@ class CommandsSSHTest < Test::Unit::TestCase
context "executing" do
setup do
@env.ssh.stubs(:connect)
@persisted_vm.ssh.stubs(:connect)
end
should "require a persisted VM" do
@ -25,7 +25,7 @@ class CommandsSSHTest < Test::Unit::TestCase
end
should "connect to SSH" do
@env.ssh.expects(:connect).once
@persisted_vm.ssh.expects(:connect).once
@instance.execute
end
end

View File

@ -139,7 +139,6 @@ class EnvironmentTest < Test::Unit::TestCase
@env.expects(:load_config!).once.in_sequence(call_seq)
Vagrant::Environment.expects(:check_virtualbox!).once.in_sequence(call_seq)
@env.expects(:load_vm!).once.in_sequence(call_seq)
@env.expects(:load_ssh!).once.in_sequence(call_seq)
@env.expects(:load_active_list!).once.in_sequence(call_seq)
@env.expects(:load_commands!).once.in_sequence(call_seq)
assert_equal @env, @env.load!
@ -397,19 +396,6 @@ class EnvironmentTest < Test::Unit::TestCase
end
end
context "loading SSH" do
setup do
@env = mock_environment
end
should "initialize the SSH object with the given environment" do
ssh = mock("ssh")
Vagrant::SSH.expects(:new).with(@env).returns(ssh)
@env.load_ssh!
assert_equal ssh, @env.ssh
end
end
context "loading the active list" do
setup do
@env = mock_environment

View File

@ -107,7 +107,7 @@ class ChefServerProvisionerTest < Test::Unit::TestCase
should "create the folder using the dirname of the path" do
ssh = mock("ssh")
ssh.expects(:exec!).with("sudo mkdir -p #{@path.dirname}").once
@env.ssh.expects(:execute).yields(ssh)
@vm.ssh.expects(:execute).yields(ssh)
@action.create_client_key_folder
end
end
@ -116,7 +116,7 @@ class ChefServerProvisionerTest < Test::Unit::TestCase
should "upload the validation key to the provisioning path" do
@action.expects(:validation_key_path).once.returns("foo")
@action.expects(:guest_validation_key_path).once.returns("bar")
@env.ssh.expects(:upload!).with("foo", "bar").once
@vm.ssh.expects(:upload!).with("foo", "bar").once
@action.upload_validation_key
end
end
@ -159,7 +159,7 @@ class ChefServerProvisionerTest < Test::Unit::TestCase
should "cd into the provisioning directory and run chef client" do
ssh = mock("ssh")
ssh.expects(:exec!).with("cd #{@env.config.chef.provisioning_path} && sudo chef-client -c client.rb -j dna.json").once
@env.ssh.expects(:execute).yields(ssh)
@vm.ssh.expects(:execute).yields(ssh)
@action.run_chef_client
end
end

View File

@ -149,7 +149,7 @@ class ChefSoloProvisionerTest < Test::Unit::TestCase
context "generating and uploading chef solo configuration file" do
setup do
@env.ssh.stubs(:upload!)
@vm.ssh.stubs(:upload!)
end
should "call setup_config with proper variables" do
@ -167,7 +167,7 @@ class ChefSoloProvisionerTest < Test::Unit::TestCase
should "cd into the provisioning directory and run chef solo" do
ssh = mock("ssh")
ssh.expects(:exec!).with("cd #{@env.config.chef.provisioning_path} && sudo chef-solo -c solo.rb -j dna.json").once
@env.ssh.expects(:execute).yields(ssh)
@vm.ssh.expects(:execute).yields(ssh)
@action.run_chef_solo
end
end