Restore handling of disk_device domain setting (#1365)

Re-enable handling of the disk_device domain volume setting to ensure it
can be overridden from the default of vda to a value chosen.

Provide a disk resolver to resolve devices after the box has been downloaded
so that initial devices can be correctly allocated and avoid conflicts with
additional disks added that would otherwise get assigned the same device.

Removes hack for destroy domain when more than one disk, as now devices
in the config are only present if provided by the configuration.

Fixes: #1353
This commit is contained in:
Darragh Bailey
2021-11-22 10:02:18 +00:00
committed by GitHub
parent f8eff3d7a9
commit 91401a6559
13 changed files with 420 additions and 54 deletions

View File

@@ -33,7 +33,6 @@ describe VagrantPlugins::ProviderLibvirt::Action::CreateDomain do
allow(connection).to receive(:volumes).and_return(volumes)
allow(volumes).to receive(:all).and_return([domain_volume])
allow(domain_volume).to receive(:pool_name).and_return('default')
allow(domain_volume).to receive(:[]).with('name').and_return('vagrant-test_default.img')
allow(domain_volume).to receive(:path).and_return('/var/lib/libvirt/images/vagrant-test_default.img')
allow(machine).to receive_message_chain("box.name") { 'vagrant-libvirt/test' }
@@ -117,6 +116,48 @@ describe VagrantPlugins::ProviderLibvirt::Action::CreateDomain do
end
end
end
context 'with custom disk device setting' do
let(:domain_xml_file) { 'custom_disk_settings.xml' }
let(:vagrantfile_providerconfig) {
<<-EOF
libvirt.disk_device = 'sda'
EOF
}
it 'should set the domain device' do
expect(ui).to receive(:info).with(/ -- Image\(sda\):.*/)
expect(servers).to receive(:create).with(xml: domain_xml).and_return(machine)
expect(subject.call(env)).to be_nil
end
end
context 'with two domain disks' do
let(:domain_xml_file) { 'two_disk_settings.xml' }
let(:domain_volume_2) { double('domain_volume 2') }
before do
expect(volumes).to receive(:all).and_return([domain_volume])
expect(volumes).to receive(:all).and_return([domain_volume_2])
expect(domain_volume_2).to receive(:pool_name).and_return('default')
expect(domain_volume_2).to receive(:path).and_return('/var/lib/libvirt/images/vagrant-test_default_1.img')
env[:box_volumes].push({
:path=>"/test/box_1.img",
:name=>"test_vagrant_box_image_1.1.1_1.img",
:virtual_size=> ByteNumber.new(5),
})
end
it 'should correctly assign device entries' do
expect(ui).to receive(:info).with(/ -- Image\(vda\):.*/)
expect(ui).to receive(:info).with(/ -- Image\(vdb\):.*/)
expect(servers).to receive(:create).with(xml: domain_xml).and_return(machine)
expect(subject.call(env)).to be_nil
end
end
end
context 'no default pool' do