beaker-vagrant 0.6.7 → 0.7.0

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.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: cc3033b00b34521daab9d6221f02c1514cffaff1c64863dcb5643bf964e28f10
4
- data.tar.gz: be554ffaf55e253e2ef2c61f86c3b9fec52f043f3ce496d1eb5c898e4c4c9da2
3
+ metadata.gz: 4ee5ce13c977a0b3bd07ff792f1f722d986e1e50a332bb4762d1d15c8c8dfe48
4
+ data.tar.gz: 9e17a0f6f245ba61142e42883f0d2b5ac456e40b92b26d6b8c22d08dffc0c7b2
5
5
  SHA512:
6
- metadata.gz: bf38bd6c73c279461c5f9f8a9334a5bbbfb37658dfb0e8463b861fdfbd6c81e1c0132fd8a865a5c3ad08766a89f1ec1792bde7457d9a7d258e2891d5061537c3
7
- data.tar.gz: 54d4ecc9660e53f1c49a1e786407ed1c5c20461fc3ff6756cfe1699d91468c0c9fa01b4e5717258d6f70454e825c8d5fda7ec65d3a3ec17bc49365364b57a122
6
+ metadata.gz: 6b2c6c0ed39876e4f630d9dac376f782a00277011c8b5321567ed09635e55f04b7656df59f0658b1565a3fd474bf632017ea9a9ca99bdd5ba083ebc2791aea7e
7
+ data.tar.gz: 4f429aeccdbb05b4a9eeccf817e44327a463315a16c7a517914469a4a09f9b046d3ea8fc4342208ae2071f1a907324c20c23e1006feff3fe9e96979f6739a6a4
@@ -0,0 +1,24 @@
1
+ name: Release
2
+
3
+ on:
4
+ create:
5
+ ref_type: tag
6
+
7
+ jobs:
8
+ release:
9
+ runs-on: ubuntu-latest
10
+ if: github.repository == 'voxpupuli/beaker-vagrant'
11
+ env:
12
+ BUNDLE_WITHOUT: release
13
+ steps:
14
+ - uses: actions/checkout@v2
15
+ - name: Install Ruby 2.7
16
+ uses: ruby/setup-ruby@v1
17
+ with:
18
+ ruby-version: '2.7'
19
+ - name: Build gem
20
+ run: gem build *.gemspec
21
+ - name: Publish gem
22
+ run: gem push *.gem
23
+ env:
24
+ GEM_HOST_API_KEY: '${{ secrets.RUBYGEMS_AUTH_TOKEN }}'
@@ -24,18 +24,14 @@ Gem::Specification.new do |s|
24
24
  if RUBY_VERSION < "2.3"
25
25
  s.add_development_dependency 'fakefs', '~> 0.6', '< 0.14'
26
26
  else
27
- s.add_development_dependency 'fakefs', '~> 0.6'
27
+ s.add_development_dependency 'fakefs', '>= 0.6', '< 2.0'
28
28
  end
29
- s.add_development_dependency 'rake', '~> 10.1'
29
+ s.add_development_dependency 'rake', '~> 13.0'
30
30
  s.add_development_dependency 'simplecov'
31
31
  s.add_development_dependency 'pry', '~> 0.10'
32
32
 
33
33
  # Documentation dependencies
34
34
  s.add_development_dependency 'yard'
35
35
  s.add_development_dependency 'thin'
36
-
37
- # Run time dependencies
38
- s.add_runtime_dependency 'stringify-hash', '~> 0.0.0'
39
-
40
36
  end
41
37
 
@@ -1,3 +1,3 @@
1
1
  module BeakerVagrant
2
- VERSION = '0.6.7'
2
+ VERSION = '0.7.0'
3
3
  end
@@ -5,12 +5,6 @@ module Beaker
5
5
 
6
6
  require 'beaker/hypervisor/vagrant/mount_folder'
7
7
  require 'beaker/hypervisor/vagrant_virtualbox'
8
- # Return a random mac address
9
- #
10
- # @return [String] a random mac address
11
- def randmac
12
- "080027" + (1..3).map{"%0.2X"%rand(256)}.join
13
- end
14
8
 
15
9
  def rand_chunk
16
10
  (2 + rand(252)).to_s #don't want a 0, 1, or a 255
@@ -27,19 +21,17 @@ module Beaker
27
21
 
28
22
  def private_network_generator(host)
29
23
  private_network_string = " v.vm.network :private_network, ip: \"#{host['ip'].to_s}\", :netmask => \"#{host['netmask'] ||= "255.255.0.0"}\""
30
- case host['network_mac']
31
- when 'false'
32
- @mac = randmac
33
- private_network_string << "\n"
34
- when nil
35
- @mac = randmac
36
- private_network_string << ", :mac => \"#{@mac}\"\n"
24
+ if host['network_mac']
25
+ private_network_string << ", :mac => \"#{host['network_mac']}\"\n"
37
26
  else
38
- @mac = host['network_mac']
39
- private_network_string << ", :mac => \"#{@mac}\"\n"
27
+ private_network_string << "\n"
40
28
  end
41
29
  end
42
30
 
31
+ def connection_preference(host)
32
+ [:hostname]
33
+ end
34
+
43
35
  def shell_provisioner_generator(provisioner_config)
44
36
  unless provisioner_config['path'].nil? || provisioner_config['path'].empty?
45
37
  unless provisioner_config['args'].nil?
@@ -62,7 +54,7 @@ module Beaker
62
54
 
63
55
  hosts.each do |host|
64
56
  host.name.tr!('_','-') # Rewrite Hostname with hyphens instead of underscores to get legal hostname
65
- host['ip'] ||= randip(host.host_hash[:hypervisor]) #use the existing ip, otherwise default to a random ip
57
+ set_host_default_ip(host)
66
58
  v_file << " c.vm.define '#{host.name}' do |v|\n"
67
59
  v_file << " v.vm.hostname = '#{host.name}'\n"
68
60
  v_file << " v.vm.box = '#{host['box']}'\n"
@@ -72,7 +64,7 @@ module Beaker
72
64
  v_file << " v.vm.box_check_update = '#{host['box_check_update'] ||= 'true'}'\n"
73
65
  v_file << " v.vm.synced_folder '.', '/vagrant', disabled: true\n" if host['synced_folder'] == 'disabled'
74
66
  v_file << shell_provisioner_generator(host['shell_provisioner']) if host['shell_provisioner']
75
- v_file << private_network_generator(host)
67
+ v_file << private_network_generator(host) if host['ip']
76
68
 
77
69
  unless host['mount_folders'].nil?
78
70
  host['mount_folders'].each do |name, folder|
@@ -132,7 +124,6 @@ module Beaker
132
124
  else
133
125
  v_file << " v.vm.synced_folder '.', '/vagrant', :nfs => true\n"
134
126
  end
135
- v_file << " v.vm.base_mac = '#{@mac}'\n"
136
127
  end
137
128
 
138
129
  v_file << self.class.provider_vfile_section(host, options)
@@ -189,72 +180,45 @@ module Beaker
189
180
  end
190
181
 
191
182
  def set_ssh_config host, user
192
- f = Tempfile.new("#{host.name}")
193
- ssh_config = Dir.chdir(@vagrant_path) do
194
- stdin, stdout, stderr, wait_thr = Open3.popen3(@vagrant_env, 'vagrant', 'ssh-config', host.name)
195
- if not wait_thr.value.success?
196
- raise "Failed to 'vagrant ssh-config' for #{host.name}"
197
- end
198
- stdout.read
199
- end
200
- #replace hostname with ip
201
- ssh_config = ssh_config.gsub(/Host #{host.name}/, "Host #{host['ip']}") unless not host['ip']
202
-
203
- #set the user
204
- ssh_config = ssh_config.gsub(/User vagrant/, "User #{user}")
183
+ return unless Dir.exist?(@vagrant_path)
205
184
 
206
- if @options[:forward_ssh_agent] == true
207
- ssh_config = ssh_config.gsub(/IdentitiesOnly yes/, "IdentitiesOnly no")
185
+ ssh_config = Dir.chdir(@vagrant_path) do
186
+ stdout, _, status = Open3.capture3(@vagrant_env, 'vagrant', 'ssh-config', host.name)
187
+ unless status.success?
188
+ raise "Failed to 'vagrant ssh-config' for #{host.name}"
208
189
  end
209
190
 
210
- f.write(ssh_config)
211
- f.rewind
212
-
213
- host[:vagrant_ssh_config] = f.path
214
- host['ssh'] = host['ssh'].merge(Net::SSH.configuration_for(host['ip'], f.path))
215
- host['user'] = user
216
- @temp_files << f
217
- end
191
+ Tempfile.create do |f|
192
+ f.write(stdout)
193
+ f.flush
218
194
 
219
- def get_ip_from_vagrant_file(hostname)
220
- ip = ''
221
- if File.file?(@vagrant_file) #we should have a vagrant file available to us for reading
222
- f = File.read(@vagrant_file)
223
- m = /'#{hostname}'.*?ip:\s*('|")\s*([^'"]+)('|")/m.match(f)
224
- if m
225
- ip = m[2]
226
- @logger.debug("Determined existing vagrant box #{hostname} ip to be: #{ip} ")
227
- else
228
- ip = nil
229
- @logger.debug("Unable to determine ip for vagrant box #{hostname}")
195
+ Net::SSH::Config.for(host.name, [f.path])
230
196
  end
231
- else
232
- raise("No vagrant file found (should be located at #{@vagrant_file})")
233
197
  end
234
- ip
198
+
199
+ ssh_config[:user] = user
200
+ ssh_config[:keys_only] = false if @options[:forward_ssh_agent] == true
201
+
202
+ host['ssh'] = host['ssh'].merge(ssh_config)
203
+ host['user'] = user
235
204
  end
236
205
 
237
206
  def initialize(vagrant_hosts, options)
238
207
  require 'tempfile'
239
208
  @options = options
240
209
  @logger = options[:logger]
241
- @temp_files = []
242
210
  @hosts = vagrant_hosts
243
- @vagrant_path = File.expand_path(File.join(File.basename(__FILE__), '..', '.vagrant', 'beaker_vagrant_files', 'beaker_' + File.basename(options[:hosts_file])))
211
+ @vagrant_path = File.expand_path(File.join('.vagrant', 'beaker_vagrant_files', 'beaker_' + File.basename(options[:hosts_file])))
244
212
  @vagrant_file = File.expand_path(File.join(@vagrant_path, "Vagrantfile"))
245
213
  @vagrant_env = { "RUBYLIB" => "", "RUBYOPT" => "" }
246
214
  end
247
215
 
248
216
  def configure(opts = {})
249
- if !@options[:provision]
250
- if !File.file?(@vagrant_file)
217
+ unless @options[:provision]
218
+ unless File.file?(@vagrant_file)
251
219
  raise "Beaker is configured with provision = false but no vagrant file was found at #{@vagrant_file}. You need to enable provision"
252
220
  end
253
221
 
254
- @hosts.each do |host|
255
- host[:ip] = get_ip_from_vagrant_file(host.name)
256
- end
257
-
258
222
  set_all_ssh_config
259
223
  end
260
224
  super
@@ -292,9 +256,6 @@ module Beaker
292
256
 
293
257
  def cleanup
294
258
  @logger.debug "removing temporary ssh-config files per-vagrant box"
295
- @temp_files.each do |f|
296
- f.close()
297
- end
298
259
  @logger.notify "Destroying vagrant boxes"
299
260
  vagrant_cmd("destroy --force")
300
261
  FileUtils.rm_rf(@vagrant_path)
@@ -350,5 +311,11 @@ module Beaker
350
311
  end
351
312
  end
352
313
  end
314
+
315
+ private
316
+
317
+ def set_host_default_ip(host)
318
+ host['ip'] ||= randip(host.host_hash[:hypervisor]) # use the existing ip, otherwise default to a random ip
319
+ end
353
320
  end
354
321
  end
@@ -6,6 +6,7 @@ class Beaker::VagrantCustom < Beaker::Vagrant
6
6
  end
7
7
 
8
8
  def make_vfile hosts, options = {}
9
+ FileUtils.mkdir_p(@vagrant_path)
9
10
  FileUtils.cp(@options[:vagrantfile_path], @vagrant_file)
10
11
  end
11
12
  end
@@ -1,27 +1,17 @@
1
1
  require 'beaker/hypervisor/vagrant'
2
2
 
3
3
  class Beaker::VagrantLibvirt < Beaker::Vagrant
4
- @memory = nil
5
- @cpu = nil
6
-
7
- class << self
8
- attr_reader :memory
9
- end
10
-
11
- # Return a random mac address with colons
12
- #
13
- # @return [String] a random mac address
14
- def randmac
15
- "08:00:27:" + (1..3).map{"%0.2X"%rand(256)}.join(':')
16
- end
4
+ def initialize(*)
5
+ super
17
6
 
18
- def provision(provider = 'libvirt')
19
7
  # This needs to be unique for every system with the same hostname but does
20
8
  # not affect VirtualBox
21
9
  vagrant_path_digest = Digest::SHA256.hexdigest(@vagrant_path)
22
- @vagrant_path = @vagrant_path + '_' + vagrant_path_digest[0..2] + vagrant_path_digest[-3..-1]
10
+ @vagrant_path += '_' + vagrant_path_digest[0..2] + vagrant_path_digest[-3..-1]
23
11
  @vagrant_file = File.expand_path(File.join(@vagrant_path, "Vagrantfile"))
12
+ end
24
13
 
14
+ def provision(provider = 'libvirt')
25
15
  super
26
16
  end
27
17
 
@@ -30,19 +20,19 @@ class Beaker::VagrantLibvirt < Beaker::Vagrant
30
20
  " node.cpus = #{cpus(host, options)}\n" +
31
21
  " node.memory = #{memsize(host, options)}\n" +
32
22
  " node.qemu_use_session = false\n" +
33
- build_options_str(options) +
23
+ build_options(options).join("\n") + "\n" +
34
24
  " end\n"
35
25
  end
36
26
 
37
- def self.build_options_str(options)
38
- other_options_str = ''
39
- if options['libvirt']
40
- other_options = []
41
- options['libvirt'].each do |k, v|
42
- other_options << " node.#{k} = '#{v}'"
43
- end
44
- other_options_str = other_options.join("\n")
45
- end
46
- "#{other_options_str}\n"
27
+ def self.build_options(options)
28
+ return [] unless options['libvirt']
29
+
30
+ options['libvirt'].map { |k, v| " node.#{k} = '#{v}'" }
31
+ end
32
+
33
+ private
34
+
35
+ def set_host_default_ip(host)
36
+ # In vagrant-libvirt hosts get a management IP, no need for a default
47
37
  end
48
38
  end
@@ -19,9 +19,10 @@ describe Beaker::VagrantCustom do
19
19
  expect( vagrant ).to receive( :set_ssh_config ).with( host, host_prev_name ).once
20
20
  end
21
21
  expect( vagrant ).to receive( :hack_etc_hosts ).with( @hosts, options ).once
22
- FakeFS.activate!
23
22
  expect( vagrant ).to receive( :vagrant_cmd ).with( "up" ).once
24
- vagrant.provision
23
+ FakeFS do
24
+ vagrant.provision
25
+ end
25
26
  end
26
27
 
27
28
  context 'takes vagrant configuration from existing file' do
@@ -2,71 +2,57 @@ require 'spec_helper'
2
2
 
3
3
  describe Beaker::VagrantDesktop do
4
4
  let( :options ) { make_opts.merge({ :hosts_file => 'sample.cfg', 'logger' => double().as_null_object }) }
5
- let( :vagrant ) { Beaker::VagrantDesktop.new( @hosts, options ) }
6
-
7
- before :each do
8
- @hosts = make_hosts()
9
- end
5
+ let( :vagrant ) { described_class.new( hosts, options ) }
6
+ let( :hosts ) { make_hosts }
10
7
 
11
8
  it "uses the vmware_desktop provider for provisioning" do
12
- @hosts.each do |host|
9
+ hosts.each do |host|
13
10
  host_prev_name = host['user']
14
11
  expect( vagrant ).to receive( :set_ssh_config ).with( host, 'vagrant' ).once
15
12
  expect( vagrant ).to receive( :copy_ssh_to_root ).with( host, options ).once
16
13
  expect( vagrant ).to receive( :set_ssh_config ).with( host, host_prev_name ).once
17
14
  end
18
- expect( vagrant ).to receive( :hack_etc_hosts ).with( @hosts, options ).once
15
+ expect( vagrant ).to receive( :hack_etc_hosts ).with( hosts, options ).once
19
16
  expect( vagrant ).to receive( :vagrant_cmd ).with( "up --provider vmware_desktop" ).once
20
- vagrant.provision
21
- end
22
-
23
- it "can make a Vagranfile for a set of hosts" do
24
- path = vagrant.instance_variable_get( :@vagrant_path )
25
- allow( vagrant ).to receive( :randmac ).and_return( "0123456789" )
26
-
27
- vagrant.make_vfile( @hosts )
28
-
29
- vagrantfile = File.read( File.expand_path( File.join( path, "Vagrantfile")))
30
- expect( vagrantfile ).to include( %Q{ v.vm.provider :vmware_desktop do |v|\n v.vmx['memsize'] = '1024'\n end})
17
+ FakeFS do
18
+ vagrant.provision
19
+ end
31
20
  end
32
21
 
33
- it "can enable whitelist_verified on hosts" do
34
- path = vagrant.instance_variable_get( :@vagrant_path )
35
- hosts = make_hosts({:whitelist_verified => true},1)
36
-
37
- vagrant.make_vfile( hosts )
38
-
39
- vagrantfile = File.read( File.expand_path( File.join( path, 'Vagrantfile' )))
40
- expect( vagrantfile ).to include( %Q{ v.vmx['whitelist_verified'] = 'true'})
41
- end
22
+ context 'can make a Vagrantfile' do
23
+ subject do
24
+ FakeFS do
25
+ vagrant.make_vfile(hosts)
26
+ File.read(vagrant.instance_variable_get(:@vagrant_file))
27
+ end
28
+ end
42
29
 
43
- it "can enable functional_hgfs on hosts" do
44
- path = vagrant.instance_variable_get( :@vagrant_path )
45
- hosts = make_hosts({:functional_hgfs => true},1)
30
+ it "for a set of hosts" do
31
+ is_expected.to include( %Q{ v.vm.provider :vmware_desktop do |v|\n v.vmx['memsize'] = '1024'\n end})
32
+ end
46
33
 
47
- vagrant.make_vfile( hosts )
34
+ context 'with whitelist_verified' do
35
+ let(:hosts) { make_hosts({:whitelist_verified => true}, 1) }
48
36
 
49
- vagrantfile = File.read( File.expand_path( File.join( path, 'Vagrantfile' )))
50
- expect( vagrantfile ).to include( %Q{ v.vmx['functional_hgfs'] = 'true'})
51
- end
37
+ it { is_expected.to include( %Q{ v.vmx['whitelist_verified'] = 'true'}) }
38
+ end
52
39
 
53
- it "can enable unmount_default_hgfs on hosts" do
54
- path = vagrant.instance_variable_get( :@vagrant_path )
55
- hosts = make_hosts({:unmount_default_hgfs => true},1)
40
+ context 'with functional_hgfs' do
41
+ let(:hosts) { make_hosts({:functional_hgfs => true}, 1) }
56
42
 
57
- vagrant.make_vfile( hosts )
43
+ it { is_expected.to include( %Q{ v.vmx['functional_hgfs'] = 'true'}) }
44
+ end
58
45
 
59
- vagrantfile = File.read( File.expand_path( File.join( path, 'Vagrantfile' )))
60
- expect( vagrantfile ).to include( %Q{ v.vmx['unmount_default_hgfs'] = 'true'})
61
- end
46
+ context 'with unmount_default_hgfs' do
47
+ let(:hosts) { make_hosts({:unmount_default_hgfs => true}, 1) }
62
48
 
63
- it "can enable gui on hosts" do
64
- path = vagrant.instance_variable_get( :@vagrant_path )
65
- hosts = make_hosts({:gui => true},1)
49
+ it { is_expected.to include( %Q{ v.vmx['unmount_default_hgfs'] = 'true'}) }
50
+ end
66
51
 
67
- vagrant.make_vfile( hosts )
52
+ context "with gui" do
53
+ let(:hosts) { make_hosts({:gui => true},1) }
68
54
 
69
- vagrantfile = File.read( File.expand_path( File.join( path, 'Vagrantfile' )))
70
- expect( vagrantfile ).to include( %Q{ v.vmx['gui'] = true})
55
+ it { is_expected.to include( %Q{ v.vmx['gui'] = true}) }
56
+ end
71
57
  end
72
58
  end
@@ -2,31 +2,31 @@ require 'spec_helper'
2
2
 
3
3
  describe Beaker::VagrantFusion do
4
4
  let( :options ) { make_opts.merge({ :hosts_file => 'sample.cfg', 'logger' => double().as_null_object }) }
5
- let( :vagrant ) { Beaker::VagrantFusion.new( @hosts, options ) }
6
-
7
- before :each do
8
- @hosts = make_hosts()
9
- end
5
+ let( :vagrant ) { described_class.new( hosts, options ) }
6
+ let( :hosts ) { make_hosts() }
10
7
 
11
8
  it "uses the vmware_fusion provider for provisioning" do
12
- @hosts.each do |host|
9
+ hosts.each do |host|
13
10
  host_prev_name = host['user']
14
11
  expect( vagrant ).to receive( :set_ssh_config ).with( host, 'vagrant' ).once
15
12
  expect( vagrant ).to receive( :copy_ssh_to_root ).with( host, options ).once
16
13
  expect( vagrant ).to receive( :set_ssh_config ).with( host, host_prev_name ).once
17
14
  end
18
- expect( vagrant ).to receive( :hack_etc_hosts ).with( @hosts, options ).once
15
+ expect( vagrant ).to receive( :hack_etc_hosts ).with( hosts, options ).once
19
16
  expect( vagrant ).to receive( :vagrant_cmd ).with( "up --provider vmware_fusion" ).once
20
17
  vagrant.provision
21
18
  end
22
19
 
23
- it "can make a Vagranfile for a set of hosts" do
24
- path = vagrant.instance_variable_get( :@vagrant_path )
25
- allow( vagrant ).to receive( :randmac ).and_return( "0123456789" )
26
-
27
- vagrant.make_vfile( @hosts )
20
+ context 'Correct vagrant configuration' do
21
+ subject do
22
+ FakeFS do
23
+ vagrant.make_vfile( hosts, options )
24
+ File.read(vagrant.instance_variable_get(:@vagrant_file))
25
+ end
26
+ end
28
27
 
29
- vagrantfile = File.read( File.expand_path( File.join( path, "Vagrantfile")))
30
- expect( vagrantfile ).to include( %Q{ v.vm.provider :vmware_fusion do |v|\n v.vmx['memsize'] = '1024'\n end})
28
+ it 'has a provider section' do
29
+ is_expected.to include( %Q{ v.vm.provider :vmware_fusion do |v|\n v.vmx['memsize'] = '1024'\n end})
30
+ end
31
31
  end
32
32
  end