diff --git a/lib/vagrant-libvirt/action/package_domain.rb b/lib/vagrant-libvirt/action/package_domain.rb index dfac9ab..f72e705 100644 --- a/lib/vagrant-libvirt/action/package_domain.rb +++ b/lib/vagrant-libvirt/action/package_domain.rb @@ -32,9 +32,7 @@ module VagrantPlugins ) domain = env[:machine].provider.driver.connection.servers.get(env[:machine].id.to_s) root_disk = domain.volumes.select do |x| - !x.nil? - end.select do |x| - x.name == libvirt_domain.name + '.img' + !x.nil? && x.name == libvirt_domain.name + '.img' end.first raise Errors::NoDomainVolume if root_disk.nil? diff --git a/spec/unit/action/package_domain_spec.rb b/spec/unit/action/package_domain_spec.rb index 44d2f6b..1a8d571 100644 --- a/spec/unit/action/package_domain_spec.rb +++ b/spec/unit/action/package_domain_spec.rb @@ -60,6 +60,31 @@ describe VagrantPlugins::ProviderLibvirt::Action::PackageDomain do expect(File.exist?(File.join(temp_dir, 'Vagrantfile'))).to eq(true) end end + + context 'with nil volume' do + let(:root_disk) { double('libvirt_domain_disk') } + before do + allow(root_disk).to receive(:name).and_return('default_domain.img') + allow(domain).to receive(:volumes).and_return([nil, root_disk]) + allow(libvirt_domain).to receive(:name).and_return('default_domain') + allow(subject).to receive(:download_image).and_return(true) + end + + it 'should succeed' do + expect(ui).to receive(:info).with('Packaging domain...') + expect(ui).to receive(:info).with(/Downloading default_domain.img to .*\/box.img/) + expect(ui).to receive(:info).with('Image has backing image, copying image and rebasing ...') + expect(subject).to receive(:`).with(/qemu-img info .*\/box.img | grep 'backing file:' | cut -d ':' -f2/).and_return("some image") + expect(subject).to receive(:`).with(/qemu-img rebase -p -b "" .*\/box.img/) + expect(subject).to receive(:`).with(/virt-sysprep --no-logfile --operations .* -a .*\/box.img .*/) + expect(subject).to receive(:`).with(/virt-sparsify --in-place .*\/box.img/) + expect(subject).to receive(:`).with(/qemu-img info --output=json .*\/box.img/).and_return( + { 'virtual-size': 5*1024*1024*1024 }.to_json + ) + + expect(subject.call(env)).to be_nil + end + end end describe '#vagrantfile_content' do