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:
@@ -1,6 +1,8 @@
|
||||
# frozen_string_literal: true
|
||||
|
||||
require 'fog/libvirt'
|
||||
require 'fog/libvirt/models/compute/server'
|
||||
require 'libvirt'
|
||||
|
||||
shared_context 'libvirt' do
|
||||
include_context 'unit'
|
||||
@@ -8,7 +10,9 @@ shared_context 'libvirt' do
|
||||
let(:libvirt_context) { true }
|
||||
let(:id) { 'dummy-vagrant_dummy' }
|
||||
let(:connection) { double('connection') }
|
||||
let(:domain) { double('domain') }
|
||||
let(:domain) { instance_double('::Fog::Libvirt::Compute::Server') }
|
||||
let(:libvirt_client) { instance_double('::Libvirt::Connect') }
|
||||
let(:libvirt_domain) { instance_double('::Libvirt::Domain') }
|
||||
let(:logger) { double('logger') }
|
||||
|
||||
def connection_result(options = {})
|
||||
@@ -22,11 +26,10 @@ shared_context 'libvirt' do
|
||||
stub_const('::Fog::Compute', connection)
|
||||
|
||||
# drivers also call vm_exists? during init;
|
||||
allow(connection).to receive(:servers).with(kind_of(String))
|
||||
allow(connection).to receive(:servers)
|
||||
.and_return(connection_result(result: nil))
|
||||
|
||||
# return some information for domain when needed
|
||||
allow(domain).to receive(:mac).and_return('9C:D5:53:F1:5A:E7')
|
||||
allow(connection).to receive(:client).and_return(libvirt_client)
|
||||
|
||||
allow(machine).to receive(:id).and_return(id)
|
||||
allow(Log4r::Logger).to receive(:new).and_return(logger)
|
||||
|
||||
Reference in New Issue
Block a user