2016-12-06 23:20:29 +01:00
|
|
|
require 'spec_helper'
|
|
|
|
|
require 'support/sharedcontext'
|
2016-11-25 15:08:33 +00:00
|
|
|
|
2016-12-06 23:20:29 +01:00
|
|
|
require 'vagrant-libvirt/config'
|
2016-11-25 15:08:33 +00:00
|
|
|
|
|
|
|
|
describe VagrantPlugins::ProviderLibvirt::Config do
|
2016-12-06 23:20:29 +01:00
|
|
|
include_context 'unit'
|
2016-11-25 15:08:33 +00:00
|
|
|
|
|
|
|
|
def assert_invalid
|
|
|
|
|
errors = subject.validate(machine)
|
2017-05-16 14:14:30 +01:00
|
|
|
raise "No errors: #{errors.inspect}" if errors.values.all?(&:empty?)
|
2016-11-25 15:08:33 +00:00
|
|
|
end
|
|
|
|
|
|
|
|
|
|
def assert_valid
|
|
|
|
|
errors = subject.validate(machine)
|
2016-12-06 23:20:29 +01:00
|
|
|
raise "Errors: #{errors.inspect}" unless errors.values.all?(&:empty?)
|
2016-11-25 15:08:33 +00:00
|
|
|
end
|
|
|
|
|
|
2016-12-06 23:20:29 +01:00
|
|
|
describe '#validate' do
|
|
|
|
|
it 'is valid with defaults' do
|
2016-11-25 15:08:33 +00:00
|
|
|
assert_valid
|
|
|
|
|
end
|
|
|
|
|
|
2017-05-16 14:14:30 +01:00
|
|
|
context 'with disks defined' do
|
|
|
|
|
before { expect(machine).to receive(:provider_config).and_return(subject).at_least(:once) }
|
|
|
|
|
|
|
|
|
|
it 'is valid if relative path used for disk' do
|
|
|
|
|
subject.storage :file, path: '../path/to/file.qcow2'
|
|
|
|
|
assert_valid
|
|
|
|
|
end
|
2016-11-25 15:08:33 +00:00
|
|
|
|
2017-05-16 14:14:30 +01:00
|
|
|
it 'should be invalid if absolute path used for disk' do
|
|
|
|
|
subject.storage :file, path: '/absolute/path/to/file.qcow2'
|
|
|
|
|
assert_invalid
|
|
|
|
|
end
|
2016-11-25 15:08:33 +00:00
|
|
|
end
|
|
|
|
|
|
2016-12-06 23:20:29 +01:00
|
|
|
context 'with mac defined' do
|
|
|
|
|
let (:vm) { double('vm') }
|
2017-05-16 14:14:30 +01:00
|
|
|
before { expect(machine.config).to receive(:vm).and_return(vm) }
|
2016-11-25 15:08:33 +00:00
|
|
|
|
2016-12-06 23:20:29 +01:00
|
|
|
it 'is valid with valid mac' do
|
2017-05-16 14:14:30 +01:00
|
|
|
expect(vm).to receive(:networks).and_return([[:public, { mac: 'aa:bb:cc:dd:ee:ff' }]])
|
2016-11-25 15:08:33 +00:00
|
|
|
assert_valid
|
|
|
|
|
end
|
|
|
|
|
|
2016-12-06 23:20:29 +01:00
|
|
|
it 'should be invalid if MAC not formatted correctly' do
|
2017-05-16 14:14:30 +01:00
|
|
|
expect(vm).to receive(:networks).and_return([[:public, { mac: 'aabbccddeeff' }]])
|
2016-11-25 15:08:33 +00:00
|
|
|
assert_invalid
|
|
|
|
|
end
|
|
|
|
|
end
|
|
|
|
|
end
|
|
|
|
|
|
2016-12-06 23:20:29 +01:00
|
|
|
describe '#merge' do
|
2016-11-25 15:08:33 +00:00
|
|
|
let(:one) { described_class.new }
|
|
|
|
|
let(:two) { described_class.new }
|
|
|
|
|
|
|
|
|
|
subject { one.merge(two) }
|
|
|
|
|
|
2016-12-06 23:20:29 +01:00
|
|
|
context 'storage' do
|
|
|
|
|
context 'with disks' do
|
|
|
|
|
context 'assigned specific devices' do
|
|
|
|
|
it 'should merge disks with specific devices' do
|
|
|
|
|
one.storage(:file, device: 'vdb')
|
|
|
|
|
two.storage(:file, device: 'vdc')
|
2016-11-25 15:08:33 +00:00
|
|
|
subject.finalize!
|
2016-12-06 23:20:29 +01:00
|
|
|
expect(subject.disks).to include(include(device: 'vdb'),
|
|
|
|
|
include(device: 'vdc'))
|
2016-11-25 15:08:33 +00:00
|
|
|
end
|
|
|
|
|
end
|
|
|
|
|
|
2016-12-06 23:20:29 +01:00
|
|
|
context 'without devices given' do
|
|
|
|
|
it 'should merge disks with different devices assigned automatically' do
|
2016-11-25 15:08:33 +00:00
|
|
|
one.storage(:file)
|
|
|
|
|
two.storage(:file)
|
|
|
|
|
subject.finalize!
|
2016-12-06 23:20:29 +01:00
|
|
|
expect(subject.disks).to include(include(device: 'vdb'),
|
|
|
|
|
include(device: 'vdc'))
|
2016-11-25 15:08:33 +00:00
|
|
|
end
|
|
|
|
|
end
|
|
|
|
|
end
|
|
|
|
|
|
2016-12-06 23:20:29 +01:00
|
|
|
context 'with cdroms only' do
|
|
|
|
|
context 'assigned specific devs' do
|
|
|
|
|
it 'should merge disks with specific devices' do
|
|
|
|
|
one.storage(:file, device: :cdrom, dev: 'hda')
|
|
|
|
|
two.storage(:file, device: :cdrom, dev: 'hdb')
|
2016-11-25 15:08:33 +00:00
|
|
|
subject.finalize!
|
2016-12-06 23:20:29 +01:00
|
|
|
expect(subject.cdroms).to include(include(dev: 'hda'),
|
|
|
|
|
include(dev: 'hdb'))
|
2016-11-25 15:08:33 +00:00
|
|
|
end
|
|
|
|
|
end
|
|
|
|
|
|
2016-12-06 23:20:29 +01:00
|
|
|
context 'without devs given' do
|
|
|
|
|
it 'should merge cdroms with different devs assigned automatically' do
|
|
|
|
|
one.storage(:file, device: :cdrom)
|
|
|
|
|
two.storage(:file, device: :cdrom)
|
2016-11-25 15:08:33 +00:00
|
|
|
subject.finalize!
|
2016-12-06 23:20:29 +01:00
|
|
|
expect(subject.cdroms).to include(include(dev: 'hda'),
|
|
|
|
|
include(dev: 'hdb'))
|
2016-11-25 15:08:33 +00:00
|
|
|
end
|
|
|
|
|
end
|
|
|
|
|
end
|
|
|
|
|
end
|
|
|
|
|
end
|
|
|
|
|
end
|