Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Do not set an explicit mac address #43

Merged
merged 1 commit into from
May 18, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
19 changes: 3 additions & 16 deletions lib/beaker/hypervisor/vagrant.rb
Original file line number Diff line number Diff line change
Expand Up @@ -5,12 +5,6 @@ class Vagrant < Beaker::Hypervisor

require 'beaker/hypervisor/vagrant/mount_folder'
require 'beaker/hypervisor/vagrant_virtualbox'
# Return a random mac address
#
# @return [String] a random mac address
def randmac
"080027" + (1..3).map{"%0.2X"%rand(256)}.join
end

def rand_chunk
(2 + rand(252)).to_s #don't want a 0, 1, or a 255
Expand All @@ -27,16 +21,10 @@ def randip(hypervisor=nil)

def private_network_generator(host)
private_network_string = " v.vm.network :private_network, ip: \"#{host['ip'].to_s}\", :netmask => \"#{host['netmask'] ||= "255.255.0.0"}\""
case host['network_mac']
when 'false'
@mac = randmac
private_network_string << "\n"
when nil
@mac = randmac
private_network_string << ", :mac => \"#{@mac}\"\n"
if host['network_mac']
private_network_string << ", :mac => \"#{host['network_mac']}\"\n"
else
@mac = host['network_mac']
private_network_string << ", :mac => \"#{@mac}\"\n"
private_network_string << "\n"
end
end

Expand Down Expand Up @@ -132,7 +120,6 @@ def make_vfile hosts, options = {}
else
v_file << " v.vm.synced_folder '.', '/vagrant', :nfs => true\n"
end
v_file << " v.vm.base_mac = '#{@mac}'\n"
end

v_file << self.class.provider_vfile_section(host, options)
Expand Down
7 changes: 0 additions & 7 deletions lib/beaker/hypervisor/vagrant_libvirt.rb
Original file line number Diff line number Diff line change
@@ -1,13 +1,6 @@
require 'beaker/hypervisor/vagrant'

class Beaker::VagrantLibvirt < Beaker::Vagrant
# Return a random mac address with colons
#
# @return [String] a random mac address
def randmac
"08:00:27:" + (1..3).map{"%0.2X"%rand(256)}.join(':')
end

def provision(provider = 'libvirt')
# This needs to be unique for every system with the same hostname but does
# not affect VirtualBox
Expand Down
1 change: 0 additions & 1 deletion spec/beaker/hypervisor/vagrant_desktop_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,6 @@

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" )

vagrant.make_vfile( @hosts )

Expand Down
1 change: 0 additions & 1 deletion spec/beaker/hypervisor/vagrant_fusion_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,6 @@

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" )

vagrant.make_vfile( @hosts )

Expand Down
5 changes: 0 additions & 5 deletions spec/beaker/hypervisor/vagrant_libvirt_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -54,10 +54,5 @@
expect( @vagrantfile.split("\n").map(&:strip) )
.to include("node.uri = 'qemu+ssh://root@host/system'")
end

it "has a mac address in the proper format" do
expect( @vagrantfile.split("\n").map(&:strip) )
.to include(/:mac => "08:00:27:\h{2}:\h{2}:\h{2}"/)
end
end
end
1 change: 0 additions & 1 deletion spec/beaker/hypervisor/vagrant_parallels_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,6 @@

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" )

vagrant.make_vfile( @hosts )

Expand Down
47 changes: 3 additions & 44 deletions spec/beaker/hypervisor/vagrant_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,6 @@ module Beaker
end

it "stores the vagrant file in $WORKINGDIR/.vagrant/beaker_vagrant_files/beaker_sample.cfg" do
allow( vagrant ).to receive( :randmac ).and_return( "0123456789" )
path = vagrant.instance_variable_get( :@vagrant_path )

expect( path ).to be === File.join(Dir.pwd, '.vagrant', 'beaker_vagrant_files', 'beaker_sample.cfg')
Expand All @@ -39,7 +38,6 @@ module Beaker

it "can make a Vagrantfile for a set of hosts" do
path = vagrant.instance_variable_get( :@vagrant_path )
allow( vagrant ).to receive( :randmac ).and_return( "0123456789" )

vagrant.make_vfile( @hosts )

Expand All @@ -53,7 +51,7 @@ module Beaker
v.vm.box = 'vm2vm1_of_my_box'
v.vm.box_url = 'http://address.for.my.box.vm1'
v.vm.box_check_update = 'true'
v.vm.network :private_network, ip: "ip.address.for.vm1", :netmask => "255.255.0.0", :mac => "0123456789"
v.vm.network :private_network, ip: "ip.address.for.vm1", :netmask => "255.255.0.0"
v.vm.synced_folder './', '/temp', create: true
v.vm.synced_folder '../', '/tmp', create: true
v.vm.network :forwarded_port, guest: 80, host: 10080
Expand All @@ -68,7 +66,7 @@ module Beaker
v.vm.box = 'vm2vm2_of_my_box'
v.vm.box_url = 'http://address.for.my.box.vm2'
v.vm.box_check_update = 'true'
v.vm.network :private_network, ip: "ip.address.for.vm2", :netmask => "255.255.0.0", :mac => "0123456789"
v.vm.network :private_network, ip: "ip.address.for.vm2", :netmask => "255.255.0.0"
v.vm.synced_folder './', '/temp', create: true
v.vm.synced_folder '../', '/tmp', create: true
v.vm.network :forwarded_port, guest: 80, host: 10080
Expand All @@ -83,7 +81,7 @@ module Beaker
v.vm.box = 'vm2vm3_of_my_box'
v.vm.box_url = 'http://address.for.my.box.vm3'
v.vm.box_check_update = 'true'
v.vm.network :private_network, ip: "ip.address.for.vm3", :netmask => "255.255.0.0", :mac => "0123456789"
v.vm.network :private_network, ip: "ip.address.for.vm3", :netmask => "255.255.0.0"
v.vm.synced_folder './', '/temp', create: true
v.vm.synced_folder '../', '/tmp', create: true
v.vm.network :forwarded_port, guest: 80, host: 10080
Expand All @@ -99,7 +97,6 @@ module Beaker

it "can make a Vagrantfile with ssh agent forwarding enabled" do
path = vagrant.instance_variable_get( :@vagrant_path )
allow( vagrant ).to receive( :randmac ).and_return( "0123456789" )

hosts = make_hosts({},1)
vagrant.make_vfile( hosts, options )
Expand All @@ -110,7 +107,6 @@ module Beaker

it "can replace underscores in host.name with hypens" do
path = vagrant.instance_variable_get( :@vagrant_path )
allow( vagrant ).to receive( :randmac ).and_return( "0123456789" )

host = make_host( 'name-with_underscore', {} )
vagrant.make_vfile( [host,], options )
Expand All @@ -122,7 +118,6 @@ module Beaker

it "can make a Vagrantfile with synced_folder disabled" do
path = vagrant.instance_variable_get( :@vagrant_path )
allow( vagrant ).to receive( :randmac ).and_return( "0123456789" )

hosts = make_hosts({:synced_folder => 'disabled'},1)
vagrant.make_vfile( hosts, options )
Expand All @@ -131,16 +126,6 @@ module Beaker
expect( vagrantfile ).to match(/v.vm.synced_folder .* disabled: true/)
end

it "can make a Vagrantfile with network mac autogenerated" do
path = vagrant.instance_variable_get( :@vagrant_path )

hosts = make_hosts({},1)
vagrant.make_vfile( hosts, options )

vagrantfile = File.read( File.expand_path( File.join( path, "Vagrantfile")))
expect( vagrantfile ).to match(/v.vm.network :private_network, ip: "ip.address.for.vm1", :netmask => "255.255.0.0", :mac => ".+/)
end

it "can make a Vagrantfile with network mac specified" do
path = vagrant.instance_variable_get( :@vagrant_path )

Expand All @@ -151,16 +136,6 @@ module Beaker
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/)
end

it "can make a Vagrantfile with network mac disabled" do
path = vagrant.instance_variable_get( :@vagrant_path )

hosts = make_hosts({:network_mac => 'false'},1)
vagrant.make_vfile( hosts, options )

vagrantfile = File.read( File.expand_path( File.join( path, "Vagrantfile")))
expect( vagrantfile ).to match(/v.vm.network :private_network, ip: "ip.address.for.vm1", :netmask => "255.255.0.0"/)
end

it "can make a Vagrantfile with improper keys for synced folders" do
path = vagrant.instance_variable_get( :@vagrant_path )

Expand All @@ -182,7 +157,6 @@ module Beaker

it "can make a Vagrantfile with optional shell provisioner" do
path = vagrant.instance_variable_get( :@vagrant_path )
allow( vagrant ).to receive( :randmac ).and_return( "0123456789" )

shell_path = '/path/to/shell/script'
hosts = make_hosts({
Expand All @@ -198,7 +172,6 @@ module Beaker

it "can make a Vagrantfile with optional shell provisioner with args" do
path = vagrant.instance_variable_get( :@vagrant_path )
allow( vagrant ).to receive( :randmac ).and_return( "0123456789" )

shell_path = '/path/to/shell/script.sh'
shell_args = 'arg1 arg2'
Expand All @@ -216,15 +189,13 @@ module Beaker

it "raises an error if path is not set on shell_provisioner" do
path = vagrant.instance_variable_get( :@vagrant_path )
allow( vagrant ).to receive( :randmac ).and_return( "0123456789" )

hosts = make_hosts({:shell_provisioner => {}}, 1)
expect{ vagrant.make_vfile( hosts, options ) }.to raise_error RuntimeError, /No path defined for shell_provisioner or path empty/
end

it "raises an error if path is EMPTY on shell_provisioner" do
path = vagrant.instance_variable_get( :@vagrant_path )
allow( vagrant ).to receive( :randmac ).and_return( "0123456789" )

empty_shell_path = ''
hosts = make_hosts({
Expand All @@ -238,7 +209,6 @@ module Beaker
context "when generating a windows config" do
before do
path = vagrant.instance_variable_get( :@vagrant_path )
allow( vagrant ).to receive( :randmac ).and_return( "0123456789" )
@hosts[0][:platform] = 'windows'

vagrant.make_vfile( @hosts )
Expand Down Expand Up @@ -270,7 +240,6 @@ module Beaker
context 'when generating a freebsd config' do
before do
path = vagrant.instance_variable_get( :@vagrant_path )
allow( vagrant ).to receive( :randmac ).and_return( "0123456789" )
@hosts[0][:platform] = 'freebsd'

vagrant.make_vfile( @hosts )
Expand All @@ -285,15 +254,10 @@ module Beaker
it 'has the proper guest setting' do
expect( @generated_file ).to match /v.vm.guest = :freebsd\n/
end

it 'sets the vm.base_mac setting' do
expect( @generated_file ).to match /v.vm.base_mac = '0123456789'\n/
end
end

it "uses the memsize defined per vagrant host" do
path = vagrant.instance_variable_get( :@vagrant_path )
allow( vagrant ).to receive( :randmac ).and_return( "0123456789" )

vagrant.make_vfile( @hosts, {'vagrant_memsize' => 'hello!'} )

Expand All @@ -307,7 +271,6 @@ module Beaker

it "uses the cpus defined per vagrant host" do
path = vagrant.instance_variable_get( :@vagrant_path )
allow( vagrant ).to receive( :randmac ).and_return( "0123456789" )

vagrant.make_vfile( @hosts, {'vagrant_cpus' => 'goodbye!'} )

Expand All @@ -322,7 +285,6 @@ module Beaker
context "port forwarding rules" do
it "supports all Vagrant parameters" do
path = vagrant.instance_variable_get( :@vagrant_path )
allow( vagrant ).to receive( :randmac ).and_return( "0123456789" )

hosts = make_hosts(
{
Expand All @@ -344,7 +306,6 @@ module Beaker

it "supports supports from_ip" do
path = vagrant.instance_variable_get( :@vagrant_path )
allow( vagrant ).to receive( :randmac ).and_return( "0123456789" )

hosts = make_hosts(
{
Expand All @@ -364,7 +325,6 @@ module Beaker

it "supports all to_ip" do
path = vagrant.instance_variable_get( :@vagrant_path )
allow( vagrant ).to receive( :randmac ).and_return( "0123456789" )

hosts = make_hosts(
{
Expand All @@ -384,7 +344,6 @@ module Beaker

it "supports all protocol" do
path = vagrant.instance_variable_get( :@vagrant_path )
allow( vagrant ).to receive( :randmac ).and_return( "0123456789" )

hosts = make_hosts(
{
Expand Down
1 change: 0 additions & 1 deletion spec/beaker/hypervisor/vagrant_virtualbox_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,6 @@

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" )

vagrant.make_vfile( @hosts )

Expand Down
1 change: 0 additions & 1 deletion spec/beaker/hypervisor/vagrant_workstation_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,6 @@

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" )

vagrant.make_vfile( @hosts )

Expand Down