From 35dcf3dfb62590f6ab0452033b7b4731beed0cdb Mon Sep 17 00:00:00 2001 From: Ewoud Kohl van Wijngaarden Date: Fri, 21 Aug 2020 15:19:28 +0200 Subject: [PATCH] Do not set an explicit mac address Vagrant can generate this itself and beaker shouldn't care about the exact mac address unless explicitly told to. --- lib/beaker/hypervisor/vagrant.rb | 19 ++------ lib/beaker/hypervisor/vagrant_libvirt.rb | 7 --- .../beaker/hypervisor/vagrant_desktop_spec.rb | 1 - spec/beaker/hypervisor/vagrant_fusion_spec.rb | 1 - .../beaker/hypervisor/vagrant_libvirt_spec.rb | 5 -- .../hypervisor/vagrant_parallels_spec.rb | 1 - spec/beaker/hypervisor/vagrant_spec.rb | 47 ++----------------- .../hypervisor/vagrant_virtualbox_spec.rb | 1 - .../hypervisor/vagrant_workstation_spec.rb | 1 - 9 files changed, 6 insertions(+), 77 deletions(-) diff --git a/lib/beaker/hypervisor/vagrant.rb b/lib/beaker/hypervisor/vagrant.rb index fef46e0..8f64c3a 100644 --- a/lib/beaker/hypervisor/vagrant.rb +++ b/lib/beaker/hypervisor/vagrant.rb @@ -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 @@ -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 @@ -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) diff --git a/lib/beaker/hypervisor/vagrant_libvirt.rb b/lib/beaker/hypervisor/vagrant_libvirt.rb index 3c902c9..c4a3033 100644 --- a/lib/beaker/hypervisor/vagrant_libvirt.rb +++ b/lib/beaker/hypervisor/vagrant_libvirt.rb @@ -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 diff --git a/spec/beaker/hypervisor/vagrant_desktop_spec.rb b/spec/beaker/hypervisor/vagrant_desktop_spec.rb index 8480e79..287c67f 100644 --- a/spec/beaker/hypervisor/vagrant_desktop_spec.rb +++ b/spec/beaker/hypervisor/vagrant_desktop_spec.rb @@ -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 ) diff --git a/spec/beaker/hypervisor/vagrant_fusion_spec.rb b/spec/beaker/hypervisor/vagrant_fusion_spec.rb index 399084f..1d3f6d5 100644 --- a/spec/beaker/hypervisor/vagrant_fusion_spec.rb +++ b/spec/beaker/hypervisor/vagrant_fusion_spec.rb @@ -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 ) diff --git a/spec/beaker/hypervisor/vagrant_libvirt_spec.rb b/spec/beaker/hypervisor/vagrant_libvirt_spec.rb index fc8a58a..af98504 100644 --- a/spec/beaker/hypervisor/vagrant_libvirt_spec.rb +++ b/spec/beaker/hypervisor/vagrant_libvirt_spec.rb @@ -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 diff --git a/spec/beaker/hypervisor/vagrant_parallels_spec.rb b/spec/beaker/hypervisor/vagrant_parallels_spec.rb index 5d4d5e1..a86ddc5 100644 --- a/spec/beaker/hypervisor/vagrant_parallels_spec.rb +++ b/spec/beaker/hypervisor/vagrant_parallels_spec.rb @@ -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 ) diff --git a/spec/beaker/hypervisor/vagrant_spec.rb b/spec/beaker/hypervisor/vagrant_spec.rb index dd253cb..e682d3c 100644 --- a/spec/beaker/hypervisor/vagrant_spec.rb +++ b/spec/beaker/hypervisor/vagrant_spec.rb @@ -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') @@ -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 ) @@ -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 @@ -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 @@ -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 @@ -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 ) @@ -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 ) @@ -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 ) @@ -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 ) @@ -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 ) @@ -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({ @@ -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' @@ -216,7 +189,6 @@ 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/ @@ -224,7 +196,6 @@ module Beaker 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({ @@ -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 ) @@ -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 ) @@ -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!'} ) @@ -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!'} ) @@ -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( { @@ -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( { @@ -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( { @@ -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( { diff --git a/spec/beaker/hypervisor/vagrant_virtualbox_spec.rb b/spec/beaker/hypervisor/vagrant_virtualbox_spec.rb index 01d7d68..add73ef 100644 --- a/spec/beaker/hypervisor/vagrant_virtualbox_spec.rb +++ b/spec/beaker/hypervisor/vagrant_virtualbox_spec.rb @@ -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 ) diff --git a/spec/beaker/hypervisor/vagrant_workstation_spec.rb b/spec/beaker/hypervisor/vagrant_workstation_spec.rb index 3c9d344..2308c16 100644 --- a/spec/beaker/hypervisor/vagrant_workstation_spec.rb +++ b/spec/beaker/hypervisor/vagrant_workstation_spec.rb @@ -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 )