add sysinfo support (#1500)

For testing certain scenarios with vagrant-libvirt, need in the guest system a
value for the systems serial number in the DMI/SMBIOS system information.
The domain https://libvirt.org/formatdomain.html#smbios-system-information
format of libvirt allows to specify those values.

While adding `-smbios type=1,serial=$serial_value` to the `qemuargs` parameter
of the libvirt provider is already able to achieve this, a dedicated provider config
value adds native support from the `Vagrantfile` layering system. For example,
in the .box included Vagrantfile a random serial number can be enforced by
adding the following:

require 'securerandom'
Vagrant.configure("2") do |config|
  config.vm.provider :libvirt do |libvirt|
    libvirt.dmi_system_serial = SecureRandom.alphanumeric(8).upcase
  end
end

Then in an instance specific Vagrantfile this value can be overwritten by adding:

Vagrant.configure("2") do |config|
  config.vm.provider :libvirt do |libvirt|
    libvirt.dmi_system_serial = "ABCDEFGH"
  end
end

Co-authored-by: Nils Ballmann <nils.ballmann.ext@siemens.com>
Co-authored-by: Darragh Bailey <daragh.bailey@gmail.com>
This commit is contained in:
Nils Ballmann
2022-08-16 18:44:11 +02:00
committed by GitHub
parent 77e53a2f53
commit 63d265d9ca
11 changed files with 444 additions and 6 deletions

View File

@@ -170,6 +170,70 @@ describe VagrantPlugins::ProviderLibvirt::Action::CreateDomain do
expect(subject.call(env)).to be_nil
end
end
context 'sysinfo' do
let(:domain_xml_file) { 'sysinfo.xml' }
let(:vagrantfile_providerconfig) do
<<-EOF
libvirt.sysinfo = {
'bios': {
'vendor': 'Test Vendor',
'version': '',
},
'system': {
'manufacturer': 'Test Manufacturer',
'version': '0.1.0',
'serial': '',
},
'base board': {
'manufacturer': 'Test Manufacturer',
'version': '',
},
'chassis': {
'manufacturer': 'Test Manufacturer',
'serial': 'AABBCCDDEE',
'asset': '',
},
'oem strings': [
'app1: string1',
'app1: string2',
'app2: string1',
'app2: string2',
'',
'',
],
}
EOF
end
it 'should populate sysinfo as expected' do
expect(servers).to receive(:create).with(xml: domain_xml).and_return(machine)
expect(subject.call(env)).to be_nil
end
context 'with block of empty entries' do
let(:domain_xml_file) { 'sysinfo_only_required.xml' }
let(:vagrantfile_providerconfig) do
<<-EOF
libvirt.sysinfo = {
'bios': {
'vendor': 'Test Vendor',
},
'system': {
'serial': '',
},
}
EOF
end
it 'should skip outputting the surrounding tags' do
expect(servers).to receive(:create).with(xml: domain_xml).and_return(machine)
expect(subject.call(env)).to be_nil
end
end
end
end
context 'connection => qemu:///session' do