mirror of
https://github.com/vagrant-libvirt/vagrant-libvirt.git
synced 2025-02-25 18:55:27 -06:00
Reorder qemu agent usage for use with sessions (#1396)
Adjust the order of checks around use of qemu sessions to allow use of the agent as a priority when enabled, which should remove the need to retrieve the address from the system connection when enabled. Additionally adjust the call to the agent to ensure it uses the default connection to retrieve the correct domain, rather than forcing the system connection, which will fail to find the domain if it was created via a user session. Add tests that validate most of this behaviour, as well as resulting in some minor fixes around downcasing the mac address for comparisons, and also using instance mocks with rspec instead of pure doubles to help catch false positives where mocks are allowing calls that done exist. Related: #1342
This commit is contained in:
@@ -970,7 +970,7 @@ module VagrantPlugins
|
||||
# Additional QEMU commandline environment variables
|
||||
@qemu_env = {} if @qemu_env == UNSET_VALUE
|
||||
|
||||
@qemu_use_agent = true if @qemu_use_agent != UNSET_VALUE
|
||||
@qemu_use_agent = false if @qemu_use_agent == UNSET_VALUE
|
||||
|
||||
@serials = [{:type => 'pty', :source => nil}] if @serials == []
|
||||
end
|
||||
@@ -986,6 +986,9 @@ module VagrantPlugins
|
||||
end
|
||||
end
|
||||
|
||||
unless @qemu_use_agent == true || @qemu_use_agent == false
|
||||
errors << "libvirt.qemu_use_agent must be a boolean."
|
||||
end
|
||||
|
||||
if @qemu_use_agent == true
|
||||
# if qemu agent is used to optain domain ip configuration, at least
|
||||
|
||||
@@ -98,16 +98,16 @@ module VagrantPlugins
|
||||
end
|
||||
|
||||
def get_domain_ipaddress(machine, domain)
|
||||
if @machine.provider_config.qemu_use_session
|
||||
return get_ipaddress_from_system domain.mac
|
||||
end
|
||||
|
||||
# attempt to get ip address from qemu agent
|
||||
if @machine.provider_config.qemu_use_agent == true
|
||||
@logger.info('Get IP via qemu agent')
|
||||
return get_ipaddress_from_qemu_agent(domain, machine.id)
|
||||
end
|
||||
|
||||
if @machine.provider_config.qemu_use_session
|
||||
return get_ipaddress_from_system domain.mac
|
||||
end
|
||||
|
||||
# Get IP address from dhcp leases table
|
||||
begin
|
||||
ip_address = get_ipaddress_from_domain(domain)
|
||||
@@ -168,9 +168,9 @@ module VagrantPlugins
|
||||
def get_ipaddress_from_qemu_agent(domain, machine_id)
|
||||
ip_address = nil
|
||||
addresses = nil
|
||||
dom = system_connection.lookup_domain_by_uuid(machine_id)
|
||||
libvirt_domain = connection.client.lookup_domain_by_uuid(machine_id)
|
||||
begin
|
||||
response = dom.qemu_agent_command('{"execute":"guest-network-get-interfaces"}', timeout=10)
|
||||
response = libvirt_domain.qemu_agent_command('{"execute":"guest-network-get-interfaces"}', timeout=10)
|
||||
@logger.debug("Got Response from qemu agent")
|
||||
@logger.debug(response)
|
||||
addresses = JSON.parse(response)
|
||||
@@ -180,7 +180,7 @@ module VagrantPlugins
|
||||
|
||||
unless addresses.nil?
|
||||
addresses["return"].each{ |interface|
|
||||
if domain.mac == interface["hardware-address"]
|
||||
if domain.mac.downcase == interface["hardware-address"].downcase
|
||||
@logger.debug("Found mathing interface: [%s]" % interface["name"])
|
||||
if interface.has_key?("ip-addresses")
|
||||
interface["ip-addresses"].each{ |ip|
|
||||
|
||||
Reference in New Issue
Block a user