spec/unit/config_spec.rb in vagrant-libvirt-0.7.0 vs spec/unit/config_spec.rb in vagrant-libvirt-0.8.0
- old
+ new
@@ -169,59 +169,59 @@
],
# ignore LIBVIRT_DEFAULT_URI due to explicit settings
[ # when uri explicitly set
{: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
{: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
{: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
{: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
{: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
{: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
[ # set to kvm only
{:driver => 'kvm'},
- {:uri => "qemu:///system"},
+ {:uri => %r{qemu:///(system|session)}},
],
[ # set to qemu only
{:driver => 'qemu'},
- {:uri => "qemu:///system"},
+ {:uri => %r{qemu:///(system|session)}},
],
[ # set to qemu with session enabled
{:driver => 'qemu', :qemu_use_session => true},
{:uri => "qemu:///session"},
],
@@ -239,53 +239,53 @@
],
# connect_via_ssh settings
[ # enabled
{: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
{: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
{: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
[ # set should take given value
{: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
{: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 => 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 {
expect(File).to receive(:file?).with("/home/tests/.ssh/id_rsa").and_return(false)
}
}
],
[ # connect_via_ssh should enable default and include due to existing
{: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 {
expect(File).to receive(:file?).with("/home/tests/.ssh/id_rsa").and_return(true)
}
}
],
# socket behaviour
[ # set
{: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|
opts = {}
opts.merge!(options) if options
@@ -315,11 +315,12 @@
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)
+
+ expect(got).to match(outputs.inject({}) { |h, (k, v)| h[k] = v.is_a?(Regexp) ? a_string_matching(v) : v; h })
end
end
context 'when invalid @driver is defined' do
it "should raise exception for unrecognized" do
@@ -529,10 +530,51 @@
expect(subject.usbctl_dev).to eq({:model => 'pii3-uchi'})
end
end
end
end
+
+ context '@channels' do
+ it 'should be empty by default' do
+ subject.finalize!
+
+ expect(subject.channels).to be_empty
+ end
+
+ context 'when qemu_use_agent is set' do
+ before do
+ subject.qemu_use_agent = true
+ end
+
+ it 'should inject a qemu agent channel' do
+ subject.finalize!
+
+ expect(subject.channels).to_not be_empty
+ expect(subject.channels).to match([a_hash_including({:target_name => 'org.qemu.guest_agent.0'})])
+ end
+
+ context 'when agent channel already added' do
+ it 'should not modify the channels' do
+ subject.channel :type => 'unix', :target_name => 'org.qemu.guest_agent.0', :target_type => 'virtio'
+
+ subject.finalize!
+
+ expect(subject.channels.length).to eq(1)
+ end
+
+ context 'when agent channel explicitly disbaled' do
+ it 'should not include an agent channel' do
+ subject.channel :type => 'unix', :target_name => 'org.qemu.guest_agent.0', :disabled => true
+
+ subject.finalize!
+
+ expect(subject.channels).to be_empty
+ end
+ end
+ end
+ end
+ end
end
def assert_invalid
subject.finalize!
errors = subject.validate(machine)
@@ -564,11 +606,13 @@
end
end
context 'with mac defined' do
let (:vm) { double('vm') }
- before { expect(machine.config).to receive(:vm).and_return(vm) }
+ before do
+ machine.config.instance_variable_get("@keys")[:vm] = vm
+ end
it 'is valid with valid mac' do
expect(vm).to receive(:networks).and_return([[:public, { mac: 'aa:bb:cc:dd:ee:ff' }]])
assert_valid
end
@@ -583,10 +627,25 @@
it 'should be invalid if MAC not formatted correctly' do
expect(vm).to receive(:networks).and_return([[:public, { mac: 'aa/bb/cc/dd/ee/ff' }]])
assert_invalid
end
end
+
+ context 'with cpu_mode and cpu_model defined' do
+ it 'should discard model if mode is passthrough' do
+ subject.cpu_mode = 'host-passthrough'
+ subject.cpu_model = 'qemu64'
+ assert_valid
+ expect(subject.cpu_model).to be_empty
+ end
+
+ it 'should allow custom mode with model' do
+ subject.cpu_mode = 'custom'
+ subject.cpu_model = 'qemu64'
+ assert_valid
+ end
+ end
end
describe '#merge' do
let(:one) { described_class.new }
let(:two) { described_class.new }
@@ -604,14 +663,14 @@
include(device: 'vdc'))
end
end
context 'without devices given' do
- it 'should merge disks with different devices assigned automatically' do
+ it 'should merge disks without assigning devices automatically' do
one.storage(:file)
two.storage(:file)
subject.finalize!
- expect(subject.disks).to include(include(device: 'vdb'),
+ expect(subject.disks).to_not include(include(device: 'vdb'),
include(device: 'vdc'))
end
end
end