mirror of
https://github.com/vagrant-libvirt/vagrant-libvirt.git
synced 2025-02-25 18:55:27 -06:00
Add support for clock setup (#1047)
This adds support for setting clock offset and timers. See https://libvirt.org/formatdomain.html#elementsTime for more info.
This commit is contained in:
@@ -27,7 +27,9 @@ describe VagrantPlugins::ProviderLibvirt::Action::StartDomain do
|
||||
|
||||
allow(connection).to receive(:servers).and_return(servers)
|
||||
allow(servers).to receive(:get).and_return(domain)
|
||||
|
||||
expect(logger).to receive(:info)
|
||||
expect(ui).to_not receive(:error)
|
||||
end
|
||||
|
||||
context 'default config' do
|
||||
@@ -164,5 +166,66 @@ describe VagrantPlugins::ProviderLibvirt::Action::StartDomain do
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
context 'clock_timers' do
|
||||
let(:test_file) { 'clock_timer_rtc.xml' }
|
||||
|
||||
before do
|
||||
allow(libvirt_domain).to receive(:xml_desc).and_return(domain_xml)
|
||||
|
||||
allow(libvirt_domain).to receive(:max_memory).and_return(512*1024)
|
||||
allow(libvirt_domain).to receive(:num_vcpus).and_return(1)
|
||||
end
|
||||
|
||||
context 'timers unchanged' do
|
||||
let(:vagrantfile_providerconfig) do
|
||||
<<-EOF
|
||||
libvirt.clock_timer(:name => "rtc")
|
||||
EOF
|
||||
end
|
||||
|
||||
it 'should not modify the domain' do
|
||||
expect(logger).to_not receive(:debug).with('clock timers config changed')
|
||||
expect(servers).to_not receive(:create)
|
||||
expect(libvirt_domain).to receive(:autostart=)
|
||||
expect(domain).to receive(:start)
|
||||
|
||||
expect(subject.call(env)).to be_nil
|
||||
end
|
||||
end
|
||||
|
||||
context 'timers added' do
|
||||
let(:vagrantfile_providerconfig) do
|
||||
<<-EOF
|
||||
libvirt.clock_timer(:name => "rtc")
|
||||
libvirt.clock_timer(:name => "tsc")
|
||||
EOF
|
||||
end
|
||||
|
||||
it 'should modify the domain' do
|
||||
expect(libvirt_domain).to receive(:undefine)
|
||||
expect(logger).to receive(:debug).with('clock timers config changed')
|
||||
expect(servers).to receive(:create).with(xml: match(/<clock offset='utc'>\s*<timer name='rtc'\/>\s*<timer name='tsc'\/>\s*<\/clock>/))
|
||||
expect(libvirt_domain).to receive(:autostart=)
|
||||
expect(domain).to receive(:start)
|
||||
|
||||
expect(subject.call(env)).to be_nil
|
||||
end
|
||||
end
|
||||
|
||||
context 'timers removed' do
|
||||
let(:updated_test_file) { 'default.xml' }
|
||||
|
||||
it 'should modify the domain' do
|
||||
expect(libvirt_domain).to receive(:undefine)
|
||||
expect(logger).to receive(:debug).with('clock timers config changed')
|
||||
expect(servers).to receive(:create).with(xml: match(/<clock offset='utc'>\s*<\/clock>/))
|
||||
expect(libvirt_domain).to receive(:autostart=)
|
||||
expect(domain).to receive(:start)
|
||||
|
||||
expect(subject.call(env)).to be_nil
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
50
spec/unit/action/start_domain_spec/clock_timer_rtc.xml
Normal file
50
spec/unit/action/start_domain_spec/clock_timer_rtc.xml
Normal file
@@ -0,0 +1,50 @@
|
||||
<domain xmlns:qemu='http://libvirt.org/schemas/domain/qemu/1.0' type=''>
|
||||
<name/>
|
||||
<title/>
|
||||
<description/>
|
||||
<uuid/>
|
||||
<memory/>
|
||||
<vcpu>1</vcpu>
|
||||
|
||||
|
||||
<cpu mode='host-model'>
|
||||
<model fallback='allow'/>
|
||||
</cpu>
|
||||
|
||||
|
||||
<os>
|
||||
<type>hvm</type>
|
||||
<kernel/>
|
||||
<initrd/>
|
||||
<cmdline/>
|
||||
</os>
|
||||
<features>
|
||||
<acpi/>
|
||||
<apic/>
|
||||
<pae/>
|
||||
</features>
|
||||
<clock offset='utc'>
|
||||
<timer name='rtc'/>
|
||||
</clock>
|
||||
<devices>
|
||||
|
||||
|
||||
<serial type='pty'>
|
||||
<target port='0'/>
|
||||
</serial>
|
||||
<console type='pty'>
|
||||
<target port='0'/>
|
||||
</console>
|
||||
|
||||
|
||||
<input bus='ps2' type='mouse'/>
|
||||
|
||||
<graphics autoport='yes' keymap='en-us' listen='127.0.0.1' port='-1' type='vnc'/>
|
||||
<video>
|
||||
<model heads='1' type='cirrus' vram='9216'/>
|
||||
</video>
|
||||
|
||||
|
||||
</devices>
|
||||
|
||||
</domain>
|
||||
@@ -8,6 +8,50 @@ describe VagrantPlugins::ProviderLibvirt::Config do
|
||||
|
||||
let(:fake_env) { Hash.new }
|
||||
|
||||
describe '#clock_timer' do
|
||||
it 'should handle all options' do
|
||||
expect(
|
||||
subject.clock_timer(
|
||||
:name => 'rtc',
|
||||
:track => 'wall',
|
||||
:tickpolicy => 'delay',
|
||||
:present => 'yes',
|
||||
).length
|
||||
).to be(1)
|
||||
expect(
|
||||
subject.clock_timer(
|
||||
:name => 'tsc',
|
||||
:tickpolicy => 'delay',
|
||||
:frequency => '100',
|
||||
:mode => 'auto',
|
||||
:present => 'yes',
|
||||
).length
|
||||
).to be(2)
|
||||
end
|
||||
|
||||
it 'should correctly save the options' do
|
||||
opts = {:name => 'rtc', :track => 'wall'}
|
||||
expect(subject.clock_timer(opts).length).to be(1)
|
||||
|
||||
expect(subject.clock_timers[0]).to eq(opts)
|
||||
|
||||
opts[:name] = 'tsc'
|
||||
expect(subject.clock_timers[0]).to_not eq(opts)
|
||||
end
|
||||
|
||||
it 'should error name option is missing' do
|
||||
expect{ subject.clock_timer(:track => "wall") }.to raise_error("Clock timer name must be specified")
|
||||
end
|
||||
|
||||
it 'should error if nil value for option supplied' do
|
||||
expect{ subject.clock_timer(:name => "rtc", :track => nil) }.to raise_error("Value of timer option track is nil")
|
||||
end
|
||||
|
||||
it 'should error if unrecognized option specified' do
|
||||
expect{ subject.clock_timer(:name => "tsc", :badopt => "value") }.to raise_error("Unknown clock timer option: badopt")
|
||||
end
|
||||
end
|
||||
|
||||
describe '#finalize!' do
|
||||
it 'is valid with defaults' do
|
||||
subject.finalize!
|
||||
@@ -282,5 +326,15 @@ describe VagrantPlugins::ProviderLibvirt::Config do
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
context 'clock_timers' do
|
||||
it 'should merge clock_timers' do
|
||||
one.clock_timer(:name => 'rtc', :tickpolicy => 'catchup')
|
||||
two.clock_timer(:name => 'hpet', :present => 'no')
|
||||
|
||||
expect(subject.clock_timers).to include(include(name: 'rtc'),
|
||||
include(name: 'hpet'))
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
@@ -36,7 +36,10 @@
|
||||
<BBB state='on' />
|
||||
</hyperv>
|
||||
</features>
|
||||
<clock offset='utc'/>
|
||||
<clock offset='variable'>
|
||||
<timer name='t1'/>
|
||||
<timer name='t2' track='b' tickpolicy='c' frequency='d' mode='e' present='yes'/>
|
||||
</clock>
|
||||
<devices>
|
||||
<emulator>/usr/bin/kvm-spice</emulator>
|
||||
<disk type='file' device='disk'>
|
||||
|
||||
@@ -23,7 +23,8 @@
|
||||
<apic/>
|
||||
<pae/>
|
||||
</features>
|
||||
<clock offset='utc'/>
|
||||
<clock offset='utc'>
|
||||
</clock>
|
||||
<devices>
|
||||
|
||||
|
||||
|
||||
@@ -23,7 +23,8 @@
|
||||
<apic/>
|
||||
<pae/>
|
||||
</features>
|
||||
<clock offset='utc'/>
|
||||
<clock offset='utc'>
|
||||
</clock>
|
||||
<devices>
|
||||
|
||||
|
||||
|
||||
@@ -33,6 +33,9 @@ describe 'templates/domain' do
|
||||
domain.cpu_mode = 'custom'
|
||||
domain.cpu_feature(name: 'AAA', policy: 'required')
|
||||
domain.hyperv_feature(name: 'BBB', state: 'on')
|
||||
domain.clock_offset = 'variable'
|
||||
domain.clock_timer(name: 't1')
|
||||
domain.clock_timer(name: 't2', track: 'b', tickpolicy: 'c', frequency: 'd', mode: 'e', present: 'yes')
|
||||
domain.cputopology(sockets: '1', cores: '3', threads: '2')
|
||||
domain.machine_type = 'pc-compatible'
|
||||
domain.machine_arch = 'x86_64'
|
||||
|
||||
@@ -23,7 +23,8 @@
|
||||
<apic/>
|
||||
<pae/>
|
||||
</features>
|
||||
<clock offset='utc'/>
|
||||
<clock offset='utc'>
|
||||
</clock>
|
||||
<devices>
|
||||
|
||||
|
||||
|
||||
@@ -23,7 +23,8 @@
|
||||
<apic/>
|
||||
<pae/>
|
||||
</features>
|
||||
<clock offset='utc'/>
|
||||
<clock offset='utc'>
|
||||
</clock>
|
||||
<devices>
|
||||
|
||||
|
||||
|
||||
Reference in New Issue
Block a user