fixed-vagrant 0.7.4.dev
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- data/.gitignore +15 -0
- data/.yardopts +1 -0
- data/CHANGELOG.md +272 -0
- data/Gemfile +21 -0
- data/LICENSE +21 -0
- data/README.md +75 -0
- data/Rakefile +22 -0
- data/bin/vagrant +22 -0
- data/config/default.rb +39 -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 +42 -0
- data/lib/vagrant/action.rb +134 -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 +104 -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 +109 -0
- data/lib/vagrant/action/general/validate.rb +19 -0
- data/lib/vagrant/action/vm.rb +31 -0
- data/lib/vagrant/action/vm/boot.rb +48 -0
- data/lib/vagrant/action/vm/check_box.rb +28 -0
- data/lib/vagrant/action/vm/check_guest_additions.rb +30 -0
- data/lib/vagrant/action/vm/clean_machine_folder.rb +43 -0
- data/lib/vagrant/action/vm/clear_forwarded_ports.rb +39 -0
- data/lib/vagrant/action/vm/clear_nfs_exports.rb +20 -0
- data/lib/vagrant/action/vm/clear_shared_folders.rb +32 -0
- data/lib/vagrant/action/vm/customize.rb +21 -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 +134 -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 +35 -0
- data/lib/vagrant/action/vm/match_mac_address.rb +21 -0
- data/lib/vagrant/action/vm/network.rb +139 -0
- data/lib/vagrant/action/vm/nfs.rb +159 -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 +41 -0
- data/lib/vagrant/action/vm/resume.rb +20 -0
- data/lib/vagrant/action/vm/share_folders.rb +70 -0
- data/lib/vagrant/action/vm/suspend.rb +20 -0
- data/lib/vagrant/action/warden.rb +79 -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 +17 -0
- data/lib/vagrant/command/reload.rb +17 -0
- data/lib/vagrant/command/resume.rb +17 -0
- data/lib/vagrant/command/ssh.rb +42 -0
- data/lib/vagrant/command/ssh_config.rb +26 -0
- data/lib/vagrant/command/status.rb +22 -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 +33 -0
- data/lib/vagrant/config/top.rb +61 -0
- data/lib/vagrant/config/vagrant.rb +16 -0
- data/lib/vagrant/config/vm.rb +137 -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 +64 -0
- data/lib/vagrant/environment.rb +392 -0
- data/lib/vagrant/errors.rb +332 -0
- data/lib/vagrant/hosts.rb +8 -0
- data/lib/vagrant/hosts/arch.rb +27 -0
- data/lib/vagrant/hosts/base.rb +78 -0
- data/lib/vagrant/hosts/bsd.rb +52 -0
- data/lib/vagrant/hosts/linux.rb +47 -0
- data/lib/vagrant/plugin.rb +57 -0
- data/lib/vagrant/provisioners.rb +9 -0
- data/lib/vagrant/provisioners/base.rb +63 -0
- data/lib/vagrant/provisioners/chef.rb +130 -0
- data/lib/vagrant/provisioners/chef_server.rb +103 -0
- data/lib/vagrant/provisioners/chef_solo.rb +142 -0
- data/lib/vagrant/provisioners/puppet.rb +137 -0
- data/lib/vagrant/provisioners/puppet_server.rb +55 -0
- data/lib/vagrant/provisioners/shell.rb +52 -0
- data/lib/vagrant/ssh.rb +173 -0
- data/lib/vagrant/ssh/session.rb +125 -0
- data/lib/vagrant/systems.rb +11 -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 +83 -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 +39 -0
- data/lib/vagrant/systems/solaris.rb +62 -0
- data/lib/vagrant/systems/ubuntu.rb +17 -0
- data/lib/vagrant/test_helpers.rb +128 -0
- data/lib/vagrant/ui.rb +69 -0
- data/lib/vagrant/util.rb +13 -0
- data/lib/vagrant/util/busy.rb +59 -0
- data/lib/vagrant/util/hash_with_indifferent_access.rb +63 -0
- data/lib/vagrant/util/plain_logger.rb +25 -0
- data/lib/vagrant/util/platform.rb +65 -0
- data/lib/vagrant/util/resource_logger.rb +63 -0
- data/lib/vagrant/util/retryable.rb +25 -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 +177 -0
- data/templates/chef_server_client.erb +18 -0
- data/templates/chef_solo_solo.erb +19 -0
- data/templates/commands/init/Vagrantfile.erb +82 -0
- data/templates/config/validation_failed.erb +7 -0
- data/templates/locales/en.yml +535 -0
- data/templates/network_entry_debian.erb +8 -0
- data/templates/network_entry_gentoo.erb +5 -0
- data/templates/network_entry_redhat.erb +8 -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 +9 -0
- data/test/locales/en.yml +8 -0
- data/test/test_helper.rb +26 -0
- data/test/vagrant/action/box/destroy_test.rb +18 -0
- data/test/vagrant/action/box/download_test.rb +125 -0
- data/test/vagrant/action/box/package_test.rb +25 -0
- data/test/vagrant/action/box/unpackage_test.rb +84 -0
- data/test/vagrant/action/box/verify_test.rb +30 -0
- data/test/vagrant/action/builder_test.rb +203 -0
- data/test/vagrant/action/env/set_test.rb +24 -0
- data/test/vagrant/action/environment_test.rb +27 -0
- data/test/vagrant/action/general/package_test.rb +268 -0
- data/test/vagrant/action/general/validate_test.rb +31 -0
- data/test/vagrant/action/vm/boot_test.rb +66 -0
- data/test/vagrant/action/vm/check_box_test.rb +56 -0
- data/test/vagrant/action/vm/check_guest_additions_test.rb +9 -0
- data/test/vagrant/action/vm/clean_machine_folder_test.rb +84 -0
- data/test/vagrant/action/vm/clear_forwarded_ports_test.rb +72 -0
- data/test/vagrant/action/vm/clear_nfs_exports_test.rb +22 -0
- data/test/vagrant/action/vm/clear_shared_folders_test.rb +49 -0
- data/test/vagrant/action/vm/customize_test.rb +30 -0
- data/test/vagrant/action/vm/destroy_test.rb +25 -0
- data/test/vagrant/action/vm/destroy_unused_network_interfaces_test.rb +49 -0
- data/test/vagrant/action/vm/discard_state_test.rb +45 -0
- data/test/vagrant/action/vm/export_test.rb +107 -0
- data/test/vagrant/action/vm/forward_ports_helpers_test.rb +70 -0
- data/test/vagrant/action/vm/forward_ports_test.rb +194 -0
- data/test/vagrant/action/vm/halt_test.rb +79 -0
- data/test/vagrant/action/vm/host_name_test.rb +36 -0
- data/test/vagrant/action/vm/import_test.rb +66 -0
- data/test/vagrant/action/vm/match_mac_address_test.rb +36 -0
- data/test/vagrant/action/vm/network_test.rb +286 -0
- data/test/vagrant/action/vm/nfs_helpers_test.rb +26 -0
- data/test/vagrant/action/vm/nfs_test.rb +260 -0
- data/test/vagrant/action/vm/package_test.rb +25 -0
- data/test/vagrant/action/vm/package_vagrantfile_test.rb +46 -0
- data/test/vagrant/action/vm/provision_test.rb +90 -0
- data/test/vagrant/action/vm/resume_test.rb +35 -0
- data/test/vagrant/action/vm/share_folders_test.rb +139 -0
- data/test/vagrant/action/vm/suspend_test.rb +35 -0
- data/test/vagrant/action/warden_test.rb +119 -0
- data/test/vagrant/action_test.rb +89 -0
- data/test/vagrant/box_collection_test.rb +45 -0
- data/test/vagrant/box_test.rb +74 -0
- data/test/vagrant/cli_test.rb +35 -0
- data/test/vagrant/command/base_test.rb +23 -0
- data/test/vagrant/command/group_base_test.rb +15 -0
- data/test/vagrant/command/helpers_test.rb +88 -0
- data/test/vagrant/command/package_test.rb +27 -0
- data/test/vagrant/config/base_test.rb +52 -0
- data/test/vagrant/config/error_recorder_test.rb +18 -0
- data/test/vagrant/config/ssh_test.rb +12 -0
- data/test/vagrant/config/vagrant_test.rb +35 -0
- data/test/vagrant/config/vm/provisioner_test.rb +92 -0
- data/test/vagrant/config/vm_test.rb +86 -0
- data/test/vagrant/config_test.rb +162 -0
- data/test/vagrant/data_store_test.rb +77 -0
- data/test/vagrant/downloaders/base_test.rb +28 -0
- data/test/vagrant/downloaders/file_test.rb +48 -0
- data/test/vagrant/downloaders/http_test.rb +80 -0
- data/test/vagrant/environment_test.rb +508 -0
- data/test/vagrant/errors_test.rb +42 -0
- data/test/vagrant/hosts/base_test.rb +46 -0
- data/test/vagrant/hosts/bsd_test.rb +53 -0
- data/test/vagrant/hosts/linux_test.rb +54 -0
- data/test/vagrant/plugin_test.rb +9 -0
- data/test/vagrant/provisioners/base_test.rb +63 -0
- data/test/vagrant/provisioners/chef_server_test.rb +188 -0
- data/test/vagrant/provisioners/chef_solo_test.rb +219 -0
- data/test/vagrant/provisioners/chef_test.rb +179 -0
- data/test/vagrant/provisioners/puppet_server_test.rb +68 -0
- data/test/vagrant/provisioners/puppet_test.rb +182 -0
- data/test/vagrant/provisioners/shell_test.rb +68 -0
- data/test/vagrant/ssh/session_test.rb +40 -0
- data/test/vagrant/ssh_test.rb +342 -0
- data/test/vagrant/systems/base_test.rb +18 -0
- data/test/vagrant/systems/linux_test.rb +114 -0
- data/test/vagrant/ui_test.rb +29 -0
- data/test/vagrant/util/busy_test.rb +106 -0
- data/test/vagrant/util/hash_with_indifferent_access_test.rb +39 -0
- data/test/vagrant/util/plain_logger_test.rb +17 -0
- data/test/vagrant/util/platform_test.rb +18 -0
- data/test/vagrant/util/resource_logger_test.rb +78 -0
- data/test/vagrant/util/retryable_test.rb +50 -0
- data/test/vagrant/util/stacked_proc_runner_test.rb +43 -0
- data/test/vagrant/util/template_renderer_test.rb +145 -0
- data/test/vagrant/vm_test.rb +291 -0
- data/vagrant.gemspec +36 -0
- metadata +514 -0
|
@@ -0,0 +1,43 @@
|
|
|
1
|
+
require "test_helper"
|
|
2
|
+
|
|
3
|
+
class StackedProcRunnerUtilTest < Test::Unit::TestCase
|
|
4
|
+
class TestClass
|
|
5
|
+
include Vagrant::Util::StackedProcRunner
|
|
6
|
+
end
|
|
7
|
+
|
|
8
|
+
setup do
|
|
9
|
+
@instance = TestClass.new
|
|
10
|
+
@instance.proc_stack.clear
|
|
11
|
+
end
|
|
12
|
+
|
|
13
|
+
should "not run the procs right away" do
|
|
14
|
+
obj = mock("obj")
|
|
15
|
+
obj.expects(:foo).never
|
|
16
|
+
@instance.push_proc { |config| obj.foo }
|
|
17
|
+
@instance.push_proc { |config| obj.foo }
|
|
18
|
+
@instance.push_proc { |config| obj.foo }
|
|
19
|
+
end
|
|
20
|
+
|
|
21
|
+
should "run the blocks when run_procs! is ran" do
|
|
22
|
+
obj = mock("obj")
|
|
23
|
+
obj.expects(:foo).times(2)
|
|
24
|
+
@instance.push_proc { obj.foo }
|
|
25
|
+
@instance.push_proc { obj.foo }
|
|
26
|
+
@instance.run_procs!
|
|
27
|
+
end
|
|
28
|
+
|
|
29
|
+
should "run the blocks with the same arguments" do
|
|
30
|
+
passed_config = mock("config")
|
|
31
|
+
@instance.push_proc { |config| assert passed_config.equal?(config) }
|
|
32
|
+
@instance.push_proc { |config| assert passed_config.equal?(config) }
|
|
33
|
+
@instance.run_procs!(passed_config)
|
|
34
|
+
end
|
|
35
|
+
|
|
36
|
+
should "not clear the blocks after running" do
|
|
37
|
+
obj = mock("obj")
|
|
38
|
+
obj.expects(:foo).times(2)
|
|
39
|
+
@instance.push_proc { obj.foo }
|
|
40
|
+
@instance.run_procs!
|
|
41
|
+
@instance.run_procs!
|
|
42
|
+
end
|
|
43
|
+
end
|
|
@@ -0,0 +1,145 @@
|
|
|
1
|
+
require "test_helper"
|
|
2
|
+
|
|
3
|
+
class TemplateRendererUtilTest < Test::Unit::TestCase
|
|
4
|
+
context "initializing" do
|
|
5
|
+
should "set the template to the given argument" do
|
|
6
|
+
r = Vagrant::Util::TemplateRenderer.new("foo")
|
|
7
|
+
assert_equal "foo", r.template
|
|
8
|
+
end
|
|
9
|
+
|
|
10
|
+
should "set any additional variables" do
|
|
11
|
+
r = Vagrant::Util::TemplateRenderer.new("foo", {:bar => :baz})
|
|
12
|
+
assert_equal :baz, r.bar
|
|
13
|
+
end
|
|
14
|
+
end
|
|
15
|
+
|
|
16
|
+
context "rendering" do
|
|
17
|
+
setup do
|
|
18
|
+
@template = "foo"
|
|
19
|
+
@r = Vagrant::Util::TemplateRenderer.new(@template)
|
|
20
|
+
@r.stubs(:full_template_path).returns(@template + "!")
|
|
21
|
+
|
|
22
|
+
@contents = "bar"
|
|
23
|
+
|
|
24
|
+
@file = mock("file")
|
|
25
|
+
@file.stubs(:read).returns(@contents)
|
|
26
|
+
File.stubs(:open).yields(@file)
|
|
27
|
+
end
|
|
28
|
+
|
|
29
|
+
should "open the template file for reading" do
|
|
30
|
+
File.expects(:open).with(@r.full_template_path, 'r').once
|
|
31
|
+
@r.render
|
|
32
|
+
end
|
|
33
|
+
|
|
34
|
+
should "set the template to the file contents, render, then set it back" do
|
|
35
|
+
result = "bar"
|
|
36
|
+
|
|
37
|
+
template_seq = sequence("template_seq")
|
|
38
|
+
@r.expects(:template=).with(@file.read).in_sequence(template_seq)
|
|
39
|
+
@r.expects(:render_string).returns(result).in_sequence(template_seq)
|
|
40
|
+
@r.expects(:template=).with(@template).in_sequence(template_seq)
|
|
41
|
+
assert_equal result, @r.render
|
|
42
|
+
end
|
|
43
|
+
|
|
44
|
+
should "render the ERB file in the context of the renderer" do
|
|
45
|
+
result = "bar"
|
|
46
|
+
template = "<%= foo %>"
|
|
47
|
+
@r.foo = result
|
|
48
|
+
@file.expects(:read).returns(template)
|
|
49
|
+
assert_equal result, @r.render
|
|
50
|
+
end
|
|
51
|
+
end
|
|
52
|
+
|
|
53
|
+
context "rendering as string" do
|
|
54
|
+
setup do
|
|
55
|
+
@result = "foo"
|
|
56
|
+
@erb = mock("erb")
|
|
57
|
+
@erb.stubs(:result).returns(@result)
|
|
58
|
+
|
|
59
|
+
@r = Vagrant::Util::TemplateRenderer.new("foo")
|
|
60
|
+
end
|
|
61
|
+
|
|
62
|
+
should "simply render the template as a string" do
|
|
63
|
+
Erubis::Eruby.expects(:new).with(@r.template, :trim => true).returns(@erb)
|
|
64
|
+
@erb.expects(:result).returns(@result)
|
|
65
|
+
assert_equal @result, @r.render_string
|
|
66
|
+
end
|
|
67
|
+
end
|
|
68
|
+
|
|
69
|
+
context "the full template path" do
|
|
70
|
+
setup do
|
|
71
|
+
@template = "foo"
|
|
72
|
+
@r = Vagrant::Util::TemplateRenderer.new(@template)
|
|
73
|
+
end
|
|
74
|
+
|
|
75
|
+
should "be the ERB file in the templates directory" do
|
|
76
|
+
result = Vagrant.source_root.join("templates", "#{@template}.erb")
|
|
77
|
+
assert_equal result.to_s, @r.full_template_path
|
|
78
|
+
end
|
|
79
|
+
|
|
80
|
+
should "remove duplicate path separators" do
|
|
81
|
+
@r.template = "foo///bar"
|
|
82
|
+
result = Vagrant.source_root.join("templates", "foo", "bar.erb")
|
|
83
|
+
assert_equal result.to_s, @r.full_template_path
|
|
84
|
+
end
|
|
85
|
+
end
|
|
86
|
+
|
|
87
|
+
context "class methods" do
|
|
88
|
+
context "render_with method" do
|
|
89
|
+
setup do
|
|
90
|
+
@template = "foo"
|
|
91
|
+
@r = Vagrant::Util::TemplateRenderer.new(@template)
|
|
92
|
+
@r.stubs(:render)
|
|
93
|
+
|
|
94
|
+
@method = :rawr
|
|
95
|
+
|
|
96
|
+
Vagrant::Util::TemplateRenderer.stubs(:new).with(@template, {}).returns(@r)
|
|
97
|
+
end
|
|
98
|
+
|
|
99
|
+
should "use the second argument as the template" do
|
|
100
|
+
Vagrant::Util::TemplateRenderer.expects(:new).with(@template, {}).returns(@r)
|
|
101
|
+
Vagrant::Util::TemplateRenderer.render_with(@method, @template)
|
|
102
|
+
end
|
|
103
|
+
|
|
104
|
+
should "send in additional argument to the renderer" do
|
|
105
|
+
data = {:hey => :foo}
|
|
106
|
+
Vagrant::Util::TemplateRenderer.expects(:new).with(@template, data).returns(@r)
|
|
107
|
+
Vagrant::Util::TemplateRenderer.render_with(@method, @template, data)
|
|
108
|
+
end
|
|
109
|
+
|
|
110
|
+
should "yield a block if given with the renderer as the argument" do
|
|
111
|
+
@r.expects(:yielded=).with(true).once
|
|
112
|
+
Vagrant::Util::TemplateRenderer.render_with(@method, @template) do |r|
|
|
113
|
+
r.yielded = true
|
|
114
|
+
end
|
|
115
|
+
end
|
|
116
|
+
|
|
117
|
+
should "render the result using the given method" do
|
|
118
|
+
result = mock('result')
|
|
119
|
+
@r.expects(@method).returns(result)
|
|
120
|
+
assert_equal result, Vagrant::Util::TemplateRenderer.render_with(@method, @template)
|
|
121
|
+
end
|
|
122
|
+
|
|
123
|
+
should "convert the given method to a sym prior to calling" do
|
|
124
|
+
@r.expects(@method.to_sym).returns(nil)
|
|
125
|
+
Vagrant::Util::TemplateRenderer.render_with(@method.to_s, @template)
|
|
126
|
+
end
|
|
127
|
+
end
|
|
128
|
+
|
|
129
|
+
context "render method" do
|
|
130
|
+
should "call render_with the render! method" do
|
|
131
|
+
args = ["foo", "bar", "baz"]
|
|
132
|
+
Vagrant::Util::TemplateRenderer.expects(:render_with).with(:render, *args)
|
|
133
|
+
Vagrant::Util::TemplateRenderer.render(*args)
|
|
134
|
+
end
|
|
135
|
+
end
|
|
136
|
+
|
|
137
|
+
context "render_string method" do
|
|
138
|
+
should "call render_with the render! method" do
|
|
139
|
+
args = ["foo", "bar", "baz"]
|
|
140
|
+
Vagrant::Util::TemplateRenderer.expects(:render_with).with(:render_string, *args)
|
|
141
|
+
Vagrant::Util::TemplateRenderer.render_string(*args)
|
|
142
|
+
end
|
|
143
|
+
end
|
|
144
|
+
end
|
|
145
|
+
end
|
|
@@ -0,0 +1,291 @@
|
|
|
1
|
+
require "test_helper"
|
|
2
|
+
|
|
3
|
+
class VMTest < Test::Unit::TestCase
|
|
4
|
+
setup do
|
|
5
|
+
@env = vagrant_env
|
|
6
|
+
end
|
|
7
|
+
|
|
8
|
+
context "finding a VM" do
|
|
9
|
+
should "return return an uncreated VM object if the VM is not found" do
|
|
10
|
+
VirtualBox::VM.expects(:find).returns(nil)
|
|
11
|
+
result = Vagrant::VM.find("foo")
|
|
12
|
+
assert result.is_a?(Vagrant::VM)
|
|
13
|
+
assert !result.created?
|
|
14
|
+
end
|
|
15
|
+
|
|
16
|
+
should "return a Vagrant::VM object for that VM if found" do
|
|
17
|
+
VirtualBox::VM.expects(:find).with("foo").returns("bar")
|
|
18
|
+
result = Vagrant::VM.find("foo", @env)
|
|
19
|
+
assert result.is_a?(Vagrant::VM)
|
|
20
|
+
assert_equal "bar", result.vm
|
|
21
|
+
end
|
|
22
|
+
end
|
|
23
|
+
|
|
24
|
+
context "vagrant VM instance" do
|
|
25
|
+
setup do
|
|
26
|
+
@vm_name = "foo"
|
|
27
|
+
@mock_vm = mock("vm")
|
|
28
|
+
@mock_vm.stubs(:running?).returns(false)
|
|
29
|
+
@vm = Vagrant::VM.new(:env => @env, :vm => @mock_vm, :name => @vm_name)
|
|
30
|
+
@mock_vm.stubs(:uuid).returns("foo")
|
|
31
|
+
end
|
|
32
|
+
|
|
33
|
+
context "checking if created" do
|
|
34
|
+
should "return true if the VM object is not nil" do
|
|
35
|
+
@vm.stubs(:vm).returns(:foo)
|
|
36
|
+
assert @vm.created?
|
|
37
|
+
end
|
|
38
|
+
|
|
39
|
+
should "return false if the VM object is nil" do
|
|
40
|
+
@vm.stubs(:vm).returns(nil)
|
|
41
|
+
assert !@vm.created?
|
|
42
|
+
end
|
|
43
|
+
end
|
|
44
|
+
|
|
45
|
+
context "setting the VM" do
|
|
46
|
+
setup do
|
|
47
|
+
@raw_vm = mock("vm")
|
|
48
|
+
@raw_vm.stubs(:uuid).returns("foobar")
|
|
49
|
+
end
|
|
50
|
+
|
|
51
|
+
should "set the VM" do
|
|
52
|
+
@vm.vm = @raw_vm
|
|
53
|
+
assert_equal @raw_vm, @vm.vm
|
|
54
|
+
end
|
|
55
|
+
|
|
56
|
+
should "add the VM to the active list" do
|
|
57
|
+
assert @env.local_data.empty?
|
|
58
|
+
@vm.vm = @raw_vm
|
|
59
|
+
assert_equal @raw_vm.uuid, @env.local_data[:active][@vm.name.to_s]
|
|
60
|
+
end
|
|
61
|
+
|
|
62
|
+
should "remove the VM from the active list if nil is given" do
|
|
63
|
+
@env.local_data[:active] = { @vm.name.to_s => "foo" }
|
|
64
|
+
|
|
65
|
+
assert @env.local_data[:active].has_key?(@vm.name.to_s) # sanity
|
|
66
|
+
@vm.vm = nil
|
|
67
|
+
|
|
68
|
+
# This becomes empty because vm= will commit the local data which
|
|
69
|
+
# actually prunes out the empty values.
|
|
70
|
+
assert @env.local_data.empty?
|
|
71
|
+
end
|
|
72
|
+
end
|
|
73
|
+
|
|
74
|
+
context "accessing the SSH object" do
|
|
75
|
+
setup do
|
|
76
|
+
# Reset this to nil to force the reload
|
|
77
|
+
@vm.instance_variable_set(:@ssh, nil)
|
|
78
|
+
|
|
79
|
+
@ssh = mock("ssh")
|
|
80
|
+
Vagrant::SSH.stubs(:new).returns(@ssh)
|
|
81
|
+
end
|
|
82
|
+
|
|
83
|
+
should "load it the first time, and only load it once" do
|
|
84
|
+
Vagrant::SSH.expects(:new).with(@vm.env).once.returns(@ssh)
|
|
85
|
+
@vm.ssh
|
|
86
|
+
@vm.ssh
|
|
87
|
+
@vm.ssh
|
|
88
|
+
end
|
|
89
|
+
end
|
|
90
|
+
|
|
91
|
+
context "loading associated system" do
|
|
92
|
+
should "error and exit if system is not specified" do
|
|
93
|
+
@vm.env.config.vm.system = nil
|
|
94
|
+
|
|
95
|
+
assert_raises(Vagrant::Errors::VMSystemError) {
|
|
96
|
+
@vm.load_system!
|
|
97
|
+
}
|
|
98
|
+
end
|
|
99
|
+
|
|
100
|
+
should "load the given system if specified" do
|
|
101
|
+
fake_class = Class.new(Vagrant::Systems::Base)
|
|
102
|
+
|
|
103
|
+
assert_nothing_raised { @vm.load_system!(fake_class) }
|
|
104
|
+
assert @vm.system.is_a?(fake_class)
|
|
105
|
+
end
|
|
106
|
+
|
|
107
|
+
context "with a class" do
|
|
108
|
+
should "initialize class if given" do
|
|
109
|
+
@vm.env.config.vm.system = Vagrant::Systems::Linux
|
|
110
|
+
|
|
111
|
+
assert_nothing_raised { @vm.load_system!}
|
|
112
|
+
assert @vm.system.is_a?(Vagrant::Systems::Linux)
|
|
113
|
+
end
|
|
114
|
+
|
|
115
|
+
should "raise error if class has invalid parent" do
|
|
116
|
+
@vm.env.config.vm.system = Class.new
|
|
117
|
+
assert_raises(Vagrant::Errors::VMSystemError) {
|
|
118
|
+
@vm.load_system!
|
|
119
|
+
}
|
|
120
|
+
end
|
|
121
|
+
end
|
|
122
|
+
|
|
123
|
+
context "with a symbol" do
|
|
124
|
+
should "initialize proper symbols" do
|
|
125
|
+
valid = {
|
|
126
|
+
:linux => Vagrant::Systems::Linux,
|
|
127
|
+
:solaris => Vagrant::Systems::Solaris
|
|
128
|
+
}
|
|
129
|
+
|
|
130
|
+
valid.each do |symbol, klass|
|
|
131
|
+
@vm.env.config.vm.system = symbol
|
|
132
|
+
|
|
133
|
+
assert_nothing_raised { @vm.load_system! }
|
|
134
|
+
assert @vm.system.is_a?(klass)
|
|
135
|
+
assert_equal @vm, @vm.system.vm
|
|
136
|
+
end
|
|
137
|
+
end
|
|
138
|
+
|
|
139
|
+
should "error and exit with invalid symbol" do
|
|
140
|
+
@vm.env.config.vm.system = :shall_never_exist
|
|
141
|
+
|
|
142
|
+
assert_raises(Vagrant::Errors::VMSystemError) {
|
|
143
|
+
@vm.load_system!
|
|
144
|
+
}
|
|
145
|
+
end
|
|
146
|
+
end
|
|
147
|
+
|
|
148
|
+
context "loading the distro" do
|
|
149
|
+
setup do
|
|
150
|
+
@vm.vm.stubs(:running?).returns(true)
|
|
151
|
+
end
|
|
152
|
+
|
|
153
|
+
should "not replace the distro if it is nil" do
|
|
154
|
+
@vm.env.config.vm.system = Class.new(Vagrant::Systems::Base)
|
|
155
|
+
|
|
156
|
+
@vm.load_system!
|
|
157
|
+
assert @vm.system.is_a?(@vm.env.config.vm.system)
|
|
158
|
+
end
|
|
159
|
+
|
|
160
|
+
should "replace the distro if it is not nil" do
|
|
161
|
+
@vm.env.config.vm.system = Class.new(Vagrant::Systems::Base) do
|
|
162
|
+
def distro_dispatch
|
|
163
|
+
:linux
|
|
164
|
+
end
|
|
165
|
+
end
|
|
166
|
+
|
|
167
|
+
@vm.load_system!
|
|
168
|
+
assert @vm.system.is_a?(Vagrant::Systems::Linux)
|
|
169
|
+
end
|
|
170
|
+
end
|
|
171
|
+
end
|
|
172
|
+
|
|
173
|
+
context "uuid" do
|
|
174
|
+
should "call UUID on VM object" do
|
|
175
|
+
uuid = mock("uuid")
|
|
176
|
+
@mock_vm.expects(:uuid).once.returns(uuid)
|
|
177
|
+
assert_equal uuid, @vm.uuid
|
|
178
|
+
end
|
|
179
|
+
|
|
180
|
+
should "return nil if vm is nil" do
|
|
181
|
+
@vm.expects(:vm).returns(nil)
|
|
182
|
+
assert @vm.uuid.nil?
|
|
183
|
+
end
|
|
184
|
+
end
|
|
185
|
+
|
|
186
|
+
context "reloading" do
|
|
187
|
+
should "load the same VM and set it" do
|
|
188
|
+
new_vm = mock("vm")
|
|
189
|
+
VirtualBox::VM.expects(:find).with(@mock_vm.uuid).returns(new_vm)
|
|
190
|
+
@vm.reload!
|
|
191
|
+
assert_equal new_vm, @vm.vm
|
|
192
|
+
end
|
|
193
|
+
end
|
|
194
|
+
|
|
195
|
+
context "packaging" do
|
|
196
|
+
should "execute the package action" do
|
|
197
|
+
@vm.env.actions.expects(:run).once.with() do |action, options|
|
|
198
|
+
assert_equal :package, action
|
|
199
|
+
assert_equal :bar, options[:foo]
|
|
200
|
+
true
|
|
201
|
+
end
|
|
202
|
+
|
|
203
|
+
@vm.package(:foo => :bar)
|
|
204
|
+
end
|
|
205
|
+
end
|
|
206
|
+
|
|
207
|
+
context "upping" do
|
|
208
|
+
should "execute the up action" do
|
|
209
|
+
@vm.env.actions.expects(:run).with(:up, nil).once
|
|
210
|
+
@vm.up
|
|
211
|
+
end
|
|
212
|
+
|
|
213
|
+
should "forward options to the action sequence" do
|
|
214
|
+
@vm.env.actions.expects(:run).with(:up, :foo => :bar).once
|
|
215
|
+
@vm.up(:foo => :bar)
|
|
216
|
+
end
|
|
217
|
+
end
|
|
218
|
+
|
|
219
|
+
context "halting" do
|
|
220
|
+
should "execute the halt action" do
|
|
221
|
+
@vm.env.actions.expects(:run).with(:halt, :foo => :bar).once
|
|
222
|
+
@vm.halt({:foo => :bar})
|
|
223
|
+
end
|
|
224
|
+
end
|
|
225
|
+
|
|
226
|
+
context "reloading action" do
|
|
227
|
+
should "execute the reload action" do
|
|
228
|
+
@vm.env.actions.expects(:run).with(:reload).once
|
|
229
|
+
@vm.reload
|
|
230
|
+
end
|
|
231
|
+
end
|
|
232
|
+
|
|
233
|
+
context "provisioning" do
|
|
234
|
+
should "execute the provision action" do
|
|
235
|
+
@vm.env.actions.expects(:run).with(:provision).once
|
|
236
|
+
@vm.provision
|
|
237
|
+
end
|
|
238
|
+
end
|
|
239
|
+
|
|
240
|
+
context "destroying" do
|
|
241
|
+
should "execute the destroy action" do
|
|
242
|
+
@vm.env.actions.expects(:run).with(:destroy).once
|
|
243
|
+
@vm.destroy
|
|
244
|
+
end
|
|
245
|
+
end
|
|
246
|
+
|
|
247
|
+
context "suspending" do
|
|
248
|
+
should "execute the suspend action" do
|
|
249
|
+
@vm.env.actions.expects(:run).with(:suspend).once
|
|
250
|
+
@vm.suspend
|
|
251
|
+
end
|
|
252
|
+
end
|
|
253
|
+
|
|
254
|
+
context "resuming" do
|
|
255
|
+
should "execute the resume action" do
|
|
256
|
+
@vm.env.actions.expects(:run).with(:resume).once
|
|
257
|
+
@vm.resume
|
|
258
|
+
end
|
|
259
|
+
end
|
|
260
|
+
|
|
261
|
+
context "starting" do
|
|
262
|
+
setup do
|
|
263
|
+
@mock_vm.stubs(:running?).returns(false)
|
|
264
|
+
@mock_vm.stubs(:saved?).returns(false)
|
|
265
|
+
end
|
|
266
|
+
|
|
267
|
+
should "not do anything if the VM is already running" do
|
|
268
|
+
@mock_vm.stubs(:running?).returns(true)
|
|
269
|
+
@vm.expects(:execute!).never
|
|
270
|
+
@vm.start
|
|
271
|
+
end
|
|
272
|
+
|
|
273
|
+
should "execute the resume action if saved" do
|
|
274
|
+
@mock_vm.expects(:saved?).returns(true)
|
|
275
|
+
@vm.expects(:resume).once
|
|
276
|
+
@vm.env.actions.expects(:run).with(:start, nil).never
|
|
277
|
+
@vm.start
|
|
278
|
+
end
|
|
279
|
+
|
|
280
|
+
should "execute the start action" do
|
|
281
|
+
@vm.env.actions.expects(:run).with(:start, nil).once
|
|
282
|
+
@vm.start
|
|
283
|
+
end
|
|
284
|
+
|
|
285
|
+
should "forward options to the action sequence" do
|
|
286
|
+
@vm.env.actions.expects(:run).with(:start, :foo => :bar).once
|
|
287
|
+
@vm.start(:foo => :bar)
|
|
288
|
+
end
|
|
289
|
+
end
|
|
290
|
+
end
|
|
291
|
+
end
|