vagrantup 0.2.0 → 0.3.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/Gemfile +4 -4
- data/Rakefile +3 -3
- data/VERSION +1 -1
- data/bin/vagrant +5 -13
- data/config/default.rb +1 -0
- data/keys/README.md +8 -1
- data/keys/vagrant.ppk +26 -0
- data/lib/vagrant.rb +3 -3
- data/lib/vagrant/actions/base.rb +15 -4
- data/lib/vagrant/actions/box/add.rb +1 -1
- data/lib/vagrant/actions/box/download.rb +72 -66
- data/lib/vagrant/actions/box/unpackage.rb +1 -4
- data/lib/vagrant/actions/runner.rb +1 -1
- data/lib/vagrant/actions/vm/boot.rb +5 -7
- data/lib/vagrant/actions/vm/customize.rb +2 -2
- data/lib/vagrant/actions/vm/destroy.rb +2 -2
- data/lib/vagrant/actions/vm/down.rb +7 -0
- data/lib/vagrant/actions/vm/export.rb +10 -4
- data/lib/vagrant/actions/vm/forward_ports.rb +5 -15
- data/lib/vagrant/actions/vm/halt.rb +5 -3
- data/lib/vagrant/actions/vm/import.rb +10 -3
- data/lib/vagrant/actions/vm/move_hard_drive.rb +1 -3
- data/lib/vagrant/actions/vm/package.rb +33 -10
- data/lib/vagrant/actions/vm/provision.rb +4 -4
- data/lib/vagrant/actions/vm/reload.rb +1 -1
- data/lib/vagrant/actions/vm/resume.rb +1 -1
- data/lib/vagrant/actions/vm/shared_folders.rb +7 -7
- data/lib/vagrant/actions/vm/start.rb +3 -2
- data/lib/vagrant/actions/vm/suspend.rb +2 -2
- data/lib/vagrant/actions/vm/up.rb +7 -17
- data/lib/vagrant/active_list.rb +52 -45
- data/lib/vagrant/box.rb +18 -11
- data/lib/vagrant/busy.rb +7 -0
- data/lib/vagrant/command.rb +27 -0
- data/lib/vagrant/commands/base.rb +163 -0
- data/lib/vagrant/commands/box.rb +16 -0
- data/lib/vagrant/commands/box/add.rb +24 -0
- data/lib/vagrant/commands/box/list.rb +30 -0
- data/lib/vagrant/commands/box/remove.rb +31 -0
- data/lib/vagrant/commands/destroy.rb +23 -0
- data/lib/vagrant/commands/down.rb +16 -0
- data/lib/vagrant/commands/halt.rb +23 -0
- data/lib/vagrant/commands/init.rb +32 -0
- data/lib/vagrant/commands/package.rb +46 -0
- data/lib/vagrant/commands/reload.rb +22 -0
- data/lib/vagrant/commands/resume.rb +22 -0
- data/lib/vagrant/commands/ssh.rb +22 -0
- data/lib/vagrant/commands/ssh_config.rb +30 -0
- data/lib/vagrant/commands/status.rb +58 -0
- data/lib/vagrant/commands/suspend.rb +23 -0
- data/lib/vagrant/commands/up.rb +26 -0
- data/lib/vagrant/config.rb +21 -11
- data/lib/vagrant/downloaders/file.rb +5 -5
- data/lib/vagrant/downloaders/http.rb +10 -15
- data/lib/vagrant/environment.rb +259 -0
- data/lib/vagrant/provisioners/base.rb +7 -0
- data/lib/vagrant/provisioners/chef.rb +24 -9
- data/lib/vagrant/provisioners/chef_server.rb +23 -48
- data/lib/vagrant/provisioners/chef_solo.rb +48 -22
- data/lib/vagrant/ssh.rb +95 -46
- data/lib/vagrant/util.rb +2 -2
- data/lib/vagrant/util/errors.rb +36 -0
- data/lib/vagrant/util/platform.rb +12 -0
- data/lib/vagrant/util/progress_meter.rb +33 -0
- data/lib/vagrant/util/stacked_proc_runner.rb +35 -0
- data/lib/vagrant/util/template_renderer.rb +83 -0
- data/lib/vagrant/vm.rb +1 -0
- data/templates/{Vagrantfile → Vagrantfile.erb} +2 -2
- data/templates/chef_server_client.erb +16 -0
- data/templates/chef_solo_solo.erb +4 -0
- data/templates/errors.yml +157 -0
- data/templates/package_Vagrantfile.erb +11 -0
- data/templates/ssh_config.erb +7 -0
- data/test/test_helper.rb +12 -15
- data/test/vagrant/actions/box/add_test.rb +1 -2
- data/test/vagrant/actions/box/destroy_test.rb +0 -1
- data/test/vagrant/actions/box/download_test.rb +40 -15
- data/test/vagrant/actions/box/unpackage_test.rb +2 -3
- data/test/vagrant/actions/collection_test.rb +8 -5
- data/test/vagrant/actions/runner_test.rb +8 -6
- data/test/vagrant/actions/vm/boot_test.rb +12 -11
- data/test/vagrant/actions/vm/customize_test.rb +2 -3
- data/test/vagrant/actions/vm/destroy_test.rb +2 -3
- data/test/vagrant/actions/vm/down_test.rb +16 -3
- data/test/vagrant/actions/vm/export_test.rb +4 -5
- data/test/vagrant/actions/vm/forward_ports_test.rb +6 -5
- data/test/vagrant/actions/vm/halt_test.rb +8 -2
- data/test/vagrant/actions/vm/import_test.rb +5 -5
- data/test/vagrant/actions/vm/move_hard_drive_test.rb +4 -6
- data/test/vagrant/actions/vm/package_test.rb +60 -22
- data/test/vagrant/actions/vm/provision_test.rb +7 -16
- data/test/vagrant/actions/vm/reload_test.rb +3 -2
- data/test/vagrant/actions/vm/resume_test.rb +0 -1
- data/test/vagrant/actions/vm/shared_folders_test.rb +17 -12
- data/test/vagrant/actions/vm/start_test.rb +10 -3
- data/test/vagrant/actions/vm/suspend_test.rb +1 -2
- data/test/vagrant/actions/vm/up_test.rb +19 -11
- data/test/vagrant/active_list_test.rb +148 -129
- data/test/vagrant/box_test.rb +26 -14
- data/test/vagrant/busy_test.rb +15 -6
- data/test/vagrant/command_test.rb +53 -0
- data/test/vagrant/commands/base_test.rb +118 -0
- data/test/vagrant/commands/box/add_test.rb +34 -0
- data/test/vagrant/commands/box/list_test.rb +32 -0
- data/test/vagrant/commands/box/remove_test.rb +41 -0
- data/test/vagrant/commands/destroy_test.rb +32 -0
- data/test/vagrant/commands/down_test.rb +17 -0
- data/test/vagrant/commands/halt_test.rb +28 -0
- data/test/vagrant/commands/init_test.rb +55 -0
- data/test/vagrant/commands/package_test.rb +84 -0
- data/test/vagrant/commands/reload_test.rb +28 -0
- data/test/vagrant/commands/resume_test.rb +33 -0
- data/test/vagrant/commands/ssh_config_test.rb +54 -0
- data/test/vagrant/commands/ssh_test.rb +32 -0
- data/test/vagrant/commands/status_test.rb +20 -0
- data/test/vagrant/commands/suspend_test.rb +33 -0
- data/test/vagrant/commands/up_test.rb +41 -0
- data/test/vagrant/config_test.rb +42 -17
- data/test/vagrant/downloaders/file_test.rb +7 -0
- data/test/vagrant/downloaders/http_test.rb +12 -0
- data/test/vagrant/environment_test.rb +595 -0
- data/test/vagrant/provisioners/base_test.rb +7 -1
- data/test/vagrant/provisioners/chef_server_test.rb +41 -51
- data/test/vagrant/provisioners/chef_solo_test.rb +93 -62
- data/test/vagrant/provisioners/chef_test.rb +61 -15
- data/test/vagrant/ssh_test.rb +166 -38
- data/test/vagrant/util/errors_test.rb +57 -0
- data/test/vagrant/util/progress_meter_test.rb +33 -0
- data/test/vagrant/{stacked_proc_runner_test.rb → util/stacked_proc_runner_test.rb} +3 -3
- data/test/vagrant/util/template_renderer_test.rb +138 -0
- data/test/vagrant/vm_test.rb +3 -2
- data/vagrant.gemspec +88 -33
- metadata +92 -49
- data/bin/vagrant-box +0 -34
- data/bin/vagrant-down +0 -27
- data/bin/vagrant-halt +0 -28
- data/bin/vagrant-init +0 -27
- data/bin/vagrant-package +0 -29
- data/bin/vagrant-reload +0 -29
- data/bin/vagrant-resume +0 -27
- data/bin/vagrant-ssh +0 -27
- data/bin/vagrant-status +0 -29
- data/bin/vagrant-suspend +0 -27
- data/bin/vagrant-up +0 -29
- data/lib/vagrant/commands.rb +0 -234
- data/lib/vagrant/env.rb +0 -189
- data/lib/vagrant/stacked_proc_runner.rb +0 -33
- data/test/vagrant/commands_test.rb +0 -269
- data/test/vagrant/env_test.rb +0 -418
data/lib/vagrant/env.rb
DELETED
@@ -1,189 +0,0 @@
|
|
1
|
-
module Vagrant
|
2
|
-
class Env
|
3
|
-
ROOTFILE_NAME = "Vagrantfile"
|
4
|
-
HOME_SUBDIRS = ["tmp", "boxes"]
|
5
|
-
|
6
|
-
# Initialize class variables used
|
7
|
-
@@persisted_vm = nil
|
8
|
-
@@root_path = nil
|
9
|
-
@@box = nil
|
10
|
-
|
11
|
-
extend Vagrant::Util
|
12
|
-
|
13
|
-
class << self
|
14
|
-
def box; @@box; end
|
15
|
-
def persisted_vm; @@persisted_vm; end
|
16
|
-
def root_path; @@root_path; end
|
17
|
-
def dotfile_path;File.join(root_path, Vagrant.config.vagrant.dotfile_name); end
|
18
|
-
def home_path; File.expand_path(Vagrant.config.vagrant.home); end
|
19
|
-
def tmp_path; File.join(home_path, "tmp"); end
|
20
|
-
def boxes_path; File.join(home_path, "boxes"); end
|
21
|
-
|
22
|
-
def load!
|
23
|
-
load_root_path!
|
24
|
-
load_config!
|
25
|
-
load_home_directory!
|
26
|
-
load_box!
|
27
|
-
load_config!
|
28
|
-
check_virtualbox!
|
29
|
-
load_vm!
|
30
|
-
end
|
31
|
-
|
32
|
-
def check_virtualbox!
|
33
|
-
version = VirtualBox::Command.version
|
34
|
-
if version.nil?
|
35
|
-
error_and_exit(<<-msg)
|
36
|
-
Vagrant could not detect VirtualBox! Make sure VirtualBox is properly installed.
|
37
|
-
If VirtualBox is installed, you may need to tweak the paths to the `VBoxManage`
|
38
|
-
application which ships with VirtualBox and the path to the global XML configuration
|
39
|
-
which VirtualBox typically stores somewhere in your home directory.
|
40
|
-
|
41
|
-
The following shows how to configure VirtualBox. This can be done in the
|
42
|
-
Vagrantfile. Note that 90% of the time, you shouldn't need to do this if VirtualBox
|
43
|
-
is installed. Please use the various Vagrant support lines to request more information
|
44
|
-
if you can't get this working.
|
45
|
-
|
46
|
-
VirtualBox::Command.vboxmanage = "/path/to/my/VBoxManage"
|
47
|
-
VirtualBox::Global.vboxconfig = "~/path/to/VirtualBox.xml"
|
48
|
-
msg
|
49
|
-
elsif version.to_f < 3.1
|
50
|
-
error_and_exit(<<-msg)
|
51
|
-
Vagrant has detected that you have VirtualBox version #{version} installed!
|
52
|
-
Vagrant requires that you use at least VirtualBox version 3.1. Please install
|
53
|
-
a more recent version of VirtualBox to continue.
|
54
|
-
msg
|
55
|
-
end
|
56
|
-
end
|
57
|
-
|
58
|
-
def load_config!
|
59
|
-
# Prepare load paths for config files
|
60
|
-
load_paths = [File.join(PROJECT_ROOT, "config", "default.rb")]
|
61
|
-
load_paths << File.join(box.directory, ROOTFILE_NAME) if box
|
62
|
-
load_paths << File.join(home_path, ROOTFILE_NAME) if Vagrant.config.vagrant.home
|
63
|
-
load_paths << File.join(root_path, ROOTFILE_NAME) if root_path
|
64
|
-
|
65
|
-
# Then clear out the old data
|
66
|
-
Config.reset!
|
67
|
-
|
68
|
-
load_paths.each do |path|
|
69
|
-
if File.exist?(path)
|
70
|
-
logger.info "Loading config from #{path}..."
|
71
|
-
load path
|
72
|
-
end
|
73
|
-
end
|
74
|
-
|
75
|
-
# Execute the configurations
|
76
|
-
Config.execute!
|
77
|
-
end
|
78
|
-
|
79
|
-
def load_home_directory!
|
80
|
-
home_dir = File.expand_path(Vagrant.config.vagrant.home)
|
81
|
-
|
82
|
-
dirs = HOME_SUBDIRS.collect { |path| File.join(home_dir, path) }
|
83
|
-
dirs.unshift(home_dir)
|
84
|
-
|
85
|
-
dirs.each do |dir|
|
86
|
-
next if File.directory?(dir)
|
87
|
-
|
88
|
-
logger.info "Creating home directory since it doesn't exist: #{dir}"
|
89
|
-
FileUtils.mkdir_p(dir)
|
90
|
-
end
|
91
|
-
end
|
92
|
-
|
93
|
-
def load_box!
|
94
|
-
return unless root_path
|
95
|
-
|
96
|
-
@@box = Box.find(Vagrant.config.vm.box) if Vagrant.config.vm.box
|
97
|
-
end
|
98
|
-
|
99
|
-
def load_vm!
|
100
|
-
return if !root_path || !File.file?(dotfile_path)
|
101
|
-
|
102
|
-
File.open(dotfile_path) do |f|
|
103
|
-
@@persisted_vm = Vagrant::VM.find(f.read)
|
104
|
-
end
|
105
|
-
rescue Errno::ENOENT
|
106
|
-
@@persisted_vm = nil
|
107
|
-
end
|
108
|
-
|
109
|
-
def persist_vm(vm)
|
110
|
-
# Save to the dotfile for this project
|
111
|
-
File.open(dotfile_path, 'w+') do |f|
|
112
|
-
f.write(vm.uuid)
|
113
|
-
end
|
114
|
-
|
115
|
-
# Also add to the global store
|
116
|
-
ActiveList.add(vm)
|
117
|
-
end
|
118
|
-
|
119
|
-
def depersist_vm(vm)
|
120
|
-
# Delete the dotfile if it exists
|
121
|
-
File.delete(dotfile_path) if File.exist?(dotfile_path)
|
122
|
-
|
123
|
-
# Remove from the global store
|
124
|
-
ActiveList.remove(vm)
|
125
|
-
end
|
126
|
-
|
127
|
-
def load_root_path!(path=nil)
|
128
|
-
path = Pathname.new(File.expand_path(path || Dir.pwd))
|
129
|
-
|
130
|
-
# Stop if we're at the root.
|
131
|
-
return false if path.root?
|
132
|
-
|
133
|
-
file = "#{path}/#{ROOTFILE_NAME}"
|
134
|
-
if File.exist?(file)
|
135
|
-
@@root_path = path.to_s
|
136
|
-
return true
|
137
|
-
end
|
138
|
-
|
139
|
-
load_root_path!(path.parent)
|
140
|
-
end
|
141
|
-
|
142
|
-
def require_root_path
|
143
|
-
if !root_path
|
144
|
-
error_and_exit(<<-msg)
|
145
|
-
A `#{ROOTFILE_NAME}` was not found! This file is required for vagrant to run
|
146
|
-
since it describes the expected environment that vagrant is supposed
|
147
|
-
to manage. Please create a #{ROOTFILE_NAME} and place it in your project
|
148
|
-
root.
|
149
|
-
msg
|
150
|
-
end
|
151
|
-
end
|
152
|
-
|
153
|
-
def require_box
|
154
|
-
require_root_path
|
155
|
-
|
156
|
-
if !box
|
157
|
-
if !Vagrant.config.vm.box
|
158
|
-
error_and_exit(<<-msg)
|
159
|
-
No base box was specified! A base box is required as a staring point
|
160
|
-
for every vagrant virtual machine. Please specify one in your Vagrantfile
|
161
|
-
using `config.vm.box`
|
162
|
-
msg
|
163
|
-
else
|
164
|
-
error_and_exit(<<-msg)
|
165
|
-
Specified box `#{Vagrant.config.vm.box}` does not exist!
|
166
|
-
|
167
|
-
The box must be added through the `vagrant box add` command. Please view
|
168
|
-
the documentation associated with the command for more information.
|
169
|
-
msg
|
170
|
-
end
|
171
|
-
end
|
172
|
-
end
|
173
|
-
|
174
|
-
def require_persisted_vm
|
175
|
-
require_root_path
|
176
|
-
|
177
|
-
if !persisted_vm
|
178
|
-
error_and_exit(<<-error)
|
179
|
-
The task you're trying to run requires that the vagrant environment
|
180
|
-
already be created, but unfortunately this vagrant still appears to
|
181
|
-
have no box! You can setup the environment by setting up your
|
182
|
-
#{ROOTFILE_NAME} and running `vagrant up`
|
183
|
-
error
|
184
|
-
return
|
185
|
-
end
|
186
|
-
end
|
187
|
-
end
|
188
|
-
end
|
189
|
-
end
|
@@ -1,33 +0,0 @@
|
|
1
|
-
module Vagrant
|
2
|
-
# Represents the "stacked proc runner" behavior which is used a
|
3
|
-
# couple places within Vagrant. This allows procs to "stack" on
|
4
|
-
# each other, then all execute in a single action. An example of
|
5
|
-
# its uses can be seen in the {Config} class.
|
6
|
-
module StackedProcRunner
|
7
|
-
# Returns the proc stack. This should always be called as the
|
8
|
-
# accessor of the stack. The instance variable itself should _never_
|
9
|
-
# be used.
|
10
|
-
#
|
11
|
-
# @return [Array<Proc>]
|
12
|
-
def proc_stack
|
13
|
-
@_proc_stack ||= []
|
14
|
-
end
|
15
|
-
|
16
|
-
# Adds (pushes) a proc to the stack. The actual proc added here is
|
17
|
-
# not executed, but merely stored.
|
18
|
-
#
|
19
|
-
# @param [Proc] block
|
20
|
-
def push_proc(&block)
|
21
|
-
proc_stack << block
|
22
|
-
end
|
23
|
-
|
24
|
-
# Executes all the procs on the stack, passing in the given arguments.
|
25
|
-
# The stack is not cleared afterwords. It is up to the user of this
|
26
|
-
# mixin to clear the stack by calling `proc_stack.clear`.
|
27
|
-
def run_procs!(*args)
|
28
|
-
proc_stack.each do |proc|
|
29
|
-
proc.call(*args)
|
30
|
-
end
|
31
|
-
end
|
32
|
-
end
|
33
|
-
end
|
@@ -1,269 +0,0 @@
|
|
1
|
-
require File.join(File.dirname(__FILE__), '..', 'test_helper')
|
2
|
-
|
3
|
-
class CommandsTest < Test::Unit::TestCase
|
4
|
-
setup do
|
5
|
-
Vagrant::Env.stubs(:load!)
|
6
|
-
|
7
|
-
@persisted_vm = mock("persisted_vm")
|
8
|
-
@persisted_vm.stubs(:execute!)
|
9
|
-
Vagrant::Env.stubs(:persisted_vm).returns(@persisted_vm)
|
10
|
-
Vagrant::Env.stubs(:require_persisted_vm)
|
11
|
-
end
|
12
|
-
|
13
|
-
context "init" do
|
14
|
-
setup do
|
15
|
-
FileUtils.stubs(:cp)
|
16
|
-
@rootfile_path = File.join(Dir.pwd, Vagrant::Env::ROOTFILE_NAME)
|
17
|
-
@template_path = File.join(PROJECT_ROOT, "templates", Vagrant::Env::ROOTFILE_NAME)
|
18
|
-
end
|
19
|
-
|
20
|
-
should "error and exit if a rootfile already exists" do
|
21
|
-
File.expects(:exist?).with(@rootfile_path).returns(true)
|
22
|
-
Vagrant::Commands.expects(:error_and_exit).once
|
23
|
-
Vagrant::Commands.init
|
24
|
-
end
|
25
|
-
|
26
|
-
should "copy the templated rootfile to the current path" do
|
27
|
-
File.expects(:exist?).with(@rootfile_path).returns(false)
|
28
|
-
FileUtils.expects(:cp).with(@template_path, @rootfile_path).once
|
29
|
-
Vagrant::Commands.init
|
30
|
-
end
|
31
|
-
end
|
32
|
-
|
33
|
-
context "up" do
|
34
|
-
setup do
|
35
|
-
Vagrant::Env.stubs(:persisted_vm).returns(nil)
|
36
|
-
Vagrant::VM.stubs(:execute!)
|
37
|
-
Vagrant::Env.stubs(:require_box)
|
38
|
-
end
|
39
|
-
|
40
|
-
should "require load the environment" do
|
41
|
-
Vagrant::Env.expects(:load!).once
|
42
|
-
Vagrant::Commands.up
|
43
|
-
end
|
44
|
-
|
45
|
-
should "require a box" do
|
46
|
-
Vagrant::Env.expects(:require_box).once
|
47
|
-
Vagrant::Commands.up
|
48
|
-
end
|
49
|
-
|
50
|
-
should "call the up action on VM if it doesn't exist" do
|
51
|
-
Vagrant::VM.expects(:execute!).with(Vagrant::Actions::VM::Up).once
|
52
|
-
Vagrant::Commands.up
|
53
|
-
end
|
54
|
-
|
55
|
-
should "call start on the persisted vm if it exists" do
|
56
|
-
Vagrant::Env.stubs(:persisted_vm).returns(@persisted_vm)
|
57
|
-
@persisted_vm.expects(:start).once
|
58
|
-
Vagrant::VM.expects(:execute!).never
|
59
|
-
Vagrant::Commands.up
|
60
|
-
end
|
61
|
-
end
|
62
|
-
|
63
|
-
context "down" do
|
64
|
-
setup do
|
65
|
-
@persisted_vm.stubs(:destroy)
|
66
|
-
end
|
67
|
-
|
68
|
-
should "require a persisted VM" do
|
69
|
-
Vagrant::Env.expects(:require_persisted_vm).once
|
70
|
-
Vagrant::Commands.down
|
71
|
-
end
|
72
|
-
|
73
|
-
should "destroy the persisted VM and the VM image" do
|
74
|
-
@persisted_vm.expects(:destroy).once
|
75
|
-
Vagrant::Commands.down
|
76
|
-
end
|
77
|
-
end
|
78
|
-
|
79
|
-
context "reload" do
|
80
|
-
should "require a persisted VM" do
|
81
|
-
Vagrant::Env.expects(:require_persisted_vm).once
|
82
|
-
Vagrant::Commands.reload
|
83
|
-
end
|
84
|
-
|
85
|
-
should "call the `reload` action on the VM" do
|
86
|
-
@persisted_vm.expects(:execute!).with(Vagrant::Actions::VM::Reload).once
|
87
|
-
Vagrant::Commands.reload
|
88
|
-
end
|
89
|
-
end
|
90
|
-
|
91
|
-
context "ssh" do
|
92
|
-
setup do
|
93
|
-
Vagrant::SSH.stubs(:connect)
|
94
|
-
end
|
95
|
-
|
96
|
-
should "require a persisted VM" do
|
97
|
-
Vagrant::Env.expects(:require_persisted_vm).once
|
98
|
-
Vagrant::Commands.ssh
|
99
|
-
end
|
100
|
-
|
101
|
-
should "connect to SSH" do
|
102
|
-
Vagrant::SSH.expects(:connect).once
|
103
|
-
Vagrant::Commands.ssh
|
104
|
-
end
|
105
|
-
end
|
106
|
-
|
107
|
-
context "halt" do
|
108
|
-
should "require a persisted VM" do
|
109
|
-
Vagrant::Env.expects(:require_persisted_vm).once
|
110
|
-
Vagrant::Commands.halt
|
111
|
-
end
|
112
|
-
|
113
|
-
should "call the `halt` action on the VM" do
|
114
|
-
@persisted_vm.expects(:execute!).with(Vagrant::Actions::VM::Halt).once
|
115
|
-
Vagrant::Commands.halt
|
116
|
-
end
|
117
|
-
end
|
118
|
-
|
119
|
-
context "suspend" do
|
120
|
-
setup do
|
121
|
-
@persisted_vm.stubs(:suspend)
|
122
|
-
@persisted_vm.stubs(:saved?).returns(false)
|
123
|
-
end
|
124
|
-
|
125
|
-
should "require a persisted VM" do
|
126
|
-
Vagrant::Env.expects(:require_persisted_vm).once
|
127
|
-
Vagrant::Commands.suspend
|
128
|
-
end
|
129
|
-
|
130
|
-
should "suspend the VM" do
|
131
|
-
@persisted_vm.expects(:suspend).once
|
132
|
-
Vagrant::Commands.suspend
|
133
|
-
end
|
134
|
-
end
|
135
|
-
|
136
|
-
context "resume" do
|
137
|
-
setup do
|
138
|
-
@persisted_vm.stubs(:resume)
|
139
|
-
@persisted_vm.stubs(:saved?).returns(true)
|
140
|
-
end
|
141
|
-
|
142
|
-
should "require a persisted VM" do
|
143
|
-
Vagrant::Env.expects(:require_persisted_vm).once
|
144
|
-
Vagrant::Commands.resume
|
145
|
-
end
|
146
|
-
|
147
|
-
should "save the state of the VM" do
|
148
|
-
@persisted_vm.expects(:resume).once
|
149
|
-
Vagrant::Commands.resume
|
150
|
-
end
|
151
|
-
end
|
152
|
-
|
153
|
-
context "package" do
|
154
|
-
setup do
|
155
|
-
@persisted_vm.stubs(:package)
|
156
|
-
@persisted_vm.stubs(:powered_off?).returns(true)
|
157
|
-
end
|
158
|
-
|
159
|
-
should "require a persisted vm" do
|
160
|
-
Vagrant::Env.expects(:require_persisted_vm).once
|
161
|
-
Vagrant::Commands.package
|
162
|
-
end
|
163
|
-
|
164
|
-
should "error and exit if the VM is not powered off" do
|
165
|
-
@persisted_vm.stubs(:powered_off?).returns(false)
|
166
|
-
Vagrant::Commands.expects(:error_and_exit).once
|
167
|
-
@persisted_vm.expects(:package).never
|
168
|
-
Vagrant::Commands.package
|
169
|
-
end
|
170
|
-
|
171
|
-
should "call package on the persisted VM" do
|
172
|
-
@persisted_vm.expects(:package).once
|
173
|
-
Vagrant::Commands.package
|
174
|
-
end
|
175
|
-
|
176
|
-
should "pass the out path and include_files to the package method" do
|
177
|
-
out_path = mock("out_path")
|
178
|
-
include_files = mock("include_files")
|
179
|
-
@persisted_vm.expects(:package).with(out_path, include_files).once
|
180
|
-
Vagrant::Commands.package(out_path, include_files)
|
181
|
-
end
|
182
|
-
|
183
|
-
should "default to an empty array when not include_files are specified" do
|
184
|
-
out_path = mock("out_path")
|
185
|
-
@persisted_vm.expects(:package).with(out_path, []).once
|
186
|
-
Vagrant::Commands.package(out_path)
|
187
|
-
end
|
188
|
-
end
|
189
|
-
|
190
|
-
context "box" do
|
191
|
-
setup do
|
192
|
-
Vagrant::Commands.stubs(:box_foo)
|
193
|
-
Vagrant::Commands.stubs(:box_add)
|
194
|
-
Vagrant::Commands.stubs(:box_remove)
|
195
|
-
end
|
196
|
-
|
197
|
-
should "load the environment" do
|
198
|
-
Vagrant::Env.expects(:load!).once
|
199
|
-
Vagrant::Commands.box(["add"])
|
200
|
-
end
|
201
|
-
|
202
|
-
should "error and exit if the first argument is not 'add' or 'remove'" do
|
203
|
-
Vagrant::Commands.expects(:error_and_exit).once
|
204
|
-
Vagrant::Commands.box(["foo"])
|
205
|
-
end
|
206
|
-
|
207
|
-
should "not error and exit if the first argument is 'add' or 'remove'" do
|
208
|
-
commands = ["add", "remove"]
|
209
|
-
|
210
|
-
commands.each do |command|
|
211
|
-
Vagrant::Commands.expects(:error_and_exit).never
|
212
|
-
Vagrant::Commands.expects("box_#{command}".to_sym).once
|
213
|
-
Vagrant::Commands.box([command])
|
214
|
-
end
|
215
|
-
end
|
216
|
-
|
217
|
-
should "forward any additional arguments" do
|
218
|
-
Vagrant::Commands.expects(:box_add).with(1,2,3).once
|
219
|
-
Vagrant::Commands.box(["add",1,2,3])
|
220
|
-
end
|
221
|
-
end
|
222
|
-
|
223
|
-
context "box list" do
|
224
|
-
setup do
|
225
|
-
@boxes = ["foo", "bar"]
|
226
|
-
|
227
|
-
Vagrant::Box.stubs(:all).returns(@boxes)
|
228
|
-
Vagrant::Commands.stubs(:puts)
|
229
|
-
end
|
230
|
-
|
231
|
-
should "call all on box and sort the results" do
|
232
|
-
@all = mock("all")
|
233
|
-
@all.expects(:sort).returns(@boxes)
|
234
|
-
Vagrant::Box.expects(:all).returns(@all)
|
235
|
-
Vagrant::Commands.box_list
|
236
|
-
end
|
237
|
-
end
|
238
|
-
|
239
|
-
context "box add" do
|
240
|
-
setup do
|
241
|
-
@name = "foo"
|
242
|
-
@path = "bar"
|
243
|
-
end
|
244
|
-
|
245
|
-
should "execute the add action with the name and path" do
|
246
|
-
Vagrant::Box.expects(:add).with(@name, @path).once
|
247
|
-
Vagrant::Commands.box_add(@name, @path)
|
248
|
-
end
|
249
|
-
end
|
250
|
-
|
251
|
-
context "box remove" do
|
252
|
-
setup do
|
253
|
-
@name = "foo"
|
254
|
-
end
|
255
|
-
|
256
|
-
should "error and exit if the box doesn't exist" do
|
257
|
-
Vagrant::Box.expects(:find).returns(nil)
|
258
|
-
Vagrant::Commands.expects(:error_and_exit).once
|
259
|
-
Vagrant::Commands.box_remove(@name)
|
260
|
-
end
|
261
|
-
|
262
|
-
should "call destroy on the box if it exists" do
|
263
|
-
@box = mock("box")
|
264
|
-
Vagrant::Box.expects(:find).with(@name).returns(@box)
|
265
|
-
@box.expects(:destroy).once
|
266
|
-
Vagrant::Commands.box_remove(@name)
|
267
|
-
end
|
268
|
-
end
|
269
|
-
end
|