rvagrant 0.8.7.dev
Sign up to get free protection for your applications and to get access to all the features.
- data/.gitignore +25 -0
- data/.yardopts +1 -0
- data/CHANGELOG.md +386 -0
- data/Gemfile +21 -0
- data/LICENSE +21 -0
- data/README.md +61 -0
- data/Rakefile +11 -0
- data/bin/vagrant +28 -0
- data/config/default.rb +38 -0
- data/contrib/README.md +12 -0
- data/contrib/emacs/vagrant.el +8 -0
- data/contrib/vim/vagrantfile.vim +9 -0
- data/keys/README.md +17 -0
- data/keys/vagrant +27 -0
- data/keys/vagrant.ppk +26 -0
- data/keys/vagrant.pub +1 -0
- data/lib/vagrant.rb +44 -0
- data/lib/vagrant/action.rb +138 -0
- data/lib/vagrant/action/box.rb +11 -0
- data/lib/vagrant/action/box/destroy.rb +21 -0
- data/lib/vagrant/action/box/download.rb +72 -0
- data/lib/vagrant/action/box/package.rb +19 -0
- data/lib/vagrant/action/box/unpackage.rb +55 -0
- data/lib/vagrant/action/box/verify.rb +23 -0
- data/lib/vagrant/action/builder.rb +124 -0
- data/lib/vagrant/action/builtin.rb +108 -0
- data/lib/vagrant/action/env.rb +7 -0
- data/lib/vagrant/action/env/set.rb +18 -0
- data/lib/vagrant/action/environment.rb +50 -0
- data/lib/vagrant/action/general.rb +8 -0
- data/lib/vagrant/action/general/package.rb +113 -0
- data/lib/vagrant/action/general/validate.rb +19 -0
- data/lib/vagrant/action/vm.rb +34 -0
- data/lib/vagrant/action/vm/boot.rb +48 -0
- data/lib/vagrant/action/vm/check_accessible.rb +23 -0
- data/lib/vagrant/action/vm/check_box.rb +28 -0
- data/lib/vagrant/action/vm/check_guest_additions.rb +35 -0
- data/lib/vagrant/action/vm/clean_machine_folder.rb +43 -0
- data/lib/vagrant/action/vm/clear_forwarded_ports.rb +26 -0
- data/lib/vagrant/action/vm/clear_nfs_exports.rb +20 -0
- data/lib/vagrant/action/vm/clear_shared_folders.rb +27 -0
- data/lib/vagrant/action/vm/customize.rb +26 -0
- data/lib/vagrant/action/vm/destroy.rb +19 -0
- data/lib/vagrant/action/vm/destroy_unused_network_interfaces.rb +30 -0
- data/lib/vagrant/action/vm/discard_state.rb +22 -0
- data/lib/vagrant/action/vm/export.rb +52 -0
- data/lib/vagrant/action/vm/forward_ports.rb +133 -0
- data/lib/vagrant/action/vm/forward_ports_helpers.rb +28 -0
- data/lib/vagrant/action/vm/halt.rb +29 -0
- data/lib/vagrant/action/vm/host_name.rb +21 -0
- data/lib/vagrant/action/vm/import.rb +40 -0
- data/lib/vagrant/action/vm/match_mac_address.rb +26 -0
- data/lib/vagrant/action/vm/modify.rb +37 -0
- data/lib/vagrant/action/vm/network.rb +146 -0
- data/lib/vagrant/action/vm/nfs.rb +160 -0
- data/lib/vagrant/action/vm/nfs_helpers.rb +11 -0
- data/lib/vagrant/action/vm/package.rb +23 -0
- data/lib/vagrant/action/vm/package_vagrantfile.rb +33 -0
- data/lib/vagrant/action/vm/provision.rb +34 -0
- data/lib/vagrant/action/vm/provisioner_cleanup.rb +26 -0
- data/lib/vagrant/action/vm/resume.rb +20 -0
- data/lib/vagrant/action/vm/share_folders.rb +78 -0
- data/lib/vagrant/action/vm/suspend.rb +20 -0
- data/lib/vagrant/action/warden.rb +85 -0
- data/lib/vagrant/box.rb +90 -0
- data/lib/vagrant/box_collection.rb +53 -0
- data/lib/vagrant/cli.rb +55 -0
- data/lib/vagrant/command.rb +25 -0
- data/lib/vagrant/command/base.rb +106 -0
- data/lib/vagrant/command/box.rb +33 -0
- data/lib/vagrant/command/destroy.rb +17 -0
- data/lib/vagrant/command/group_base.rb +107 -0
- data/lib/vagrant/command/halt.rb +18 -0
- data/lib/vagrant/command/helpers.rb +33 -0
- data/lib/vagrant/command/init.rb +14 -0
- data/lib/vagrant/command/named_base.rb +14 -0
- data/lib/vagrant/command/package.rb +41 -0
- data/lib/vagrant/command/provision.rb +23 -0
- data/lib/vagrant/command/reload.rb +17 -0
- data/lib/vagrant/command/resume.rb +17 -0
- data/lib/vagrant/command/ssh.rb +49 -0
- data/lib/vagrant/command/ssh_config.rb +29 -0
- data/lib/vagrant/command/status.rb +31 -0
- data/lib/vagrant/command/suspend.rb +17 -0
- data/lib/vagrant/command/up.rb +19 -0
- data/lib/vagrant/command/upgrade_to_060.rb +45 -0
- data/lib/vagrant/command/version.rb +13 -0
- data/lib/vagrant/config.rb +123 -0
- data/lib/vagrant/config/base.rb +85 -0
- data/lib/vagrant/config/error_recorder.rb +19 -0
- data/lib/vagrant/config/nfs.rb +10 -0
- data/lib/vagrant/config/package.rb +9 -0
- data/lib/vagrant/config/ssh.rb +38 -0
- data/lib/vagrant/config/top.rb +61 -0
- data/lib/vagrant/config/vagrant.rb +17 -0
- data/lib/vagrant/config/vm.rb +148 -0
- data/lib/vagrant/config/vm/provisioner.rb +56 -0
- data/lib/vagrant/config/vm/sub_vm.rb +17 -0
- data/lib/vagrant/data_store.rb +70 -0
- data/lib/vagrant/downloaders.rb +7 -0
- data/lib/vagrant/downloaders/base.rb +23 -0
- data/lib/vagrant/downloaders/file.rb +22 -0
- data/lib/vagrant/downloaders/http.rb +70 -0
- data/lib/vagrant/environment.rb +516 -0
- data/lib/vagrant/errors.rb +352 -0
- data/lib/vagrant/hosts.rb +9 -0
- data/lib/vagrant/hosts/arch.rb +27 -0
- data/lib/vagrant/hosts/base.rb +76 -0
- data/lib/vagrant/hosts/bsd.rb +58 -0
- data/lib/vagrant/hosts/fedora.rb +11 -0
- data/lib/vagrant/hosts/linux.rb +69 -0
- data/lib/vagrant/plugin.rb +79 -0
- data/lib/vagrant/provisioners.rb +9 -0
- data/lib/vagrant/provisioners/base.rb +67 -0
- data/lib/vagrant/provisioners/chef.rb +155 -0
- data/lib/vagrant/provisioners/chef_client.rb +120 -0
- data/lib/vagrant/provisioners/chef_solo.rb +135 -0
- data/lib/vagrant/provisioners/puppet.rb +137 -0
- data/lib/vagrant/provisioners/puppet_server.rb +55 -0
- data/lib/vagrant/provisioners/shell.rb +96 -0
- data/lib/vagrant/ssh.rb +224 -0
- data/lib/vagrant/ssh/session.rb +136 -0
- data/lib/vagrant/systems.rb +13 -0
- data/lib/vagrant/systems/arch.rb +34 -0
- data/lib/vagrant/systems/base.rb +87 -0
- data/lib/vagrant/systems/debian.rb +36 -0
- data/lib/vagrant/systems/freebsd.rb +84 -0
- data/lib/vagrant/systems/gentoo.rb +27 -0
- data/lib/vagrant/systems/linux.rb +82 -0
- data/lib/vagrant/systems/linux/config.rb +21 -0
- data/lib/vagrant/systems/linux/error.rb +9 -0
- data/lib/vagrant/systems/redhat.rb +48 -0
- data/lib/vagrant/systems/solaris.rb +67 -0
- data/lib/vagrant/systems/suse.rb +9 -0
- data/lib/vagrant/systems/ubuntu.rb +17 -0
- data/lib/vagrant/test_helpers.rb +128 -0
- data/lib/vagrant/ui.rb +81 -0
- data/lib/vagrant/util.rb +13 -0
- data/lib/vagrant/util/busy.rb +59 -0
- data/lib/vagrant/util/counter.rb +24 -0
- data/lib/vagrant/util/hash_with_indifferent_access.rb +63 -0
- data/lib/vagrant/util/platform.rb +57 -0
- data/lib/vagrant/util/retryable.rb +25 -0
- data/lib/vagrant/util/safe_exec.rb +35 -0
- data/lib/vagrant/util/stacked_proc_runner.rb +35 -0
- data/lib/vagrant/util/template_renderer.rb +83 -0
- data/lib/vagrant/version.rb +6 -0
- data/lib/vagrant/vm.rb +181 -0
- data/templates/chef_server_client.erb +32 -0
- data/templates/chef_solo_solo.erb +23 -0
- data/templates/commands/init/Vagrantfile.erb +86 -0
- data/templates/config/validation_failed.erb +7 -0
- data/templates/locales/en.yml +556 -0
- data/templates/network_entry_arch.erb +9 -0
- data/templates/network_entry_debian.erb +8 -0
- data/templates/network_entry_gentoo.erb +5 -0
- data/templates/network_entry_redhat.erb +9 -0
- data/templates/nfs/exports.erb +5 -0
- data/templates/nfs/exports_linux.erb +5 -0
- data/templates/package_Vagrantfile.erb +11 -0
- data/templates/ssh_config.erb +15 -0
- data/test/unit/locales/en.yml +8 -0
- data/test/unit/test_helper.rb +28 -0
- data/test/unit/vagrant/action/box/destroy_test.rb +18 -0
- data/test/unit/vagrant/action/box/download_test.rb +125 -0
- data/test/unit/vagrant/action/box/package_test.rb +25 -0
- data/test/unit/vagrant/action/box/unpackage_test.rb +84 -0
- data/test/unit/vagrant/action/box/verify_test.rb +30 -0
- data/test/unit/vagrant/action/builder_test.rb +207 -0
- data/test/unit/vagrant/action/env/set_test.rb +24 -0
- data/test/unit/vagrant/action/environment_test.rb +27 -0
- data/test/unit/vagrant/action/general/package_test.rb +268 -0
- data/test/unit/vagrant/action/general/validate_test.rb +31 -0
- data/test/unit/vagrant/action/vm/boot_test.rb +66 -0
- data/test/unit/vagrant/action/vm/check_accessible_test.rb +61 -0
- data/test/unit/vagrant/action/vm/check_box_test.rb +56 -0
- data/test/unit/vagrant/action/vm/check_guest_additions_test.rb +9 -0
- data/test/unit/vagrant/action/vm/clean_machine_folder_test.rb +84 -0
- data/test/unit/vagrant/action/vm/clear_forwarded_ports_test.rb +52 -0
- data/test/unit/vagrant/action/vm/clear_nfs_exports_test.rb +22 -0
- data/test/unit/vagrant/action/vm/clear_shared_folders_test.rb +40 -0
- data/test/unit/vagrant/action/vm/customize_test.rb +37 -0
- data/test/unit/vagrant/action/vm/destroy_test.rb +25 -0
- data/test/unit/vagrant/action/vm/destroy_unused_network_interfaces_test.rb +49 -0
- data/test/unit/vagrant/action/vm/discard_state_test.rb +45 -0
- data/test/unit/vagrant/action/vm/export_test.rb +107 -0
- data/test/unit/vagrant/action/vm/forward_ports_helpers_test.rb +77 -0
- data/test/unit/vagrant/action/vm/forward_ports_test.rb +213 -0
- data/test/unit/vagrant/action/vm/halt_test.rb +79 -0
- data/test/unit/vagrant/action/vm/host_name_test.rb +36 -0
- data/test/unit/vagrant/action/vm/import_test.rb +66 -0
- data/test/unit/vagrant/action/vm/match_mac_address_test.rb +40 -0
- data/test/unit/vagrant/action/vm/modify_test.rb +38 -0
- data/test/unit/vagrant/action/vm/network_test.rb +286 -0
- data/test/unit/vagrant/action/vm/nfs_helpers_test.rb +26 -0
- data/test/unit/vagrant/action/vm/nfs_test.rb +260 -0
- data/test/unit/vagrant/action/vm/package_test.rb +25 -0
- data/test/unit/vagrant/action/vm/package_vagrantfile_test.rb +46 -0
- data/test/unit/vagrant/action/vm/provision_test.rb +65 -0
- data/test/unit/vagrant/action/vm/provisioner_cleanup_test.rb +56 -0
- data/test/unit/vagrant/action/vm/resume_test.rb +35 -0
- data/test/unit/vagrant/action/vm/share_folders_test.rb +144 -0
- data/test/unit/vagrant/action/vm/suspend_test.rb +35 -0
- data/test/unit/vagrant/action/warden_test.rb +125 -0
- data/test/unit/vagrant/action_test.rb +89 -0
- data/test/unit/vagrant/box_collection_test.rb +45 -0
- data/test/unit/vagrant/box_test.rb +74 -0
- data/test/unit/vagrant/cli_test.rb +35 -0
- data/test/unit/vagrant/command/base_test.rb +23 -0
- data/test/unit/vagrant/command/group_base_test.rb +15 -0
- data/test/unit/vagrant/command/helpers_test.rb +88 -0
- data/test/unit/vagrant/command/package_test.rb +27 -0
- data/test/unit/vagrant/config/base_test.rb +52 -0
- data/test/unit/vagrant/config/error_recorder_test.rb +18 -0
- data/test/unit/vagrant/config/ssh_test.rb +12 -0
- data/test/unit/vagrant/config/vagrant_test.rb +35 -0
- data/test/unit/vagrant/config/vm/provisioner_test.rb +92 -0
- data/test/unit/vagrant/config/vm_test.rb +56 -0
- data/test/unit/vagrant/config_test.rb +162 -0
- data/test/unit/vagrant/data_store_test.rb +77 -0
- data/test/unit/vagrant/downloaders/base_test.rb +28 -0
- data/test/unit/vagrant/downloaders/file_test.rb +48 -0
- data/test/unit/vagrant/downloaders/http_test.rb +82 -0
- data/test/unit/vagrant/environment_test.rb +598 -0
- data/test/unit/vagrant/errors_test.rb +42 -0
- data/test/unit/vagrant/hosts/base_test.rb +46 -0
- data/test/unit/vagrant/hosts/bsd_test.rb +53 -0
- data/test/unit/vagrant/hosts/linux_test.rb +54 -0
- data/test/unit/vagrant/plugin_test.rb +9 -0
- data/test/unit/vagrant/provisioners/base_test.rb +63 -0
- data/test/unit/vagrant/provisioners/chef_client_test.rb +190 -0
- data/test/unit/vagrant/provisioners/chef_solo_test.rb +114 -0
- data/test/unit/vagrant/provisioners/chef_test.rb +202 -0
- data/test/unit/vagrant/provisioners/puppet_server_test.rb +68 -0
- data/test/unit/vagrant/provisioners/puppet_test.rb +182 -0
- data/test/unit/vagrant/provisioners/shell_test.rb +79 -0
- data/test/unit/vagrant/ssh/session_test.rb +40 -0
- data/test/unit/vagrant/ssh_test.rb +307 -0
- data/test/unit/vagrant/systems/base_test.rb +18 -0
- data/test/unit/vagrant/systems/linux_test.rb +104 -0
- data/test/unit/vagrant/ui_test.rb +29 -0
- data/test/unit/vagrant/util/busy_test.rb +106 -0
- data/test/unit/vagrant/util/counter_test.rb +29 -0
- data/test/unit/vagrant/util/hash_with_indifferent_access_test.rb +39 -0
- data/test/unit/vagrant/util/platform_test.rb +18 -0
- data/test/unit/vagrant/util/retryable_test.rb +50 -0
- data/test/unit/vagrant/util/stacked_proc_runner_test.rb +43 -0
- data/test/unit/vagrant/util/template_renderer_test.rb +145 -0
- data/test/unit/vagrant/vm_test.rb +300 -0
- data/vagrant.gemspec +35 -0
- metadata +431 -0
@@ -0,0 +1,79 @@
|
|
1
|
+
require "test_helper"
|
2
|
+
|
3
|
+
class ShellProvisionerTest < Test::Unit::TestCase
|
4
|
+
setup do
|
5
|
+
clean_paths
|
6
|
+
|
7
|
+
@klass = Vagrant::Provisioners::Shell
|
8
|
+
@action_env = Vagrant::Action::Environment.new(vagrant_env.vms[:default].env)
|
9
|
+
@config = @klass::Config.new
|
10
|
+
@config.top = Vagrant::Config::Top.new(@action_env.env)
|
11
|
+
@action = @klass.new(@action_env, @config)
|
12
|
+
|
13
|
+
@config.path = "foo"
|
14
|
+
end
|
15
|
+
|
16
|
+
context "config" do
|
17
|
+
setup do
|
18
|
+
@errors = Vagrant::Config::ErrorRecorder.new
|
19
|
+
|
20
|
+
# Start in a valid state (verified by a test below)
|
21
|
+
@config.path = "foo"
|
22
|
+
File.open(@config.expanded_path, "w") { |f| f.puts "HELLO" }
|
23
|
+
end
|
24
|
+
|
25
|
+
should "be valid" do
|
26
|
+
@config.validate(@errors)
|
27
|
+
assert @errors.errors.empty?
|
28
|
+
end
|
29
|
+
|
30
|
+
should "be invalid if the path is not set" do
|
31
|
+
@config.path = nil
|
32
|
+
|
33
|
+
@config.validate(@errors)
|
34
|
+
assert !@errors.errors.empty?
|
35
|
+
end
|
36
|
+
|
37
|
+
should "be invalid if the path does not exist" do
|
38
|
+
@config.path = "bar"
|
39
|
+
|
40
|
+
@config.validate(@errors)
|
41
|
+
assert !@errors.errors.empty?
|
42
|
+
end
|
43
|
+
|
44
|
+
should "be invalid if the upload path is not set" do
|
45
|
+
@config.upload_path = nil
|
46
|
+
|
47
|
+
@config.validate(@errors)
|
48
|
+
assert !@errors.errors.empty?
|
49
|
+
end
|
50
|
+
end
|
51
|
+
|
52
|
+
context "provisioning" do
|
53
|
+
setup do
|
54
|
+
@ssh = mock("ssh")
|
55
|
+
@action.vm.ssh.stubs(:execute).yields(@ssh)
|
56
|
+
end
|
57
|
+
|
58
|
+
should "upload the file, chmod, then execute it" do
|
59
|
+
commands = ["chmod +x #{@config.upload_path}", @config.upload_path]
|
60
|
+
|
61
|
+
p_seq = sequence("provisioning")
|
62
|
+
@action.vm.ssh.expects(:upload!).with(@config.expanded_path.to_s, @config.upload_path).in_sequence(p_seq)
|
63
|
+
@ssh.expects(:sudo!).with(commands).in_sequence(p_seq)
|
64
|
+
|
65
|
+
@action.provision!
|
66
|
+
end
|
67
|
+
|
68
|
+
should "append arguments if provided" do
|
69
|
+
@config.args = "foo bar baz"
|
70
|
+
commands = ["chmod +x #{@config.upload_path}", "#{@config.upload_path} #{@config.args}"]
|
71
|
+
|
72
|
+
p_seq = sequence("provisioning")
|
73
|
+
@action.vm.ssh.expects(:upload!).with(@config.expanded_path.to_s, @config.upload_path).in_sequence(p_seq)
|
74
|
+
@ssh.expects(:sudo!).with(commands).in_sequence(p_seq)
|
75
|
+
|
76
|
+
@action.provision!
|
77
|
+
end
|
78
|
+
end
|
79
|
+
end
|
@@ -0,0 +1,40 @@
|
|
1
|
+
require "test_helper"
|
2
|
+
|
3
|
+
class SshSessionTest < Test::Unit::TestCase
|
4
|
+
setup do
|
5
|
+
@session = mock("session")
|
6
|
+
@env = vagrant_env
|
7
|
+
|
8
|
+
@klass = Vagrant::SSH::Session
|
9
|
+
@instance = @klass.new(@session, @env)
|
10
|
+
end
|
11
|
+
|
12
|
+
context "exec!" do
|
13
|
+
should "retry 5 times" do
|
14
|
+
@session.expects(:open_channel).times(5).raises(IOError)
|
15
|
+
assert_raises(IOError) {
|
16
|
+
@instance.exec!("foo")
|
17
|
+
}
|
18
|
+
end
|
19
|
+
end
|
20
|
+
|
21
|
+
context "checking exit status" do
|
22
|
+
should "raise an ActionException if its non-zero" do
|
23
|
+
assert_raises(Vagrant::Errors::VagrantError) {
|
24
|
+
@instance.check_exit_status(1, "foo")
|
25
|
+
}
|
26
|
+
end
|
27
|
+
|
28
|
+
should "raise the given exception if specified" do
|
29
|
+
assert_raises(Vagrant::Errors::BaseVMNotFound) {
|
30
|
+
@instance.check_exit_status(1, "foo", :_error_class => Vagrant::Errors::BaseVMNotFound)
|
31
|
+
}
|
32
|
+
end
|
33
|
+
|
34
|
+
should "raise nothing if its zero" do
|
35
|
+
assert_nothing_raised {
|
36
|
+
@instance.check_exit_status(0, "foo")
|
37
|
+
}
|
38
|
+
end
|
39
|
+
end
|
40
|
+
end
|
@@ -0,0 +1,307 @@
|
|
1
|
+
require "test_helper"
|
2
|
+
|
3
|
+
class SshTest < Test::Unit::TestCase
|
4
|
+
def mock_ssh
|
5
|
+
@env = vagrant_env.vms[:default].env
|
6
|
+
@network_adapters = []
|
7
|
+
@vm = mock("vm")
|
8
|
+
@vm.stubs(:network_adapters).returns(@network_adapters)
|
9
|
+
@env.vm.stubs(:vm).returns(@vm)
|
10
|
+
|
11
|
+
@ssh = Vagrant::SSH.new(@env)
|
12
|
+
end
|
13
|
+
|
14
|
+
setup do
|
15
|
+
VirtualBox.stubs(:version).returns("4.1.0")
|
16
|
+
end
|
17
|
+
|
18
|
+
context "connecting to external SSH" do
|
19
|
+
setup do
|
20
|
+
mock_ssh
|
21
|
+
@ssh.stubs(:check_key_permissions)
|
22
|
+
@ssh.stubs(:port).returns(2222)
|
23
|
+
@ssh.stubs(:safe_exec)
|
24
|
+
Kernel.stubs(:system).returns(true)
|
25
|
+
end
|
26
|
+
|
27
|
+
should "raise an exception if SSH is not found" do
|
28
|
+
Kernel.stubs(:system).returns(false)
|
29
|
+
Kernel.expects(:system).returns(false).with() do |command|
|
30
|
+
assert command =~ /^which ssh/
|
31
|
+
true
|
32
|
+
end
|
33
|
+
|
34
|
+
assert_raises(Vagrant::Errors::SSHUnavailable) {
|
35
|
+
@ssh.connect
|
36
|
+
}
|
37
|
+
end
|
38
|
+
|
39
|
+
should "check key permissions prior to exec" do
|
40
|
+
exec_seq = sequence("exec_seq")
|
41
|
+
@ssh.expects(:check_key_permissions).with(@env.config.ssh.private_key_path).once.in_sequence(exec_seq)
|
42
|
+
@ssh.expects(:safe_exec).in_sequence(exec_seq)
|
43
|
+
@ssh.connect
|
44
|
+
end
|
45
|
+
|
46
|
+
should "call exec with defaults when no options are supplied" do
|
47
|
+
ssh_exec_expect(@ssh.port,
|
48
|
+
@env.config.ssh.private_key_path,
|
49
|
+
@env.config.ssh.username,
|
50
|
+
@env.config.ssh.host)
|
51
|
+
@ssh.connect
|
52
|
+
end
|
53
|
+
|
54
|
+
should "call exec with supplied params" do
|
55
|
+
args = {:username => 'bar', :private_key_path => 'baz', :host => 'bak'}
|
56
|
+
ssh_exec_expect(@ssh.port, args[:private_key_path], args[:username], args[:host])
|
57
|
+
@ssh.connect(args)
|
58
|
+
end
|
59
|
+
|
60
|
+
should "add forward agent option if enabled" do
|
61
|
+
@env.config.ssh.forward_agent = true
|
62
|
+
ssh_exec_expect(@ssh.port,
|
63
|
+
@env.config.ssh.private_key_path,
|
64
|
+
@env.config.ssh.username,
|
65
|
+
@env.config.ssh.host) do |args|
|
66
|
+
assert args =~ /-o ForwardAgent=yes/
|
67
|
+
end
|
68
|
+
@ssh.connect
|
69
|
+
end
|
70
|
+
|
71
|
+
should "add forward X11 option if enabled" do
|
72
|
+
@env.config.ssh.forward_x11 = true
|
73
|
+
ssh_exec_expect(@ssh.port,
|
74
|
+
@env.config.ssh.private_key_path,
|
75
|
+
@env.config.ssh.username,
|
76
|
+
@env.config.ssh.host) do |args|
|
77
|
+
assert args =~ /-o ForwardX11=yes/
|
78
|
+
end
|
79
|
+
@ssh.connect
|
80
|
+
end
|
81
|
+
|
82
|
+
context "checking windows" do
|
83
|
+
should "error and exit if the platform is windows" do
|
84
|
+
Vagrant::Util::Platform.stubs(:windows?).returns(true)
|
85
|
+
assert_raises(Vagrant::Errors::SSHUnavailableWindows) { @ssh.connect }
|
86
|
+
end
|
87
|
+
|
88
|
+
should "not error and exit if the platform is anything other that windows" do
|
89
|
+
Vagrant::Util::Platform.stubs(:windows?).returns(false)
|
90
|
+
assert_nothing_raised { @ssh.connect }
|
91
|
+
end
|
92
|
+
end
|
93
|
+
|
94
|
+
def ssh_exec_expect(port, key_path, uname, host)
|
95
|
+
@ssh.expects(:safe_exec).with() do |arg|
|
96
|
+
assert arg =~ /^ssh/, "ssh command expected"
|
97
|
+
assert arg =~ /-p #{port}/, "-p #{port} expected"
|
98
|
+
assert arg =~ /-i #{key_path}/, "-i #{key_path} expected"
|
99
|
+
assert arg =~ /#{uname}@#{host}/, "#{uname}@{host} expected"
|
100
|
+
yield arg if block_given?
|
101
|
+
true
|
102
|
+
end
|
103
|
+
end
|
104
|
+
end
|
105
|
+
|
106
|
+
context "executing ssh commands" do
|
107
|
+
setup do
|
108
|
+
mock_ssh
|
109
|
+
@ssh.stubs(:check_key_permissions)
|
110
|
+
@ssh.stubs(:port).returns(80)
|
111
|
+
end
|
112
|
+
|
113
|
+
should "check key permissions then attempt to start connection" do
|
114
|
+
seq = sequence("seq")
|
115
|
+
@ssh.expects(:check_key_permissions).with(@env.config.ssh.private_key_path).once.in_sequence(seq)
|
116
|
+
Net::SSH.expects(:start).once.in_sequence(seq)
|
117
|
+
@ssh.execute
|
118
|
+
end
|
119
|
+
|
120
|
+
should "call net::ssh.start with the proper names" do
|
121
|
+
Net::SSH.expects(:start).once.with() do |host, username, opts|
|
122
|
+
assert_equal @env.config.ssh.host, host
|
123
|
+
assert_equal @env.config.ssh.username, username
|
124
|
+
assert_equal @ssh.port, opts[:port]
|
125
|
+
assert_equal [@env.config.ssh.private_key_path], opts[:keys]
|
126
|
+
assert opts[:keys_only]
|
127
|
+
true
|
128
|
+
end
|
129
|
+
@ssh.execute
|
130
|
+
end
|
131
|
+
|
132
|
+
should "forward agent if configured" do
|
133
|
+
@env.config.ssh.forward_agent = true
|
134
|
+
Net::SSH.expects(:start).once.with() do |host, username, opts|
|
135
|
+
assert opts[:forward_agent]
|
136
|
+
true
|
137
|
+
end
|
138
|
+
|
139
|
+
@ssh.execute
|
140
|
+
end
|
141
|
+
|
142
|
+
should "use custom host if set" do
|
143
|
+
@env.config.ssh.host = "foo"
|
144
|
+
Net::SSH.expects(:start).with(@env.config.ssh.host, @env.config.ssh.username, anything).once
|
145
|
+
@ssh.execute
|
146
|
+
end
|
147
|
+
|
148
|
+
should "yield an SSH session object" do
|
149
|
+
raw = mock("raw")
|
150
|
+
Net::SSH.expects(:start).returns(raw)
|
151
|
+
@ssh.execute do |ssh|
|
152
|
+
assert ssh.is_a?(Vagrant::SSH::Session)
|
153
|
+
assert_equal raw, ssh.session
|
154
|
+
end
|
155
|
+
end
|
156
|
+
end
|
157
|
+
|
158
|
+
context "SCPing files to the remote host" do
|
159
|
+
setup do
|
160
|
+
mock_ssh
|
161
|
+
end
|
162
|
+
|
163
|
+
should "use Vagrant::SSH execute to setup an SCP connection and upload" do
|
164
|
+
scp = mock("scp")
|
165
|
+
ssh = mock("ssh")
|
166
|
+
sess = mock("session")
|
167
|
+
ssh.stubs(:session).returns(sess)
|
168
|
+
scp.expects(:upload!).with("foo", "bar").once
|
169
|
+
Net::SCP.expects(:new).with(ssh.session).returns(scp).once
|
170
|
+
@ssh.expects(:execute).yields(ssh).once
|
171
|
+
@ssh.upload!("foo", "bar")
|
172
|
+
end
|
173
|
+
end
|
174
|
+
|
175
|
+
context "checking if host is up" do
|
176
|
+
setup do
|
177
|
+
mock_ssh
|
178
|
+
@ssh.stubs(:check_key_permissions)
|
179
|
+
@ssh.stubs(:port).returns(2222)
|
180
|
+
end
|
181
|
+
|
182
|
+
should "return true if SSH connection works" do
|
183
|
+
Net::SSH.expects(:start).yields("success")
|
184
|
+
assert @ssh.up?
|
185
|
+
end
|
186
|
+
|
187
|
+
should "return false if SSH connection times out" do
|
188
|
+
@env.config.ssh.timeout = 0.5
|
189
|
+
|
190
|
+
Net::SSH.stubs(:start).with() do
|
191
|
+
# Sleep here to artificially fake timeout
|
192
|
+
sleep 1
|
193
|
+
true
|
194
|
+
end
|
195
|
+
|
196
|
+
assert !@ssh.up?
|
197
|
+
end
|
198
|
+
|
199
|
+
should "return false if the connection is refused" do
|
200
|
+
Net::SSH.expects(:start).times(5).raises(Errno::ECONNREFUSED)
|
201
|
+
assert_nothing_raised {
|
202
|
+
assert !@ssh.up?
|
203
|
+
}
|
204
|
+
end
|
205
|
+
|
206
|
+
should "specifity the timeout as an option to execute" do
|
207
|
+
@ssh.expects(:execute).yields(true).with() do |opts|
|
208
|
+
assert_equal @env.config.ssh.timeout, opts[:timeout]
|
209
|
+
true
|
210
|
+
end
|
211
|
+
|
212
|
+
assert @ssh.up?
|
213
|
+
end
|
214
|
+
|
215
|
+
should "error and exit if a Net::SSH::AuthenticationFailed is raised" do
|
216
|
+
@ssh.expects(:execute).raises(Net::SSH::AuthenticationFailed)
|
217
|
+
assert_raises(Vagrant::Errors::SSHAuthenticationFailed) { @ssh.up? }
|
218
|
+
end
|
219
|
+
|
220
|
+
should "only get the port once (in the main thread)" do
|
221
|
+
@ssh.expects(:port).once.returns(2222)
|
222
|
+
@ssh.up?
|
223
|
+
end
|
224
|
+
end
|
225
|
+
|
226
|
+
context "getting the ssh port" do
|
227
|
+
setup do
|
228
|
+
mock_ssh
|
229
|
+
end
|
230
|
+
|
231
|
+
should "return the port given in options if it exists" do
|
232
|
+
assert_equal "47", @ssh.port({ :port => "47" })
|
233
|
+
end
|
234
|
+
end
|
235
|
+
|
236
|
+
context "checking key permissions" do
|
237
|
+
setup do
|
238
|
+
mock_ssh
|
239
|
+
@ssh.stubs(:file_perms)
|
240
|
+
|
241
|
+
@key_path = "foo"
|
242
|
+
|
243
|
+
|
244
|
+
@stat = mock("stat")
|
245
|
+
@stat.stubs(:owned?).returns(true)
|
246
|
+
File.stubs(:stat).returns(@stat)
|
247
|
+
|
248
|
+
Vagrant::Util::Platform.stubs(:windows?).returns(false)
|
249
|
+
end
|
250
|
+
|
251
|
+
should "do nothing if on windows" do
|
252
|
+
Vagrant::Util::Platform.stubs(:windows?).returns(true)
|
253
|
+
File.expects(:stat).never
|
254
|
+
@ssh.check_key_permissions(@key_path)
|
255
|
+
end
|
256
|
+
|
257
|
+
should "do nothing if the user is not the owner" do
|
258
|
+
@stat.expects(:owned?).returns(false)
|
259
|
+
File.expects(:chmod).never
|
260
|
+
@ssh.check_key_permissions(@key_path)
|
261
|
+
end
|
262
|
+
|
263
|
+
should "do nothing if the file perms equal 600" do
|
264
|
+
@ssh.expects(:file_perms).with(@key_path).returns("600")
|
265
|
+
File.expects(:chmod).never
|
266
|
+
@ssh.check_key_permissions(@key_path)
|
267
|
+
end
|
268
|
+
|
269
|
+
should "chmod the file if the file perms aren't 600" do
|
270
|
+
perm_sequence = sequence("perm_seq")
|
271
|
+
@ssh.expects(:file_perms).returns("900").in_sequence(perm_sequence)
|
272
|
+
File.expects(:chmod).with(0600, @key_path).once.in_sequence(perm_sequence)
|
273
|
+
@ssh.expects(:file_perms).returns("600").in_sequence(perm_sequence)
|
274
|
+
assert_nothing_raised { @ssh.check_key_permissions(@key_path) }
|
275
|
+
end
|
276
|
+
|
277
|
+
should "error and exit if the resulting chmod doesn't work" do
|
278
|
+
perm_sequence = sequence("perm_seq")
|
279
|
+
@ssh.expects(:file_perms).returns("900").in_sequence(perm_sequence)
|
280
|
+
File.expects(:chmod).with(0600, @key_path).once.in_sequence(perm_sequence)
|
281
|
+
@ssh.expects(:file_perms).returns("900").in_sequence(perm_sequence)
|
282
|
+
assert_raises(Vagrant::Errors::SSHKeyBadPermissions) { @ssh.check_key_permissions(@key_path) }
|
283
|
+
end
|
284
|
+
|
285
|
+
should "error and exit if a bad file perm is raised" do
|
286
|
+
@ssh.expects(:file_perms).with(@key_path).returns("900")
|
287
|
+
File.expects(:chmod).raises(Errno::EPERM)
|
288
|
+
assert_raises(Vagrant::Errors::SSHKeyBadPermissions) { @ssh.check_key_permissions(@key_path) }
|
289
|
+
end
|
290
|
+
end
|
291
|
+
|
292
|
+
context "getting file permissions" do
|
293
|
+
setup do
|
294
|
+
mock_ssh
|
295
|
+
end
|
296
|
+
|
297
|
+
should "return the last 3 characters of the file mode" do
|
298
|
+
path = "foo"
|
299
|
+
mode = "10000foo"
|
300
|
+
stat = mock("stat")
|
301
|
+
File.expects(:stat).with(path).returns(stat)
|
302
|
+
stat.expects(:mode).returns(mode)
|
303
|
+
@ssh.expects(:sprintf).with("%o", mode).returns(mode)
|
304
|
+
assert_equal path, @ssh.file_perms(path)
|
305
|
+
end
|
306
|
+
end
|
307
|
+
end
|
@@ -0,0 +1,18 @@
|
|
1
|
+
require "test_helper"
|
2
|
+
|
3
|
+
class BaseSystemTest < Test::Unit::TestCase
|
4
|
+
setup do
|
5
|
+
@klass = Vagrant::Systems::Base
|
6
|
+
|
7
|
+
@vm = mock("vm")
|
8
|
+
@instance = @klass.new(@vm)
|
9
|
+
end
|
10
|
+
|
11
|
+
should "provide access to the VM" do
|
12
|
+
assert_equal @vm, @instance.vm
|
13
|
+
end
|
14
|
+
|
15
|
+
should "error on preparing host only network" do
|
16
|
+
assert_raises(@klass::BaseError) { @instance.prepare_host_only_network }
|
17
|
+
end
|
18
|
+
end
|
@@ -0,0 +1,104 @@
|
|
1
|
+
require "test_helper"
|
2
|
+
|
3
|
+
class LinuxSystemTest < Test::Unit::TestCase
|
4
|
+
setup do
|
5
|
+
@klass = Vagrant::Systems::Linux
|
6
|
+
@ssh = mock("ssh")
|
7
|
+
@mock_env = vagrant_env
|
8
|
+
@vm = mock("vm")
|
9
|
+
@vm.stubs(:env).returns(@mock_env)
|
10
|
+
@instance = @klass.new(@vm)
|
11
|
+
end
|
12
|
+
|
13
|
+
context "halting" do
|
14
|
+
setup do
|
15
|
+
@ssh_session = mock("ssh_session")
|
16
|
+
@ssh.stubs(:execute).yields(@ssh_session)
|
17
|
+
@vm.stubs(:ssh).returns(@ssh)
|
18
|
+
|
19
|
+
@real_vm = mock("real_vm")
|
20
|
+
@real_vm.stubs(:state).returns(:powered_off)
|
21
|
+
@vm.stubs(:vm).returns(@real_vm)
|
22
|
+
end
|
23
|
+
|
24
|
+
should "execute halt via SSH" do
|
25
|
+
@ssh_session.expects(:exec!).with("sudo halt").once
|
26
|
+
@instance.halt
|
27
|
+
end
|
28
|
+
end
|
29
|
+
|
30
|
+
context "mounting shared folders" do
|
31
|
+
setup do
|
32
|
+
@name = "foo"
|
33
|
+
@guestpath = "/bar"
|
34
|
+
@owner = "owner"
|
35
|
+
@group = "group"
|
36
|
+
end
|
37
|
+
|
38
|
+
should "create the dir, mount the folder, then set permissions" do
|
39
|
+
mount_seq = sequence("mount_seq")
|
40
|
+
@ssh.expects(:exec!).with("sudo mkdir -p #{@guestpath}").in_sequence(mount_seq)
|
41
|
+
@instance.expects(:mount_folder).with(@ssh, @name, @guestpath, @owner, @group).in_sequence(mount_seq)
|
42
|
+
@ssh.expects(:exec!).with("sudo chown `id -u #{@owner}`:`id -g #{@group}` #{@guestpath}").in_sequence(mount_seq)
|
43
|
+
|
44
|
+
@instance.mount_shared_folder(@ssh, @name, @guestpath, @owner, @group)
|
45
|
+
end
|
46
|
+
end
|
47
|
+
|
48
|
+
#-------------------------------------------------------------------
|
49
|
+
# "Private" methods tests
|
50
|
+
#-------------------------------------------------------------------
|
51
|
+
context "mounting the main folder" do
|
52
|
+
setup do
|
53
|
+
@name = "foo"
|
54
|
+
@guestpath = "bar"
|
55
|
+
@owner = "owner"
|
56
|
+
@group = "group"
|
57
|
+
@sleeptime = 0
|
58
|
+
@limit = 10
|
59
|
+
|
60
|
+
@success_return = false
|
61
|
+
end
|
62
|
+
|
63
|
+
def mount_folder
|
64
|
+
@instance.mount_folder(@ssh, @name, @guestpath, @owner, @group, @sleeptime)
|
65
|
+
end
|
66
|
+
|
67
|
+
should "execute the proper mount command" do
|
68
|
+
@ssh.expects(:exec!).with("sudo mount -t vboxsf -o uid=`id -u #{@owner}`,gid=`id -g #{@group}` #{@name} #{@guestpath}").returns(@success_return)
|
69
|
+
mount_folder
|
70
|
+
end
|
71
|
+
|
72
|
+
should "test type of text and text string to detect error" do
|
73
|
+
data = mock("data")
|
74
|
+
data.expects(:[]=).with(:result, !@success_return)
|
75
|
+
|
76
|
+
@ssh.expects(:exec!).yields(data, :stderr, "No such device").returns(@success_return)
|
77
|
+
mount_folder
|
78
|
+
end
|
79
|
+
|
80
|
+
should "test type of text and test string to detect success" do
|
81
|
+
data = mock("data")
|
82
|
+
data.expects(:[]=).with(:result, @success_return)
|
83
|
+
|
84
|
+
@ssh.expects(:exec!).yields(data, :stdout, "Nothing such device").returns(@success_return)
|
85
|
+
mount_folder
|
86
|
+
end
|
87
|
+
|
88
|
+
should "raise an ActionException if the command fails constantly" do
|
89
|
+
@ssh.expects(:exec!).times(@limit).returns(!@success_return)
|
90
|
+
|
91
|
+
assert_raises(Vagrant::Systems::Linux::LinuxError) {
|
92
|
+
mount_folder
|
93
|
+
}
|
94
|
+
end
|
95
|
+
|
96
|
+
should "not raise any exception if the command succeeded" do
|
97
|
+
@ssh.expects(:exec!).once.returns(@success_return)
|
98
|
+
|
99
|
+
assert_nothing_raised {
|
100
|
+
mount_folder
|
101
|
+
}
|
102
|
+
end
|
103
|
+
end
|
104
|
+
end
|