spec/beaker/hypervisor/vagrant_virtualbox_spec.rb in beaker-vagrant-0.6.7 vs spec/beaker/hypervisor/vagrant_virtualbox_spec.rb in beaker-vagrant-0.7.0

- old
+ new

@@ -1,100 +1,78 @@ require 'spec_helper' describe Beaker::VagrantVirtualbox do let( :options ) { make_opts.merge({ :hosts_file => 'sample.cfg', 'logger' => double().as_null_object }) } - let( :vagrant ) { Beaker::VagrantVirtualbox.new( @hosts, options ) } - let(:vagrantfile_path) do - path = vagrant.instance_variable_get( :@vagrant_path ) - File.expand_path( File.join( path, 'Vagrantfile' )) - end + let( :vagrant ) { described_class.new( hosts, options ) } + let(:vagrantfile_path) { vagrant.instance_variable_get( :@vagrant_file ) } + let(:hosts) { make_hosts() } - before :each do - @hosts = make_hosts() - end - it "uses the virtualbox provider for provisioning" do - @hosts.each do |host| + hosts.each do |host| host_prev_name = host['user'] expect( vagrant ).to receive( :set_ssh_config ).with( host, 'vagrant' ).once expect( vagrant ).to receive( :copy_ssh_to_root ).with( host, options ).once expect( vagrant ).to receive( :set_ssh_config ).with( host, host_prev_name ).once end - expect( vagrant ).to receive( :hack_etc_hosts ).with( @hosts, options ).once + expect( vagrant ).to receive( :hack_etc_hosts ).with( hosts, options ).once expect( vagrant ).to receive( :vagrant_cmd ).with( "up --provider virtualbox" ).once vagrant.provision end - it "can make a Vagranfile for a set of hosts" do - path = vagrant.instance_variable_get( :@vagrant_path ) - allow( vagrant ).to receive( :randmac ).and_return( "0123456789" ) + context 'can make a Vagrantfile' do + subject do + FakeFS do + vagrant.make_vfile(hosts) + File.read(vagrant.instance_variable_get(:@vagrant_file)) + end + end - vagrant.make_vfile( @hosts ) + it "can make a Vagrantfile for a set of hosts" do + is_expected.to include( %Q{ v.vm.provider :virtualbox do |vb|\n vb.customize ['modifyvm', :id, '--memory', '1024', '--cpus', '1', '--audio', 'none']\n end}) + end - vagrantfile = File.read( File.expand_path( File.join( path, 'Vagrantfile' ))) - expect( vagrantfile ).to include( %Q{ v.vm.provider :virtualbox do |vb|\n vb.customize ['modifyvm', :id, '--memory', '1024', '--cpus', '1', '--audio', 'none']\n end}) - end + context 'with ioapic(multiple cores)' do + let(:hosts) { make_hosts({:ioapic => 'true'}, 1) } - it "can disable the vb guest plugin" do - options.merge!({ :vbguest_plugin => 'disable' }) + it { is_expected.to include( " vb.customize ['modifyvm', :id, '--ioapic', 'on']") } + end - vfile_section = vagrant.class.provider_vfile_section( @hosts.first, options ) + context 'with NAT DNS' do + let(:hosts) { make_hosts({:natdns => 'on'}, 1) } - match = vfile_section.match(/vb.vbguest.auto_update = false/) + it { is_expected.to include( " vb.customize ['modifyvm', :id, '--natdnshostresolver1', 'on']") } + it { is_expected.to include( " vb.customize ['modifyvm', :id, '--natdnsproxy1', 'on']") } + end - expect( match ).to_not be nil + context 'storage with the USB controller' do + let(:hosts) { make_hosts({:volumes => { 'test_disk' => { size: '5120' }}, :volume_storage_controller => 'USB' }) } - end + it { is_expected.to include(" vb.customize ['modifyvm', :id, '--usb', 'on']") } + it { is_expected.to include(" vb.customize ['storagectl', :id, '--name', 'Beaker USB Controller', '--add', 'usb', '--portcount', '8', '--controller', 'USB', '--bootable', 'off']") } + it { is_expected.to include(" vb.customize ['createhd', '--filename', 'vm1-test_disk.vdi', '--size', '5120']") } + it { is_expected.to include(" vb.customize ['storageattach', :id, '--storagectl', 'Beaker USB Controller', '--port', '0', '--device', '0', '--type', 'hdd', '--medium', 'vm1-test_disk.vdi']") } + end - it "can enable ioapic(multiple cores) on hosts" do - path = vagrant.instance_variable_get( :@vagrant_path ) - hosts = make_hosts({:ioapic => 'true'},1) + context 'storage with the LSILogic controller' do + let(:hosts) { make_hosts({:volumes => { 'test_disk' => { size: '5120' }}, :volume_storage_controller => 'LSILogic' }) } - vagrant.make_vfile( hosts ) + it { is_expected.to include(" vb.customize ['storagectl', :id, '--name', 'Beaker LSILogic Controller', '--add', 'scsi', '--portcount', '16', '--controller', 'LSILogic', '--bootable', 'off']") } + it { is_expected.to include(" vb.customize ['createhd', '--filename', 'vm1-test_disk.vdi', '--size', '5120']") } + it { is_expected.to include(" vb.customize ['storageattach', :id, '--storagectl', 'Beaker LSILogic Controller', '--port', '0', '--device', '0', '--type', 'hdd', '--medium', 'vm1-test_disk.vdi']") } + end - vagrantfile = File.read( File.expand_path( File.join( path, 'Vagrantfile' ))) - expect( vagrantfile ).to include( " vb.customize ['modifyvm', :id, '--ioapic', 'on']") - end + context "storage with the default controller" do + let(:hosts) { make_hosts({:volumes => { 'test_disk' => { size: '5120' }}}) } - it "can enable NAT DNS on hosts" do - hosts = make_hosts({:natdns => 'on'},1) - vagrant.make_vfile( hosts ) - vagrantfile = File.read( vagrantfile_path ) - - expect( vagrantfile ).to include( " vb.customize ['modifyvm', :id, '--natdnshostresolver1', 'on']") - expect( vagrantfile ).to include( " vb.customize ['modifyvm', :id, '--natdnsproxy1', 'on']") + it { is_expected.to include(" vb.customize ['storagectl', :id, '--name', 'Beaker IntelAHCI Controller', '--add', 'sata', '--portcount', '2', '--controller', 'IntelAHCI', '--bootable', 'off']") } + it { is_expected.to include(" vb.customize ['createhd', '--filename', 'vm1-test_disk.vdi', '--size', '5120']") } + it { is_expected.to include(" vb.customize ['storageattach', :id, '--storagectl', 'Beaker IntelAHCI Controller', '--port', '0', '--device', '0', '--type', 'hdd', '--medium', 'vm1-test_disk.vdi']") } + end end - it "correctly provisions storage with the USB controller" do - path = vagrant.instance_variable_get( :@vagrant_path ) - hosts = make_hosts({:volumes => { 'test_disk' => { size: '5120' }}, :volume_storage_controller => 'USB' }) + context 'disabled vb guest plugin' do + let(:options) { super().merge({ :vbguest_plugin => 'disable' }) } + subject { vagrant.class.provider_vfile_section( hosts.first, options ) } - vagrant.make_vfile( hosts ) - vagrantfile = File.read( File.expand_path( File.join( path, 'Vagrantfile' ))) - expect( vagrantfile ).to include(" vb.customize ['modifyvm', :id, '--usb', 'on']") - expect( vagrantfile ).to include(" vb.customize ['storagectl', :id, '--name', 'Beaker USB Controller', '--add', 'usb', '--portcount', '8', '--controller', 'USB', '--bootable', 'off']") - expect( vagrantfile ).to include(" vb.customize ['createhd', '--filename', 'vm1-test_disk.vdi', '--size', '5120']") - expect( vagrantfile ).to include(" vb.customize ['storageattach', :id, '--storagectl', 'Beaker USB Controller', '--port', '0', '--device', '0', '--type', 'hdd', '--medium', 'vm1-test_disk.vdi']") - end - - it "correctly provisions storage with the LSILogic controller" do - path = vagrant.instance_variable_get( :@vagrant_path ) - hosts = make_hosts({:volumes => { 'test_disk' => { size: '5120' }}, :volume_storage_controller => 'LSILogic' }) - - vagrant.make_vfile( hosts ) - vagrantfile = File.read( File.expand_path( File.join( path, 'Vagrantfile' ))) - expect( vagrantfile ).to include(" vb.customize ['storagectl', :id, '--name', 'Beaker LSILogic Controller', '--add', 'scsi', '--portcount', '16', '--controller', 'LSILogic', '--bootable', 'off']") - expect( vagrantfile ).to include(" vb.customize ['createhd', '--filename', 'vm1-test_disk.vdi', '--size', '5120']") - expect( vagrantfile ).to include(" vb.customize ['storageattach', :id, '--storagectl', 'Beaker LSILogic Controller', '--port', '0', '--device', '0', '--type', 'hdd', '--medium', 'vm1-test_disk.vdi']") - end - - it "correctly provisions storage with the default controller" do - path = vagrant.instance_variable_get( :@vagrant_path ) - hosts = make_hosts({:volumes => { 'test_disk' => { size: '5120' }}}) - - vagrant.make_vfile( hosts ) - vagrantfile = File.read( File.expand_path( File.join( path, 'Vagrantfile' ))) - expect( vagrantfile ).to include(" vb.customize ['storagectl', :id, '--name', 'Beaker IntelAHCI Controller', '--add', 'sata', '--portcount', '2', '--controller', 'IntelAHCI', '--bootable', 'off']") - expect( vagrantfile ).to include(" vb.customize ['createhd', '--filename', 'vm1-test_disk.vdi', '--size', '5120']") - expect( vagrantfile ).to include(" vb.customize ['storageattach', :id, '--storagectl', 'Beaker IntelAHCI Controller', '--port', '0', '--device', '0', '--type', 'hdd', '--medium', 'vm1-test_disk.vdi']") + it { is_expected.to match(/vb\.vbguest\.auto_update = false/) } end end