mirror of
https://github.com/vagrant-libvirt/vagrant-libvirt.git
synced 2025-02-25 18:55:27 -06:00
Derive system URI from default URI (#1398)
To facilitate using session on a remote instance, ensure the system_uri configuration attribute is by default derived from the default uri provided or constructed based on other settings, so that it contains any host and transport settings.
This commit is contained in:
parent
e917a2dbda
commit
bb267e3910
@ -840,7 +840,6 @@ module VagrantPlugins
|
||||
@management_network_pci_slot = nil if @management_network_pci_slot == UNSET_VALUE
|
||||
@management_network_domain = nil if @management_network_domain == UNSET_VALUE
|
||||
@management_network_mtu = nil if @management_network_mtu == UNSET_VALUE
|
||||
@system_uri = 'qemu:///system' if @system_uri == UNSET_VALUE
|
||||
|
||||
# Domain specific settings.
|
||||
@title = '' if @title == UNSET_VALUE
|
||||
@ -1066,6 +1065,10 @@ module VagrantPlugins
|
||||
# Parse uri to extract individual components
|
||||
uri = _parse_uri(@uri)
|
||||
|
||||
system_uri = uri.dup
|
||||
system_uri.path = '/system'
|
||||
@system_uri = system_uri.to_s if @system_uri == UNSET_VALUE
|
||||
|
||||
# only set @connect_via_ssh if not explicitly to avoid overriding
|
||||
# and allow an error to occur if the @uri and @connect_via_ssh disagree
|
||||
@connect_via_ssh = uri.scheme.include? "ssh" if @connect_via_ssh == UNSET_VALUE
|
||||
|
@ -338,6 +338,54 @@ describe VagrantPlugins::ProviderLibvirt::Config do
|
||||
end
|
||||
end
|
||||
|
||||
context '@system_uri' do
|
||||
[
|
||||
# system uri
|
||||
[ # transport and hostname
|
||||
{:uri => "qemu+ssh://localhost/session"},
|
||||
{:uri => "qemu+ssh://localhost/session", :system_uri => "qemu+ssh://localhost/system"},
|
||||
],
|
||||
[ # explicitly set
|
||||
{:qemu_use_session => true, :system_uri => "custom://remote/system"},
|
||||
{:uri => "qemu:///session", :system_uri => "custom://remote/system"},
|
||||
],
|
||||
].each do |inputs, outputs, options|
|
||||
opts = {}
|
||||
opts.merge!(options) if options
|
||||
|
||||
it "should handle inputs #{inputs} with env (#{opts[:env]})" do
|
||||
# allow some of these to fail for now if marked as such
|
||||
if !opts[:allow_failure].nil?
|
||||
pending(opts[:allow_failure])
|
||||
end
|
||||
|
||||
if !opts[:setup].nil?
|
||||
opts[:setup].apply_binding(binding)
|
||||
end
|
||||
|
||||
inputs.each do |k, v|
|
||||
subject.instance_variable_set("@#{k}", v)
|
||||
end
|
||||
|
||||
if !opts[:env].nil?
|
||||
opts[:env].each do |k, v|
|
||||
fake_env[k] = v
|
||||
end
|
||||
end
|
||||
|
||||
subject.finalize!
|
||||
|
||||
# ensure failed output indicates which settings are incorrect in the failed test
|
||||
got = subject.instance_variables.each_with_object({}) do |name, hash|
|
||||
if outputs.key?(name.to_s[1..-1].to_sym)
|
||||
hash["#{name.to_s[1..-1]}".to_sym] =subject.instance_variable_get(name)
|
||||
end
|
||||
end
|
||||
expect(got).to eq(outputs)
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
context '@proxy_command' do
|
||||
before(:example) do
|
||||
stub_const("ENV", fake_env)
|
||||
|
@ -80,15 +80,15 @@ describe VagrantPlugins::ProviderLibvirt::Driver do
|
||||
# system_uri should be 'qemu+ssh://user@remote1/system'
|
||||
# and not 'qemu:///system'.
|
||||
it 'should configure a separate connection per machine' do
|
||||
expect(Libvirt).to receive(:open_read_only).with('qemu:///system').and_return(system_connection1)
|
||||
expect(Libvirt).to receive(:open_read_only).with('qemu:///system').and_return(system_connection2)
|
||||
expect(Libvirt).to receive(:open_read_only).with('qemu+ssh://user@remote1/system').and_return(system_connection1)
|
||||
expect(Libvirt).to receive(:open_read_only).with('qemu+ssh://vms@remote2/system').and_return(system_connection2)
|
||||
|
||||
expect(machine.provider.driver.system_connection).to eq(system_connection1)
|
||||
expect(machine2.provider.driver.system_connection).to eq(system_connection2)
|
||||
end
|
||||
|
||||
it 'should configure the connection once' do
|
||||
expect(Libvirt).to receive(:open_read_only).with('qemu:///system').and_return(system_connection1)
|
||||
expect(Libvirt).to receive(:open_read_only).with('qemu+ssh://user@remote1/system').and_return(system_connection1)
|
||||
|
||||
expect(machine.provider.driver.system_connection).to eq(system_connection1)
|
||||
expect(machine.provider.driver.system_connection).to eq(system_connection1)
|
||||
|
Loading…
Reference in New Issue
Block a user