Query host interfaces directly as libvirt may not include them (#1627)

On some distros the libvirt does not appear to always return all of the
host interfaces. Switch to using 'ip -j link show' to read them directly
from the system in order to ensure all devices are read.

Refactor the driver tests to better isolate between test setup for the
different sets of functions and avoid accidental setting of
configuration details that may not be obvious.

Fixes: #1624
This commit is contained in:
Darragh Bailey
2022-10-05 14:29:44 +01:00
committed by GitHub
parent 2c67743f07
commit f5b70bc074
6 changed files with 201 additions and 96 deletions

View File

@@ -110,7 +110,7 @@ module VagrantPlugins
end
).map { |s| ['-o', s] }.flatten
options += ['-o', "ProxyCommand=\"#{ssh_info[:proxy_command]}\""] if machine.provider_config.proxy_command
options += ['-o', "ProxyCommand=\"#{ssh_info[:proxy_command]}\""] if machine.provider_config.proxy_command && !machine.provider_config.proxy_command.empty?
ssh_cmd = ['ssh'] + options + params

View File

@@ -19,6 +19,7 @@ module VagrantPlugins
# The name of the server, where Libvirtd is running.
attr_accessor :host
attr_accessor :port
# If use ssh tunnel to connect to Libvirt.
attr_accessor :connect_via_ssh
@@ -1218,14 +1219,9 @@ module VagrantPlugins
end
def host_devices(machine)
@host_devices ||= begin
(
machine.provider.driver.list_host_devices.map { |iface| iface.name } +
machine.provider.driver.list_networks.map { |net| net.bridge_name }
).uniq.select do |dev|
next if dev.empty?
dev != "lo" && !@host_device_exclude_prefixes.any? { |exclude| dev.start_with?(exclude) }
end
machine.provider.driver.host_devices.select do |dev|
next if dev.empty?
dev != "lo" && !@host_device_exclude_prefixes.any? { |exclude| dev.start_with?(exclude) }
end
end

View File

@@ -197,12 +197,28 @@ module VagrantPlugins
domain
end
def list_host_devices
connection.client.list_all_interfaces
end
def host_devices
@host_devices ||= begin
cmd = []
unless @machine.provider_config.proxy_command.nil? || @machine.provider_config.proxy_command.empty?
cmd = ['ssh', @machine.provider_config.host]
cmd += ['-p', @machine.provider_config.port.to_s] if @machine.provider_config.port
cmd += ['-l', @machine.provider_config.username] if @machine.provider_config.username
cmd += ['-i', @machine.provider_config.id_ssh_key_file] if @machine.provider_config.id_ssh_key_file
end
ip_cmd = cmd + %W(ip -j link show)
def list_networks
connection.client.list_all_networks
result = Vagrant::Util::Subprocess.execute(*ip_cmd)
raise Errors::FogLibvirtConnectionError unless result.exit_code == 0
info = JSON.parse(result.stdout)
(
info.map { |iface| iface['ifname'] } +
connection.client.list_all_interfaces.map { |iface| iface.name } +
connection.client.list_all_networks.map { |net| net.bridge_name }
).uniq.reject(&:empty?)
end
end
def attach_device(xml)

View File

@@ -70,7 +70,7 @@ module VagrantPlugins
forward_x11: @machine.config.ssh.forward_x11
}
ssh_info[:proxy_command] = @machine.provider_config.proxy_command if @machine.provider_config.proxy_command
ssh_info[:proxy_command] = @machine.provider_config.proxy_command if @machine.provider_config.proxy_command && !@machine.provider_config.proxy_command.empty?
ssh_info
end