mirror of
https://github.com/vagrant-libvirt/vagrant-libvirt.git
synced 2025-02-25 18:55:27 -06:00
Reduce patching for distro default session use (#1424)
Reduce the patching needed should a distro wish to switch the default from using the system connection by default to using a session connection by default. Should now only require patching the default value and a single test checking the defaults.
This commit is contained in:
@@ -4,6 +4,8 @@ require 'spec_helper'
|
|||||||
require 'support/sharedcontext'
|
require 'support/sharedcontext'
|
||||||
require 'support/libvirt_context'
|
require 'support/libvirt_context'
|
||||||
|
|
||||||
|
require 'fog/libvirt/models/compute/volume'
|
||||||
|
|
||||||
require 'vagrant-libvirt/errors'
|
require 'vagrant-libvirt/errors'
|
||||||
require 'vagrant-libvirt/util/byte_number'
|
require 'vagrant-libvirt/util/byte_number'
|
||||||
require 'vagrant-libvirt/action/create_domain'
|
require 'vagrant-libvirt/action/create_domain'
|
||||||
@@ -14,10 +16,9 @@ describe VagrantPlugins::ProviderLibvirt::Action::CreateDomain do
|
|||||||
include_context 'unit'
|
include_context 'unit'
|
||||||
include_context 'libvirt'
|
include_context 'libvirt'
|
||||||
|
|
||||||
let(:libvirt_client) { double('libvirt_client') }
|
|
||||||
let(:servers) { double('servers') }
|
let(:servers) { double('servers') }
|
||||||
let(:volumes) { double('volumes') }
|
let(:volumes) { double('volumes') }
|
||||||
let(:domain_volume) { double('domain_volume') }
|
let(:domain_volume) { instance_double(::Fog::Libvirt::Compute::Volume) }
|
||||||
|
|
||||||
let(:domain_xml) { File.read(File.join(File.dirname(__FILE__), File.basename(__FILE__, '.rb'), domain_xml_file)) }
|
let(:domain_xml) { File.read(File.join(File.dirname(__FILE__), File.basename(__FILE__, '.rb'), domain_xml_file)) }
|
||||||
let(:storage_pool_xml) { File.read(File.join(File.dirname(__FILE__), File.basename(__FILE__, '.rb'), storage_pool_xml_file)) }
|
let(:storage_pool_xml) { File.read(File.join(File.dirname(__FILE__), File.basename(__FILE__, '.rb'), storage_pool_xml_file)) }
|
||||||
@@ -56,6 +57,10 @@ describe VagrantPlugins::ProviderLibvirt::Action::CreateDomain do
|
|||||||
context 'connection => qemu:///system' do
|
context 'connection => qemu:///system' do
|
||||||
let(:domain_xml_file) { 'default_domain.xml' }
|
let(:domain_xml_file) { 'default_domain.xml' }
|
||||||
|
|
||||||
|
before do
|
||||||
|
allow(machine.provider_config).to receive(:qemu_use_session).and_return(false)
|
||||||
|
end
|
||||||
|
|
||||||
context 'default pool' do
|
context 'default pool' do
|
||||||
it 'should execute correctly' do
|
it 'should execute correctly' do
|
||||||
expect(servers).to receive(:create).with(xml: domain_xml).and_return(machine)
|
expect(servers).to receive(:create).with(xml: domain_xml).and_return(machine)
|
||||||
@@ -178,10 +183,8 @@ describe VagrantPlugins::ProviderLibvirt::Action::CreateDomain do
|
|||||||
end
|
end
|
||||||
|
|
||||||
context 'connection => qemu:///session' do
|
context 'connection => qemu:///session' do
|
||||||
let(:vagrantfile_providerconfig) do
|
before do
|
||||||
<<-EOF
|
allow(machine.provider_config).to receive(:qemu_use_session).and_return(true)
|
||||||
libvirt.qemu_use_session = true
|
|
||||||
EOF
|
|
||||||
end
|
end
|
||||||
|
|
||||||
context 'default pool' do
|
context 'default pool' do
|
||||||
|
|||||||
@@ -4,6 +4,8 @@ require 'spec_helper'
|
|||||||
require 'support/sharedcontext'
|
require 'support/sharedcontext'
|
||||||
require 'support/libvirt_context'
|
require 'support/libvirt_context'
|
||||||
|
|
||||||
|
require 'fog/libvirt/models/compute/volume'
|
||||||
|
|
||||||
require 'vagrant-libvirt/action/destroy_domain'
|
require 'vagrant-libvirt/action/destroy_domain'
|
||||||
require 'vagrant-libvirt/util/byte_number'
|
require 'vagrant-libvirt/util/byte_number'
|
||||||
|
|
||||||
@@ -14,11 +16,9 @@ describe VagrantPlugins::ProviderLibvirt::Action::CreateDomainVolume do
|
|||||||
include_context 'unit'
|
include_context 'unit'
|
||||||
include_context 'libvirt'
|
include_context 'libvirt'
|
||||||
|
|
||||||
let(:libvirt_domain) { double('libvirt_domain') }
|
|
||||||
let(:libvirt_client) { double('libvirt_client') }
|
|
||||||
let(:volumes) { double('volumes') }
|
let(:volumes) { double('volumes') }
|
||||||
let(:all) { double('all') }
|
let(:all) { double('all') }
|
||||||
let(:box_volume) { double('box_volume') }
|
let(:box_volume) { instance_double(::Fog::Libvirt::Compute::Volume) }
|
||||||
|
|
||||||
def read_test_file(name)
|
def read_test_file(name)
|
||||||
File.read(File.join(File.dirname(__FILE__), File.basename(__FILE__, '.rb'), name))
|
File.read(File.join(File.dirname(__FILE__), File.basename(__FILE__, '.rb'), name))
|
||||||
@@ -35,6 +35,8 @@ describe VagrantPlugins::ProviderLibvirt::Action::CreateDomainVolume do
|
|||||||
allow(box_volume).to receive(:id).and_return(nil)
|
allow(box_volume).to receive(:id).and_return(nil)
|
||||||
env[:domain_name] = 'test'
|
env[:domain_name] = 'test'
|
||||||
|
|
||||||
|
allow(machine.provider_config).to receive(:qemu_use_session).and_return(false)
|
||||||
|
|
||||||
allow(logger).to receive(:debug)
|
allow(logger).to receive(:debug)
|
||||||
end
|
end
|
||||||
|
|
||||||
|
|||||||
@@ -24,6 +24,8 @@ describe VagrantPlugins::ProviderLibvirt::Action::WaitTillUp do
|
|||||||
allow(driver).to receive(:state).and_return(:running)
|
allow(driver).to receive(:state).and_return(:running)
|
||||||
# return some information for domain when needed
|
# return some information for domain when needed
|
||||||
allow(domain).to receive(:mac).and_return('9C:D5:53:F1:5A:E7')
|
allow(domain).to receive(:mac).and_return('9C:D5:53:F1:5A:E7')
|
||||||
|
|
||||||
|
allow(machine.provider_config).to receive(:qemu_use_session).and_return(false)
|
||||||
end
|
end
|
||||||
|
|
||||||
context 'when machine does not exist' do
|
context 'when machine does not exist' do
|
||||||
|
|||||||
@@ -171,55 +171,55 @@ describe VagrantPlugins::ProviderLibvirt::Config do
|
|||||||
# ignore LIBVIRT_DEFAULT_URI due to explicit settings
|
# ignore LIBVIRT_DEFAULT_URI due to explicit settings
|
||||||
[ # when uri explicitly set
|
[ # when uri explicitly set
|
||||||
{:uri => 'qemu:///system'},
|
{:uri => 'qemu:///system'},
|
||||||
{:uri => 'qemu:///system'},
|
{:uri => %r{qemu:///(system|session)}},
|
||||||
{
|
{
|
||||||
:env => {'LIBVIRT_DEFAULT_URI' => 'qemu://session'},
|
:env => {'LIBVIRT_DEFAULT_URI' => 'qemu:///custom'},
|
||||||
}
|
}
|
||||||
],
|
],
|
||||||
[ # when host explicitly set
|
[ # when host explicitly set
|
||||||
{:host => 'remote'},
|
{:host => 'remote'},
|
||||||
{:uri => 'qemu://remote/system'},
|
{:uri => %r{qemu://remote/(system|session)}},
|
||||||
{
|
{
|
||||||
:env => {'LIBVIRT_DEFAULT_URI' => 'qemu://session'},
|
:env => {'LIBVIRT_DEFAULT_URI' => 'qemu:///custom'},
|
||||||
}
|
}
|
||||||
],
|
],
|
||||||
[ # when connect_via_ssh explicitly set
|
[ # when connect_via_ssh explicitly set
|
||||||
{:connect_via_ssh => true},
|
{:connect_via_ssh => true},
|
||||||
{:uri => 'qemu+ssh://localhost/system?no_verify=1'},
|
{:uri => %r{qemu\+ssh://localhost/(system|session)\?no_verify=1}},
|
||||||
{
|
{
|
||||||
:env => {'LIBVIRT_DEFAULT_URI' => 'qemu://session'},
|
:env => {'LIBVIRT_DEFAULT_URI' => 'qemu:///custom'},
|
||||||
}
|
}
|
||||||
],
|
],
|
||||||
[ # when username explicitly set without ssh
|
[ # when username explicitly set without ssh
|
||||||
{:username => 'my_user' },
|
{:username => 'my_user' },
|
||||||
{:uri => 'qemu:///system', :username => 'my_user'},
|
{:uri => %r{qemu:///(system|session)}, :username => 'my_user'},
|
||||||
{
|
{
|
||||||
:env => {'LIBVIRT_DEFAULT_URI' => 'qemu://session'},
|
:env => {'LIBVIRT_DEFAULT_URI' => 'qemu:///custom'},
|
||||||
}
|
}
|
||||||
],
|
],
|
||||||
[ # when username explicitly set with host but without ssh
|
[ # when username explicitly set with host but without ssh
|
||||||
{:username => 'my_user', :host => 'remote'},
|
{:username => 'my_user', :host => 'remote'},
|
||||||
{:uri => 'qemu://remote/system', :username => 'my_user'},
|
{:uri => %r{qemu://remote/(system|session)}, :username => 'my_user'},
|
||||||
{
|
{
|
||||||
:env => {'LIBVIRT_DEFAULT_URI' => 'qemu://session'},
|
:env => {'LIBVIRT_DEFAULT_URI' => 'qemu:///custom'},
|
||||||
}
|
}
|
||||||
],
|
],
|
||||||
[ # when password explicitly set
|
[ # when password explicitly set
|
||||||
{:password => 'some_password'},
|
{:password => 'some_password'},
|
||||||
{:uri => 'qemu:///system', :password => 'some_password'},
|
{:uri => %r{qemu:///(system|session)}, :password => 'some_password'},
|
||||||
{
|
{
|
||||||
:env => {'LIBVIRT_DEFAULT_URI' => 'qemu://session'},
|
:env => {'LIBVIRT_DEFAULT_URI' => 'qemu:///custom'},
|
||||||
}
|
}
|
||||||
],
|
],
|
||||||
|
|
||||||
# driver settings
|
# driver settings
|
||||||
[ # set to kvm only
|
[ # set to kvm only
|
||||||
{:driver => 'kvm'},
|
{:driver => 'kvm'},
|
||||||
{:uri => "qemu:///system"},
|
{:uri => %r{qemu:///(system|session)}},
|
||||||
],
|
],
|
||||||
[ # set to qemu only
|
[ # set to qemu only
|
||||||
{:driver => 'qemu'},
|
{:driver => 'qemu'},
|
||||||
{:uri => "qemu:///system"},
|
{:uri => %r{qemu:///(system|session)}},
|
||||||
],
|
],
|
||||||
[ # set to qemu with session enabled
|
[ # set to qemu with session enabled
|
||||||
{:driver => 'qemu', :qemu_use_session => true},
|
{:driver => 'qemu', :qemu_use_session => true},
|
||||||
@@ -241,29 +241,29 @@ describe VagrantPlugins::ProviderLibvirt::Config do
|
|||||||
# connect_via_ssh settings
|
# connect_via_ssh settings
|
||||||
[ # enabled
|
[ # enabled
|
||||||
{:connect_via_ssh => true},
|
{:connect_via_ssh => true},
|
||||||
{:uri => "qemu+ssh://localhost/system?no_verify=1"},
|
{:uri => %r{qemu\+ssh://localhost/(system|session)\?no_verify=1}},
|
||||||
],
|
],
|
||||||
[ # enabled with user
|
[ # enabled with user
|
||||||
{:connect_via_ssh => true, :username => 'my_user'},
|
{:connect_via_ssh => true, :username => 'my_user'},
|
||||||
{:uri => "qemu+ssh://my_user@localhost/system?no_verify=1"},
|
{:uri => %r{qemu\+ssh://my_user@localhost/(system|session)\?no_verify=1}},
|
||||||
],
|
],
|
||||||
[ # enabled with host
|
[ # enabled with host
|
||||||
{:connect_via_ssh => true, :host => 'remote_server'},
|
{:connect_via_ssh => true, :host => 'remote_server'},
|
||||||
{:uri => "qemu+ssh://remote_server/system?no_verify=1"},
|
{:uri => %r{qemu\+ssh://remote_server/(system|session)\?no_verify=1}},
|
||||||
],
|
],
|
||||||
|
|
||||||
# id_ssh_key_file behaviour
|
# id_ssh_key_file behaviour
|
||||||
[ # set should take given value
|
[ # set should take given value
|
||||||
{:connect_via_ssh => true, :id_ssh_key_file => '/path/to/keyfile'},
|
{:connect_via_ssh => true, :id_ssh_key_file => '/path/to/keyfile'},
|
||||||
{:uri => 'qemu+ssh://localhost/system?no_verify=1&keyfile=/path/to/keyfile', :connect_via_ssh => true},
|
{:uri => %r{qemu\+ssh://localhost/(system|session)\?no_verify=1&keyfile=/path/to/keyfile}, :connect_via_ssh => true},
|
||||||
],
|
],
|
||||||
[ # set should infer use of ssh
|
[ # set should infer use of ssh
|
||||||
{:id_ssh_key_file => '/path/to/keyfile'},
|
{:id_ssh_key_file => '/path/to/keyfile'},
|
||||||
{:uri => 'qemu+ssh://localhost/system?no_verify=1&keyfile=/path/to/keyfile', :connect_via_ssh => true},
|
{:uri => %r{qemu\+ssh://localhost/(system|session)\?no_verify=1&keyfile=/path/to/keyfile}, :connect_via_ssh => true},
|
||||||
],
|
],
|
||||||
[ # connect_via_ssh should enable default but ignore due to not existing
|
[ # connect_via_ssh should enable default but ignore due to not existing
|
||||||
{:connect_via_ssh => true},
|
{:connect_via_ssh => true},
|
||||||
{:uri => 'qemu+ssh://localhost/system?no_verify=1', :id_ssh_key_file => nil},
|
{:uri => %r{qemu\+ssh://localhost/(system|session)\?no_verify=1}, :id_ssh_key_file => nil},
|
||||||
{
|
{
|
||||||
:setup => ProcWithBinding.new {
|
:setup => ProcWithBinding.new {
|
||||||
expect(File).to receive(:file?).with("/home/tests/.ssh/id_rsa").and_return(false)
|
expect(File).to receive(:file?).with("/home/tests/.ssh/id_rsa").and_return(false)
|
||||||
@@ -272,7 +272,7 @@ describe VagrantPlugins::ProviderLibvirt::Config do
|
|||||||
],
|
],
|
||||||
[ # connect_via_ssh should enable default and include due to existing
|
[ # connect_via_ssh should enable default and include due to existing
|
||||||
{:connect_via_ssh => true},
|
{:connect_via_ssh => true},
|
||||||
{:uri => 'qemu+ssh://localhost/system?no_verify=1&keyfile=/home/tests/.ssh/id_rsa', :id_ssh_key_file => '/home/tests/.ssh/id_rsa'},
|
{:uri => %r{qemu\+ssh://localhost/(system|session)\?no_verify=1&keyfile=/home/tests/\.ssh/id_rsa}, :id_ssh_key_file => '/home/tests/.ssh/id_rsa'},
|
||||||
{
|
{
|
||||||
:setup => ProcWithBinding.new {
|
:setup => ProcWithBinding.new {
|
||||||
expect(File).to receive(:file?).with("/home/tests/.ssh/id_rsa").and_return(true)
|
expect(File).to receive(:file?).with("/home/tests/.ssh/id_rsa").and_return(true)
|
||||||
@@ -283,7 +283,7 @@ describe VagrantPlugins::ProviderLibvirt::Config do
|
|||||||
# socket behaviour
|
# socket behaviour
|
||||||
[ # set
|
[ # set
|
||||||
{:socket => '/var/run/libvirt/libvirt-sock'},
|
{:socket => '/var/run/libvirt/libvirt-sock'},
|
||||||
{:uri => "qemu:///system?socket=/var/run/libvirt/libvirt-sock"},
|
{:uri => %r{qemu:///(system|session)\?socket=/var/run/libvirt/libvirt-sock}},
|
||||||
],
|
],
|
||||||
].each do |inputs, outputs, options|
|
].each do |inputs, outputs, options|
|
||||||
opts = {}
|
opts = {}
|
||||||
@@ -317,7 +317,8 @@ describe VagrantPlugins::ProviderLibvirt::Config do
|
|||||||
hash["#{name.to_s[1..-1]}".to_sym] =subject.instance_variable_get(name)
|
hash["#{name.to_s[1..-1]}".to_sym] =subject.instance_variable_get(name)
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
expect(got).to eq(outputs)
|
|
||||||
|
expect(got).to match(outputs.inject({}) { |h, (k, v)| h[k] = v.is_a?(Regexp) ? a_string_matching(v) : v; h })
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user