beaker-vagrant 0.7.1 → 1.1.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/.github/dependabot.yml +9 -0
- data/.github/workflows/release.yml +17 -9
- data/.github/workflows/test.yml +40 -11
- data/.rubocop.yml +4 -0
- data/.rubocop_todo.yml +383 -0
- data/CHANGELOG.md +203 -19
- data/Gemfile +3 -24
- data/README.md +26 -9
- data/Rakefile +34 -120
- data/beaker-vagrant.gemspec +21 -24
- data/bin/beaker-vagrant +1 -3
- data/lib/beaker/hypervisor/vagrant/mount_folder.rb +1 -1
- data/lib/beaker/hypervisor/vagrant.rb +79 -80
- data/lib/beaker/hypervisor/vagrant_custom.rb +1 -1
- data/lib/beaker/hypervisor/vagrant_desktop.rb +9 -5
- data/lib/beaker/hypervisor/vagrant_libvirt.rb +1 -1
- data/lib/beaker/hypervisor/vagrant_parallels.rb +2 -2
- data/lib/beaker/hypervisor/vagrant_virtualbox.rb +35 -32
- data/lib/beaker/hypervisor/vagrant_workstation.rb +9 -5
- data/lib/beaker-vagrant/version.rb +1 -1
- data/spec/beaker/hypervisor/vagrant_custom_spec.rb +14 -15
- data/spec/beaker/hypervisor/vagrant_desktop_spec.rb +20 -20
- data/spec/beaker/hypervisor/vagrant_fusion_spec.rb +11 -11
- data/spec/beaker/hypervisor/vagrant_libvirt_spec.rb +22 -21
- data/spec/beaker/hypervisor/vagrant_parallels_spec.rb +15 -15
- data/spec/beaker/hypervisor/vagrant_spec.rb +300 -309
- data/spec/beaker/hypervisor/vagrant_virtualbox_spec.rb +50 -29
- data/spec/beaker/hypervisor/vagrant_workstation_spec.rb +20 -20
- data/spec/spec_helper.rb +1 -2
- metadata +42 -52
@@ -3,414 +3,412 @@ require 'spec_helper'
|
|
3
3
|
|
4
4
|
module Beaker
|
5
5
|
describe Vagrant do
|
6
|
-
|
7
|
-
let( :options ) {
|
6
|
+
let(:options) do
|
8
7
|
make_opts.merge({
|
9
|
-
|
10
|
-
|
11
|
-
|
12
|
-
|
13
|
-
|
8
|
+
'logger' => double.as_null_object,
|
9
|
+
:hosts_file => 'sample.cfg',
|
10
|
+
:forward_ssh_agent => true,
|
11
|
+
})
|
12
|
+
end
|
14
13
|
|
15
|
-
let(
|
14
|
+
let(:vagrant) { Beaker::Vagrant.new(@hosts, options) }
|
16
15
|
|
17
16
|
before :each do
|
18
17
|
@hosts = make_hosts({
|
19
|
-
|
20
|
-
|
21
|
-
|
22
|
-
|
23
|
-
|
24
|
-
|
25
|
-
|
26
|
-
|
27
|
-
|
28
|
-
|
29
|
-
|
18
|
+
mount_folders: {
|
19
|
+
test_temp: { from: './', to: '/temp' },
|
20
|
+
test_tmp: { from: '../', to: '/tmp' }
|
21
|
+
},
|
22
|
+
forwarded_ports: {
|
23
|
+
http: { from: 10_080, to: 80 },
|
24
|
+
ssl: { from: 4443, to: 443 },
|
25
|
+
tomcat: { from: 8080, to: 8080 }
|
26
|
+
},
|
27
|
+
platform: Beaker::Platform.new('centos-8-x86_64')
|
28
|
+
})
|
30
29
|
end
|
31
30
|
|
32
|
-
it
|
33
|
-
path = vagrant.instance_variable_get(
|
34
|
-
|
35
|
-
expect( path ).to be === File.join(Dir.pwd, '.vagrant', 'beaker_vagrant_files', 'beaker_sample.cfg')
|
31
|
+
it 'stores the vagrant file in $WORKINGDIR/.vagrant/beaker_vagrant_files/beaker_sample.cfg' do
|
32
|
+
path = vagrant.instance_variable_get(:@vagrant_path)
|
36
33
|
|
34
|
+
expect(path).to be === File.join(Dir.pwd, '.vagrant', 'beaker_vagrant_files', 'beaker_sample.cfg')
|
37
35
|
end
|
38
36
|
|
39
|
-
it
|
40
|
-
path = vagrant.instance_variable_get(
|
37
|
+
it 'can make a Vagrantfile for a set of hosts' do
|
38
|
+
path = vagrant.instance_variable_get(:@vagrant_path)
|
41
39
|
|
42
|
-
vagrant.make_vfile(
|
40
|
+
vagrant.make_vfile(@hosts)
|
43
41
|
|
44
|
-
vagrantfile = File.read(
|
42
|
+
vagrantfile = File.read(File.expand_path(File.join(path, 'Vagrantfile')))
|
45
43
|
puts "file is #{path}\n"
|
46
|
-
expect(
|
47
|
-
Vagrant.configure("2") do |c|
|
48
|
-
|
49
|
-
|
50
|
-
|
51
|
-
|
52
|
-
|
53
|
-
|
54
|
-
|
55
|
-
|
56
|
-
|
57
|
-
|
58
|
-
|
59
|
-
|
60
|
-
|
61
|
-
|
62
|
-
|
63
|
-
|
64
|
-
|
65
|
-
|
66
|
-
|
67
|
-
|
68
|
-
|
69
|
-
|
70
|
-
|
71
|
-
|
72
|
-
|
73
|
-
|
74
|
-
|
75
|
-
|
76
|
-
|
77
|
-
|
78
|
-
|
79
|
-
|
80
|
-
|
81
|
-
|
82
|
-
|
83
|
-
|
84
|
-
|
85
|
-
|
86
|
-
|
87
|
-
|
88
|
-
|
89
|
-
|
90
|
-
|
91
|
-
|
92
|
-
|
93
|
-
|
94
|
-
end
|
95
|
-
EOF
|
44
|
+
expect(vagrantfile).to be === <<~EOF
|
45
|
+
Vagrant.configure("2") do |c|
|
46
|
+
c.ssh.insert_key = false
|
47
|
+
c.vm.define 'vm1' do |v|
|
48
|
+
v.vm.hostname = 'vm1'
|
49
|
+
v.vm.box = 'vm2vm1_of_my_box'
|
50
|
+
v.vm.box_url = 'http://address.for.my.box.vm1'
|
51
|
+
v.vm.box_check_update = 'true'
|
52
|
+
v.vm.network :private_network, ip: "ip.address.for.vm1", :netmask => "255.255.0.0"
|
53
|
+
v.vm.synced_folder './', '/temp', create: true
|
54
|
+
v.vm.synced_folder '../', '/tmp', create: true
|
55
|
+
v.vm.network :forwarded_port, guest: 80, host: 10080
|
56
|
+
v.vm.network :forwarded_port, guest: 443, host: 4443
|
57
|
+
v.vm.network :forwarded_port, guest: 8080, host: 8080
|
58
|
+
v.vm.provider :virtualbox do |vb|
|
59
|
+
vb.customize ['modifyvm', :id, '--memory', '1024', '--cpus', '1', '--audio', 'none']
|
60
|
+
end
|
61
|
+
end
|
62
|
+
c.vm.define 'vm2' do |v|
|
63
|
+
v.vm.hostname = 'vm2'
|
64
|
+
v.vm.box = 'vm2vm2_of_my_box'
|
65
|
+
v.vm.box_url = 'http://address.for.my.box.vm2'
|
66
|
+
v.vm.box_check_update = 'true'
|
67
|
+
v.vm.network :private_network, ip: "ip.address.for.vm2", :netmask => "255.255.0.0"
|
68
|
+
v.vm.synced_folder './', '/temp', create: true
|
69
|
+
v.vm.synced_folder '../', '/tmp', create: true
|
70
|
+
v.vm.network :forwarded_port, guest: 80, host: 10080
|
71
|
+
v.vm.network :forwarded_port, guest: 443, host: 4443
|
72
|
+
v.vm.network :forwarded_port, guest: 8080, host: 8080
|
73
|
+
v.vm.provider :virtualbox do |vb|
|
74
|
+
vb.customize ['modifyvm', :id, '--memory', '1024', '--cpus', '1', '--audio', 'none']
|
75
|
+
end
|
76
|
+
end
|
77
|
+
c.vm.define 'vm3' do |v|
|
78
|
+
v.vm.hostname = 'vm3'
|
79
|
+
v.vm.box = 'vm2vm3_of_my_box'
|
80
|
+
v.vm.box_url = 'http://address.for.my.box.vm3'
|
81
|
+
v.vm.box_check_update = 'true'
|
82
|
+
v.vm.network :private_network, ip: "ip.address.for.vm3", :netmask => "255.255.0.0"
|
83
|
+
v.vm.synced_folder './', '/temp', create: true
|
84
|
+
v.vm.synced_folder '../', '/tmp', create: true
|
85
|
+
v.vm.network :forwarded_port, guest: 80, host: 10080
|
86
|
+
v.vm.network :forwarded_port, guest: 443, host: 4443
|
87
|
+
v.vm.network :forwarded_port, guest: 8080, host: 8080
|
88
|
+
v.vm.provider :virtualbox do |vb|
|
89
|
+
vb.customize ['modifyvm', :id, '--memory', '1024', '--cpus', '1', '--audio', 'none']
|
90
|
+
end
|
91
|
+
end
|
92
|
+
end
|
93
|
+
EOF
|
96
94
|
end
|
97
95
|
|
98
|
-
it
|
99
|
-
path = vagrant.instance_variable_get(
|
96
|
+
it 'can make a Vagrantfile with ssh agent forwarding enabled' do
|
97
|
+
path = vagrant.instance_variable_get(:@vagrant_path)
|
100
98
|
|
101
|
-
hosts = make_hosts({},1)
|
102
|
-
vagrant.make_vfile(
|
99
|
+
hosts = make_hosts({}, 1)
|
100
|
+
vagrant.make_vfile(hosts, options)
|
103
101
|
|
104
|
-
vagrantfile = File.read(
|
105
|
-
expect(
|
102
|
+
vagrantfile = File.read(File.expand_path(File.join(path, 'Vagrantfile')))
|
103
|
+
expect(vagrantfile).to match(/(ssh.forward_agent = true)/)
|
106
104
|
end
|
107
105
|
|
108
|
-
it
|
109
|
-
path = vagrant.instance_variable_get(
|
110
|
-
|
111
|
-
host = make_host( 'name-with_underscore', {} )
|
112
|
-
vagrant.make_vfile( [host,], options )
|
106
|
+
it 'can replace underscores in host.name with hypens' do
|
107
|
+
path = vagrant.instance_variable_get(:@vagrant_path)
|
113
108
|
|
114
|
-
|
115
|
-
|
109
|
+
host = make_host('name-with_underscore', {})
|
110
|
+
vagrant.make_vfile([host,], options)
|
116
111
|
|
112
|
+
vagrantfile = File.read(File.expand_path(File.join(path, 'Vagrantfile')))
|
113
|
+
expect(vagrantfile).to match(/v.vm.hostname = .*name-with-underscore/)
|
117
114
|
end
|
118
115
|
|
119
|
-
it
|
120
|
-
path = vagrant.instance_variable_get(
|
116
|
+
it 'can make a Vagrantfile with synced_folder disabled' do
|
117
|
+
path = vagrant.instance_variable_get(:@vagrant_path)
|
121
118
|
|
122
|
-
hosts = make_hosts({:
|
123
|
-
vagrant.make_vfile(
|
119
|
+
hosts = make_hosts({ synced_folder: 'disabled' }, 1)
|
120
|
+
vagrant.make_vfile(hosts, options)
|
124
121
|
|
125
|
-
vagrantfile = File.read(
|
126
|
-
expect(
|
122
|
+
vagrantfile = File.read(File.expand_path(File.join(path, 'Vagrantfile')))
|
123
|
+
expect(vagrantfile).to match(/v.vm.synced_folder .* disabled: true/)
|
127
124
|
end
|
128
125
|
|
129
|
-
it
|
130
|
-
path = vagrant.instance_variable_get(
|
126
|
+
it 'can make a Vagrantfile with network mac specified' do
|
127
|
+
path = vagrant.instance_variable_get(:@vagrant_path)
|
131
128
|
|
132
|
-
hosts = make_hosts({:
|
133
|
-
vagrant.make_vfile(
|
129
|
+
hosts = make_hosts({ network_mac: 'b6:33:ae:19:48:f9' }, 1)
|
130
|
+
vagrant.make_vfile(hosts, options)
|
134
131
|
|
135
|
-
vagrantfile = File.read(
|
136
|
-
expect(
|
132
|
+
vagrantfile = File.read(File.expand_path(File.join(path, 'Vagrantfile')))
|
133
|
+
expect(vagrantfile).to match(/v.vm.network :private_network, ip: "ip.address.for.vm1", :netmask => "255.255.0.0", :mac => "b6:33:ae:19:48:f9/)
|
137
134
|
end
|
138
135
|
|
139
|
-
it
|
140
|
-
path = vagrant.instance_variable_get(
|
136
|
+
it 'can make a Vagrantfile with improper keys for synced folders' do
|
137
|
+
path = vagrant.instance_variable_get(:@vagrant_path)
|
141
138
|
|
142
|
-
hosts = make_hosts({:
|
143
|
-
|
144
|
-
|
145
|
-
|
146
|
-
|
147
|
-
|
148
|
-
vagrant.make_vfile(
|
139
|
+
hosts = make_hosts({ mount_folders: {
|
140
|
+
test_invalid1: { host_path: '/invalid1', container_path: '/invalid1' },
|
141
|
+
test_invalid2: { from: '/invalid2', container_path: '/invalid2' },
|
142
|
+
test_invalid3: { host_path: '/invalid3', to: '/invalid3' },
|
143
|
+
test_valid: { from: '/valid', to: '/valid' }
|
144
|
+
} }, 1)
|
145
|
+
vagrant.make_vfile(hosts, options)
|
149
146
|
|
150
|
-
vagrantfile = File.read(
|
147
|
+
vagrantfile = File.read(File.expand_path(File.join(path, 'Vagrantfile')))
|
151
148
|
|
152
|
-
expect(
|
153
|
-
expect(
|
154
|
-
expect(
|
155
|
-
expect(
|
149
|
+
expect(vagrantfile).not_to match(/v.vm.synced_folder '', '', create: true/)
|
150
|
+
expect(vagrantfile).not_to match(%r{v.vm.synced_folder '/invalid2', '', create: true})
|
151
|
+
expect(vagrantfile).not_to match(%r{v.vm.synced_folder '', '/invalid3', create: true})
|
152
|
+
expect(vagrantfile).to match(%r{v.vm.synced_folder '/valid', '/valid', create: true})
|
156
153
|
end
|
157
154
|
|
158
|
-
it
|
159
|
-
path = vagrant.instance_variable_get(
|
155
|
+
it 'can make a Vagrantfile with optional shell provisioner' do
|
156
|
+
path = vagrant.instance_variable_get(:@vagrant_path)
|
160
157
|
|
161
158
|
shell_path = '/path/to/shell/script'
|
162
159
|
hosts = make_hosts({
|
163
|
-
|
164
|
-
|
165
|
-
|
166
|
-
|
167
|
-
vagrant.make_vfile(
|
168
|
-
|
169
|
-
vagrantfile = File.read(
|
170
|
-
expect(
|
160
|
+
shell_provisioner: {
|
161
|
+
path: shell_path
|
162
|
+
}
|
163
|
+
}, 1)
|
164
|
+
vagrant.make_vfile(hosts, options)
|
165
|
+
|
166
|
+
vagrantfile = File.read(File.expand_path(File.join(path, 'Vagrantfile')))
|
167
|
+
expect(vagrantfile).to match(/v.vm.provision 'shell', :path => '#{shell_path}'/)
|
171
168
|
end
|
172
169
|
|
173
|
-
it
|
174
|
-
path = vagrant.instance_variable_get(
|
170
|
+
it 'can make a Vagrantfile with optional shell provisioner with args' do
|
171
|
+
path = vagrant.instance_variable_get(:@vagrant_path)
|
175
172
|
|
176
173
|
shell_path = '/path/to/shell/script.sh'
|
177
174
|
shell_args = 'arg1 arg2'
|
178
175
|
hosts = make_hosts({
|
179
|
-
|
180
|
-
|
181
|
-
|
182
|
-
|
183
|
-
|
184
|
-
vagrant.make_vfile(
|
185
|
-
|
186
|
-
vagrantfile = File.read(
|
187
|
-
expect(
|
176
|
+
shell_provisioner: {
|
177
|
+
path: shell_path,
|
178
|
+
args: shell_args
|
179
|
+
}
|
180
|
+
}, 1)
|
181
|
+
vagrant.make_vfile(hosts, options)
|
182
|
+
|
183
|
+
vagrantfile = File.read(File.expand_path(File.join(path, 'Vagrantfile')))
|
184
|
+
expect(vagrantfile).to match(/v.vm.provision 'shell', :path => '#{shell_path}', :args => '#{shell_args}'/)
|
188
185
|
end
|
189
186
|
|
190
|
-
it
|
191
|
-
path = vagrant.instance_variable_get(
|
187
|
+
it 'raises an error if path is not set on shell_provisioner' do
|
188
|
+
path = vagrant.instance_variable_get(:@vagrant_path)
|
192
189
|
|
193
|
-
hosts = make_hosts({:
|
194
|
-
expect
|
190
|
+
hosts = make_hosts({ shell_provisioner: {} }, 1)
|
191
|
+
expect do
|
192
|
+
vagrant.make_vfile(hosts, options)
|
193
|
+
end.to raise_error RuntimeError, /No path defined for shell_provisioner or path empty/
|
195
194
|
end
|
196
195
|
|
197
|
-
it
|
198
|
-
path = vagrant.instance_variable_get(
|
196
|
+
it 'raises an error if path is EMPTY on shell_provisioner' do
|
197
|
+
path = vagrant.instance_variable_get(:@vagrant_path)
|
199
198
|
|
200
199
|
empty_shell_path = ''
|
201
200
|
hosts = make_hosts({
|
202
|
-
|
203
|
-
|
204
|
-
|
205
|
-
|
206
|
-
expect
|
201
|
+
shell_provisioner: {
|
202
|
+
path: empty_shell_path
|
203
|
+
}
|
204
|
+
}, 1)
|
205
|
+
expect do
|
206
|
+
vagrant.make_vfile(hosts, options)
|
207
|
+
end.to raise_error RuntimeError, /No path defined for shell_provisioner or path empty/
|
207
208
|
end
|
208
209
|
|
209
|
-
context
|
210
|
+
context 'when generating a windows config' do
|
210
211
|
before do
|
211
|
-
path = vagrant.instance_variable_get(
|
212
|
+
path = vagrant.instance_variable_get(:@vagrant_path)
|
212
213
|
@hosts[0][:platform] = 'windows'
|
213
214
|
|
214
|
-
vagrant.make_vfile(
|
215
|
+
vagrant.make_vfile(@hosts)
|
215
216
|
|
216
|
-
@generated_file = File.read(
|
217
|
+
@generated_file = File.read(File.expand_path(File.join(path, 'Vagrantfile')))
|
217
218
|
end
|
218
219
|
|
219
220
|
it 'has the proper port forwarding for RDP' do
|
220
|
-
expect(
|
221
|
+
expect(@generated_file).to match /v.vm.network :forwarded_port, guest: 3389, host: 3389, id: 'rdp', auto_correct: true/
|
221
222
|
end
|
222
223
|
|
223
224
|
it 'has the proper port forwarding for WinRM' do
|
224
|
-
expect(
|
225
|
+
expect(@generated_file).to match /v.vm.network :forwarded_port, guest: 5985, host: 5985, id: 'winrm', auto_correct: true/
|
225
226
|
end
|
226
227
|
|
227
228
|
it 'configures the guest type to windows' do
|
228
|
-
expect(
|
229
|
+
expect(@generated_file).to match /v.vm.guest = :windows/
|
229
230
|
end
|
230
231
|
|
231
232
|
it 'configures the guest type to use winrm' do
|
232
|
-
expect(
|
233
|
+
expect(@generated_file).to match /v.vm.communicator = 'winrm'/
|
233
234
|
end
|
234
235
|
|
235
236
|
it 'sets a non-default memsize' do
|
236
|
-
expect(
|
237
|
+
expect(@generated_file).to match /'--memory', '2048',/
|
237
238
|
end
|
238
239
|
end
|
239
240
|
|
240
241
|
context 'when generating a freebsd config' do
|
241
242
|
before do
|
242
|
-
path = vagrant.instance_variable_get(
|
243
|
+
path = vagrant.instance_variable_get(:@vagrant_path)
|
243
244
|
@hosts[0][:platform] = 'freebsd'
|
244
245
|
|
245
|
-
vagrant.make_vfile(
|
246
|
+
vagrant.make_vfile(@hosts)
|
246
247
|
|
247
|
-
@generated_file = File.read(
|
248
|
+
@generated_file = File.read(File.expand_path(File.join(path, 'Vagrantfile')))
|
248
249
|
end
|
249
250
|
|
250
251
|
it 'has the proper ssh shell' do
|
251
|
-
expect(
|
252
|
+
expect(@generated_file).to match /v.ssh.shell = 'sh'\n/
|
252
253
|
end
|
253
254
|
|
254
255
|
it 'has the proper guest setting' do
|
255
|
-
expect(
|
256
|
+
expect(@generated_file).to match /v.vm.guest = :freebsd\n/
|
256
257
|
end
|
257
258
|
end
|
258
259
|
|
259
|
-
it
|
260
|
-
path = vagrant.instance_variable_get(
|
260
|
+
it 'uses the memsize defined per vagrant host' do
|
261
|
+
path = vagrant.instance_variable_get(:@vagrant_path)
|
261
262
|
|
262
|
-
vagrant.make_vfile(
|
263
|
+
vagrant.make_vfile(@hosts, { 'vagrant_memsize' => 'hello!' })
|
263
264
|
|
264
|
-
generated_file = File.read(
|
265
|
+
generated_file = File.read(File.expand_path(File.join(path, 'Vagrantfile')))
|
265
266
|
|
266
267
|
match = generated_file.match(/vb.customize \['modifyvm', :id, '--memory', 'hello!', '--cpus', '1', '--audio', 'none'\]/)
|
267
268
|
|
268
|
-
expect(
|
269
|
-
|
269
|
+
expect(match).to_not be nil
|
270
270
|
end
|
271
271
|
|
272
|
-
it
|
273
|
-
path = vagrant.instance_variable_get(
|
272
|
+
it 'uses the cpus defined per vagrant host' do
|
273
|
+
path = vagrant.instance_variable_get(:@vagrant_path)
|
274
274
|
|
275
|
-
vagrant.make_vfile(
|
275
|
+
vagrant.make_vfile(@hosts, { 'vagrant_cpus' => 'goodbye!' })
|
276
276
|
|
277
|
-
generated_file = File.read(
|
277
|
+
generated_file = File.read(File.expand_path(File.join(path, 'Vagrantfile')))
|
278
278
|
|
279
279
|
match = generated_file.match(/vb.customize \['modifyvm', :id, '--memory', '1024', '--cpus', 'goodbye!', '--audio', 'none'\]/)
|
280
280
|
|
281
|
-
expect(
|
282
|
-
|
281
|
+
expect(match).to_not be nil
|
283
282
|
end
|
284
283
|
|
285
|
-
context
|
286
|
-
it
|
287
|
-
path = vagrant.instance_variable_get(
|
284
|
+
context 'port forwarding rules' do
|
285
|
+
it 'supports all Vagrant parameters' do
|
286
|
+
path = vagrant.instance_variable_get(:@vagrant_path)
|
288
287
|
|
289
288
|
hosts = make_hosts(
|
290
289
|
{
|
291
|
-
:
|
292
|
-
:
|
293
|
-
:
|
294
|
-
:
|
295
|
-
:
|
296
|
-
:
|
297
|
-
:
|
290
|
+
forwarded_ports: {
|
291
|
+
http: {
|
292
|
+
from: 10_080,
|
293
|
+
from_ip: '127.0.0.1',
|
294
|
+
to: 80,
|
295
|
+
to_ip: '0.0.0.0',
|
296
|
+
protocol: 'udp'
|
298
297
|
}
|
299
298
|
}
|
300
|
-
},1
|
301
|
-
|
299
|
+
}, 1
|
300
|
+
)
|
301
|
+
vagrant.make_vfile(hosts, options)
|
302
302
|
|
303
|
-
vagrantfile = File.read(
|
304
|
-
expect(
|
303
|
+
vagrantfile = File.read(File.expand_path(File.join(path, 'Vagrantfile')))
|
304
|
+
expect(vagrantfile).to match(/v.vm.network :forwarded_port, protocol: 'udp', guest_ip: '0.0.0.0', guest: 80, host_ip: '127.0.0.1', host: 10080/)
|
305
305
|
end
|
306
306
|
|
307
|
-
it
|
308
|
-
path = vagrant.instance_variable_get(
|
307
|
+
it 'supports supports from_ip' do
|
308
|
+
path = vagrant.instance_variable_get(:@vagrant_path)
|
309
309
|
|
310
310
|
hosts = make_hosts(
|
311
|
-
|
312
|
-
|
313
|
-
|
314
|
-
|
315
|
-
|
316
|
-
|
317
|
-
|
318
|
-
|
319
|
-
|
320
|
-
|
311
|
+
{
|
312
|
+
forwarded_ports: {
|
313
|
+
http: {
|
314
|
+
from: 10_080,
|
315
|
+
from_ip: '127.0.0.1',
|
316
|
+
to: 80,
|
317
|
+
}
|
318
|
+
}
|
319
|
+
}, 1
|
320
|
+
)
|
321
|
+
vagrant.make_vfile(hosts, options)
|
321
322
|
|
322
|
-
vagrantfile = File.read(
|
323
|
-
expect(
|
323
|
+
vagrantfile = File.read(File.expand_path(File.join(path, 'Vagrantfile')))
|
324
|
+
expect(vagrantfile).to match(/v.vm.network :forwarded_port, guest: 80, host_ip: '127.0.0.1', host: 10080/)
|
324
325
|
end
|
325
326
|
|
326
|
-
it
|
327
|
-
path = vagrant.instance_variable_get(
|
327
|
+
it 'supports all to_ip' do
|
328
|
+
path = vagrant.instance_variable_get(:@vagrant_path)
|
328
329
|
|
329
330
|
hosts = make_hosts(
|
330
|
-
|
331
|
-
|
332
|
-
|
333
|
-
|
334
|
-
|
335
|
-
|
336
|
-
|
337
|
-
|
338
|
-
|
339
|
-
|
331
|
+
{
|
332
|
+
forwarded_ports: {
|
333
|
+
http: {
|
334
|
+
from: 10_080,
|
335
|
+
to: 80,
|
336
|
+
to_ip: '0.0.0.0',
|
337
|
+
}
|
338
|
+
}
|
339
|
+
}, 1
|
340
|
+
)
|
341
|
+
vagrant.make_vfile(hosts, options)
|
340
342
|
|
341
|
-
vagrantfile = File.read(
|
342
|
-
expect(
|
343
|
+
vagrantfile = File.read(File.expand_path(File.join(path, 'Vagrantfile')))
|
344
|
+
expect(vagrantfile).to match(/v.vm.network :forwarded_port, guest_ip: '0.0.0.0', guest: 80, host: 10080/)
|
343
345
|
end
|
344
346
|
|
345
|
-
it
|
346
|
-
path = vagrant.instance_variable_get(
|
347
|
+
it 'supports all protocol' do
|
348
|
+
path = vagrant.instance_variable_get(:@vagrant_path)
|
347
349
|
|
348
350
|
hosts = make_hosts(
|
349
|
-
|
350
|
-
|
351
|
-
|
352
|
-
|
353
|
-
|
354
|
-
|
355
|
-
|
356
|
-
|
357
|
-
|
358
|
-
|
359
|
-
|
360
|
-
vagrantfile = File.read( File.expand_path( File.join( path, "Vagrantfile")))
|
361
|
-
expect( vagrantfile ).to match(/v.vm.network :forwarded_port, protocol: 'udp', guest: 80, host: 10080/)
|
351
|
+
{
|
352
|
+
forwarded_ports: {
|
353
|
+
http: {
|
354
|
+
from: 10_080,
|
355
|
+
to: 80,
|
356
|
+
protocol: 'udp'
|
357
|
+
}
|
358
|
+
}
|
359
|
+
}, 1
|
360
|
+
)
|
361
|
+
vagrant.make_vfile(hosts, options)
|
362
362
|
|
363
|
+
vagrantfile = File.read(File.expand_path(File.join(path, 'Vagrantfile')))
|
364
|
+
expect(vagrantfile).to match(/v.vm.network :forwarded_port, protocol: 'udp', guest: 80, host: 10080/)
|
363
365
|
end
|
364
366
|
end
|
365
367
|
|
366
|
-
it
|
367
|
-
|
368
|
+
it 'can generate a new /etc/hosts file referencing each host' do
|
368
369
|
@hosts.each do |host|
|
369
|
-
expect(
|
370
|
-
expect(
|
370
|
+
expect(vagrant).to receive(:get_domain_name).with(host).and_return('labs.lan')
|
371
|
+
expect(vagrant).to receive(:set_etc_hosts).with(host,
|
372
|
+
"127.0.0.1\tlocalhost localhost.localdomain\nip.address.for.vm1\tvm1.labs.lan vm1\nip.address.for.vm2\tvm2.labs.lan vm2\nip.address.for.vm3\tvm3.labs.lan vm3\n").once
|
371
373
|
end
|
372
374
|
|
373
|
-
vagrant.hack_etc_hosts(
|
374
|
-
|
375
|
+
vagrant.hack_etc_hosts(@hosts, options)
|
375
376
|
end
|
376
377
|
|
377
378
|
context "can copy vagrant's key to root .ssh on each host" do
|
378
|
-
|
379
|
-
it "can copy to root on unix" do
|
379
|
+
it 'can copy to root on unix' do
|
380
380
|
host = @hosts[0]
|
381
381
|
host[:platform] = 'unix'
|
382
382
|
|
383
|
-
expect(
|
384
|
-
expect(
|
385
|
-
expect(
|
386
|
-
|
387
|
-
vagrant.copy_ssh_to_root( host, options )
|
383
|
+
expect(Command).to receive(:new).with('sudo su -c "cp -r .ssh /root/."').once
|
384
|
+
expect(Command).to receive(:new).with('sudo fixfiles restore /root').once
|
385
|
+
expect(Command).to receive(:new).with('sudo selinuxenabled').once
|
388
386
|
|
387
|
+
vagrant.copy_ssh_to_root(host, options)
|
389
388
|
end
|
390
389
|
|
391
|
-
it
|
390
|
+
it 'can copy to Administrator on windows' do
|
392
391
|
host = @hosts[0]
|
393
392
|
host[:platform] = 'windows'
|
394
|
-
expect(
|
393
|
+
expect(host).to receive(:is_cygwin?).and_return(true)
|
395
394
|
|
396
|
-
expect(
|
397
|
-
expect(
|
398
|
-
expect(
|
395
|
+
expect(Command).to_not receive(:new).with('sudo fixfiles restore /root')
|
396
|
+
expect(Command).to receive(:new).with('cp -r .ssh /cygdrive/c/Users/Administrator/.').once
|
397
|
+
expect(Command).to receive(:new).with('chown -R Administrator /cygdrive/c/Users/Administrator/.ssh').once
|
399
398
|
|
400
399
|
# This is checked on all platforms since Linux isn't called out specifically in the code
|
401
400
|
# If this fails, nothing further is activated
|
402
401
|
result = Beaker::Result.new(host, '')
|
403
402
|
result.exit_code = 1
|
404
|
-
expect(
|
405
|
-
allow(
|
406
|
-
|
407
|
-
vagrant.copy_ssh_to_root( host, options )
|
403
|
+
expect(Command).to receive(:new).with('sudo selinuxenabled')
|
404
|
+
allow(host).to receive(:exec).and_return(result)
|
408
405
|
|
406
|
+
vagrant.copy_ssh_to_root(host, options)
|
409
407
|
end
|
410
408
|
end
|
411
409
|
|
412
|
-
describe
|
413
|
-
let(
|
410
|
+
describe 'set_ssh_config' do
|
411
|
+
let(:out) do
|
414
412
|
<<-CONFIG
|
415
413
|
Host #{name}
|
416
414
|
HostName 127.0.0.1
|
@@ -423,9 +421,9 @@ EOF
|
|
423
421
|
IdentitiesOnly yes
|
424
422
|
CONFIG
|
425
423
|
end
|
426
|
-
let(
|
427
|
-
let(
|
428
|
-
let(
|
424
|
+
let(:host) { @hosts[0] }
|
425
|
+
let(:name) { host.name }
|
426
|
+
let(:override_options) { {} }
|
429
427
|
|
430
428
|
before :each do
|
431
429
|
# FakeFS is just broken with Tempfile
|
@@ -433,11 +431,11 @@ EOF
|
|
433
431
|
Dir.mktmpdir do |dir|
|
434
432
|
vagrant.instance_variable_get(:@options).merge!(override_options)
|
435
433
|
vagrant.instance_variable_set(:@vagrant_path, dir)
|
436
|
-
state = double(
|
437
|
-
allow(
|
438
|
-
allow(
|
434
|
+
state = double('state')
|
435
|
+
allow(state).to receive(:success?).and_return(true)
|
436
|
+
allow(Open3).to receive(:capture3).with({}, 'vagrant', 'ssh-config', name).and_return([out, '', state])
|
439
437
|
|
440
|
-
vagrant.set_ssh_config(
|
438
|
+
vagrant.set_ssh_config(host, 'root')
|
441
439
|
end
|
442
440
|
end
|
443
441
|
|
@@ -454,13 +452,13 @@ EOF
|
|
454
452
|
expect(host['ssh'][:keys_only]).to be === false
|
455
453
|
end
|
456
454
|
|
457
|
-
context
|
455
|
+
context 'when :forward_ssh_agent is false' do
|
458
456
|
let(:override_options) do
|
459
|
-
{forward_ssh_agent: false}
|
457
|
+
{ forward_ssh_agent: false }
|
460
458
|
end
|
461
459
|
|
462
|
-
it
|
463
|
-
expect(
|
460
|
+
it 'should keep IdentitiesOnly to yes' do
|
461
|
+
expect(host['ssh'][:keys_only]).to be === true
|
464
462
|
end
|
465
463
|
end
|
466
464
|
end
|
@@ -517,87 +515,80 @@ EOF
|
|
517
515
|
end
|
518
516
|
end
|
519
517
|
|
520
|
-
describe
|
521
|
-
|
518
|
+
describe 'provisioning and cleanup' do
|
522
519
|
before :each do
|
523
|
-
expect(
|
520
|
+
expect(vagrant).to receive(:vagrant_cmd).with('up').once
|
524
521
|
@hosts.each do |host|
|
525
522
|
host_prev_name = host['user']
|
526
|
-
expect(
|
527
|
-
expect(
|
528
|
-
expect(
|
523
|
+
expect(vagrant).to receive(:set_ssh_config).with(host, 'vagrant').once
|
524
|
+
expect(vagrant).to receive(:copy_ssh_to_root).with(host, options).once
|
525
|
+
expect(vagrant).to receive(:set_ssh_config).with(host, host_prev_name).once
|
529
526
|
end
|
530
|
-
expect(
|
527
|
+
expect(vagrant).to receive(:hack_etc_hosts).with(@hosts, options).once
|
531
528
|
end
|
532
529
|
|
533
|
-
it
|
534
|
-
options = vagrant.instance_variable_get(
|
535
|
-
expect(
|
536
|
-
expect(
|
530
|
+
it 'can provision a set of hosts' do
|
531
|
+
options = vagrant.instance_variable_get(:@options)
|
532
|
+
expect(vagrant).to receive(:make_vfile).with(@hosts, options).once
|
533
|
+
expect(vagrant).to receive(:vagrant_cmd).with('destroy --force').never
|
537
534
|
vagrant.provision
|
538
535
|
end
|
539
536
|
|
540
|
-
it
|
541
|
-
vagrant.make_vfile(
|
542
|
-
expect(
|
537
|
+
it 'destroys an existing set of hosts before provisioning' do
|
538
|
+
vagrant.make_vfile(@hosts)
|
539
|
+
expect(vagrant).to receive(:vagrant_cmd).with('destroy --force').once
|
543
540
|
vagrant.provision
|
544
541
|
end
|
545
542
|
|
546
|
-
it
|
543
|
+
it 'notifies user of failed provision' do
|
547
544
|
vagrant.provision
|
548
|
-
expect(
|
549
|
-
expect(
|
550
|
-
expect{ vagrant.provision }.to raise_error(
|
545
|
+
expect(vagrant).to receive(:vagrant_cmd).with('destroy --force').and_raise(RuntimeError)
|
546
|
+
expect(options['logger']).to receive(:debug).with(/Vagrantfile/)
|
547
|
+
expect { vagrant.provision }.to raise_error(RuntimeError)
|
551
548
|
end
|
552
549
|
|
553
|
-
it
|
554
|
-
expect(
|
555
|
-
expect(
|
550
|
+
it 'can cleanup' do
|
551
|
+
expect(vagrant).to receive(:vagrant_cmd).with('destroy --force').once
|
552
|
+
expect(FileUtils).to receive(:rm_rf).once
|
556
553
|
|
557
554
|
vagrant.provision
|
558
555
|
vagrant.cleanup
|
559
|
-
|
560
556
|
end
|
561
|
-
|
562
557
|
end
|
563
558
|
|
564
|
-
describe
|
559
|
+
describe 'provisioning and cleanup on windows' do
|
565
560
|
before :each do
|
566
|
-
expect(
|
561
|
+
expect(vagrant).to receive(:vagrant_cmd).with('up').once
|
567
562
|
@hosts.each do |host|
|
568
563
|
host[:platform] = 'windows'
|
569
564
|
host_prev_name = host['user']
|
570
|
-
expect(
|
571
|
-
expect(
|
572
|
-
expect(
|
565
|
+
expect(vagrant).not_to receive(:set_ssh_config).with(host, 'vagrant')
|
566
|
+
expect(vagrant).not_to receive(:copy_ssh_to_root).with(host, options)
|
567
|
+
expect(vagrant).to receive(:set_ssh_config).with(host, host_prev_name).once
|
573
568
|
end
|
574
|
-
expect(
|
569
|
+
expect(vagrant).to receive(:hack_etc_hosts).with(@hosts, options).once
|
575
570
|
end
|
576
571
|
|
577
|
-
it
|
578
|
-
options = vagrant.instance_variable_get(
|
579
|
-
expect(
|
580
|
-
expect(
|
572
|
+
it 'can provision a set of hosts' do
|
573
|
+
options = vagrant.instance_variable_get(:@options)
|
574
|
+
expect(vagrant).to receive(:make_vfile).with(@hosts, options).once
|
575
|
+
expect(vagrant).to receive(:vagrant_cmd).with('destroy --force').never
|
581
576
|
vagrant.provision
|
582
577
|
end
|
583
578
|
|
584
|
-
it
|
585
|
-
vagrant.make_vfile(
|
586
|
-
expect(
|
579
|
+
it 'destroys an existing set of hosts before provisioning' do
|
580
|
+
vagrant.make_vfile(@hosts)
|
581
|
+
expect(vagrant).to receive(:vagrant_cmd).with('destroy --force').once
|
587
582
|
vagrant.provision
|
588
583
|
end
|
589
584
|
|
590
|
-
it
|
591
|
-
expect(
|
592
|
-
expect(
|
585
|
+
it 'can cleanup' do
|
586
|
+
expect(vagrant).to receive(:vagrant_cmd).with('destroy --force').once
|
587
|
+
expect(FileUtils).to receive(:rm_rf).once
|
593
588
|
|
594
589
|
vagrant.provision
|
595
590
|
vagrant.cleanup
|
596
|
-
|
597
591
|
end
|
598
|
-
|
599
592
|
end
|
600
|
-
|
601
593
|
end
|
602
|
-
|
603
594
|
end
|