mirror of
https://github.com/vagrant-libvirt/vagrant-libvirt.git
synced 2025-02-25 18:55:27 -06:00
Ensure updating loader tag supported (#1494)
The loader tag is required when nvram is being enabled. Ensure it is marked as a requirement of validation and also support it's configuration during the start domain action.
This commit is contained in:
@@ -375,12 +375,32 @@ module VagrantPlugins
|
||||
end
|
||||
end
|
||||
|
||||
loader = REXML::XPath.first(xml_descr, '/domain/os/loader')
|
||||
if config.loader
|
||||
if loader.nil?
|
||||
descr_changed = true
|
||||
loader = REXML::Element.new('loader')
|
||||
REXML::XPath.first(xml_descr, '/domain/os').insert_after('//type', loader)
|
||||
loader.text = config.loader
|
||||
else
|
||||
if (loader.text or '').strip != config.loader
|
||||
descr_changed = true
|
||||
loader.text = config.loader
|
||||
end
|
||||
end
|
||||
loader.attributes['type'] = config.nvram ? 'pflash' : 'rom'
|
||||
elsif !loader.nil?
|
||||
descr_changed = true
|
||||
loader.parent.delete_element(loader)
|
||||
end
|
||||
|
||||
undefine_flags = 0
|
||||
nvram = REXML::XPath.first(xml_descr, '/domain/os/nvram')
|
||||
if config.nvram
|
||||
if nvram.nil?
|
||||
descr_changed = true
|
||||
nvram = REXML::Element.new('nvram', REXML::XPath.first(xml_descr, '/domain/os'))
|
||||
nvram = REXML::Element.new('nvram')
|
||||
REXML::XPath.first(xml_descr, '/domain/os').insert_after(loader, nvram)
|
||||
nvram.text = config.nvram
|
||||
else
|
||||
if (nvram.text or '').strip != config.nvram
|
||||
|
||||
@@ -994,6 +994,10 @@ module VagrantPlugins
|
||||
errors << "libvirt.qemu_use_agent must be a boolean."
|
||||
end
|
||||
|
||||
if !@nvram.nil? && @loader.nil?
|
||||
errors << "use of 'nvram' requires a 'loader' to be specified, please add one to the configuration"
|
||||
end
|
||||
|
||||
if @qemu_use_agent == true
|
||||
# if qemu agent is used to optain domain ip configuration, at least
|
||||
# one qemu channel has to be configured. As there are various options,
|
||||
|
||||
@@ -66,6 +66,7 @@ describe VagrantPlugins::ProviderLibvirt::Action::StartDomain do
|
||||
context 'when being added to existing' do
|
||||
let(:vagrantfile_providerconfig) do
|
||||
<<-EOF
|
||||
libvirt.loader = "/path/to/loader/file"
|
||||
libvirt.nvram = "/path/to/nvram/file"
|
||||
EOF
|
||||
end
|
||||
@@ -85,6 +86,7 @@ describe VagrantPlugins::ProviderLibvirt::Action::StartDomain do
|
||||
context 'when it was already in use' do
|
||||
let(:vagrantfile_providerconfig) do
|
||||
<<-EOF
|
||||
libvirt.loader = "/path/to/loader/file"
|
||||
libvirt.nvram = "/path/to/nvram/file"
|
||||
# change another setting to trigger the undefine/create
|
||||
libvirt.cpus = 4
|
||||
|
||||
@@ -6,9 +6,9 @@
|
||||
<currentMemory unit='KiB'>2097152</currentMemory>
|
||||
<vcpu placement='static'>2</vcpu>
|
||||
<os>
|
||||
<type arch='x86_64' machine='pc-i440fx-6.0'>hvm</type>
|
||||
<type arch='x86_64' machine='pc-i440fx-6.0'>hvm</type><loader type='pflash'>/path/to/loader/file</loader><nvram>/path/to/nvram/file</nvram>
|
||||
<boot dev='hd'/>
|
||||
<nvram>/path/to/nvram/file</nvram></os>
|
||||
</os>
|
||||
<features>
|
||||
<acpi/>
|
||||
<apic/>
|
||||
|
||||
@@ -7,8 +7,9 @@
|
||||
<vcpu placement='static'>2</vcpu>
|
||||
<os>
|
||||
<type arch='x86_64' machine='pc-i440fx-6.0'>hvm</type>
|
||||
<boot dev='hd'/>
|
||||
<loader type='pflash'>/path/to/loader/file</loader>
|
||||
<nvram>/path/to/nvram/file</nvram>
|
||||
<boot dev='hd'/>
|
||||
</os>
|
||||
<features>
|
||||
<acpi/>
|
||||
|
||||
@@ -7,8 +7,9 @@
|
||||
<vcpu placement='static'>4</vcpu>
|
||||
<os>
|
||||
<type arch='x86_64' machine='pc-i440fx-6.0'>hvm</type>
|
||||
<boot dev='hd'/>
|
||||
<loader type='pflash'>/path/to/loader/file</loader>
|
||||
<nvram>/path/to/nvram/file</nvram>
|
||||
<boot dev='hd'/>
|
||||
</os>
|
||||
<features>
|
||||
<acpi/>
|
||||
|
||||
@@ -7,8 +7,9 @@
|
||||
<vcpu placement='static'>2</vcpu>
|
||||
<os>
|
||||
<type arch='x86_64' machine='pc-i440fx-6.0'>hvm</type>
|
||||
<boot dev='hd'/>
|
||||
|
||||
|
||||
<boot dev='hd'/>
|
||||
</os>
|
||||
<features>
|
||||
<acpi/>
|
||||
|
||||
@@ -630,6 +630,24 @@ describe VagrantPlugins::ProviderLibvirt::Config do
|
||||
end
|
||||
end
|
||||
|
||||
context 'with nvram defined' do
|
||||
before do
|
||||
subject.nvram = '/path/to/some/nvram'
|
||||
end
|
||||
|
||||
it 'should be invalid as loader not set' do
|
||||
assert_invalid
|
||||
end
|
||||
|
||||
context 'with loader defined' do
|
||||
it 'should be valid' do
|
||||
subject.loader = '/path/to/some/loader'
|
||||
|
||||
assert_valid
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
context 'with cpu_mode and cpu_model defined' do
|
||||
it 'should discard model if mode is passthrough' do
|
||||
subject.cpu_mode = 'host-passthrough'
|
||||
|
||||
Reference in New Issue
Block a user