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:
Darragh Bailey
2021-05-08 17:27:04 +01:00
committed by GitHub
parent fbf32889d7
commit 86cf4e08a7
2 changed files with 2 additions and 2 deletions

View File

@@ -70,7 +70,7 @@ module VagrantPlugins
# remove root storage
root_disk = domain.volumes.select do |x|
x.name == libvirt_domain.name + '.img'
x.name == libvirt_domain.name + '.img' if x
end.first
root_disk.destroy if root_disk
end

View File

@@ -85,7 +85,7 @@ describe VagrantPlugins::ProviderLibvirt::Action::DestroyDomain do
it 'uses explicit removal of disks' do
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(root_disk).to receive(:destroy) # root disk remove