Allow to use many disks in vagrant box for libvirt provider
Adds support for a new multi disk box format and handling to upload the
multiple disks to the storage pool.
New format is:
{
'disks': [
{
'name': 'disk1.img',
'virtual_size': 10,
'format': 'qcow2'
},
{
'name': 'disk2.img',
'virtual_size': 15,
'format': 'qcow2'
},
{
'name': 'disk3.img',
}
],
'provider': 'libvirt',
'format': 'qcow2'
}
It is expected to remove format from being set at the top level when
using the new format, with the assuming that qcow2 should be the default
format, and other formats should be permitted to be specified as needed.
Includes tests for handling the box images and creation of domain
volumes. Additionally includes an integration test to ensure a box with
2 disks will work as expected.
Partially fixes: #602
2020-09-10 10:03:00 +02:00
|
|
|
require 'spec_helper'
|
|
|
|
|
require 'support/sharedcontext'
|
|
|
|
|
require 'support/libvirt_context'
|
|
|
|
|
|
|
|
|
|
require 'vagrant-libvirt/action/destroy_domain'
|
2021-06-09 22:16:15 +02:00
|
|
|
require 'vagrant-libvirt/util/byte_number'
|
|
|
|
|
|
Allow to use many disks in vagrant box for libvirt provider
Adds support for a new multi disk box format and handling to upload the
multiple disks to the storage pool.
New format is:
{
'disks': [
{
'name': 'disk1.img',
'virtual_size': 10,
'format': 'qcow2'
},
{
'name': 'disk2.img',
'virtual_size': 15,
'format': 'qcow2'
},
{
'name': 'disk3.img',
}
],
'provider': 'libvirt',
'format': 'qcow2'
}
It is expected to remove format from being set at the top level when
using the new format, with the assuming that qcow2 should be the default
format, and other formats should be permitted to be specified as needed.
Includes tests for handling the box images and creation of domain
volumes. Additionally includes an integration test to ensure a box with
2 disks will work as expected.
Partially fixes: #602
2020-09-10 10:03:00 +02:00
|
|
|
|
|
|
|
|
describe VagrantPlugins::ProviderLibvirt::Action::CreateDomainVolume do
|
|
|
|
|
subject { described_class.new(app, env) }
|
|
|
|
|
|
|
|
|
|
include_context 'unit'
|
|
|
|
|
include_context 'libvirt'
|
|
|
|
|
|
|
|
|
|
let(:libvirt_domain) { double('libvirt_domain') }
|
|
|
|
|
let(:libvirt_client) { double('libvirt_client') }
|
|
|
|
|
let(:volumes) { double('volumes') }
|
|
|
|
|
let(:all) { double('all') }
|
|
|
|
|
let(:box_volume) { double('box_volume') }
|
|
|
|
|
|
|
|
|
|
def read_test_file(name)
|
|
|
|
|
File.read(File.join(File.dirname(__FILE__), File.basename(__FILE__, '.rb'), name))
|
|
|
|
|
end
|
|
|
|
|
|
|
|
|
|
describe '#call' do
|
|
|
|
|
before do
|
|
|
|
|
allow_any_instance_of(VagrantPlugins::ProviderLibvirt::Driver)
|
|
|
|
|
.to receive(:connection).and_return(connection)
|
|
|
|
|
allow(connection).to receive(:client).and_return(libvirt_client)
|
|
|
|
|
allow(connection).to receive(:volumes).and_return(volumes)
|
|
|
|
|
allow(volumes).to receive(:all).and_return(all)
|
|
|
|
|
allow(all).to receive(:first).and_return(box_volume)
|
|
|
|
|
allow(box_volume).to receive(:id).and_return(nil)
|
|
|
|
|
env[:domain_name] = 'test'
|
|
|
|
|
end
|
|
|
|
|
|
|
|
|
|
context 'when one disk' do
|
|
|
|
|
before do
|
|
|
|
|
allow(box_volume).to receive(:path).and_return('/test/path_0.img')
|
|
|
|
|
env[:box_volumes] = [
|
|
|
|
|
{
|
|
|
|
|
:name=>"test_vagrant_box_image_1.1.1_0.img",
|
2021-06-09 22:16:15 +02:00
|
|
|
:virtual_size=>ByteNumber.new(5368709120)
|
Allow to use many disks in vagrant box for libvirt provider
Adds support for a new multi disk box format and handling to upload the
multiple disks to the storage pool.
New format is:
{
'disks': [
{
'name': 'disk1.img',
'virtual_size': 10,
'format': 'qcow2'
},
{
'name': 'disk2.img',
'virtual_size': 15,
'format': 'qcow2'
},
{
'name': 'disk3.img',
}
],
'provider': 'libvirt',
'format': 'qcow2'
}
It is expected to remove format from being set at the top level when
using the new format, with the assuming that qcow2 should be the default
format, and other formats should be permitted to be specified as needed.
Includes tests for handling the box images and creation of domain
volumes. Additionally includes an integration test to ensure a box with
2 disks will work as expected.
Partially fixes: #602
2020-09-10 10:03:00 +02:00
|
|
|
}
|
|
|
|
|
]
|
|
|
|
|
end
|
|
|
|
|
|
|
|
|
|
it 'should create one disk in storage' do
|
|
|
|
|
expected_xml = read_test_file('one_disk_in_storage.xml')
|
|
|
|
|
expect(ui).to receive(:info).with('Creating image (snapshot of base box volume).')
|
|
|
|
|
expect(logger).to receive(:debug).with('Using pool default for base box snapshot')
|
|
|
|
|
expect(volumes).to receive(:create).with(
|
|
|
|
|
:xml => expected_xml,
|
|
|
|
|
:pool_name => "default"
|
|
|
|
|
)
|
|
|
|
|
expect(subject.call(env)).to be_nil
|
|
|
|
|
end
|
|
|
|
|
end
|
|
|
|
|
|
|
|
|
|
context 'when three disks' do
|
|
|
|
|
before do
|
|
|
|
|
allow(box_volume).to receive(:path).and_return(
|
|
|
|
|
'/test/path_0.img',
|
|
|
|
|
'/test/path_1.img',
|
|
|
|
|
'/test/path_2.img',
|
|
|
|
|
)
|
|
|
|
|
env[:box_volumes] = [
|
|
|
|
|
{
|
|
|
|
|
:name=>"test_vagrant_box_image_1.1.1_0.img",
|
2021-06-09 22:16:15 +02:00
|
|
|
:virtual_size=>ByteNumber.new(5368709120)
|
Allow to use many disks in vagrant box for libvirt provider
Adds support for a new multi disk box format and handling to upload the
multiple disks to the storage pool.
New format is:
{
'disks': [
{
'name': 'disk1.img',
'virtual_size': 10,
'format': 'qcow2'
},
{
'name': 'disk2.img',
'virtual_size': 15,
'format': 'qcow2'
},
{
'name': 'disk3.img',
}
],
'provider': 'libvirt',
'format': 'qcow2'
}
It is expected to remove format from being set at the top level when
using the new format, with the assuming that qcow2 should be the default
format, and other formats should be permitted to be specified as needed.
Includes tests for handling the box images and creation of domain
volumes. Additionally includes an integration test to ensure a box with
2 disks will work as expected.
Partially fixes: #602
2020-09-10 10:03:00 +02:00
|
|
|
},
|
|
|
|
|
{
|
|
|
|
|
:name=>"test_vagrant_box_image_1.1.1_1.img",
|
2021-06-09 22:16:15 +02:00
|
|
|
:virtual_size=>ByteNumber.new(10737423360)
|
Allow to use many disks in vagrant box for libvirt provider
Adds support for a new multi disk box format and handling to upload the
multiple disks to the storage pool.
New format is:
{
'disks': [
{
'name': 'disk1.img',
'virtual_size': 10,
'format': 'qcow2'
},
{
'name': 'disk2.img',
'virtual_size': 15,
'format': 'qcow2'
},
{
'name': 'disk3.img',
}
],
'provider': 'libvirt',
'format': 'qcow2'
}
It is expected to remove format from being set at the top level when
using the new format, with the assuming that qcow2 should be the default
format, and other formats should be permitted to be specified as needed.
Includes tests for handling the box images and creation of domain
volumes. Additionally includes an integration test to ensure a box with
2 disks will work as expected.
Partially fixes: #602
2020-09-10 10:03:00 +02:00
|
|
|
},
|
|
|
|
|
{
|
|
|
|
|
:name=>"test_vagrant_box_image_1.1.1_2.img",
|
2021-06-09 22:16:15 +02:00
|
|
|
:virtual_size=>ByteNumber.new(21474836480)
|
Allow to use many disks in vagrant box for libvirt provider
Adds support for a new multi disk box format and handling to upload the
multiple disks to the storage pool.
New format is:
{
'disks': [
{
'name': 'disk1.img',
'virtual_size': 10,
'format': 'qcow2'
},
{
'name': 'disk2.img',
'virtual_size': 15,
'format': 'qcow2'
},
{
'name': 'disk3.img',
}
],
'provider': 'libvirt',
'format': 'qcow2'
}
It is expected to remove format from being set at the top level when
using the new format, with the assuming that qcow2 should be the default
format, and other formats should be permitted to be specified as needed.
Includes tests for handling the box images and creation of domain
volumes. Additionally includes an integration test to ensure a box with
2 disks will work as expected.
Partially fixes: #602
2020-09-10 10:03:00 +02:00
|
|
|
}
|
|
|
|
|
]
|
|
|
|
|
end
|
|
|
|
|
|
|
|
|
|
it 'should create three disks in storage' do
|
|
|
|
|
expect(ui).to receive(:info).with('Creating image (snapshot of base box volume).')
|
|
|
|
|
expect(logger).to receive(:debug).with('Using pool default for base box snapshot')
|
|
|
|
|
expect(volumes).to receive(:create).with(
|
|
|
|
|
:xml => read_test_file('three_disks_in_storage_disk_0.xml'),
|
|
|
|
|
:pool_name => "default"
|
|
|
|
|
)
|
|
|
|
|
expect(logger).to receive(:debug).with('Using pool default for base box snapshot')
|
|
|
|
|
expect(volumes).to receive(:create).with(
|
|
|
|
|
:xml => read_test_file('three_disks_in_storage_disk_1.xml'),
|
|
|
|
|
:pool_name => "default"
|
|
|
|
|
)
|
|
|
|
|
expect(logger).to receive(:debug).with('Using pool default for base box snapshot')
|
|
|
|
|
expect(volumes).to receive(:create).with(
|
|
|
|
|
:xml => read_test_file('three_disks_in_storage_disk_2.xml'),
|
|
|
|
|
:pool_name => "default"
|
|
|
|
|
)
|
|
|
|
|
expect(subject.call(env)).to be_nil
|
|
|
|
|
end
|
|
|
|
|
end
|
|
|
|
|
end
|
|
|
|
|
end
|