beaker-vagrant 0.1.0

Sign up to get free protection for your applications and to get access to all the features.
@@ -0,0 +1,25 @@
1
+ HOSTS:
2
+ redhat7-64-1:
3
+ roles:
4
+ - master
5
+ - agent
6
+ - dashboard
7
+ - databse
8
+ - classifier
9
+ - default
10
+ platform: el-7-x86_64
11
+ template: redhat-7-x86_64
12
+ box: puppetlabs/centos-7.0-64-nocm
13
+ box_url: https://vagrantcloud.com/puppetlabs/boxes/centos-7.0-64-nocm
14
+ hypervisor: vagrant
15
+ redhat7-64-2:
16
+ roles:
17
+ - agent
18
+ platform: el-7-x86_64
19
+ template: redhat-7-x86_64
20
+ box: puppetlabs/centos-7.0-64-nocm
21
+ box_url: https://vagrantcloud.com/puppetlabs/boxes/centos-7.0-64-nocm
22
+ hypervisor: vagrant
23
+ CONFIG:
24
+ nfs_server: none
25
+ consoleport: 443
@@ -0,0 +1,37 @@
1
+ # -*- encoding: utf-8 -*-
2
+ $LOAD_PATH.unshift File.expand_path("../lib", __FILE__)
3
+ require 'beaker-vagrant/version'
4
+
5
+ Gem::Specification.new do |s|
6
+ s.name = "beaker-vagrant"
7
+ s.version = BeakerVagrant::VERSION
8
+ s.authors = ["Rishi Javia, Kevin Imber, Tony Vu"]
9
+ s.email = ["rishi.javia@puppet.com, kevin.imber@puppet.com, tony.vu@puppet.com"]
10
+ s.homepage = "https://github.com/puppetlabs/beaker-vagrant"
11
+ s.summary = %q{Beaker DSL Extension Helpers!}
12
+ s.description = %q{For use for the Beaker acceptance testing tool}
13
+ s.license = 'Apache2'
14
+
15
+ s.files = `git ls-files`.split("\n")
16
+ s.test_files = `git ls-files -- {test,spec,features}/*`.split("\n")
17
+ s.executables = `git ls-files -- bin/*`.split("\n").map{ |f| File.basename(f) }
18
+ s.require_paths = ["lib"]
19
+
20
+ # Testing dependencies
21
+ s.add_development_dependency 'rspec', '~> 3.0'
22
+ s.add_development_dependency 'rspec-its'
23
+ s.add_development_dependency 'fakefs', '~> 0.6'
24
+ s.add_development_dependency 'rake', '~> 10.1'
25
+ s.add_development_dependency 'simplecov'
26
+ s.add_development_dependency 'pry', '~> 0.10'
27
+
28
+ # Documentation dependencies
29
+ s.add_development_dependency 'yard'
30
+ s.add_development_dependency 'markdown'
31
+ s.add_development_dependency 'thin'
32
+
33
+ # Run time dependencies
34
+ s.add_runtime_dependency 'stringify-hash', '~> 0.0.0'
35
+
36
+ end
37
+
@@ -0,0 +1,32 @@
1
+ #!/usr/bin/env ruby
2
+
3
+ require 'rubygems' unless defined?(Gem)
4
+ require 'beaker-vagrant'
5
+
6
+ VERSION_STRING =
7
+ "
8
+ _ .--.
9
+ ( ` )
10
+ beaker-vagrant .-' `--,
11
+ _..----.. ( )`-.
12
+ .'_|` _|` _|( .__, )
13
+ /_| _| _| _( (_, .-'
14
+ ;| _| _| _| '-'__,--'`--'
15
+ | _| _| _| _| |
16
+ _ || _| _| _| _| %s
17
+ _( `--.\\_| _| _| _|/
18
+ .-' )--,| _| _|.`
19
+ (__, (_ ) )_| _| /
20
+ `-.__.\\ _,--'\\|__|__/
21
+ ;____;
22
+ \\YT/
23
+ ||
24
+ |\"\"|
25
+ '=='
26
+ "
27
+
28
+
29
+
30
+ puts BeakerVagrant::Version
31
+
32
+ exit 0
data/docs/vagrant.md ADDED
@@ -0,0 +1,165 @@
1
+ # Vagrant
2
+
3
+ Vagrant's slogan is "development environments made easy". They provide an
4
+ abstraction on top of a VM or cloud provider that allows you to manage
5
+ hosts and their provisioning. [Their Site](https://www.vagrantup.com/).
6
+
7
+ # Getting Started
8
+
9
+ ### Requirements
10
+
11
+ A prerequisite for using the vagrant hypervisor with beaker is that the
12
+ **Vagrant 1.7+** package needs to installed -
13
+ see [downloads.vagrantup.com](http://downloads.vagrantup.com/) for downloads.
14
+
15
+ Currently, we provide a suite of pre-built, publicly available vagrant boxes for
16
+ use in constructing tests: [Puppet Labs Vagrant Boxes](https://vagrantcloud.com/puppetlabs/).
17
+ You can use these boxes easily by pulling one of our
18
+ [Example Vagrant Hosts Files](vagrant_hosts_file_examples.md).
19
+
20
+ ### Setup a Vagrant Hosts File
21
+
22
+ A vm is identified by `box` or `box_url` in the config file. No snapshot name
23
+ is required as the vm is reverted back to original state post testing using
24
+ `vagrant destroy --force`.
25
+
26
+ **Example Vagrant hosts file**
27
+
28
+ HOSTS:
29
+ ubuntu-1404-x64:
30
+ roles:
31
+ - master
32
+ - agent
33
+ - dashboard
34
+ - cloudpro
35
+ platform: ubuntu-1404-x86_64
36
+ hypervisor: vagrant
37
+ box: puppetlabs/ubuntu-14.04-64-nocm
38
+ box_url: https://vagrantcloud.com/puppetlabs/boxes/ubuntu-14.04-64-nocm
39
+ CONFIG:
40
+ nfs_server: none
41
+ consoleport: 443
42
+
43
+ VagrantFiles are created per host configuration file. They can be found in the
44
+ `.vagrant/beaker_vagrant_files` directory of the current working directory in a
45
+ subdirectory named after the host configuration file.
46
+
47
+ > beaker --hosts sample.cfg
48
+ > cd .vagrant/beaker_vagrant_files; ls
49
+ sample.cfg
50
+ > cd sample.c
51
+
52
+ Below are details of vagrants features as they're supported through beaker. If
53
+ you'd like to see more examples of vagrant hosts files, checkout our
54
+ [vagrant hosts file examples doc](vagrant_hosts_file_examples.md).
55
+
56
+ # Vagrant-Specific Hosts File Settings
57
+
58
+ ### Running With a GUI
59
+
60
+ It is possible to have the VirtualBox VM run with a GUI (i.e. non-headless mode)
61
+ by specifying ``vb_gui`` of any non-nil value in the config file, i.e.:
62
+
63
+ **Example Vagrant hosts file with vb_gui**
64
+
65
+ HOSTS:
66
+ ubuntu-1404-x64:
67
+ roles:
68
+ - master
69
+ - agent
70
+ - dashboard
71
+ - cloudpro
72
+ platform: ubuntu-1404-x86_64
73
+ hypervisor: vagrant
74
+ box: puppetlabs/ubuntu-14.04-64-nocm
75
+ box_url: https://vagrantcloud.com/puppetlabs/boxes/ubuntu-14.04-64-nocm
76
+ vb_gui: true
77
+ CONFIG:
78
+ nfs_server: none
79
+ consoleport: 443
80
+
81
+ ### Mounting Local Folders
82
+
83
+ When using the Vagrant Hypervisor, beaker can mount specific local directories
84
+ as synced_folders inside the vagrant box. This is done by using the
85
+ `mount_folders` option in the nodeset file.
86
+
87
+ **Example hosts file**
88
+
89
+ HOSTS:
90
+ ubuntu-1404-x64-master:
91
+ roles:
92
+ - master
93
+ - agent
94
+ - dashboard
95
+ - database
96
+ platform: ubuntu-1404-x86_64
97
+ hypervisor: vagrant
98
+ box: puppetlabs/ubuntu-14.04-64-nocm
99
+ box_url: https://vagrantcloud.com/puppetlabs/boxes/ubuntu-14.04-64-nocm
100
+ mount_folders:
101
+ folder1:
102
+ from: ./
103
+ to: /vagrant/folder1
104
+ tmp:
105
+ from: /tmp
106
+ to: /vagrant/tmp
107
+ ip: 192.168.20.20
108
+ ubuntu-1404-x64-agent:
109
+ roles:
110
+ - agent
111
+ platform: ubuntu-1404-x86_64
112
+ hypervisor: vagrant
113
+ box: puppetlabs/ubuntu-14.04-64-nocm
114
+ box_url: https://vagrantcloud.com/puppetlabs/boxes/ubuntu-14.04-64-nocm
115
+ ip: 192.168.21.21
116
+ CONFIG:
117
+ nfs_server: none
118
+ consoleport: 443
119
+
120
+ In the above beaker will mount the folders `./` to `/vagrant/folder1` and the
121
+ folder `/tmp` to `/vagrant/tmp`.
122
+
123
+ ### Forwarding Ports to Guest
124
+
125
+ When using the Vagrant Hypervisor, beaker can create the Vagrantfile to forward specified ports to a specific box. This is done by using the `forwarded_ports` option in the nodeset file.
126
+
127
+ **Example hosts file**
128
+
129
+ HOSTS:
130
+ ubuntu-1404-x64-master:
131
+ roles:
132
+ - master
133
+ - agent
134
+ - dashboard
135
+ - database
136
+ platform: ubuntu-1404-x86_64
137
+ hypervisor: vagrant
138
+ box: puppetlabs/ubuntu-14.04-64-nocm
139
+ box_url: https://vagrantcloud.com/puppetlabs/boxes/ubuntu-14.04-64-nocm
140
+ ip: 192.168.20.20
141
+ ubuntu-1404-x64-agent:
142
+ roles:
143
+ - agent
144
+ platform: ubuntu-1404-x86_64
145
+ hypervisor: vagrant
146
+ box: puppetlabs/ubuntu-14.04-64-nocm
147
+ box_url: https://vagrantcloud.com/puppetlabs/boxes/ubuntu-14.04-64-nocm
148
+ ip: 192.168.21.21
149
+ forwarded_ports:
150
+ apache:
151
+ from: 10080
152
+ to: 80
153
+ tomcat:
154
+ from: 8080
155
+ to: 8080
156
+ from_ip: '127.0.0.1'
157
+ to_ip: '0.0.0.0'
158
+
159
+ In the above, beaker will forward port 10080 and 8080 on the Host to port 80 and 8080 (respectively) on the Agent guest.
160
+
161
+ # vagrant plugins #
162
+
163
+ You can check more information for some suported vagrant plugins:
164
+
165
+ - [vagrant-libvirt](vagrant_libvirt.md)
@@ -0,0 +1,60 @@
1
+ #centos-511-x64.yml
2
+ ```
3
+ HOSTS:
4
+ centos-511-x64:
5
+ roles:
6
+ - master
7
+ platform: el-5-x86_64
8
+ box: puppetlabs/centos-5.11-64-nocm
9
+ hypervisor: vagrant
10
+ ```
11
+ #centos-65-x64.yml
12
+ ```
13
+ HOSTS:
14
+ centos-65-x64:
15
+ roles:
16
+ - master
17
+ platform: el-6-x86_64
18
+ box: puppetlabs/centos-6.5-64-nocm
19
+ hypervisor: vagrant
20
+ ```
21
+ #debian-609-x64.yml
22
+ ```
23
+ HOSTS:
24
+ debian-609-x64:
25
+ roles:
26
+ - master
27
+ platform: debian-6-amd64
28
+ box: puppetlabs/debian-6.0.9-64-nocm
29
+ hypervisor: vagrant
30
+ ```
31
+ #debian-78-x64.yml
32
+ ```
33
+ HOSTS:
34
+ debian-78-x64:
35
+ roles:
36
+ - master
37
+ platform: debian-7-amd64
38
+ box: puppetlabs/debian-7.8-64-nocm
39
+ hypervisor: vagrant
40
+ ```
41
+ #ubuntu-server-1204-x64.yml
42
+ ```
43
+ HOSTS:
44
+ ubuntu-server-1204-x64:
45
+ roles:
46
+ - master
47
+ platform: ubuntu-1204-amd64
48
+ box: puppetlabs/ubuntu-12.04-64-nocm
49
+ hypervisor: vagrant
50
+ ```
51
+ #ubuntu-server-1404-x64.yml
52
+ ```
53
+ HOSTS:
54
+ ubuntu-server-1404-x64:
55
+ roles:
56
+ - master
57
+ platform: ubuntu-14.04-amd64
58
+ box: puppetlabs/ubuntu-14.04-64-nocm
59
+ hypervisor: vagrant
60
+ ```
@@ -0,0 +1,58 @@
1
+ # Vagrant Libvirt #
2
+
3
+ This driver enabled a tester to trigger tests using libvirtd daemon.
4
+ It is based
5
+ on [libvirt](https://github.com/vagrant-libvirt/vagrant-libvirt)'s
6
+ plugin for vagrant.
7
+
8
+ ## Basic Options ##
9
+
10
+ Once you've setup the libvirt daemon on your beaker coordinator, you
11
+ can use the vagrant_libvirt hypervisor by providing beaker with a
12
+ configuration similar to this:
13
+
14
+ ```yaml
15
+ HOSTS
16
+ centos-puppet-keystone:
17
+ hostname: puppet-keystone.example.net
18
+ roles:
19
+ - master
20
+ platform: el-7-x86_64
21
+ box: centos/7
22
+ box_url: http://cloud.centos.org/centos/7/vagrant/x86_64/images/CentOS-7.LibVirt.box
23
+ hypervisor: vagrant_libvirt
24
+ vagrant_memsize: 4096
25
+ vagrant_cpus: 2
26
+ ```
27
+
28
+ Those are the usual beaker parameters. Note the `hypervisor`
29
+ parameter. Multiple VMs is supported.
30
+
31
+
32
+ ## Advanced Options and remote libvirt daemon ##
33
+
34
+ This driver gives the tester access to all available parameters from
35
+ the vagrant-libvirt plugin. Beware there could be dragons here as
36
+ beaker has some expectations about the created VMs.
37
+
38
+ To pass them down the operator adds them in the config section, here
39
+ is a example.
40
+
41
+ ```yaml
42
+ CONFIG:
43
+ libvirt:
44
+ uri: qemu+ssh://root@libvirt.system.com/system
45
+ ```
46
+
47
+ The `uri` parameter is one of the most useful. The user can have its
48
+ test done on a remote libvirt daemon. The network setup between the
49
+ VMs and the host running beaker will have to be done manually though.
50
+ `management_network_name` and `management_network_address` parameters
51
+ can be useful here.
52
+
53
+ Another good cadidate is `volume_cache: unsafe`.
54
+
55
+ A complete list of options is available in
56
+ the
57
+ [vagrant plugin](https://github.com/vagrant-libvirt/vagrant-libvirt)
58
+ repository.
@@ -0,0 +1,3 @@
1
+ module BeakerVagrant
2
+ VERSION = '0.1.0'
3
+ end
@@ -0,0 +1,287 @@
1
+ require 'open3'
2
+
3
+ module Beaker
4
+ class Vagrant < Beaker::Hypervisor
5
+
6
+ require 'beaker/hypervisor/vagrant_virtualbox'
7
+ # Return a random mac address
8
+ #
9
+ # @return [String] a random mac address
10
+ def randmac
11
+ "080027" + (1..3).map{"%0.2X"%rand(256)}.join
12
+ end
13
+
14
+ def rand_chunk
15
+ (2 + rand(252)).to_s #don't want a 0, 1, or a 255
16
+ end
17
+
18
+ def randip
19
+ "10.255.#{rand_chunk}.#{rand_chunk}"
20
+ end
21
+
22
+ def private_network_generator(host)
23
+ private_network_string = " v.vm.network :private_network, ip: \"#{host['ip'].to_s}\", :netmask => \"#{host['netmask'] ||= "255.255.0.0"}\""
24
+ case host['network_mac']
25
+ when 'false'
26
+ private_network_string << "\n"
27
+ when nil
28
+ private_network_string << ", :mac => \"#{randmac}\"\n"
29
+ else
30
+ private_network_string << ", :mac => \"#{host['network_mac']}\"\n"
31
+ end
32
+ end
33
+
34
+ def make_vfile hosts, options = {}
35
+ #HACK HACK HACK - add checks here to ensure that we have box + box_url
36
+ #generate the VagrantFile
37
+ v_file = "Vagrant.configure(\"2\") do |c|\n"
38
+ v_file << " c.ssh.forward_agent = true\n" if options[:forward_ssh_agent] == true
39
+ v_file << " c.ssh.insert_key = false\n"
40
+ hosts.each do |host|
41
+ host['ip'] ||= randip #use the existing ip, otherwise default to a random ip
42
+ v_file << " c.vm.define '#{host.name}' do |v|\n"
43
+ v_file << " v.vm.hostname = '#{host.name}'\n"
44
+ v_file << " v.vm.box = '#{host['box']}'\n"
45
+ v_file << " v.vm.box_url = '#{host['box_url']}'\n" unless host['box_url'].nil?
46
+ v_file << " v.vm.box_version = '#{host['box_version']}'\n" unless host['box_version'].nil?
47
+ v_file << " v.vm.box_check_update = '#{host['box_check_update'] ||= 'true'}'\n"
48
+ v_file << " v.vm.synced_folder '.', '/vagrant', disabled: true\n" if host['synced_folder'] == 'disabled'
49
+ v_file << private_network_generator(host)
50
+
51
+ unless host['mount_folders'].nil?
52
+ host['mount_folders'].each do |name, folder|
53
+ v_file << " v.vm.synced_folder '#{folder[:from]}', '#{folder[:to]}', create: true\n"
54
+ end
55
+ end
56
+
57
+ unless host['forwarded_ports'].nil?
58
+ host['forwarded_ports'].each do |_name, port|
59
+ fwd = " v.vm.network :forwarded_port,"
60
+ fwd << " protocol: '#{port[:protocol]}'," unless port[:protocol].nil?
61
+ fwd << " guest_ip: '#{port[:to_ip]}'," unless port[:to_ip].nil?
62
+ fwd << " guest: #{port[:to]},"
63
+ fwd << " host_ip: '#{port[:from_ip]}'," unless port[:from_ip].nil?
64
+ fwd << " host: #{port[:from]}"
65
+ fwd << "\n"
66
+
67
+ v_file << fwd
68
+ end
69
+ end
70
+
71
+ if /windows/i.match(host['platform'])
72
+ #due to a regression bug in versions of vagrant 1.6.2, 1.6.3, 1.6.4, >= 1.7.3 ssh fails to forward
73
+ #automatically (note <=1.6.1, 1.6.5, 1.7.0 - 1.7.2 are uneffected)
74
+ #Explicitly setting SSH port forwarding due to this bug
75
+ v_file << " v.vm.network :forwarded_port, guest: 22, host: 2222, id: 'ssh', auto_correct: true\n"
76
+ v_file << " v.vm.network :forwarded_port, guest: 3389, host: 3389, id: 'rdp', auto_correct: true\n"
77
+ v_file << " v.vm.network :forwarded_port, guest: 5985, host: 5985, id: 'winrm', auto_correct: true\n"
78
+ v_file << " v.vm.guest = :windows\n"
79
+ end
80
+
81
+ if /osx/i.match(host['platform'])
82
+ v_file << " v.vm.network 'private_network', ip: '10.0.1.10'\n"
83
+ v_file << " v.vm.synced_folder '.', '/vagrant', :nfs => true\n"
84
+ end
85
+
86
+ if /freebsd/i.match(host['platform'])
87
+ v_file << " v.ssh.shell = 'sh'\n"
88
+ v_file << " v.vm.guest = :freebsd\n"
89
+
90
+ # FreeBSD NFS has a character restriction of 88 characters
91
+ # So you can enable it but if your module has a long name it probably won't work...
92
+ # So to keep things simple let's rsync by default!
93
+ #
94
+ # Further reading if interested:
95
+ # http://www.secnetix.de/olli/FreeBSD/mnamelen.hawk
96
+ # https://bugs.freebsd.org/bugzilla/show_bug.cgi?id=167105
97
+ #
98
+ if host['vagrant_freebsd_nfs'].nil?
99
+ v_file << " v.vm.synced_folder '.', '/vagrant', type: 'rsync'\n"
100
+ else
101
+ v_file << " v.vm.synced_folder '.', '/vagrant', :nfs => true\n"
102
+ end
103
+ end
104
+
105
+ v_file << self.class.provider_vfile_section(host, options)
106
+
107
+ v_file << " end\n"
108
+ @logger.debug "created Vagrantfile for VagrantHost #{host.name}"
109
+ end
110
+ v_file << "end\n"
111
+ File.open(@vagrant_file, 'w') do |f|
112
+ f.write(v_file)
113
+ end
114
+ end
115
+
116
+ def self.provider_vfile_section host, options
117
+ # Backwards compatibility; default to virtualbox
118
+ Beaker::VagrantVirtualbox.provider_vfile_section(host, options)
119
+ end
120
+
121
+ def set_ssh_config host, user
122
+ f = Tempfile.new("#{host.name}")
123
+ ssh_config = Dir.chdir(@vagrant_path) do
124
+ stdin, stdout, stderr, wait_thr = Open3.popen3(@vagrant_env, 'vagrant', 'ssh-config', host.name)
125
+ if not wait_thr.value.success?
126
+ raise "Failed to 'vagrant ssh-config' for #{host.name}"
127
+ end
128
+ stdout.read
129
+ end
130
+ #replace hostname with ip
131
+ ssh_config = ssh_config.gsub(/Host #{host.name}/, "Host #{host['ip']}") unless not host['ip']
132
+
133
+ #set the user
134
+ ssh_config = ssh_config.gsub(/User vagrant/, "User #{user}")
135
+ f.write(ssh_config)
136
+ f.rewind
137
+ host['ssh'] = {:config => f.path()}
138
+ host['user'] = user
139
+ @temp_files << f
140
+ end
141
+
142
+ def get_ip_from_vagrant_file(hostname)
143
+ ip = ''
144
+ if File.file?(@vagrant_file) #we should have a vagrant file available to us for reading
145
+ f = File.read(@vagrant_file)
146
+ m = /'#{hostname}'.*?ip:\s*('|")\s*([^'"]+)('|")/m.match(f)
147
+ if m
148
+ ip = m[2]
149
+ @logger.debug("Determined existing vagrant box #{hostname} ip to be: #{ip} ")
150
+ else
151
+ ip = nil
152
+ @logger.debug("Unable to determine ip for vagrant box #{hostname}")
153
+ end
154
+ else
155
+ raise("No vagrant file found (should be located at #{@vagrant_file})")
156
+ end
157
+ ip
158
+ end
159
+
160
+ def initialize(vagrant_hosts, options)
161
+ require 'tempfile'
162
+ @options = options
163
+ @logger = options[:logger]
164
+ @temp_files = []
165
+ @hosts = vagrant_hosts
166
+ @vagrant_path = File.expand_path(File.join(File.basename(__FILE__), '..', '.vagrant', 'beaker_vagrant_files', File.basename(options[:hosts_file])))
167
+ FileUtils.mkdir_p(@vagrant_path)
168
+ @vagrant_file = File.expand_path(File.join(@vagrant_path, "Vagrantfile"))
169
+ @vagrant_env = { "RUBYLIB" => "" }
170
+ end
171
+
172
+ def provision(provider = nil)
173
+ if !@options[:provision] and !File.file?(@vagrant_file)
174
+ raise "Beaker is configured with provision = false but no vagrant file was found at #{@vagrant_file}. You need to enable provision"
175
+ end
176
+ if @options[:provision]
177
+ #setting up new vagrant hosts
178
+ #make sure that any old boxes are dead dead dead
179
+ begin
180
+ vagrant_cmd("destroy --force") if File.file?(@vagrant_file)
181
+ rescue RuntimeError => e
182
+ # LATER: use <<~MESSAGE once we're on Ruby 2.3
183
+ @logger.debug(%Q{
184
+ Beaker failed to destroy the existing VM's. If you think this is
185
+ an error or you upgraded from an older version of beaker try
186
+ verifying the VM exists and deleting the existing Vagrantfile if
187
+ you believe it is safe to do so. WARNING: If a VM still exists
188
+ please run 'vagrant destroy'.
189
+
190
+ cd #{@vagrant_path}
191
+ vagrant status
192
+ vagrant destroy # only need to run this is a VM is not created
193
+ rm #{@vagrant_file} # only do this if all VM's are actually destroyed
194
+ }.each_line.map(&:strip).join("\n"))
195
+ raise e
196
+ end
197
+
198
+ make_vfile @hosts, @options
199
+
200
+ vagrant_cmd("up#{" --provider #{provider}" if provider}")
201
+ else #set host ip of already up boxes
202
+ @hosts.each do |host|
203
+ host[:ip] = get_ip_from_vagrant_file(host.name)
204
+ end
205
+ end
206
+
207
+ @logger.debug "configure vagrant boxes (set ssh-config, switch to root user, hack etc/hosts)"
208
+ @hosts.each do |host|
209
+ if host[:platform] =~ /windows/
210
+ @logger.debug "skip ssh hacks on windows box #{host[:name]}"
211
+ set_ssh_config host, host['user']
212
+ next
213
+ end
214
+
215
+ default_user = host['user']
216
+
217
+ set_ssh_config host, 'vagrant'
218
+
219
+ #copy vagrant's keys to roots home dir, to allow for login as root
220
+ copy_ssh_to_root host, @options
221
+ #ensure that root login is enabled for this host
222
+ enable_root_login host, @options
223
+ #shut down connection, will reconnect on next exec
224
+ host.close
225
+
226
+ set_ssh_config host, default_user
227
+ end
228
+
229
+ hack_etc_hosts @hosts, @options
230
+
231
+ end
232
+
233
+ def cleanup
234
+ @logger.debug "removing temporary ssh-config files per-vagrant box"
235
+ @temp_files.each do |f|
236
+ f.close()
237
+ end
238
+ @logger.notify "Destroying vagrant boxes"
239
+ vagrant_cmd("destroy --force")
240
+ FileUtils.rm_rf(@vagrant_path)
241
+ end
242
+
243
+ def vagrant_cmd(args)
244
+ Dir.chdir(@vagrant_path) do
245
+ exit_status = 1
246
+ Open3.popen3(@vagrant_env, "vagrant #{args}") {|stdin, stdout, stderr, wait_thr|
247
+ while line = stdout.gets
248
+ @logger.info(line)
249
+ end
250
+ if not wait_thr.value.success?
251
+ raise "Failed to exec 'vagrant #{args}'. Error was #{stderr.read}"
252
+ end
253
+ exit_status = wait_thr.value
254
+ }
255
+ if exit_status != 0
256
+ raise "Failed to execute vagrant_cmd ( #{args} ). Error was #{stderr.read}"
257
+ end
258
+ end
259
+ end
260
+
261
+ def self.cpus(host, options)
262
+ case
263
+ when host['vagrant_cpus']
264
+ host['vagrant_cpus']
265
+ when options['vagrant_cpus']
266
+ options['vagrant_cpus']
267
+ else
268
+ '1'
269
+ end
270
+ end
271
+
272
+ def self.memsize(host, options)
273
+ case
274
+ when host['vagrant_memsize']
275
+ host['vagrant_memsize']
276
+ when options['vagrant_memsize']
277
+ options['vagrant_memsize']
278
+ else
279
+ if host['platform'] =~ /windows/
280
+ '2048'
281
+ else
282
+ '1024'
283
+ end
284
+ end
285
+ end
286
+ end
287
+ end