Merge pull request #7605 from mitchellh/sethvargo/integ

Fix guest bugs
This commit is contained in:
Seth Vargo 2016-07-18 21:44:47 -04:00 committed by GitHub
commit 1277f19251
93 changed files with 636 additions and 902 deletions

View File

@ -780,6 +780,14 @@ module Vagrant
error_key(:virtualbox_no_name)
end
class VirtualBoxMountFailed < VagrantError
error_key(:virtualbox_mount_failed)
end
class VirtualBoxMountNotSupportedBSD < VagrantError
error_key(:virtualbox_mount_not_supported_bsd)
end
class VirtualBoxNameExists < VagrantError
error_key(:virtualbox_name_exists)
end

View File

@ -5,19 +5,22 @@ module VagrantPlugins
def self.change_host_name(machine, name)
comm = machine.communicate
if !comm.test("hostname | grep -w '#{name}'")
if !comm.test("hostname -f | grep '^#{name}$'", sudo: false)
basename = name.split(".", 2)[0]
comm.sudo <<-EOH
hostnamectl set-hostname '#{name}'
comm.sudo <<-EOH.gsub(/^ {14}/, "")
set -e
# Remove comments and blank lines from /etc/hosts
sed -i'' -e 's/#.*$//' -e '/^$/d' /etc/hosts
# Set hostname
hostnamectl set-hostname '#{basename}'
# Prepend ourselves to /etc/hosts
grep -w '#{name}' /etc/hosts || {
sed -i'' '1i 127.0.0.1\\t#{name}\\t#{basename}' /etc/hosts
}
EOH
# Remove comments and blank lines from /etc/hosts
sed -i'' -e 's/#.*$//' -e '/^$/d' /etc/hosts
# Prepend ourselves to /etc/hosts
grep -w '#{name}' /etc/hosts || {
sed -i'' '1i 127.0.0.1\\t#{name}\\t#{basename}' /etc/hosts
}
EOH
end
end
end

View File

@ -1,3 +1,5 @@
require "ipaddr"
require "socket"
require "tempfile"
require_relative "../../../../lib/vagrant/util/template_renderer"
@ -11,18 +13,19 @@ module VagrantPlugins
def self.configure_networks(machine, networks)
comm = machine.communicate
commands = []
interfaces = []
# The result will be something like:
# eth0\nenp0s8\nenp0s9
comm.sudo("ip -o -0 addr | grep -v LOOPBACK | awk '{print $2}' | sed 's/://'") do |_, stdout|
interfaces = stdout.split("\n")
end
commands = ["set -e"]
interfaces = machine.guest.capability(:network_interfaces)
networks.each.with_index do |network, i|
network[:device] = interfaces[network[:interface]]
# Arch expects netmasks to be in the "24" or "64", but users may
# specify IPV4 netmasks like "255.255.255.0". This magic converts
# the netmask to the proper value.
if network[:netmask] && network[:netmask].to_s.include?(".")
network[:netmask] = (32-Math.log2((IPAddr.new(network[:netmask], Socket::AF_INET).to_i^0xffffffff)+1)).to_i
end
entry = TemplateRenderer.render("guests/arch/network_#{network[:type]}",
options: network,
)

View File

@ -0,0 +1,35 @@
module VagrantPlugins
module GuestArch
module Cap
class NFS
def self.nfs_client_installed(machine)
machine.communicate.test("pacman -Q nfs-utils")
end
def self.nfs_pre(machine)
comm = machine.communicate
# There is a bug in NFS where the rpcbind functionality is not started
# and it's not a dependency of nfs-utils. Read more here:
#
# https://bbs.archlinux.org/viewtopic.php?id=193410
#
comm.sudo <<-EOH.gsub(/^ {12}/, "")
set -e
systemctl enable rpcbind
systemctl start rpcbind
EOH
end
def self.nfs_client_install(machine)
comm = machine.communicate
comm.sudo <<-EOH.gsub(/^ {12}/, "")
set -e
pacman --noconfirm -Syy
pacman --noconfirm -S nfs-utils ntp
EOH
end
end
end
end
end

View File

@ -20,6 +20,21 @@ module VagrantPlugins
require_relative "cap/configure_networks"
Cap::ConfigureNetworks
end
guest_capability(:arch, :nfs_client_install) do
require_relative "cap/nfs"
Cap::NFS
end
guest_capability(:arch, :nfs_client_installed) do
require_relative "cap/nfs"
Cap::NFS
end
guest_capability(:arch, :nfs_pre) do
require_relative "cap/nfs"
Cap::NFS
end
end
end
end

View File

@ -5,19 +5,22 @@ module VagrantPlugins
def self.change_host_name(machine, name)
comm = machine.communicate
if !comm.test("hostname | grep -w '#{name}'")
if !comm.test("hostname -f | grep '^#{name}$'", sudo: false)
basename = name.split(".", 2)[0]
comm.sudo <<-EOH
hostnamectl set-hostname '#{name}'
comm.sudo <<-EOH.gsub(/^ {14}/, "")
set -e
# Remove comments and blank lines from /etc/hosts
sed -i'' -e 's/#.*$//' -e '/^$/d' /etc/hosts
# Set hostname
hostnamectl set-hostname '#{basename}'
# Prepend ourselves to /etc/hosts
grep -w '#{name}' /etc/hosts || {
sed -i'' '1i 127.0.0.1\\t#{name}\\t#{basename}' /etc/hosts
}
EOH
# Remove comments and blank lines from /etc/hosts
sed -i'' -e 's/#.*$//' -e '/^$/d' /etc/hosts
# Prepend ourselves to /etc/hosts
grep -w '#{name}' /etc/hosts || {
sed -i'' '1i 127.0.0.1\\t#{name}\\t#{basename}' /etc/hosts
}
EOH
end
end
end

View File

@ -4,7 +4,7 @@ module VagrantPlugins
class Halt
def self.halt(machine)
begin
machine.communicate.sudo("/sbin/shutdown -p -h now", shell: "sh")
machine.communicate.sudo("/sbin/shutdown -p now", shell: "sh")
rescue IOError
# Do nothing, because it probably means the machine shut down
# and SSH connection was lost.

View File

@ -0,0 +1,16 @@
module VagrantPlugins
module GuestBSD
module Cap
class VirtualBox
# BSD-based guests do not currently support VirtualBox synced folders.
# Instead of raising an error about a missing capability, this defines
# the capability and then provides a more detailed error message,
# linking to sources on the Internet where the problem is
# better-described.
def self.mount_virtualbox_shared_folder(machine, name, guestpath, options)
raise Vagrant::Errors::VirtualBoxMountNotSupportedBSD
end
end
end
end
end

View File

@ -26,6 +26,11 @@ module VagrantPlugins
Cap::NFS
end
guest_capability(:bsd, :mount_virtualbox_shared_folder) do
require_relative "cap/virtualbox"
Cap::VirtualBox
end
guest_capability(:bsd, :remove_public_key) do
require_relative "cap/public_key"
Cap::PublicKey

View File

@ -5,7 +5,7 @@ module VagrantPlugins
def self.change_host_name(machine, name)
comm = machine.communicate
if !comm.test("hostname --fqdn | grep -w '#{name}'")
if !comm.test("hostname -f | grep '^#{name}$'", sudo: false)
basename = name.split(".", 2)[0]
comm.sudo("hostname '#{basename}'")

View File

@ -5,10 +5,13 @@ module VagrantPlugins
def self.change_host_name(machine, name)
comm = machine.communicate
if !comm.test("hostname -f | grep -w '#{name}' || hostname -s | grep -w '#{name}'")
if !comm.test("hostname -f | grep '^#{name}$'", sudo: false)
basename = name.split(".", 2)[0]
comm.sudo <<-EOH.gsub(/^ {14}/, '')
set -e
# Set hostname
scutil --set ComputerName '#{name}'
scutil --set HostName '#{name}'

View File

@ -1,3 +1,5 @@
require "shellwords"
module VagrantPlugins
module GuestDarwin
module Cap
@ -11,9 +13,8 @@ module VagrantPlugins
end
def self.rsync_pre(machine, opts)
machine.communicate.tap do |comm|
comm.sudo("mkdir -p '#{opts[:guestpath]}'")
end
guest_path = Shellwords.escape(opts[:guestpath])
machine.communicate.sudo("mkdir -p #{guest_path}")
end
def self.rsync_post(machine, opts)
@ -21,8 +22,10 @@ module VagrantPlugins
return
end
guest_path = Shellwords.escape(opts[:guestpath])
machine.communicate.sudo(
"find '#{opts[:guestpath]}' '(' ! -user #{opts[:owner]} -or ! -group #{opts[:group]} ')' -print0 | " +
"find #{guest_path} '(' ! -user #{opts[:owner]} -or ! -group #{opts[:group]} ')' -print0 | " +
"xargs -0 chown #{opts[:owner]}:#{opts[:group]}")
end
end

View File

@ -2,20 +2,23 @@ module VagrantPlugins
module GuestDebian
module Cap
class ChangeHostName
# For more information, please see:
#
# https://wiki.debian.org/HowTo/ChangeHostname
#
def self.change_host_name(machine, name)
comm = machine.communicate
if !comm.test("hostname -f | grep -w '#{name}'")
if !comm.test("hostname -f | grep '^#{name}$'", sudo: false)
basename = name.split(".", 2)[0]
comm.sudo <<-EOH.gsub(/^ {14}/, '')
# Ensure exit on command error
set -e
# Set the hostname
echo '#{name}' > /etc/hostname
echo '#{basename}' > /etc/hostname
hostname -F /etc/hostname
if command -v hostnamectl; then
hostnamectl set-hostname '#{basename}'
fi
# Remove comments and blank lines from /etc/hosts
sed -i'' -e 's/#.*$//' -e '/^$/d' /etc/hosts
@ -27,17 +30,13 @@ module VagrantPlugins
# Update mailname
echo '#{name}' > /etc/mailname
# Restart networking and force new DHCP
if [ test -f /etc/init.d/hostname.sh ]; then
invoke-rc.d hostname.sh start
# Restart hostname services
if test -f /etc/init.d/hostname; then
/etc/init.d/hostname start || true
fi
if [ test -f /etc/init.d/networking ]; then
invoke-rc.d networking force-reload
fi
if [ test -f /etc/init.d/network-manager ]; then
invoke-rc.d network-manager force-reload
if test -f /etc/init.d/hostname.sh; then
/etc/init.d/hostname.sh start || true
fi
EOH
end

View File

@ -11,13 +11,9 @@ module VagrantPlugins
def self.configure_networks(machine, networks)
comm = machine.communicate
commands = []
commands = ["set -e"]
entries = []
interfaces = []
comm.sudo("ip -o -0 addr | grep -v LOOPBACK | awk '{print $2}' | sed 's/://'") do |_, stdout|
interfaces = stdout.split("\n")
end
interfaces = machine.guest.capability(:network_interfaces)
networks.each do |network|
network[:device] = interfaces[network[:interface]]

View File

@ -1,10 +1,11 @@
module VagrantPlugins
module GuestDebian
module Cap
class NFSClient
class NFS
def self.nfs_client_install(machine)
comm = machine.communicate
comm.sudo <<-EOH.gsub(/^ {12}/, '')
set -e
apt-get -yqq update
apt-get -yqq install nfs-common portmap
EOH

View File

@ -4,12 +4,11 @@ module VagrantPlugins
class RSync
def self.rsync_install(machine)
comm = machine.communicate
if !comm.test("command -v rsync")
comm.sudo <<-EOH.gsub(/^ {14}/, '')
apt-get -yqq update
apt-get -yqq install rsync
EOH
end
comm.sudo <<-EOH.gsub(/^ {14}/, '')
set -e
apt-get -yqq update
apt-get -yqq install rsync
EOH
end
end
end

View File

@ -22,8 +22,8 @@ module VagrantPlugins
end
guest_capability(:debian, :nfs_client_install) do
require_relative "cap/nfs_client"
Cap::NFSClient
require_relative "cap/nfs"
Cap::NFS
end
guest_capability(:debian, :rsync_install) do

View File

@ -1,29 +0,0 @@
module VagrantPlugins
module GuestFedora
module Cap
class ChangeHostName
def self.change_host_name(machine, name)
comm = machine.communicate
if !comm.test("hostname | grep -w '#{name}'")
basename = name.split(".", 2)[0]
comm.sudo <<-EOH
echo '#{name}' > /etc/hostname
hostname -F /etc/hostname
hostnamectl set-hostname --static '#{name}'
hostnamectl set-hostname --transient '#{name}'
# Remove comments and blank lines from /etc/hosts
sed -i'' -e 's/#.*$//' -e '/^$/d' /etc/hosts
# Prepend ourselves to /etc/hosts
grep -w '#{name}' /etc/hosts || {
sed -i'' '1i 127.0.0.1\\t#{name}\\t#{basename}' /etc/hosts
}
EOH
end
end
end
end
end
end

View File

@ -1,135 +0,0 @@
require "set"
require "tempfile"
require_relative "../../../../lib/vagrant/util/retryable"
require_relative "../../../../lib/vagrant/util/template_renderer"
module VagrantPlugins
module GuestFedora
module Cap
class ConfigureNetworks
extend Vagrant::Util::Retryable
include Vagrant::Util
def self.configure_networks(machine, networks)
network_scripts_dir = machine.guest.capability("network_scripts_dir")
virtual = false
interface_names = Array.new
interface_names_by_slot = Array.new
machine.communicate.sudo("/usr/sbin/biosdevname &>/dev/null; echo $?") do |_, result|
# The above command returns:
# - '4' if /usr/sbin/biosdevname detects it is running in a virtual machine
# - '127' if /usr/sbin/biosdevname doesn't exist
virtual = true if ['4', '127'].include? result.chomp
end
if virtual
machine.communicate.sudo("ls -v /sys/class/net | egrep -v lo\\|docker") do |_, result|
interface_names = result.split("\n")
end
interface_names_by_slot = networks.map do |network|
"#{interface_names[network[:interface]]}"
end
else
machine.communicate.sudo("/usr/sbin/biosdevname -d | grep Kernel | cut -f2 -d: | sed -e 's/ //;'") do |_, result|
interface_names = result.split("\n")
end
interface_name_pairs = Array.new
interface_names.each do |interface_name|
machine.communicate.sudo("/usr/sbin/biosdevname --policy=all_ethN -i #{interface_name}") do |_, result|
interface_name_pairs.push([interface_name, result.gsub("\n", "")])
end
end
setting_interface_names = networks.map do |network|
"eth#{network[:interface]}"
end
interface_names_by_slot = interface_names.dup
interface_name_pairs.each do |interface_name, previous_interface_name|
if setting_interface_names.index(previous_interface_name) == nil
interface_names_by_slot.delete(interface_name)
end
end
end
# Read interface MAC addresses for later matching
mac_addresses = Array.new(interface_names.length)
interface_names.each_with_index do |ifname, index|
machine.communicate.sudo("cat /sys/class/net/#{ifname}/address") do |_, result|
mac_addresses[index] = result.strip
end
end
# Accumulate the configurations to add to the interfaces file as well
# as what interfaces we're actually configuring since we use that later.
interfaces = Set.new
networks.each do |network|
interface = nil
if network[:mac_address]
found_idx = mac_addresses.find_index(network[:mac_address])
# Ignore network if requested MAC address could not be found
next if found_idx.nil?
interface = interface_names[found_idx]
else
ifname_by_slot = interface_names_by_slot[network[:interface]-1]
# Don't overwrite if interface was already matched via MAC address
next if interfaces.include?(ifname_by_slot)
interface = ifname_by_slot
end
interfaces.add(interface)
network[:device] = interface
# Remove any previous vagrant configuration in this network
# interface's configuration files.
machine.communicate.sudo("touch #{network_scripts_dir}/ifcfg-#{interface}")
machine.communicate.sudo("sed -e '/^#VAGRANT-BEGIN/,/^#VAGRANT-END/ d' #{network_scripts_dir}/ifcfg-#{interface} > /tmp/vagrant-ifcfg-#{interface}")
machine.communicate.sudo("cat /tmp/vagrant-ifcfg-#{interface} > #{network_scripts_dir}/ifcfg-#{interface}")
machine.communicate.sudo("rm -f /tmp/vagrant-ifcfg-#{interface}")
# Render and upload the network entry file to a deterministic
# temporary location.
entry = TemplateRenderer.render("guests/fedora/network_#{network[:type]}",
options: network)
Tempfile.open("vagrant-fedora-configure-networks") do |f|
f.binmode
f.write(entry)
f.fsync
f.close
machine.communicate.upload(f.path, "/tmp/vagrant-network-entry_#{interface}")
end
end
# Bring down all the interfaces we're reconfiguring. By bringing down
# each specifically, we avoid reconfiguring p7p (the NAT interface) so
# SSH never dies.
interfaces.each do |interface|
retryable(on: Vagrant::Errors::VagrantError, tries: 3, sleep: 2) do
machine.communicate.sudo(<<-SCRIPT, error_check: true)
cat /tmp/vagrant-network-entry_#{interface} >> #{network_scripts_dir}/ifcfg-#{interface}
if command -v nmcli &>/dev/null; then
if command -v systemctl &>/dev/null && systemctl -q is-enabled NetworkManager &>/dev/null; then
nmcli c reload #{interface}
elif command -v service &>/dev/null && service NetworkManager status &>/dev/null; then
nmcli c reload #{interface}
fi
fi
/sbin/ifdown #{interface}
/sbin/ifup #{interface}
rm -f /tmp/vagrant-network-entry_#{interface}
SCRIPT
end
end
end
end
end
end
end

View File

@ -14,7 +14,7 @@ module VagrantPlugins
if version.nil?
return :fedora
else
return "fedora_#{version}".to_sym
return :"fedora_#{version}"
end
end
end

View File

@ -1,15 +0,0 @@
module VagrantPlugins
module GuestFedora
module Cap
class NetworkScriptsDir
# The path to the directory with the network configuration scripts.
# This is pulled out into its own directory since there are other
# operating systems (SUSE) which behave similarly but with a different
# path to the network scripts.
def self.network_scripts_dir(machine)
"/etc/sysconfig/network-scripts"
end
end
end
end
end

View File

@ -11,21 +11,6 @@ module VagrantPlugins
Guest
end
guest_capability(:fedora, :change_host_name) do
require_relative "cap/change_host_name"
Cap::ChangeHostName
end
guest_capability(:fedora, :configure_networks) do
require_relative "cap/configure_networks"
Cap::ConfigureNetworks
end
guest_capability(:fedora, :network_scripts_dir) do
require_relative "cap/network_scripts_dir"
Cap::NetworkScriptsDir
end
guest_capability(:fedora, :flavor) do
require_relative "cap/flavor"
Cap::Flavor

View File

@ -3,10 +3,9 @@ module VagrantPlugins
module Cap
class ChangeHostName
def self.change_host_name(machine, name)
options = { shell: "sh" }
comm = machine.communicate
if !comm.test("hostname -f | grep -w '#{name}' || hostname -s | grep -w '#{name}'", options)
if !comm.test("hostname -f | grep '^#{name}$'", sudo: false, shell: "sh")
basename = name.split(".", 2)[0]
command = <<-EOH.gsub(/^ {14}/, '')
# Set the hostname
@ -23,7 +22,7 @@ module VagrantPlugins
mv /tmp/tmp-hosts /etc/hosts
}
EOH
comm.sudo(command, options)
comm.sudo(command, shell: "sh")
end
end
end

View File

@ -1,3 +1,5 @@
require "shellwords"
module VagrantPlugins
module GuestFreeBSD
module Cap
@ -15,9 +17,8 @@ module VagrantPlugins
end
def self.rsync_pre(machine, opts)
machine.communicate.tap do |comm|
comm.sudo("mkdir -p '#{opts[:guestpath]}'")
end
guest_path = Shellwords.escape(opts[:guestpath])
machine.communicate.sudo("mkdir -p #{guest_path}")
end
def self.rsync_post(machine, opts)
@ -25,8 +26,10 @@ module VagrantPlugins
return
end
guest_path = Shellwords.escape(opts[:guestpath])
machine.communicate.sudo(
"find '#{opts[:guestpath]}' '(' ! -user #{opts[:owner]} -or ! -group #{opts[:group]} ')' -print0 | " +
"find #{guest_path} '(' ! -user #{opts[:owner]} -or ! -group #{opts[:group]} ')' -print0 | " +
"xargs -0 -r chown #{opts[:owner]}:#{opts[:group]}")
end
end

View File

@ -1,17 +0,0 @@
module VagrantPlugins
module GuestFuntoo
module Cap
class ChangeHostName
def self.change_host_name(machine, name)
machine.communicate.tap do |comm|
if !comm.test("sudo hostname --fqdn | grep '#{name}'")
comm.sudo("echo 'hostname=#{name.split('.')[0]}' > /etc/conf.d/hostname")
comm.sudo("sed -i 's@^\\(127[.]0[.]0[.]1[[:space:]]\\+\\)@\\1#{name} #{name.split('.')[0]} @' /etc/hosts")
comm.sudo("hostname #{name.split('.')[0]}")
end
end
end
end
end
end
end

View File

@ -6,16 +6,11 @@ module VagrantPlugins
name "Funtoo guest"
description "Funtoo guest support."
guest(:funtoo, :linux) do
guest(:funtoo, :gentoo) do
require_relative "guest"
Guest
end
guest_capability(:funtoo, :change_host_name) do
require_relative "cap/change_host_name"
Cap::ChangeHostName
end
guest_capability(:funtoo, :configure_networks) do
require_relative "cap/configure_networks"
Cap::ConfigureNetworks

View File

@ -3,12 +3,27 @@ module VagrantPlugins
module Cap
class ChangeHostName
def self.change_host_name(machine, name)
machine.communicate.tap do |comm|
if !comm.test("sudo hostname --fqdn | grep '#{name}'")
comm.sudo("echo 'hostname=#{name.split('.')[0]}' > /etc/conf.d/hostname")
comm.sudo("sed -i 's@^\\(127[.]0[.]0[.]1[[:space:]]\\+\\)@\\1#{name} #{name.split('.')[0]} @' /etc/hosts")
comm.sudo("hostname #{name.split('.')[0]}")
end
comm = machine.communicate
if !comm.test("hostname -f | grep '^#{name}$'", sudo: false)
basename = name.split(".", 2)[0]
comm.sudo <<-EOH.gsub(/^ {14}/, "")
set -e
# Set the hostname
hostname '#{basename}'
echo "hostname=#{basename}" > /etc/conf.d/hostname
# Remove comments and blank lines from /etc/hosts
sed -i'' -e 's/#.*$//' /etc/hosts
sed -i'' -e '/^$/d' /etc/hosts
# Prepend ourselves to /etc/hosts
grep -w '#{name}' /etc/hosts || {
echo -e '127.0.0.1\\t#{name}\\t#{basename}' | cat - /etc/hosts > /tmp/tmp-hosts
mv /tmp/tmp-hosts /etc/hosts
}
EOH
end
end
end

View File

@ -9,34 +9,43 @@ module VagrantPlugins
include Vagrant::Util
def self.configure_networks(machine, networks)
machine.communicate.tap do |comm|
# Remove any previous host only network additions to the interface file
comm.sudo("sed -e '/^#VAGRANT-BEGIN/,/^#VAGRANT-END/ d' /etc/conf.d/net > /tmp/vagrant-network-interfaces")
comm.sudo("cat /tmp/vagrant-network-interfaces > /etc/conf.d/net")
comm.sudo("rm -f /tmp/vagrant-network-interfaces")
comm = machine.communicate
# Configure each network interface
networks.each do |network|
entry = TemplateRenderer.render("guests/gentoo/network_#{network[:type]}",
options: network)
commands = []
interfaces = machine.guest.capability(:network_interfaces, "/bin/ip")
# Upload the entry to a temporary location
Tempfile.open("vagrant-gentoo-configure-networks") do |f|
f.binmode
f.write(entry)
f.fsync
f.close
comm.upload(f.path, "/tmp/vagrant-network-entry")
end
# Remove any previous network additions to the configuration file.
commands << "sed -i'' -e '/^#VAGRANT-BEGIN/,/^#VAGRANT-END/ d' /etc/conf.d/net"
# Configure the interface
comm.sudo("ln -fs /etc/init.d/net.lo /etc/init.d/net.eth#{network[:interface]}")
comm.sudo("/etc/init.d/net.eth#{network[:interface]} stop")
comm.sudo("cat /tmp/vagrant-network-entry >> /etc/conf.d/net")
comm.sudo("rm -f /tmp/vagrant-network-entry")
comm.sudo("/etc/init.d/net.eth#{network[:interface]} start")
networks.each_with_index do |network, i|
network[:device] = interfaces[network[:interface]]
entry = TemplateRenderer.render("guests/gentoo/network_#{network[:type]}",
options: network,
)
remote_path = "/tmp/vagrant-network-#{network[:device]}-#{Time.now.to_i}-#{i}"
Tempfile.open("vagrant-gentoo-configure-networks") do |f|
f.binmode
f.write(entry)
f.fsync
f.close
comm.upload(f.path, remote_path)
end
commands << <<-EOH.gsub(/^ {14}/, '')
ln -sf /etc/init.d/net.lo /etc/init.d/net.#{network[:device]}
/etc/init.d/net.#{network[:device]} stop || true
cat '#{remote_path}' >> /etc/conf.d/net
rm -f '#{remote_path}'
/etc/init.d/net.#{network[:device]} start
EOH
end
comm.sudo(commands.join("\n"))
end
end
end

View File

@ -6,13 +6,12 @@ module VagrantPlugins
comm = machine.communicate
possible.each do |ip|
command = "ping -c1 -w1 -W1 #{ip}"
if comm.test(command)
if comm.test("ping -c1 -w1 -W1 #{ip}")
return ip
end
end
nil
return nil
end
end
end

View File

@ -1,31 +0,0 @@
module VagrantPlugins
module GuestLinux
module Cap
class InsertPublicKey
def self.insert_public_key(machine, contents)
comm = machine.communicate
contents = contents.strip << "\n"
remote_path = "/tmp/vagrant-authorized-keys-#{Time.now.to_i}"
Tempfile.open("vagrant-linux-insert-public-key") do |f|
f.binmode
f.write(contents)
f.fsync
f.close
comm.upload(f.path, remote_path)
end
comm.execute <<-EOH.gsub(/^ {12}/, '')
mkdir -p ~/.ssh
chmod 0700 ~/.ssh
cat '#{remote_path}' >> ~/.ssh/authorized_keys
chmod 0600 ~/.ssh/authorized_keys
# Remove the temporary file
rm -f '#{remote_path}'
EOH
end
end
end
end
end

View File

@ -1,12 +1,17 @@
require "shellwords"
require "vagrant/util/retryable"
module VagrantPlugins
module GuestLinux
module Cap
class MountVirtualBoxSharedFolder
def self.mount_virtualbox_shared_folder(machine, name, guestpath, options)
expanded_guest_path = machine.guest.capability(
:shell_expand_guest_path, guestpath)
extend Vagrant::Util::Retryable
mount_commands = []
def self.mount_virtualbox_shared_folder(machine, name, guestpath, options)
guest_path = Shellwords.escape(guestpath)
mount_commands = ["set -e"]
if options[:owner].is_a? Integer
mount_uid = options[:owner]
@ -25,73 +30,54 @@ module VagrantPlugins
# First mount command uses getent to get the group
mount_options = "-o uid=#{mount_uid},gid=#{mount_gid}"
mount_options += ",#{options[:mount_options].join(",")}" if options[:mount_options]
mount_commands << "mount -t vboxsf #{mount_options} #{name} #{expanded_guest_path}"
mount_commands << "mount -t vboxsf #{mount_options} #{name} #{guest_path}"
# Second mount command uses the old style `id -g`
mount_options = "-o uid=#{mount_uid},gid=#{mount_gid_old}"
mount_options += ",#{options[:mount_options].join(",")}" if options[:mount_options]
mount_commands << "mount -t vboxsf #{mount_options} #{name} #{expanded_guest_path}"
mount_commands << "mount -t vboxsf #{mount_options} #{name} #{guest_path}"
# Create the guest path if it doesn't exist
machine.communicate.sudo("mkdir -p #{expanded_guest_path}")
machine.communicate.sudo("mkdir -p #{guest_path}")
# Attempt to mount the folder. We retry here a few times because
# it can fail early on.
attempts = 0
while true
success = true
stderr = ""
mount_commands.each do |command|
no_such_device = false
stderr = ""
status = machine.communicate.sudo(command, error_check: false) do |type, data|
if type == :stderr
no_such_device = true if data =~ /No such device/i
stderr += data.to_s
end
end
success = status == 0 && !no_such_device
break if success
end
break if success
attempts += 1
if attempts > 10
raise Vagrant::Errors::LinuxMountFailed,
command: mount_commands.join("\n"),
output: stderr
end
sleep(2*attempts)
command = mount_commands.join("\n")
stderr = ""
retryable(on: Vagrant::Errors::VirtualBoxMountFailed, tries: 3, sleep: 5) do
machine.communicate.sudo(command,
error_class: Vagrant::Errors::VirtualBoxMountFailed,
error_key: :virtualbox_mount_failed,
command: command,
output: stderr,
) { |type, data| stderr = data if type == :stderr }
end
# Chown the directory to the proper user. We skip this if the
# mount options contained a readonly flag, because it won't work.
if !options[:mount_options] || !options[:mount_options].include?("ro")
chown_commands = []
chown_commands << "chown #{mount_uid}:#{mount_gid} #{expanded_guest_path}"
chown_commands << "chown #{mount_uid}:#{mount_gid_old} #{expanded_guest_path}"
chown_commands << "chown #{mount_uid}:#{mount_gid} #{guest_path}"
chown_commands << "chown #{mount_uid}:#{mount_gid_old} #{guest_path}"
exit_status = machine.communicate.sudo(chown_commands[0], error_check: false)
machine.communicate.sudo(chown_commands[1]) if exit_status != 0
end
# Emit an upstart event if we can
machine.communicate.sudo <<-SCRIPT
if command -v /sbin/init && /sbin/init --version | grep upstart; then
/sbin/initctl emit --no-wait vagrant-mounted MOUNTPOINT='#{expanded_guest_path}'
fi
SCRIPT
machine.communicate.sudo <<-EOH.gsub(/^ {12}/, "")
if command -v /sbin/init && /sbin/init --version | grep upstart; then
/sbin/initctl emit --no-wait vagrant-mounted MOUNTPOINT=#{guest_path}
fi
EOH
end
def self.unmount_virtualbox_shared_folder(machine, guestpath, options)
result = machine.communicate.sudo(
"umount #{guestpath}", error_check: false)
guest_path = Shellwords.escape(guestpath)
result = machine.communicate.sudo("umount #{guest_path}", error_check: false)
if result == 0
machine.communicate.sudo("rmdir #{guestpath}", error_check: false)
machine.communicate.sudo("rmdir #{guest_path}", error_check: false)
end
end
end

View File

@ -0,0 +1,20 @@
module VagrantPlugins
module GuestLinux
module Cap
class NetworkInterfaces
# Get network interfaces as a list. The result will be something like:
#
# eth0\nenp0s8\nenp0s9
#
# @return [Array<String>]
def self.network_interfaces(machine, path = "/sbin/ip")
s = ""
machine.communicate.sudo("#{path} -o -0 addr | grep -v LOOPBACK | awk '{print $2}' | sed 's/://'") do |type, data|
s << data if type == :stdout
end
s.split("\n")
end
end
end
end
end

View File

@ -3,9 +3,13 @@ require "vagrant/util/retryable"
module VagrantPlugins
module GuestLinux
module Cap
class MountNFS
class NFS
extend Vagrant::Util::Retryable
def self.nfs_client_installed(machine)
machine.communicate.test("test -x /sbin/mount.nfs")
end
def self.mount_nfs_folder(machine, ip, folders)
comm = machine.communicate

View File

@ -1,11 +0,0 @@
module VagrantPlugins
module GuestLinux
module Cap
class NFSClient
def self.nfs_client_installed(machine)
machine.communicate.test("test -x /sbin/mount.nfs")
end
end
end
end
end

View File

@ -0,0 +1,65 @@
require "tempfile"
require "vagrant/util/shell_quote"
module VagrantPlugins
module GuestLinux
module Cap
class PublicKey
def self.insert_public_key(machine, contents)
comm = machine.communicate
contents = contents.strip << "\n"
remote_path = "/tmp/vagrant-insert-pubkey-#{Time.now.to_i}"
Tempfile.open("vagrant-linux-insert-public-key") do |f|
f.binmode
f.write(contents)
f.fsync
f.close
comm.upload(f.path, remote_path)
end
# Use execute (not sudo) because we want to execute this as the SSH
# user (which is "vagrant" by default).
comm.execute <<-EOH.gsub(/^ {12}/, "")
set -e
mkdir -p ~/.ssh
chmod 0700 ~/.ssh
cat '#{remote_path}' >> ~/.ssh/authorized_keys
chmod 0600 ~/.ssh/authorized_keys
rm -f '#{remote_path}'
EOH
end
def self.remove_public_key(machine, contents)
comm = machine.communicate
contents = contents.strip << "\n"
remote_path = "/tmp/vagrant-remove-pubkey-#{Time.now.to_i}"
Tempfile.open("vagrant-bsd-remove-public-key") do |f|
f.binmode
f.write(contents)
f.fsync
f.close
comm.upload(f.path, remote_path)
end
# Use execute (not sudo) because we want to execute this as the SSH
# user (which is "vagrant" by default).
comm.execute <<-EOH.sub(/^ {12}/, "")
set -e
if test -f ~/.ssh/authorized_keys; then
grep -v -x -f '#{remote_path}' ~/.ssh/authorized_keys > ~/.ssh/authorized_keys.tmp
mv ~/.ssh/authorized_keys.tmp ~/.ssh/authorized_keys
fi
rm -f '#{remote_path}'
EOH
end
end
end
end
end

View File

@ -1,24 +0,0 @@
require "vagrant/util/shell_quote"
module VagrantPlugins
module GuestLinux
module Cap
class RemovePublicKey
def self.remove_public_key(machine, contents)
contents = contents.chomp
contents = Vagrant::Util::ShellQuote.escape(contents, "'")
machine.communicate.tap do |comm|
if comm.test("test -f ~/.ssh/authorized_keys")
comm.execute(<<SCRIPT)
sed -e '/^.*#{contents}.*$/d' ~/.ssh/authorized_keys > ~/.ssh/authorized_keys.new
mv ~/.ssh/authorized_keys.new ~/.ssh/authorized_keys
chmod 600 ~/.ssh/authorized_keys
SCRIPT
end
end
end
end
end
end
end

View File

@ -1,3 +1,5 @@
require "shellwords"
module VagrantPlugins
module GuestLinux
module Cap
@ -11,9 +13,8 @@ module VagrantPlugins
end
def self.rsync_pre(machine, opts)
machine.communicate.tap do |comm|
comm.sudo("mkdir -p '#{opts[:guestpath]}'")
end
guest_path = Shellwords.escape(opts[:guestpath])
machine.communicate.sudo("mkdir -p #{guest_path}")
end
def self.rsync_post(machine, opts)
@ -21,8 +22,10 @@ module VagrantPlugins
return
end
guest_path = Shellwords.escape(opts[:guestpath])
machine.communicate.sudo(
"find '#{opts[:guestpath]}' " +
"find #{guest_path} " +
"'!' -type l -a " +
"'(' ! -user #{opts[:owner]} -or ! -group #{opts[:group]} ')' -print0 | " +
"xargs -0 -r chown #{opts[:owner]}:#{opts[:group]}")

View File

@ -22,8 +22,8 @@ module VagrantPlugins
end
guest_capability(:linux, :insert_public_key) do
require_relative "cap/insert_public_key"
Cap::InsertPublicKey
require_relative "cap/public_key"
Cap::PublicKey
end
guest_capability(:linux, :shell_expand_guest_path) do
@ -32,8 +32,8 @@ module VagrantPlugins
end
guest_capability(:linux, :mount_nfs_folder) do
require_relative "cap/mount_nfs"
Cap::MountNFS
require_relative "cap/nfs"
Cap::NFS
end
guest_capability(:linux, :mount_smb_shared_folder) do
@ -46,9 +46,14 @@ module VagrantPlugins
Cap::MountVirtualBoxSharedFolder
end
guest_capability(:linux, :network_interfaces) do
require_relative "cap/network_interfaces"
Cap::NetworkInterfaces
end
guest_capability(:linux, :nfs_client_installed) do
require_relative "cap/nfs_client"
Cap::NFSClient
require_relative "cap/nfs"
Cap::NFS
end
# For the Docker provider
@ -63,8 +68,8 @@ module VagrantPlugins
end
guest_capability(:linux, :remove_public_key) do
require_relative "cap/remove_public_key"
Cap::RemovePublicKey
require_relative "cap/public_key"
Cap::PublicKey
end
guest_capability(:linux, :rsync_installed) do

View File

@ -5,7 +5,7 @@ module VagrantPlugins
def self.change_host_name(machine, name)
comm = machine.communicate
if !comm.test("hostname | grep -w '#{name}'", sudo: false)
if !comm.test("hostname -f | grep '^#{name}$'", sudo: false)
basename = name.split(".", 2)[0]
comm.sudo <<-EOH.gsub(/^ {14}/, '')
# Set hostname

View File

@ -3,9 +3,27 @@ module VagrantPlugins
module Cap
class ChangeHostName
def self.change_host_name(machine, name)
if !machine.communicate.test("hostname | grep '^#{name}$'")
machine.communicate.sudo("sh -c \"echo '#{name}' > /etc/myname\"")
machine.communicate.sudo("hostname #{name}")
comm = machine.communicate
if !comm.test("hostname -f | grep '^#{name}$'", sudo: false, shell: "sh")
basename = name.split(".", 2)[0]
command = <<-EOH.gsub(/^ {14}/, '')
# Set the hostname
hostname '#{name}'
sed -i'' 's/^hostname=.*$/hostname=\"#{name}\"/' /etc/rc.conf
echo '#{name}' > /etc/myname
# Remove comments and blank lines from /etc/hosts
sed -i'' -e 's/#.*$//' /etc/hosts
sed -i'' -e '/^$/d' /etc/hosts
# Prepend ourselves to /etc/hosts
grep -w '#{name}' /etc/hosts || {
echo -e '127.0.0.1\\t#{name}\\t#{basename}' | cat - /etc/hosts > /tmp/tmp-hosts
mv /tmp/tmp-hosts /etc/hosts
}
EOH
comm.sudo(command, shell: "sh")
end
end
end

View File

@ -5,7 +5,7 @@ module VagrantPlugins
def self.change_host_name(machine, name)
comm = machine.communicate
if !comm.test("hostname -f | grep -w '#{name}'", sudo: false)
if !comm.test("hostname -f | grep '^#{name}$'", sudo: false)
basename = name.split(".", 2)[0]
comm.sudo <<-EOH.gsub(/^ {14}/, '')
# Set the hostname

View File

@ -5,7 +5,7 @@ module VagrantPlugins
def self.change_host_name(machine, name)
comm = machine.communicate
if !comm.test("hostname | grep -w '#{name}'", sudo: false)
if !comm.test("hostname -f | grep '^#{name}$'", sudo: false)
basename = name.split(".", 2)[0]
comm.sudo <<-EOH.gsub(/^ {14}/, '')
hostname '#{name}'

View File

@ -5,7 +5,7 @@ module VagrantPlugins
def self.change_host_name(machine, name)
comm = machine.communicate
if !comm.test("hostname -f | grep -w '#{name}'", sudo: false)
if !comm.test("hostname -f | grep '^#{name}$'", sudo: false)
basename = name.split('.', 2)[0]
comm.sudo <<-EOH.gsub(/^ {14}/, '')
# Update sysconfig
@ -17,9 +17,10 @@ module VagrantPlugins
# Set the hostname - use hostnamectl if available
echo '#{name}' > /etc/hostname
if command -v hostnamectl; then
hostnamectl set-hostname '#{name}'
hostnamectl set-hostname --static '#{name}'
hostnamectl set-hostname --transient '#{name}'
else
hostname '#{name}'
hostname -F /etc/hostname
fi
# Remove comments and blank lines from /etc/hosts

View File

@ -1,43 +1,20 @@
require "tempfile"
require_relative "../../../../lib/vagrant/util/retryable"
require_relative "../../../../lib/vagrant/util/template_renderer"
module VagrantPlugins
module GuestRedHat
module Cap
class ConfigureNetworks
extend Vagrant::Util::Retryable
include Vagrant::Util
def self.configure_networks(machine, networks)
case machine.guest.capability(:flavor)
when :rhel_7
configure_networks_rhel7(machine, networks)
else
configure_networks_default(machine, networks)
end
end
def self.configure_networks_rhel7(machine, networks)
# This is kind of jank but the configure networks is the same as
# Fedora at this point.
require_relative "../../fedora/cap/configure_networks"
::VagrantPlugins::GuestFedora::Cap::ConfigureNetworks
.configure_networks(machine, networks)
end
def self.configure_networks_default(machine, networks)
comm = machine.communicate
network_scripts_dir = machine.guest.capability(:network_scripts_dir)
interfaces = []
commands = []
comm.sudo("/sbin/ip -o -0 addr | grep -v LOOPBACK | awk '{print $2}' | sed 's/://'") do |_, stdout|
interfaces = stdout.split("\n")
end
interfaces = machine.guest.capability(:network_interfaces)
networks.each.with_index do |network, i|
network[:device] = interfaces[network[:interface]]

View File

@ -5,7 +5,7 @@ module VagrantPlugins
def self.change_host_name(machine, name)
comm = machine.communicate
if !comm.test("hostname -f | grep -w '#{name}'", sudo: false)
if !comm.test("hostname -f | grep '^#{name}$'", sudo: false)
basename = name.split(".", 2)[0]
comm.sudo <<-EOH.gsub(/^ {14}/, '')
# Set the hostname

View File

@ -12,11 +12,7 @@ module VagrantPlugins
comm = machine.communicate
commands = []
interfaces = []
comm.sudo("ip -o -0 addr | grep -v LOOPBACK | awk '{print $2}' | sed 's/://'") do |_, result|
interfaces = result.split("\n")
end
interfaces = machine.guest.capability(:network_interfaces)
# Remove any previous configuration
commands << "sed -i'' -e '/^#VAGRANT-BEGIN/,/^#VAGRANT-END/ d' /etc/rc.d/rc.inet1.conf"

View File

@ -5,7 +5,7 @@ module VagrantPlugins
def self.change_host_name(machine, name)
comm = machine.communicate
if !comm.test("hostname -f | grep -w '#{name}'", sudo: false)
if !comm.test("hostname -f | grep '^#{name}$'", sudo: false)
basename = name.split(".", 2)[0]
comm.sudo <<-EOH.gsub(/^ {14}/, '')
echo '#{name}' > /etc/HOSTNAME

View File

@ -15,11 +15,7 @@ module VagrantPlugins
network_scripts_dir = machine.guest.capability(:network_scripts_dir)
commands = []
interfaces = []
comm.sudo("ip -o -0 addr | grep -v LOOPBACK | awk '{print $2}' | sed 's/://'") do |_, stdout|
interfaces = stdout.split("\n")
end
interfaces = machine.guest.capability(:network_interfaces)
networks.each.with_index do |network, i|
network[:device] = interfaces[network[:interface]]

View File

@ -1,52 +0,0 @@
module VagrantPlugins
module GuestUbuntu
module Cap
class ChangeHostName
def self.change_host_name(machine, name)
comm = machine.communicate
if !comm.test("hostname -f | grep -w '#{name}'")
basename = name.split(".", 2)[0]
comm.sudo <<-EOH.gsub(/^ {14}/, '')
# Set the hostname
echo '#{name}' > /etc/hostname
hostname -F /etc/hostname
if command -v hostnamectl; then
hostnamectl set-hostname '#{name}'
fi
# Remove comments and blank lines from /etc/hosts
sed -i'' -e 's/#.*$//' -e '/^$/d' /etc/hosts
# Prepend ourselves to /etc/hosts
grep -w '#{name}' /etc/hosts || {
sed -i'' '1i 127.0.0.1\\t#{name}\\t#{basename}' /etc/hosts
}
# Update mailname
echo '#{name}' > /etc/mailname
# Restart networking and force new DHCP
if [ test -f /etc/init.d/hostname ]; then
/etc/init.d/hostname start || true
fi
if [ test -f /etc/init.d/hostname.sh ]; then
/etc/init.d/hostname.sh start || true
fi
if [ test -f /etc/init.d/networking ]; then
/etc/init.d/networking force-reload
fi
if [ test -f /etc/init.d/network-manager ]; then
/etc/init.d/network-manager force-reload
fi
EOH
end
end
end
end
end
end

View File

@ -10,11 +10,6 @@ module VagrantPlugins
require_relative "guest"
Guest
end
guest_capability(:ubuntu, :change_host_name) do
require_relative "cap/change_host_name"
Cap::ChangeHostName
end
end
end
end

View File

@ -101,8 +101,16 @@ module VagrantPlugins
end
# Mount them!
machine.guest.capability(
:mount_nfs_folder, nfsopts[:nfs_host_ip], mount_folders)
if machine.guest.capability?(:nfs_pre)
machine.guest.capability(:nfs_pre)
end
machine.guest.capability(:mount_nfs_folder,
nfsopts[:nfs_host_ip], mount_folders)
if machine.guest.capability?(:nfs_post)
machine.guest.capability(:nfs_post)
end
end
def cleanup(machine, opts)

View File

@ -1,3 +1,5 @@
require "shellwords"
require "vagrant/util/platform"
require "vagrant/util/subprocess"
@ -43,6 +45,9 @@ module VagrantPlugins
guestpath = machine.guest.capability(:rsync_scrub_guestpath, opts)
end
# Shellescape
guestpath = Shellwords.escape(guestpath)
if Vagrant::Util::Platform.windows?
# rsync for Windows expects cygwin style paths, always.
hostpath = Vagrant::Util::Platform.cygwin_path(hostpath)

View File

@ -2,7 +2,7 @@ Connection=ethernet
Description='A basic static ethernet connection'
Interface=<%= options[:device] %>
IP=static
Address=('<%= options[:ip]%>/24')
<% if options[:gateway] %>
Address=('<%= options[:ip]%>/<%= options[:netmask] %>')
<% if options[:gateway] -%>
Gateway='<%= options[:gateway] %>'
<% end %>
<% end -%>

View File

@ -0,0 +1,8 @@
Connection=ethernet
Description='A basic IPv6 ethernet connection'
Interface=<%= options[:device] %>
IP6=static
Address6=('<%= options[:ip]%>/<%= options[:netmask] %>')
<% if options[:gateway] -%>
Gateway6='<%= options[:gateway] %>'
<% end -%>

View File

@ -1,6 +0,0 @@
#VAGRANT-BEGIN
# The contents below are automatically generated by Vagrant. Do not modify.
BOOTPROTO=dhcp
ONBOOT=yes
DEVICE=<%= options[:device] %>
#VAGRANT-END

View File

@ -1,16 +0,0 @@
#VAGRANT-BEGIN
# The contents below are automatically generated by Vagrant. Do not modify.
NM_CONTROLLED=no
BOOTPROTO=none
ONBOOT=yes
IPADDR=<%= options[:ip] %>
NETMASK=<%= options[:netmask] %>
DEVICE=<%= options[:device] %>
<% if options[:gateway] %>
GATEWAY=<%= options[:gateway] %>
<% end %>
<% if options[:mac_address] %>
HWADDR=<%= options[:mac_address] %>
<% end %>
PEERDNS=no
#VAGRANT-END

View File

@ -0,0 +1,6 @@
#VAGRANT-BEGIN
ifconfig_<%= options[:device] %>_ipv6="inet6 <%= options[:ip] %> prefixlen <%= options[:netmask] %>"
<% if options[:gateway] %>
ipv6_default_router="<%= options[:gateway] %>"
<% end %>
#VAGRANT-END

View File

@ -0,0 +1,9 @@
#VAGRANT-BEGIN
template='interface'
ipaddr='<%= options[:ip] %>/<%= options[:netmask] %>'
<% [:gateway, :nameservers, :domain, :route, :gateway6, :route6, :mtu].each do |key| %>
<% if options[key] %>
<%= key %>='<%= options[key] %>'
<% end %>
<% end %>
#VAGRANT-END

View File

@ -1,4 +1,4 @@
#VAGRANT-BEGIN
# The contents below are automatically generated by Vagrant. Do not modify.
config_eth<%= options[:interface] %>="dhcp"
config_<%= options[:device] %>="dhcp"
#VAGRANT-END

View File

@ -1,7 +1,7 @@
#VAGRANT-BEGIN
# The contents below are automatically generated by Vagrant. Do not modify.
config_eth<%= options[:interface] %>=("<%= options[:ip] %> netmask <%= options[:netmask] %>")
<% if options[:gateway] %>
gateways_eth<%= options[:interface] %>="<%= options[:gateway] %>"
<% end %>
config_<%= options[:device] %>=("<%= options[:ip] %> netmask <%= options[:netmask] %>")
<% if options[:gateway] -%>
gateways_<%= options[:device] %>="<%= options[:gateway] %>"
<% end -%>
#VAGRANT-END

View File

@ -0,0 +1,7 @@
#VAGRANT-BEGIN
# The contents below are automatically generated by Vagrant. Do not modify.
config_<%= options[:device] %>="<%= options[:ip] %>/<%= options[:netmask] %>"
<% if options[:gateway] -%>
gateways_<%= options[:device] %>="<%= options[:gateway] %>"
<% end -%>
#VAGRANT-END

View File

@ -2,5 +2,5 @@
# The contents below are automatically generated by Vagrant. Do not modify.
BOOTPROTO=dhcp
ONBOOT=yes
DEVICE=eth<%= options[:interface] %>
DEVICE=<%= options[:device] %>
#VAGRANT-END

View File

@ -5,9 +5,12 @@ BOOTPROTO=none
ONBOOT=yes
IPADDR=<%= options[:ip] %>
NETMASK=<%= options[:netmask] %>
DEVICE=eth<%= options[:interface] %>
DEVICE=<%= options[:device] %>
<% if options[:gateway] %>
GATEWAY=<%= options[:gateway] %>
<% end %>
<% if options[:mac_address] %>
HWADDR=<%= options[:mac_address] %>
<% end %>
PEERDNS=no
#VAGRANT-END

View File

@ -3,7 +3,10 @@
NM_CONTROLLED=no
BOOTPROTO=static
ONBOOT=yes
IPV6INIT=yes
IPV6ADDR=<%= options[:ip] %>
DEVICE=<%= options[:device] %>
IPV6INIT=yes
IPV6ADDR=<%= options[:ip] %>/<%= options[:netmask] %>
<% if options[:gateway] -%>
IPV6_DEFAULTGW=<%= options[:gateway] %>
<% end %>
#VAGRANT-END

View File

@ -1342,6 +1342,38 @@ en:
VirtualBox is complaining that the installation is incomplete. Please
run `VBoxManage --version` to see the error message which should contain
instructions on how to fix this error.
virtualbox_mount_failed: |-
Vagrant was unable to mount VirtualBox shared folders. This is usually
because the filesystem "vboxsf" is not available. This filesystem is
made available via the VirtualBox Guest Additions and kernel module.
Please verify that these guest additions are properly installed in the
guest. This is not a bug in Vagrant and is usually caused by a faulty
Vagrant box. For context, the command attemped was:
%{command}
The error output from the command was:
%{output}
virtualbox_mount_not_supported_bsd: |-
Vagrant is not able to mount VirtualBox shared folders on BSD-based
guests. BSD-based guests do not support the VirtualBox filesystem at
this time.
To change the type of the default synced folder, specify the type as
rsync or nfs:
config.vm.synced_folder ".", "/vagrant", type: "nfs" # or "rsync"
Alternatively, if you do not need to mount the default synced folder,
you can also disable it entirely:
config.vm.synced_folder ".", "/vagrant", disabled: true
You can read more about Vagrant's synced folder types and the various
configuration options on the Vagrant website.
This is not a bug in Vagrant.
virtualbox_name_exists: |-
The name of your virtual machine couldn't be set because VirtualBox
is reporting another VM with that name already exists. Most of the

View File

@ -20,18 +20,18 @@ describe "VagrantPlugins::GuestArch::Cap::ChangeHostName" do
end
describe ".change_host_name" do
let(:hostname) { "banana-rama.example.com" }
let(:name) { "banana-rama.example.com" }
it "sets the hostname" do
comm.stub_command("hostname | grep -w '#{hostname}'", exit_code: 1)
comm.stub_command("hostname -f | grep '^#{name}$'", exit_code: 1)
described_class.change_host_name(machine, hostname)
expect(comm.received_commands[1]).to match(/hostnamectl set-hostname '#{hostname}'/)
described_class.change_host_name(machine, name)
expect(comm.received_commands[1]).to match(/hostnamectl set-hostname 'banana-rama'/)
end
it "does not change the hostname if already set" do
comm.stub_command("hostname | grep -w '#{hostname}'", exit_code: 0)
described_class.change_host_name(machine, hostname)
comm.stub_command("hostname -f | grep '^#{name}$'", exit_code: 0)
described_class.change_host_name(machine, name)
expect(comm.received_commands.size).to eq(1)
end
end

View File

@ -1,20 +1,18 @@
require_relative "../../../../base"
describe "VagrantPlugins::GuestArch::Cap::ConfigureNetworks" do
let(:described_class) do
let(:caps) do
VagrantPlugins::GuestArch::Plugin
.components
.guest_capabilities[:arch]
.get(:configure_networks)
end
let(:machine) { double("machine") }
let(:guest) { double("guest") }
let(:machine) { double("machine", guest: guest) }
let(:comm) { VagrantTests::DummyCommunicator::Communicator.new(machine) }
before do
allow(machine).to receive(:communicate).and_return(comm)
comm.stub_command("ip -o -0 addr | grep -v LOOPBACK | awk '{print $2}' | sed 's/://'",
stdout: "eth1\neth2")
end
after do
@ -22,6 +20,13 @@ describe "VagrantPlugins::GuestArch::Cap::ConfigureNetworks" do
end
describe ".configure_networks" do
let(:cap) { caps.get(:configure_networks) }
before do
allow(guest).to receive(:capability).with(:network_interfaces)
.and_return(["eth1", "eth2"])
end
let(:network_1) do
{
interface: 0,
@ -40,16 +45,16 @@ describe "VagrantPlugins::GuestArch::Cap::ConfigureNetworks" do
end
it "creates and starts the networks" do
described_class.configure_networks(machine, [network_1, network_2])
expect(comm.received_commands[1]).to match(/mv (.+) '\/etc\/netctl\/eth1'/)
expect(comm.received_commands[1]).to match(/ip link set 'eth1' down/)
expect(comm.received_commands[1]).to match(/netctl restart 'eth1'/)
expect(comm.received_commands[1]).to match(/netctl enable 'eth1'/)
cap.configure_networks(machine, [network_1, network_2])
expect(comm.received_commands[0]).to match(/mv (.+) '\/etc\/netctl\/eth1'/)
expect(comm.received_commands[0]).to match(/ip link set 'eth1' down/)
expect(comm.received_commands[0]).to match(/netctl restart 'eth1'/)
expect(comm.received_commands[0]).to match(/netctl enable 'eth1'/)
expect(comm.received_commands[1]).to match(/mv (.+) '\/etc\/netctl\/eth2'/)
expect(comm.received_commands[1]).to match(/ip link set 'eth2' down/)
expect(comm.received_commands[1]).to match(/netctl restart 'eth2'/)
expect(comm.received_commands[1]).to match(/netctl enable 'eth2'/)
expect(comm.received_commands[0]).to match(/mv (.+) '\/etc\/netctl\/eth2'/)
expect(comm.received_commands[0]).to match(/ip link set 'eth2' down/)
expect(comm.received_commands[0]).to match(/netctl restart 'eth2'/)
expect(comm.received_commands[0]).to match(/netctl enable 'eth2'/)
end
end
end

View File

@ -1,11 +1,10 @@
require_relative "../../../../base"
describe "VagrantPlugins::GuestAtomic::Cap::ChangeHostName" do
let(:described_class) do
let(:caps) do
VagrantPlugins::GuestAtomic::Plugin
.components
.guest_capabilities[:atomic]
.get(:change_host_name)
end
let(:machine) { double("machine") }
@ -20,18 +19,20 @@ describe "VagrantPlugins::GuestAtomic::Cap::ChangeHostName" do
end
describe ".change_host_name" do
let(:hostname) { "banana-rama.example.com" }
let(:cap) { caps.get(:change_host_name) }
let(:name) { "banana-rama.example.com" }
it "sets the hostname" do
comm.stub_command("hostname | grep -w '#{hostname}'", exit_code: 1)
comm.stub_command("hostname -f | grep '^#{name}$'", exit_code: 1)
described_class.change_host_name(machine, hostname)
expect(comm.received_commands[1]).to match(/hostnamectl set-hostname '#{hostname}'/)
cap.change_host_name(machine, name)
expect(comm.received_commands[1]).to match(/hostnamectl set-hostname 'banana-rama'/)
end
it "does not change the hostname if already set" do
comm.stub_command("hostname | grep -w '#{hostname}'", exit_code: 0)
described_class.change_host_name(machine, hostname)
comm.stub_command("hostname -f | grep '^#{name}$'", exit_code: 0)
cap.change_host_name(machine, name)
expect(comm.received_commands.size).to eq(1)
end
end

View File

@ -22,12 +22,12 @@ describe "VagrantPlugins::GuestBSD::Cap::Halt" do
let(:cap) { caps.get(:halt) }
it "runs the shutdown command" do
comm.expect_command("/sbin/shutdown -p -h now")
comm.expect_command("/sbin/shutdown -p now")
cap.halt(machine)
end
it "ignores an IOError" do
comm.stub_command("/sbin/shutdown -p -h now", raise: IOError)
comm.stub_command("/sbin/shutdown -p now", raise: IOError)
expect {
cap.halt(machine)
}.to_not raise_error

View File

@ -20,17 +20,17 @@ describe "VagrantPlugins::GuestCoreOS::Cap::ChangeHostName" do
end
describe ".change_host_name" do
let(:hostname) { "banana-rama.example.com" }
let(:name) { "banana-rama.example.com" }
it "sets the hostname" do
comm.stub_command("hostname --fqdn | grep -w '#{hostname}'", exit_code: 1)
comm.stub_command("hostname -f | grep '^#{name}$'", exit_code: 1)
comm.expect_command("hostname 'banana-rama'")
described_class.change_host_name(machine, hostname)
described_class.change_host_name(machine, name)
end
it "does not change the hostname if already set" do
comm.stub_command("hostname --fqdn | grep -w '#{hostname}'", exit_code: 0)
described_class.change_host_name(machine, hostname)
comm.stub_command("hostname -f | grep '^#{name}$'", exit_code: 0)
described_class.change_host_name(machine, name)
expect(comm.received_commands.size).to eq(1)
end
end

View File

@ -20,11 +20,11 @@ describe "VagrantPlugins::GuestDarwin::Cap::ChangeHostName" do
end
describe ".change_host_name" do
let(:hostname) { "banana-rama.example.com" }
let(:name) { "banana-rama.example.com" }
it "sets the hostname" do
comm.stub_command("hostname -f | grep -w '#{hostname}' || hostname -s | grep -w '#{hostname}'", exit_code: 1)
described_class.change_host_name(machine, hostname)
comm.stub_command("hostname -f | grep '^#{name}$'", exit_code: 1)
described_class.change_host_name(machine, name)
expect(comm.received_commands[1]).to match(/scutil --set ComputerName 'banana-rama.example.com'/)
expect(comm.received_commands[1]).to match(/scutil --set HostName 'banana-rama.example.com'/)
expect(comm.received_commands[1]).to match(/scutil --set LocalHostName 'banana-rama'/)
@ -32,8 +32,8 @@ describe "VagrantPlugins::GuestDarwin::Cap::ChangeHostName" do
end
it "does not change the hostname if already set" do
comm.stub_command("hostname -f | grep -w '#{hostname}' || hostname -s | grep -w '#{hostname}'", exit_code: 0)
described_class.change_host_name(machine, hostname)
comm.stub_command("hostname -f | grep '^#{name}$'", exit_code: 0)
described_class.change_host_name(machine, name)
expect(comm.received_commands.size).to eq(1)
end
end

View File

@ -24,16 +24,14 @@ describe "VagrantPlugins::GuestDebian::Cap::ChangeHostName" do
let(:name) { 'banana-rama.example.com' }
it "sets the hostname if not set" do
comm.stub_command("hostname -f | grep -w '#{name}'", exit_code: 1)
comm.stub_command("hostname -f | grep '^#{name}$'", exit_code: 1)
cap.change_host_name(machine, name)
expect(comm.received_commands[1]).to match(/hostname -F \/etc\/hostname/)
expect(comm.received_commands[1]).to match(/invoke-rc.d hostname.sh start/)
expect(comm.received_commands[1]).to match(/invoke-rc.d networking force-reload/)
expect(comm.received_commands[1]).to match(/invoke-rc.d network-manager force-reload/)
expect(comm.received_commands[1]).to match(/hostname.sh start/)
end
it "does not set the hostname if unset" do
comm.stub_command("hostname -f | grep -w '#{name}'", exit_code: 0)
comm.stub_command("hostname -f | grep '^#{name}$'", exit_code: 0)
cap.change_host_name(machine, name)
expect(comm.received_commands.size).to eq(1)
end

View File

@ -7,13 +7,12 @@ describe "VagrantPlugins::GuestDebian::Cap::ConfigureNetworks" do
.guest_capabilities[:debian]
end
let(:machine) { double("machine") }
let(:guest) { double("guest") }
let(:machine) { double("machine", guest: guest) }
let(:comm) { VagrantTests::DummyCommunicator::Communicator.new(machine) }
before do
allow(machine).to receive(:communicate).and_return(comm)
comm.stub_command("ip -o -0 addr | grep -v LOOPBACK | awk '{print $2}' | sed 's/://'",
stdout: "eth1\neth2")
end
after do
@ -23,6 +22,11 @@ describe "VagrantPlugins::GuestDebian::Cap::ConfigureNetworks" do
describe ".configure_networks" do
let(:cap) { caps.get(:configure_networks) }
before do
allow(guest).to receive(:capability).with(:network_interfaces)
.and_return(["eth1", "eth2"])
end
let(:network_0) do
{
interface: 0,
@ -43,12 +47,12 @@ describe "VagrantPlugins::GuestDebian::Cap::ConfigureNetworks" do
it "creates and starts the networks" do
cap.configure_networks(machine, [network_0, network_1])
expect(comm.received_commands[1]).to match("/sbin/ifdown 'eth1' || true")
expect(comm.received_commands[1]).to match("/sbin/ip addr flush dev 'eth1'")
expect(comm.received_commands[1]).to match("/sbin/ifdown 'eth2' || true")
expect(comm.received_commands[1]).to match("/sbin/ip addr flush dev 'eth2'")
expect(comm.received_commands[1]).to match("/sbin/ifup 'eth1'")
expect(comm.received_commands[1]).to match("/sbin/ifup 'eth2'")
expect(comm.received_commands[0]).to match("/sbin/ifdown 'eth1' || true")
expect(comm.received_commands[0]).to match("/sbin/ip addr flush dev 'eth1'")
expect(comm.received_commands[0]).to match("/sbin/ifdown 'eth2' || true")
expect(comm.received_commands[0]).to match("/sbin/ip addr flush dev 'eth2'")
expect(comm.received_commands[0]).to match("/sbin/ifup 'eth1'")
expect(comm.received_commands[0]).to match("/sbin/ifup 'eth2'")
end
end
end

View File

@ -20,19 +20,11 @@ describe "VagrantPlugins::GuestDebian::Cap:RSync" do
end
describe ".rsync_install" do
it "installs rsync when not installed" do
comm.stub_command("command -v rsync", exit_code: 1)
it "installs rsync" do
described_class.rsync_install(machine)
expect(comm.received_commands[1]).to match(/apt-get -yqq update/)
expect(comm.received_commands[1]).to match(/apt-get -yqq install rsync/)
end
it "does not install rsync when installed" do
comm.stub_command("command -v rsync", exit_code: 0)
described_class.rsync_install(machine)
expect(comm.received_commands.join("")).to_not match(/update/)
expect(comm.received_commands[0]).to match(/apt-get -yqq update/)
expect(comm.received_commands[0]).to match(/apt-get -yqq install rsync/)
end
end
end

View File

@ -23,7 +23,7 @@ describe "VagrantPlugins::GuestFreeBSD::Cap::ChangeHostName" do
let(:name) { "banana-rama.example.com" }
it "sets the hostname and /etc/hosts" do
comm.stub_command("hostname -f | grep -w '#{name}' || hostname -s | grep -w '#{name}'", exit_code: 1)
comm.stub_command("hostname -f | grep '^#{name}$'", exit_code: 1)
described_class.change_host_name(machine, name)
expect(comm.received_commands[1]).to match(/hostname '#{name}'/)
@ -32,7 +32,7 @@ describe "VagrantPlugins::GuestFreeBSD::Cap::ChangeHostName" do
end
it "does nothing if the hostname is already set" do
comm.stub_command("hostname -f | grep -w '#{name}' || hostname -s | grep -w '#{name}'", exit_code: 0)
comm.stub_command("hostname -f | grep '^#{name}$'", exit_code: 0)
described_class.change_host_name(machine, name)
expect(comm.received_commands.size).to eq(1)
end

View File

@ -24,7 +24,7 @@ describe "VagrantPlugins::GuestOmniOS::Cap:RSync" do
let(:name) { "banana-rama.example.com" }
it "sets the hostname if unset" do
comm.stub_command("hostname | grep -w '#{name}'", exit_code: 1)
comm.stub_command("hostname -f | grep '^#{name}$'", exit_code: 1)
cap.change_host_name(machine, name)
expect(comm.received_commands[1]).to match(/echo '#{name}' > \/etc\/nodename/)
@ -32,7 +32,7 @@ describe "VagrantPlugins::GuestOmniOS::Cap:RSync" do
end
it "does not set the hostname if set" do
comm.stub_command("hostname | grep -w '#{name}'", exit_code: 0)
comm.stub_command("hostname -f | grep '^#{name}$'", exit_code: 0)
cap.change_host_name(machine, name)
expect(comm.received_commands.size).to eq(1)

View File

@ -26,7 +26,7 @@ describe "VagrantPlugins::GuestPhoton::Cap::ChangeHostName" do
let(:name) { "banana-rama.example.com" }
it "sets the hostname" do
comm.stub_command("hostname -f | grep -w '#{name}'", exit_code: 1)
comm.stub_command("hostname -f | grep '^#{name}$'", exit_code: 1)
cap.change_host_name(machine, name)
expect(comm.received_commands[1]).to match(/echo '#{name}' > \/etc\/hostname/)
@ -34,7 +34,7 @@ describe "VagrantPlugins::GuestPhoton::Cap::ChangeHostName" do
end
it "does not change the hostname if already set" do
comm.stub_command("hostname -f | grep -w '#{name}'", exit_code: 0)
comm.stub_command("hostname -f | grep '^#{name}$'", exit_code: 0)
cap.change_host_name(machine, name)
expect(comm.received_commands.size).to eq(1)
end

View File

@ -24,14 +24,14 @@ describe "VagrantPlugins::GuestPld::Cap::ChangeHostName" do
let(:name) { "banana-rama.example.com" }
it "sets the hostname" do
comm.stub_command("hostname | grep -w '#{name}'", exit_code: 1)
comm.stub_command("hostname -f | grep '^#{name}$'", exit_code: 1)
cap.change_host_name(machine, name)
expect(comm.received_commands[1]).to match(/hostname '#{name}'/)
end
it "does not change the hostname if already set" do
comm.stub_command("hostname | grep -w '#{name}'", exit_code: 0)
comm.stub_command("hostname -f | grep '^#{name}$'", exit_code: 0)
cap.change_host_name(machine, name)
expect(comm.received_commands.size).to eq(1)
end

View File

@ -24,17 +24,18 @@ describe "VagrantPlugins::GuestRedHat::Cap::ChangeHostName" do
let(:name) { "banana-rama.example.com" }
it "sets the hostname" do
comm.stub_command("hostname -f | grep -w '#{name}'", exit_code: 1)
comm.stub_command("hostname -f | grep '^#{name}$'", exit_code: 1)
cap.change_host_name(machine, name)
expect(comm.received_commands[1]).to match(/\/etc\/sysconfig\/network/)
expect(comm.received_commands[1]).to match(/\/etc\/sysconfig\/network-scripts\/ifcfg/)
expect(comm.received_commands[1]).to match(/hostnamectl set-hostname '#{name}'/)
expect(comm.received_commands[1]).to match(/hostnamectl set-hostname --static '#{name}'/)
expect(comm.received_commands[1]).to match(/hostnamectl set-hostname --transient '#{name}'/)
expect(comm.received_commands[1]).to match(/service network restart/)
end
it "does not change the hostname if already set" do
comm.stub_command("hostname -f | grep -w '#{name}'", exit_code: 0)
comm.stub_command("hostname -f | grep '^#{name}$'", exit_code: 0)
cap.change_host_name(machine, name)
expect(comm.received_commands.size).to eq(1)
end

View File

@ -7,13 +7,12 @@ describe "VagrantPlugins::GuestRedHat::Cap::ConfigureNetworks" do
.guest_capabilities[:redhat]
end
let(:machine) { double("machine") }
let(:guest) { double("guest") }
let(:machine) { double("machine", guest: guest) }
let(:comm) { VagrantTests::DummyCommunicator::Communicator.new(machine) }
before do
allow(machine).to receive(:communicate).and_return(comm)
comm.stub_command("/sbin/ip -o -0 addr | grep -v LOOPBACK | awk '{print $2}' | sed 's/://'",
stdout: "eth1\neth2")
end
after do
@ -23,6 +22,16 @@ describe "VagrantPlugins::GuestRedHat::Cap::ConfigureNetworks" do
describe ".configure_networks" do
let(:cap) { caps.get(:configure_networks) }
before do
allow(guest).to receive(:capability)
.with(:network_scripts_dir)
.and_return("/scripts")
allow(guest).to receive(:capability)
.with(:network_interfaces)
.and_return(["eth1", "eth2"])
end
let(:network_1) do
{
interface: 0,
@ -40,41 +49,16 @@ describe "VagrantPlugins::GuestRedHat::Cap::ConfigureNetworks" do
}
end
let(:network_scripts_dir) { "/" }
let(:capability) { double("capability") }
before do
allow(machine).to receive(:guest).and_return(capability)
allow(capability).to receive(:capability)
.with(:network_scripts_dir)
.and_return(network_scripts_dir)
end
it "uses fedora for rhel7 configuration" do
require_relative "../../../../../../plugins/guests/fedora/cap/configure_networks"
allow(capability).to receive(:capability)
.with(:flavor)
.and_return(:rhel_7)
allow(VagrantPlugins::GuestFedora::Cap::ConfigureNetworks)
.to receive(:configure_networks)
expect(VagrantPlugins::GuestFedora::Cap::ConfigureNetworks)
.to receive(:configure_networks).once
cap.configure_networks(machine, [network_1, network_2])
end
it "creates and starts the networks" do
allow(capability).to receive(:capability)
allow(guest).to receive(:capability)
.with(:flavor)
.and_return(:rhel)
cap.configure_networks(machine, [network_1, network_2])
expect(comm.received_commands[1]).to match(/\/sbin\/ifdown 'eth1'/)
expect(comm.received_commands[1]).to match(/\/sbin\/ifup 'eth1'/)
expect(comm.received_commands[1]).to match(/\/sbin\/ifdown 'eth2'/)
expect(comm.received_commands[1]).to match(/\/sbin\/ifup 'eth2'/)
expect(comm.received_commands[0]).to match(/\/sbin\/ifdown 'eth1'/)
expect(comm.received_commands[0]).to match(/\/sbin\/ifup 'eth1'/)
expect(comm.received_commands[0]).to match(/\/sbin\/ifdown 'eth2'/)
expect(comm.received_commands[0]).to match(/\/sbin\/ifup 'eth2'/)
end
end
end

View File

@ -24,7 +24,7 @@ describe "VagrantPlugins::GuestSlackware::Cap::ChangeHostName" do
let(:name) { "banana-rama.example.com" }
it "sets the hostname" do
comm.stub_command("hostname -f | grep -w '#{name}'", exit_code: 1)
comm.stub_command("hostname -f | grep '^#{name}$'", exit_code: 1)
cap.change_host_name(machine, name)
expect(comm.received_commands[1]).to match(/echo '#{name}' > \/etc\/hostname/)
@ -32,7 +32,7 @@ describe "VagrantPlugins::GuestSlackware::Cap::ChangeHostName" do
end
it "does not change the hostname if already set" do
comm.stub_command("hostname -f | grep -w '#{name}'", exit_code: 0)
comm.stub_command("hostname -f | grep '^#{name}$'", exit_code: 0)
cap.change_host_name(machine, name)
expect(comm.received_commands.size).to eq(1)
end

View File

@ -7,13 +7,12 @@ describe "VagrantPlugins::GuestSlackware::Cap::ConfigureNetworks" do
.guest_capabilities[:slackware]
end
let(:machine) { double("machine") }
let(:guest) { double("guest") }
let(:machine) { double("machine", guest: guest) }
let(:comm) { VagrantTests::DummyCommunicator::Communicator.new(machine) }
before do
allow(machine).to receive(:communicate).and_return(comm)
comm.stub_command("ip -o -0 addr | grep -v LOOPBACK | awk '{print $2}' | sed 's/://'",
stdout: "eth1\neth2")
end
after do
@ -23,6 +22,11 @@ describe "VagrantPlugins::GuestSlackware::Cap::ConfigureNetworks" do
describe ".configure_networks" do
let(:cap) { caps.get(:configure_networks) }
before do
allow(guest).to receive(:capability).with(:network_interfaces)
.and_return(["eth1", "eth2"])
end
let(:network_1) do
{
interface: 0,
@ -42,7 +46,7 @@ describe "VagrantPlugins::GuestSlackware::Cap::ConfigureNetworks" do
it "creates and starts the networks" do
cap.configure_networks(machine, [network_1, network_2])
expect(comm.received_commands[1]).to match(/\/etc\/rc.d\/rc.inet1/)
expect(comm.received_commands[0]).to match(/\/etc\/rc.d\/rc.inet1/)
end
end
end

View File

@ -24,7 +24,7 @@ describe "VagrantPlugins::GuestSUSE::Cap::ChangeHostName" do
let(:name) { "banana-rama.example.com" }
it "sets the hostname" do
comm.stub_command("hostname -f | grep -w '#{name}'", exit_code: 1)
comm.stub_command("hostname -f | grep '^#{name}$'", exit_code: 1)
cap.change_host_name(machine, name)
expect(comm.received_commands[1]).to match(/echo '#{name}' > \/etc\/HOSTNAME/)
@ -32,7 +32,7 @@ describe "VagrantPlugins::GuestSUSE::Cap::ChangeHostName" do
end
it "does not change the hostname if already set" do
comm.stub_command("hostname -f | grep -w '#{name}'", exit_code: 0)
comm.stub_command("hostname -f | grep '^#{name}$'", exit_code: 0)
cap.change_host_name(machine, name)
expect(comm.received_commands.size).to eq(1)
end

View File

@ -7,13 +7,12 @@ describe "VagrantPlugins::GuestSUSE::Cap::ConfigureNetworks" do
.guest_capabilities[:suse]
end
let(:machine) { double("machine") }
let(:guest) { double("guest") }
let(:machine) { double("machine", guest: guest) }
let(:comm) { VagrantTests::DummyCommunicator::Communicator.new(machine) }
before do
allow(machine).to receive(:communicate).and_return(comm)
comm.stub_command("ip -o -0 addr | grep -v LOOPBACK | awk '{print $2}' | sed 's/://'",
stdout: "eth1\neth2")
end
after do
@ -23,6 +22,13 @@ describe "VagrantPlugins::GuestSUSE::Cap::ConfigureNetworks" do
describe ".configure_networks" do
let(:cap) { caps.get(:configure_networks) }
before do
allow(guest).to receive(:capability).with(:network_scripts_dir)
.and_return("/scripts")
allow(guest).to receive(:capability).with(:network_interfaces)
.and_return(["eth1", "eth2"])
end
let(:network_1) do
{
interface: 0,
@ -40,21 +46,12 @@ describe "VagrantPlugins::GuestSUSE::Cap::ConfigureNetworks" do
}
end
let(:guest) { double("guest") }
before do
allow(machine).to receive(:guest).and_return(guest)
allow(guest).to receive(:capability)
.with(:network_scripts_dir)
.and_return("/scripts")
end
it "creates and starts the networks" do
cap.configure_networks(machine, [network_1, network_2])
expect(comm.received_commands[1]).to match(/\/sbin\/ifdown 'eth1'/)
expect(comm.received_commands[1]).to match(/\/sbin\/ifup 'eth1'/)
expect(comm.received_commands[1]).to match(/\/sbin\/ifdown 'eth2'/)
expect(comm.received_commands[1]).to match(/\/sbin\/ifup 'eth2'/)
expect(comm.received_commands[0]).to match(/\/sbin\/ifdown 'eth1'/)
expect(comm.received_commands[0]).to match(/\/sbin\/ifup 'eth1'/)
expect(comm.received_commands[0]).to match(/\/sbin\/ifdown 'eth2'/)
expect(comm.received_commands[0]).to match(/\/sbin\/ifup 'eth2'/)
end
end
end

View File

@ -1,42 +0,0 @@
require_relative "../../../../base"
describe "VagrantPlugins::GuestUbuntu::Cap::ChangeHostName" do
let(:caps) do
VagrantPlugins::GuestUbuntu::Plugin
.components
.guest_capabilities[:ubuntu]
end
let(:machine) { double("machine") }
let(:comm) { VagrantTests::DummyCommunicator::Communicator.new(machine) }
before do
allow(machine).to receive(:communicate).and_return(comm)
end
after do
comm.verify_expectations!
end
describe ".change_host_name" do
let(:cap) { caps.get(:change_host_name) }
let(:name) { 'banana-rama.example.com' }
it "sets the hostname if not set" do
comm.stub_command("hostname -f | grep -w '#{name}'", exit_code: 1)
cap.change_host_name(machine, name)
expect(comm.received_commands[1]).to match(/hostname -F \/etc\/hostname/)
expect(comm.received_commands[1]).to match(/\/etc\/init.d\/hostname.sh start/)
expect(comm.received_commands[1]).to match(/\/etc\/init.d\/hostname start/)
expect(comm.received_commands[1]).to match(/\/etc\/init.d\/networking force-reload/)
expect(comm.received_commands[1]).to match(/\/etc\/init.d\/network-manager force-reload/)
end
it "does not set the hostname if unset" do
comm.stub_command("hostname -f | grep -w '#{name}'", exit_code: 0)
cap.change_host_name(machine, name)
expect(comm.received_commands.size).to eq(1)
end
end
end

View File

@ -7,8 +7,9 @@ describe "templates/guests/arch/network_static" do
it "renders the template" do
result = Vagrant::Util::TemplateRenderer.render(template, options: {
device: "eth1",
ip: "1.1.1.1",
device: "eth1",
ip: "1.1.1.1",
netmask: "24",
})
expect(result).to eq <<-EOH.gsub(/^ {6}/, "")
Connection=ethernet
@ -24,6 +25,7 @@ describe "templates/guests/arch/network_static" do
device: "eth1",
ip: "1.1.1.1",
gateway: "1.2.3.4",
netmask: "24",
})
expect(result).to eq <<-EOH.gsub(/^ {6}/, "")
Connection=ethernet

View File

@ -1,21 +0,0 @@
require_relative "../../../base"
require "vagrant/util/template_renderer"
describe "templates/guests/fedora/network_dhcp" do
let(:template) { "guests/fedora/network_dhcp" }
it "renders the template" do
result = Vagrant::Util::TemplateRenderer.render(template, options: {
device: "en0",
})
expect(result).to eq <<-EOH.gsub(/^ {6}/, "")
#VAGRANT-BEGIN
# The contents below are automatically generated by Vagrant. Do not modify.
BOOTPROTO=dhcp
ONBOOT=yes
DEVICE=en0
#VAGRANT-END
EOH
end
end

View File

@ -1,25 +0,0 @@
require_relative "../../../base"
require "vagrant/util/template_renderer"
describe "templates/guests/fedora/network_static6" do
let(:template) { "guests/fedora/network_static6" }
it "renders the template" do
result = Vagrant::Util::TemplateRenderer.render(template, options: {
device: "en0",
ip: "fc00::10/64"
})
expect(result).to eq <<-EOH.gsub(/^ {6}/, "")
#VAGRANT-BEGIN
# The contents below are automatically generated by Vagrant. Do not modify.
NM_CONTROLLED=no
BOOTPROTO=static
ONBOOT=yes
IPV6INIT=yes
IPV6ADDR=fc00::10/64
DEVICE=en0
#VAGRANT-END
EOH
end
end

View File

@ -1,71 +0,0 @@
require_relative "../../../base"
require "vagrant/util/template_renderer"
describe "templates/guests/fedora/network_static" do
let(:template) { "guests/fedora/network_static" }
it "renders the template" do
result = Vagrant::Util::TemplateRenderer.render(template, options: {
device: "en0",
ip: "1.1.1.1",
netmask: "255.255.0.0",
})
expect(result).to eq <<-EOH.gsub(/^ {6}/, "")
#VAGRANT-BEGIN
# The contents below are automatically generated by Vagrant. Do not modify.
NM_CONTROLLED=no
BOOTPROTO=none
ONBOOT=yes
IPADDR=1.1.1.1
NETMASK=255.255.0.0
DEVICE=en0
PEERDNS=no
#VAGRANT-END
EOH
end
it "includes the gateway" do
result = Vagrant::Util::TemplateRenderer.render(template, options: {
device: "en0",
ip: "1.1.1.1",
netmask: "255.255.0.0",
gateway: "1.2.3.4",
})
expect(result).to eq <<-EOH.gsub(/^ {6}/, "")
#VAGRANT-BEGIN
# The contents below are automatically generated by Vagrant. Do not modify.
NM_CONTROLLED=no
BOOTPROTO=none
ONBOOT=yes
IPADDR=1.1.1.1
NETMASK=255.255.0.0
DEVICE=en0
GATEWAY=1.2.3.4
PEERDNS=no
#VAGRANT-END
EOH
end
it "includes the mac_address" do
result = Vagrant::Util::TemplateRenderer.render(template, options: {
device: "en0",
ip: "1.1.1.1",
netmask: "255.255.0.0",
mac_address: "abcd1234",
})
expect(result).to eq <<-EOH.gsub(/^ {6}/, "")
#VAGRANT-BEGIN
# The contents below are automatically generated by Vagrant. Do not modify.
NM_CONTROLLED=no
BOOTPROTO=none
ONBOOT=yes
IPADDR=1.1.1.1
NETMASK=255.255.0.0
DEVICE=en0
HWADDR=abcd1234
PEERDNS=no
#VAGRANT-END
EOH
end
end

View File

@ -7,12 +7,12 @@ describe "templates/guests/gentoo/network_dhcp" do
it "renders the template" do
result = Vagrant::Util::TemplateRenderer.render(template, options: {
interface: "en0",
device: "en0",
})
expect(result).to eq <<-EOH.gsub(/^ {6}/, "")
#VAGRANT-BEGIN
# The contents below are automatically generated by Vagrant. Do not modify.
config_ethen0="dhcp"
config_en0="dhcp"
#VAGRANT-END
EOH
end

View File

@ -7,30 +7,30 @@ describe "templates/guests/gentoo/network_static" do
it "renders the template" do
result = Vagrant::Util::TemplateRenderer.render(template, options: {
interface: "en0",
ip: "1.1.1.1",
netmask: "255.255.0.0",
device: "en0",
ip: "1.1.1.1",
netmask: "255.255.0.0",
})
expect(result).to eq <<-EOH.gsub(/^ {6}/, "")
#VAGRANT-BEGIN
# The contents below are automatically generated by Vagrant. Do not modify.
config_ethen0=("1.1.1.1 netmask 255.255.0.0")
config_en0=("1.1.1.1 netmask 255.255.0.0")
#VAGRANT-END
EOH
end
it "includes the gateway" do
result = Vagrant::Util::TemplateRenderer.render(template, options: {
interface: "en0",
ip: "1.1.1.1",
netmask: "255.255.0.0",
gateway: "1.2.3.4",
device: "en0",
ip: "1.1.1.1",
netmask: "255.255.0.0",
gateway: "1.2.3.4",
})
expect(result).to eq <<-EOH.gsub(/^ {6}/, "")
#VAGRANT-BEGIN
# The contents below are automatically generated by Vagrant. Do not modify.
config_ethen0=("1.1.1.1 netmask 255.255.0.0")
gateways_ethen0="1.2.3.4"
config_en0=("1.1.1.1 netmask 255.255.0.0")
gateways_en0="1.2.3.4"
#VAGRANT-END
EOH
end

View File

@ -7,14 +7,14 @@ describe "templates/guests/redhat/network_dhcp" do
it "renders the template" do
result = Vagrant::Util::TemplateRenderer.render(template, options: {
interface: "en0",
device: "en0",
})
expect(result).to eq <<-EOH.gsub(/^ {6}/, "")
#VAGRANT-BEGIN
# The contents below are automatically generated by Vagrant. Do not modify.
BOOTPROTO=dhcp
ONBOOT=yes
DEVICE=ethen0
DEVICE=en0
#VAGRANT-END
EOH
end

View File

@ -7,9 +7,9 @@ describe "templates/guests/redhat/network_static" do
it "renders the template" do
result = Vagrant::Util::TemplateRenderer.render(template, options: {
interface: "en0",
ip: "1.1.1.1",
netmask: "255.255.0.0",
device: "en0",
ip: "1.1.1.1",
netmask: "255.255.0.0",
})
expect(result).to eq <<-EOH.gsub(/^ {6}/, "")
#VAGRANT-BEGIN
@ -19,7 +19,7 @@ describe "templates/guests/redhat/network_static" do
ONBOOT=yes
IPADDR=1.1.1.1
NETMASK=255.255.0.0
DEVICE=ethen0
DEVICE=en0
PEERDNS=no
#VAGRANT-END
EOH
@ -27,10 +27,10 @@ describe "templates/guests/redhat/network_static" do
it "includes the gateway" do
result = Vagrant::Util::TemplateRenderer.render(template, options: {
interface: "en0",
ip: "1.1.1.1",
gateway: "1.2.3.4",
netmask: "255.255.0.0",
device: "en0",
ip: "1.1.1.1",
gateway: "1.2.3.4",
netmask: "255.255.0.0",
})
expect(result).to eq <<-EOH.gsub(/^ {6}/, "")
#VAGRANT-BEGIN
@ -40,7 +40,7 @@ describe "templates/guests/redhat/network_static" do
ONBOOT=yes
IPADDR=1.1.1.1
NETMASK=255.255.0.0
DEVICE=ethen0
DEVICE=en0
GATEWAY=1.2.3.4
PEERDNS=no
#VAGRANT-END