Make beaker work with libvirt instead of virtualbox
Step by step guide in order to get beaker-vagrant to work with the vagrant-libvirt plugin. It changes things to allow the vagrant-libvirt plugin to function by accessing the private dhcp network and allowing the plugin to perform an ip masquerade. This in essence is exactly the same functionality as virtualbox’s networking.
This guide assumes you have the following environment set up for ruby: https://simp.readthedocs.io/en/master/getting_started_guide/Installation_Options/ISO/ISO_Build/Environment_Preparation.html
This guide also assumes you have the following environment set up for vagrant and libvirt: https://www.onyxpoint.com/blog/vagrant-libvirt-on-centos-7/
Instructions
export BEAKER_HYPERVISOR='vagrant_libvirt'
bundle install
vim ~/.rvm/gems/ruby-2.5.7/gems/beaker-vagrant-0.6.6/lib/beaker/hypervisor/vagrant_libvirt.rb
Replace the vagrant_libvirt.rb private_network_generator and shell_provisioner_generator functions with the following:
def private_network_generator(host) #if 'dhcp_ip' not provided, use the default example IP. #:libvirt__network_address is a portion of the private network options # and here is the relevant documentation: #Used only when :type is set to dhcp. Only /24 subnet is supported. #Default is 172.28.128.0 unless host['dhcp_ip'].nil? || host['dhcp_ip'].empty? dhcp_ip = host['dhcp_ip'] else dhcp_ip = "172.28.128.0" end private_network_string = " v.vm.network :private_network, :type => \"dhcp\", :libvirt__network_address => \"#{dhcp_ip}\"\n" end def shell_provisioner_generator(provisioner_config) #hacky fix, but the default vagrant file generator overlays the route #by default to not handle the ip masquerade that the vagrant-libvirt #will provide. To work around this, by deleting the default route whenever #the vagrant libvirt vm comes up, it will correct itself and then the ip #masquerade will work as intended. if provisioner_config.nil? shell_provisioner_string = " v.vm.provision 'shell', :inline => 'ip route del default', :run => 'always'\n" else if not provisioner_config.include? 'ip route del default' shell_provisioner_string += " v.vm.provision 'shell', :inline => 'ip route del default', :run => 'always'\n" end end end
bundle exec rake beaker:suites
You should see vagrant come up via libvirt and the acceptance tests pass.