From b1b4ae2077d73021ae2d84886f379f2e2b23d027 Mon Sep 17 00:00:00 2001 From: Mitchell Hashimoto Date: Fri, 7 May 2010 21:45:40 -0700 Subject: [PATCH] Remove SSH object from environment --- lib/vagrant/actions/vm/shared_folders.rb | 2 +- lib/vagrant/commands/ssh.rb | 2 +- lib/vagrant/environment.rb | 7 ------- lib/vagrant/provisioners/chef_server.rb | 6 +++--- lib/vagrant/provisioners/chef_solo.rb | 2 +- test/test_helper.rb | 5 +++-- test/vagrant/actions/vm/shared_folders_test.rb | 2 +- test/vagrant/commands/ssh_test.rb | 10 +++++----- test/vagrant/environment_test.rb | 14 -------------- test/vagrant/provisioners/chef_server_test.rb | 6 +++--- test/vagrant/provisioners/chef_solo_test.rb | 4 ++-- 11 files changed, 20 insertions(+), 40 deletions(-) diff --git a/lib/vagrant/actions/vm/shared_folders.rb b/lib/vagrant/actions/vm/shared_folders.rb index 12b7923b1..2945743d8 100644 --- a/lib/vagrant/actions/vm/shared_folders.rb +++ b/lib/vagrant/actions/vm/shared_folders.rb @@ -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) diff --git a/lib/vagrant/commands/ssh.rb b/lib/vagrant/commands/ssh.rb index 876e3f0aa..3192842bd 100644 --- a/lib/vagrant/commands/ssh.rb +++ b/lib/vagrant/commands/ssh.rb @@ -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) diff --git a/lib/vagrant/environment.rb b/lib/vagrant/environment.rb index 73aebce84..878cdb2d2 100644 --- a/lib/vagrant/environment.rb +++ b/lib/vagrant/environment.rb @@ -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) diff --git a/lib/vagrant/provisioners/chef_server.rb b/lib/vagrant/provisioners/chef_server.rb index f69cf9547..560c01f0e 100644 --- a/lib/vagrant/provisioners/chef_server.rb +++ b/lib/vagrant/provisioners/chef_server.rb @@ -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 diff --git a/lib/vagrant/provisioners/chef_solo.rb b/lib/vagrant/provisioners/chef_solo.rb index c6f646a2d..146e1542a 100644 --- a/lib/vagrant/provisioners/chef_solo.rb +++ b/lib/vagrant/provisioners/chef_solo.rb @@ -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 diff --git a/test/test_helper.rb b/test/test_helper.rb index 6464a660d..16c87585b 100644 --- a/test/test_helper.rb +++ b/test/test_helper.rb @@ -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 diff --git a/test/vagrant/actions/vm/shared_folders_test.rb b/test/vagrant/actions/vm/shared_folders_test.rb index d5fc41676..4d7871ba4 100644 --- a/test/vagrant/actions/vm/shared_folders_test.rb +++ b/test/vagrant/actions/vm/shared_folders_test.rb @@ -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 diff --git a/test/vagrant/commands/ssh_test.rb b/test/vagrant/commands/ssh_test.rb index ac06ba63e..87d28043b 100644 --- a/test/vagrant/commands/ssh_test.rb +++ b/test/vagrant/commands/ssh_test.rb @@ -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 diff --git a/test/vagrant/environment_test.rb b/test/vagrant/environment_test.rb index aa3c90216..4f75c090c 100644 --- a/test/vagrant/environment_test.rb +++ b/test/vagrant/environment_test.rb @@ -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 diff --git a/test/vagrant/provisioners/chef_server_test.rb b/test/vagrant/provisioners/chef_server_test.rb index fae97a331..dfab93850 100644 --- a/test/vagrant/provisioners/chef_server_test.rb +++ b/test/vagrant/provisioners/chef_server_test.rb @@ -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 diff --git a/test/vagrant/provisioners/chef_solo_test.rb b/test/vagrant/provisioners/chef_solo_test.rb index 91d3d6ca5..e326632c8 100644 --- a/test/vagrant/provisioners/chef_solo_test.rb +++ b/test/vagrant/provisioners/chef_solo_test.rb @@ -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