mirror of
https://github.com/vagrant-libvirt/vagrant-libvirt.git
synced 2025-02-25 18:55:27 -06:00
Handle nil volumes when cd-rom attached (#1273)
When a cd-rom is attached as an additional storage, listing the volumes can include a nil element. Make sure to check that the element is valid before attempting to access the attribute. Update the test to better match the observed behaviour. Fixes: #1209, #1262
This commit is contained in:
@@ -70,7 +70,7 @@ module VagrantPlugins
|
|||||||
|
|
||||||
# remove root storage
|
# remove root storage
|
||||||
root_disk = domain.volumes.select do |x|
|
root_disk = domain.volumes.select do |x|
|
||||||
x.name == libvirt_domain.name + '.img'
|
x.name == libvirt_domain.name + '.img' if x
|
||||||
end.first
|
end.first
|
||||||
root_disk.destroy if root_disk
|
root_disk.destroy if root_disk
|
||||||
end
|
end
|
||||||
|
|||||||
@@ -85,7 +85,7 @@ describe VagrantPlugins::ProviderLibvirt::Action::DestroyDomain do
|
|||||||
|
|
||||||
it 'uses explicit removal of disks' do
|
it 'uses explicit removal of disks' do
|
||||||
allow(libvirt_domain).to receive(:name).and_return('test')
|
allow(libvirt_domain).to receive(:name).and_return('test')
|
||||||
allow(domain).to receive(:volumes).and_return([root_disk])
|
allow(domain).to receive(:volumes).and_return([root_disk, nil])
|
||||||
|
|
||||||
expect(domain).to_not receive(:destroy).with(destroy_volumes: true)
|
expect(domain).to_not receive(:destroy).with(destroy_volumes: true)
|
||||||
expect(root_disk).to receive(:destroy) # root disk remove
|
expect(root_disk).to receive(:destroy) # root disk remove
|
||||||
|
|||||||
Reference in New Issue
Block a user