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 def after_boot
logger.info "Mounting shared folders..." logger.info "Mounting shared folders..."
@runner.env.ssh.execute do |ssh| @runner.ssh.execute do |ssh|
shared_folders.each do |name, hostpath, guestpath| shared_folders.each do |name, hostpath, guestpath|
logger.info "-- #{name}: #{guestpath}" logger.info "-- #{name}: #{guestpath}"
@runner.system.mount_shared_folder(ssh, name, guestpath) @runner.system.mount_shared_folder(ssh, name, guestpath)

View File

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

View File

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

View File

@ -28,14 +28,14 @@ module Vagrant
logger.info "Creating folder to hold client key..." logger.info "Creating folder to hold client key..."
path = Pathname.new(env.config.chef.client_key_path) 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}") ssh.exec!("sudo mkdir -p #{path.dirname}")
end end
end end
def upload_validation_key def upload_validation_key
logger.info "Uploading chef client 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 end
def setup_server_config def setup_server_config
@ -50,7 +50,7 @@ module Vagrant
def run_chef_client def run_chef_client
logger.info "Running 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| 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 # 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 # an error, or when verbosity level is set high

View File

@ -36,7 +36,7 @@ module Vagrant
def run_chef_solo def run_chef_solo
logger.info "Running 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| 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 # 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 # an error, or when verbosity level is set high

View File

@ -74,9 +74,10 @@ class Test::Unit::TestCase
end end
# Sets up the mocks for a VM # 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 = 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.stubs(:ssh).returns(Vagrant::SSH.new(vm.env))
vm vm
end end

View File

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

View File

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

View File

@ -139,7 +139,6 @@ class EnvironmentTest < Test::Unit::TestCase
@env.expects(:load_config!).once.in_sequence(call_seq) @env.expects(:load_config!).once.in_sequence(call_seq)
Vagrant::Environment.expects(:check_virtualbox!).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_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_active_list!).once.in_sequence(call_seq)
@env.expects(:load_commands!).once.in_sequence(call_seq) @env.expects(:load_commands!).once.in_sequence(call_seq)
assert_equal @env, @env.load! assert_equal @env, @env.load!
@ -397,19 +396,6 @@ class EnvironmentTest < Test::Unit::TestCase
end end
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 context "loading the active list" do
setup do setup do
@env = mock_environment @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 should "create the folder using the dirname of the path" do
ssh = mock("ssh") ssh = mock("ssh")
ssh.expects(:exec!).with("sudo mkdir -p #{@path.dirname}").once 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 @action.create_client_key_folder
end end
end end
@ -116,7 +116,7 @@ class ChefServerProvisionerTest < Test::Unit::TestCase
should "upload the validation key to the provisioning path" do should "upload the validation key to the provisioning path" do
@action.expects(:validation_key_path).once.returns("foo") @action.expects(:validation_key_path).once.returns("foo")
@action.expects(:guest_validation_key_path).once.returns("bar") @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 @action.upload_validation_key
end end
end end
@ -159,7 +159,7 @@ class ChefServerProvisionerTest < Test::Unit::TestCase
should "cd into the provisioning directory and run chef client" do should "cd into the provisioning directory and run chef client" do
ssh = mock("ssh") ssh = mock("ssh")
ssh.expects(:exec!).with("cd #{@env.config.chef.provisioning_path} && sudo chef-client -c client.rb -j dna.json").once 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 @action.run_chef_client
end end
end end

View File

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