vagrant-libvirt 0.9.0 → 0.10.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- checksums.yaml +4 -4
- data/README.md +51 -2079
- data/lib/vagrant-libvirt/action/create_domain.rb +39 -4
- data/lib/vagrant-libvirt/action/create_network_interfaces.rb +1 -1
- data/lib/vagrant-libvirt/action/create_networks.rb +3 -3
- data/lib/vagrant-libvirt/action/destroy_domain.rb +1 -1
- data/lib/vagrant-libvirt/action/destroy_networks.rb +1 -1
- data/lib/vagrant-libvirt/action/handle_box_image.rb +1 -1
- data/lib/vagrant-libvirt/action/package_domain.rb +1 -5
- data/lib/vagrant-libvirt/action/remove_libvirt_image.rb +3 -1
- data/lib/vagrant-libvirt/action/resolve_disk_settings.rb +15 -8
- data/lib/vagrant-libvirt/action/snapshot_delete.rb +26 -0
- data/lib/vagrant-libvirt/action/snapshot_restore.rb +22 -0
- data/lib/vagrant-libvirt/action/snapshot_save.rb +27 -0
- data/lib/vagrant-libvirt/action/start_domain.rb +43 -14
- data/lib/vagrant-libvirt/action.rb +49 -1
- data/lib/vagrant-libvirt/cap/snapshots.rb +12 -0
- data/lib/vagrant-libvirt/cap/synced_folder_9p.rb +4 -4
- data/lib/vagrant-libvirt/cap/synced_folder_virtiofs.rb +4 -4
- data/lib/vagrant-libvirt/config.rb +101 -6
- data/lib/vagrant-libvirt/driver.rb +108 -46
- data/lib/vagrant-libvirt/errors.rb +23 -3
- data/lib/vagrant-libvirt/plugin.rb +7 -3
- data/lib/vagrant-libvirt/provider.rb +1 -1
- data/lib/vagrant-libvirt/templates/domain.xml.erb +30 -4
- data/lib/vagrant-libvirt/util/byte_number.rb +0 -1
- data/lib/vagrant-libvirt/util/compat.rb +23 -0
- data/lib/vagrant-libvirt/util/unindent.rb +7 -0
- data/lib/vagrant-libvirt/version +1 -1
- data/locales/en.yml +24 -2
- data/spec/acceptance/additional_storage_spec.rb +32 -0
- data/spec/acceptance/package_domain_spec.rb +90 -0
- data/spec/acceptance/provider_settings_spec.rb +54 -0
- data/spec/acceptance/simple_vm_provision_via_shell_spec.rb +31 -0
- data/spec/acceptance/snapshots_spec.rb +41 -0
- data/spec/acceptance/support-skeletons/package_complex/Vagrantfile.testbox +14 -0
- data/spec/acceptance/support-skeletons/package_complex/scripts/sysprep.sh +32 -0
- data/spec/acceptance/support-skeletons/package_simple/Vagrantfile.testbox +10 -0
- data/spec/acceptance/two_disks_spec.rb +29 -0
- data/spec/acceptance/use_qemu_agent_for_connectivity_spec.rb +35 -0
- data/spec/spec_helper.rb +3 -0
- data/spec/support/acceptance/configuration.rb +21 -0
- data/spec/support/acceptance/context.rb +70 -0
- data/spec/support/acceptance/isolated_environment.rb +41 -0
- data/spec/support/libvirt_acceptance_context.rb +64 -0
- data/spec/support/sharedcontext.rb +1 -0
- data/spec/unit/action/create_domain_spec/sysinfo.xml +66 -0
- data/spec/unit/action/create_domain_spec/sysinfo_only_required.xml +49 -0
- data/spec/unit/action/create_domain_spec.rb +82 -0
- data/spec/unit/action/forward_ports_spec.rb +0 -1
- data/spec/unit/action/handle_box_image_spec.rb +18 -1
- data/spec/unit/action/remove_libvirt_image_spec.rb +43 -0
- data/spec/unit/action/resolve_disk_settings_spec.rb +24 -0
- data/spec/unit/action/start_domain_spec/clock_timer_removed.xml +38 -0
- data/spec/unit/action/start_domain_spec/clock_timer_rtc_tsc.xml +39 -0
- data/spec/unit/action/start_domain_spec/nvram_domain_other_setting.xml +2 -2
- data/spec/unit/action/start_domain_spec.rb +72 -30
- data/spec/unit/action_spec.rb +88 -0
- data/spec/unit/cap/synced_folder_9p_spec.rb +120 -0
- data/spec/unit/cap/synced_folder_virtiofs_spec.rb +120 -0
- data/spec/unit/config_spec.rb +133 -6
- data/spec/unit/driver_spec.rb +1 -1
- data/spec/unit/plugin_spec.rb +42 -0
- data/spec/unit/templates/domain_all_settings.xml +13 -4
- data/spec/unit/templates/domain_scsi_bus_storage.xml +44 -0
- data/spec/unit/templates/domain_scsi_device_storage.xml +44 -0
- data/spec/unit/templates/domain_scsi_multiple_controllers_storage.xml +130 -0
- data/spec/unit/templates/domain_spec.rb +105 -21
- data/spec/unit/util/byte_number_spec.rb +1 -1
- metadata +155 -87
- data/spec/unit/provider_spec.rb +0 -11
@@ -0,0 +1,66 @@
|
|
1
|
+
<domain type='kvm' xmlns:qemu='http://libvirt.org/schemas/domain/qemu/1.0'>
|
2
|
+
<name>vagrant-test_default</name>
|
3
|
+
<title></title>
|
4
|
+
<description>Source: /rootpath/Vagrantfile</description>
|
5
|
+
<uuid></uuid>
|
6
|
+
<memory>524288</memory>
|
7
|
+
<vcpu>1</vcpu>
|
8
|
+
<cpu mode='host-model'>
|
9
|
+
<model fallback='allow'></model>
|
10
|
+
</cpu>
|
11
|
+
<os>
|
12
|
+
<type>hvm</type>
|
13
|
+
<kernel></kernel>
|
14
|
+
<initrd></initrd>
|
15
|
+
<cmdline></cmdline>
|
16
|
+
<smbios mode='sysinfo'/>
|
17
|
+
</os>
|
18
|
+
<sysinfo type='smbios'>
|
19
|
+
<bios>
|
20
|
+
<entry name='vendor'>Test Vendor</entry>
|
21
|
+
</bios>
|
22
|
+
<system>
|
23
|
+
<entry name='manufacturer'>Test Manufacturer</entry>
|
24
|
+
<entry name='version'>0.1.0</entry>
|
25
|
+
</system>
|
26
|
+
<baseBoard>
|
27
|
+
<entry name='manufacturer'>Test Manufacturer</entry>
|
28
|
+
</baseBoard>
|
29
|
+
<chassis>
|
30
|
+
<entry name='manufacturer'>Test Manufacturer</entry>
|
31
|
+
<entry name='serial'>AABBCCDDEE</entry>
|
32
|
+
</chassis>
|
33
|
+
<oemStrings>
|
34
|
+
<entry>app1: string1</entry>
|
35
|
+
<entry>app1: string2</entry>
|
36
|
+
<entry>app2: string1</entry>
|
37
|
+
<entry>app2: string2</entry>
|
38
|
+
</oemStrings>
|
39
|
+
</sysinfo>
|
40
|
+
<features>
|
41
|
+
<acpi/>
|
42
|
+
<apic/>
|
43
|
+
<pae/>
|
44
|
+
</features>
|
45
|
+
<clock offset='utc'>
|
46
|
+
</clock>
|
47
|
+
<devices>
|
48
|
+
<disk type='file' device='disk'>
|
49
|
+
<alias name='ua-box-volume-0'/>
|
50
|
+
<driver name='qemu' type='qcow2' cache='default'/>
|
51
|
+
<source file='/var/lib/libvirt/images/vagrant-test_default.img'/>
|
52
|
+
<target dev='vda' bus='virtio'/>
|
53
|
+
</disk>
|
54
|
+
<serial type='pty'>
|
55
|
+
<target port='0'/>
|
56
|
+
</serial>
|
57
|
+
<console type='pty'>
|
58
|
+
<target port='0'/>
|
59
|
+
</console>
|
60
|
+
<input type='mouse' bus='ps2'/>
|
61
|
+
<graphics type='vnc' port='-1' autoport='yes' listen='127.0.0.1' keymap='en-us'/>
|
62
|
+
<video>
|
63
|
+
<model type='cirrus' vram='16384' heads='1'/>
|
64
|
+
</video>
|
65
|
+
</devices>
|
66
|
+
</domain>
|
@@ -0,0 +1,49 @@
|
|
1
|
+
<domain type='kvm' xmlns:qemu='http://libvirt.org/schemas/domain/qemu/1.0'>
|
2
|
+
<name>vagrant-test_default</name>
|
3
|
+
<title></title>
|
4
|
+
<description>Source: /rootpath/Vagrantfile</description>
|
5
|
+
<uuid></uuid>
|
6
|
+
<memory>524288</memory>
|
7
|
+
<vcpu>1</vcpu>
|
8
|
+
<cpu mode='host-model'>
|
9
|
+
<model fallback='allow'></model>
|
10
|
+
</cpu>
|
11
|
+
<os>
|
12
|
+
<type>hvm</type>
|
13
|
+
<kernel></kernel>
|
14
|
+
<initrd></initrd>
|
15
|
+
<cmdline></cmdline>
|
16
|
+
<smbios mode='sysinfo'/>
|
17
|
+
</os>
|
18
|
+
<sysinfo type='smbios'>
|
19
|
+
<bios>
|
20
|
+
<entry name='vendor'>Test Vendor</entry>
|
21
|
+
</bios>
|
22
|
+
</sysinfo>
|
23
|
+
<features>
|
24
|
+
<acpi/>
|
25
|
+
<apic/>
|
26
|
+
<pae/>
|
27
|
+
</features>
|
28
|
+
<clock offset='utc'>
|
29
|
+
</clock>
|
30
|
+
<devices>
|
31
|
+
<disk type='file' device='disk'>
|
32
|
+
<alias name='ua-box-volume-0'/>
|
33
|
+
<driver name='qemu' type='qcow2' cache='default'/>
|
34
|
+
<source file='/var/lib/libvirt/images/vagrant-test_default.img'/>
|
35
|
+
<target dev='vda' bus='virtio'/>
|
36
|
+
</disk>
|
37
|
+
<serial type='pty'>
|
38
|
+
<target port='0'/>
|
39
|
+
</serial>
|
40
|
+
<console type='pty'>
|
41
|
+
<target port='0'/>
|
42
|
+
</console>
|
43
|
+
<input type='mouse' bus='ps2'/>
|
44
|
+
<graphics type='vnc' port='-1' autoport='yes' listen='127.0.0.1' keymap='en-us'/>
|
45
|
+
<video>
|
46
|
+
<model type='cirrus' vram='16384' heads='1'/>
|
47
|
+
</video>
|
48
|
+
</devices>
|
49
|
+
</domain>
|
@@ -152,6 +152,88 @@ describe VagrantPlugins::ProviderLibvirt::Action::CreateDomain do
|
|
152
152
|
expect(subject.call(env)).to be_nil
|
153
153
|
end
|
154
154
|
end
|
155
|
+
|
156
|
+
context 'with disk controller model virtio-scsi' do
|
157
|
+
before do
|
158
|
+
allow(machine.provider_config).to receive(:disk_controller_model).and_return('virtio-scsi')
|
159
|
+
expect(volumes).to receive(:all).with(name: 'vagrant-test_default.img').and_return([domain_volume])
|
160
|
+
|
161
|
+
env[:domain_volumes][0][:bus] = 'scsi'
|
162
|
+
end
|
163
|
+
|
164
|
+
it 'should add a virtio-scsi disk controller' do
|
165
|
+
expect(ui).to receive(:info).with(/ -- Image\(vda\):.*/)
|
166
|
+
expect(servers).to receive(:create) do |args|
|
167
|
+
expect(args[:xml]).to match(/<controller type='scsi' model='virtio-scsi' index='0'\/>/)
|
168
|
+
end.and_return(machine)
|
169
|
+
|
170
|
+
expect(subject.call(env)).to be_nil
|
171
|
+
end
|
172
|
+
end
|
173
|
+
|
174
|
+
context 'sysinfo' do
|
175
|
+
let(:domain_xml_file) { 'sysinfo.xml' }
|
176
|
+
let(:vagrantfile_providerconfig) do
|
177
|
+
<<-EOF
|
178
|
+
libvirt.sysinfo = {
|
179
|
+
'bios': {
|
180
|
+
'vendor': 'Test Vendor',
|
181
|
+
'version': '',
|
182
|
+
},
|
183
|
+
'system': {
|
184
|
+
'manufacturer': 'Test Manufacturer',
|
185
|
+
'version': '0.1.0',
|
186
|
+
'serial': '',
|
187
|
+
},
|
188
|
+
'base board': {
|
189
|
+
'manufacturer': 'Test Manufacturer',
|
190
|
+
'version': '',
|
191
|
+
},
|
192
|
+
'chassis': {
|
193
|
+
'manufacturer': 'Test Manufacturer',
|
194
|
+
'serial': 'AABBCCDDEE',
|
195
|
+
'asset': '',
|
196
|
+
},
|
197
|
+
'oem strings': [
|
198
|
+
'app1: string1',
|
199
|
+
'app1: string2',
|
200
|
+
'app2: string1',
|
201
|
+
'app2: string2',
|
202
|
+
'',
|
203
|
+
'',
|
204
|
+
],
|
205
|
+
}
|
206
|
+
EOF
|
207
|
+
end
|
208
|
+
|
209
|
+
it 'should populate sysinfo as expected' do
|
210
|
+
expect(servers).to receive(:create).with(xml: domain_xml).and_return(machine)
|
211
|
+
|
212
|
+
expect(subject.call(env)).to be_nil
|
213
|
+
end
|
214
|
+
|
215
|
+
context 'with block of empty entries' do
|
216
|
+
let(:domain_xml_file) { 'sysinfo_only_required.xml' }
|
217
|
+
let(:vagrantfile_providerconfig) do
|
218
|
+
<<-EOF
|
219
|
+
libvirt.sysinfo = {
|
220
|
+
'bios': {
|
221
|
+
'vendor': 'Test Vendor',
|
222
|
+
},
|
223
|
+
'system': {
|
224
|
+
'serial': '',
|
225
|
+
},
|
226
|
+
}
|
227
|
+
EOF
|
228
|
+
end
|
229
|
+
|
230
|
+
it 'should skip outputting the surrounding tags' do
|
231
|
+
expect(servers).to receive(:create).with(xml: domain_xml).and_return(machine)
|
232
|
+
|
233
|
+
expect(subject.call(env)).to be_nil
|
234
|
+
end
|
235
|
+
end
|
236
|
+
end
|
155
237
|
end
|
156
238
|
|
157
239
|
context 'connection => qemu:///session' do
|
@@ -195,7 +195,6 @@ describe VagrantPlugins::ProviderLibvirt::Action::ClearForwardedPorts do
|
|
195
195
|
end
|
196
196
|
end
|
197
197
|
it 'should terminate each of the processes' do
|
198
|
-
expect(logger).to receive(:info).with(no_args) # don't know how to test translations from vagrant
|
199
198
|
expect(subject).to receive(:ssh_pid?).with("10001").and_return(true)
|
200
199
|
expect(subject).to receive(:ssh_pid?).with("10002").and_return(true)
|
201
200
|
expect(logger).to receive(:debug).with(/Killing pid/).twice()
|
@@ -104,7 +104,7 @@ describe VagrantPlugins::ProviderLibvirt::Action::HandleBoxImage do
|
|
104
104
|
|
105
105
|
it 'should use the box file timestamp' do
|
106
106
|
expect(ui).to receive(:warn).with(
|
107
|
-
"No
|
107
|
+
"No version detected for test, using timestamp to watch for modifications. Consider\n" +
|
108
108
|
"generating a local metadata for the box with a version to allow better handling.\n" +
|
109
109
|
'See https://www.vagrantup.com/docs/boxes/format#box-metadata for further details.'
|
110
110
|
)
|
@@ -125,6 +125,23 @@ describe VagrantPlugins::ProviderLibvirt::Action::HandleBoxImage do
|
|
125
125
|
end
|
126
126
|
end
|
127
127
|
|
128
|
+
context 'when box version set to 0' do
|
129
|
+
let(:box_mtime) { Time.now }
|
130
|
+
|
131
|
+
before do
|
132
|
+
expect(env[:machine]).to receive_message_chain("box.version") { '0' }
|
133
|
+
expect(File).to receive(:mtime).and_return(box_mtime)
|
134
|
+
end
|
135
|
+
|
136
|
+
it 'should use the box file timestamp' do
|
137
|
+
expect(ui).to receive(:warn).with(/No version detected for test/)
|
138
|
+
|
139
|
+
expect(subject.call(env)).to be_nil
|
140
|
+
expect(env[:box_volume_number]).to eq(1)
|
141
|
+
expect(env[:box_volumes]).to match([hash_including({:name=>"test_vagrant_box_image_0_#{box_mtime.to_i}_box.img"})])
|
142
|
+
end
|
143
|
+
end
|
144
|
+
|
128
145
|
context 'When config.machine_virtual_size is set and smaller than box_virtual_size' do
|
129
146
|
before do
|
130
147
|
env[:machine].provider_config.machine_virtual_size = 1
|
@@ -0,0 +1,43 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
require 'spec_helper'
|
4
|
+
require 'support/sharedcontext'
|
5
|
+
|
6
|
+
require 'vagrant-libvirt/action/remove_libvirt_image'
|
7
|
+
|
8
|
+
describe VagrantPlugins::ProviderLibvirt::Action::RemoveLibvirtImage do
|
9
|
+
subject { described_class.new(app, env) }
|
10
|
+
|
11
|
+
include_context 'unit'
|
12
|
+
|
13
|
+
let(:box) { instance_double(::Vagrant::Box) }
|
14
|
+
|
15
|
+
describe '#call' do
|
16
|
+
before do
|
17
|
+
env[:box_removed] = box
|
18
|
+
allow(ui).to receive(:info)
|
19
|
+
end
|
20
|
+
|
21
|
+
context 'when called with libvirt box removed' do
|
22
|
+
before do
|
23
|
+
expect(box).to receive(:provider).and_return(:libvirt)
|
24
|
+
end
|
25
|
+
|
26
|
+
it 'should notify the user about limited removal' do
|
27
|
+
expect(ui).to receive(:info).with(/Vagrant-libvirt plugin removed box/)
|
28
|
+
expect(subject.call(env)).to be_nil
|
29
|
+
end
|
30
|
+
end
|
31
|
+
|
32
|
+
context 'when called with any other provider box' do
|
33
|
+
before do
|
34
|
+
expect(box).to receive(:provider).and_return(:virtualbox)
|
35
|
+
end
|
36
|
+
|
37
|
+
it 'call the next middle ware immediately' do
|
38
|
+
expect(ui).to_not receive(:info).with(/Vagrant-libvirt plugin removed box/)
|
39
|
+
expect(subject.call(env)).to be_nil
|
40
|
+
end
|
41
|
+
end
|
42
|
+
end
|
43
|
+
end
|
@@ -356,6 +356,30 @@ describe VagrantPlugins::ProviderLibvirt::Action::ResolveDiskSettings do
|
|
356
356
|
]
|
357
357
|
)
|
358
358
|
end
|
359
|
+
|
360
|
+
context 'when creating using pxe' do
|
361
|
+
before do
|
362
|
+
env[:domain_name] = 'vagrant-test_default'
|
363
|
+
end
|
364
|
+
|
365
|
+
it 'should not query for domain xml' do
|
366
|
+
expect(libvirt_client).to_not receive(:lookup_domain_by_uuid)
|
367
|
+
expect(libvirt_client).to receive(:lookup_storage_pool_by_name).and_return(libvirt_storage_pool)
|
368
|
+
expect(libvirt_storage_pool).to receive(:xml_desc).and_return(storage_pool_xml)
|
369
|
+
|
370
|
+
expect(subject.call(env)).to be_nil
|
371
|
+
expect(env[:disks]).to match(
|
372
|
+
[
|
373
|
+
hash_including(
|
374
|
+
device: 'vda',
|
375
|
+
path: 'vagrant-test_default-vda.qcow2',
|
376
|
+
absolute_path: '/var/lib/libvirt/images/vagrant-test_default-vda.qcow2',
|
377
|
+
pool: 'default'
|
378
|
+
),
|
379
|
+
]
|
380
|
+
)
|
381
|
+
end
|
382
|
+
end
|
359
383
|
end
|
360
384
|
end
|
361
385
|
end
|
@@ -0,0 +1,38 @@
|
|
1
|
+
<domain xmlns:qemu='http://libvirt.org/schemas/domain/qemu/1.0' type=''>
|
2
|
+
<name/>
|
3
|
+
<title/>
|
4
|
+
<description/>
|
5
|
+
<uuid/>
|
6
|
+
<memory/>
|
7
|
+
<vcpu>1</vcpu>
|
8
|
+
<cpu mode='host-model'>
|
9
|
+
<model fallback='allow'/>
|
10
|
+
</cpu>
|
11
|
+
<os>
|
12
|
+
<type>hvm</type>
|
13
|
+
<kernel/>
|
14
|
+
<initrd/>
|
15
|
+
<cmdline/>
|
16
|
+
</os>
|
17
|
+
<features>
|
18
|
+
<acpi/>
|
19
|
+
<apic/>
|
20
|
+
<pae/>
|
21
|
+
</features>
|
22
|
+
<clock offset='utc'>
|
23
|
+
|
24
|
+
</clock>
|
25
|
+
<devices>
|
26
|
+
<serial type='pty'>
|
27
|
+
<target port='0'/>
|
28
|
+
</serial>
|
29
|
+
<console type='pty'>
|
30
|
+
<target port='0'/>
|
31
|
+
</console>
|
32
|
+
<input bus='ps2' type='mouse'/>
|
33
|
+
<graphics autoport='yes' keymap='en-us' listen='127.0.0.1' port='-1' type='vnc'/>
|
34
|
+
<video>
|
35
|
+
<model heads='1' type='cirrus' vram='16384'/>
|
36
|
+
</video>
|
37
|
+
</devices>
|
38
|
+
</domain>
|
@@ -0,0 +1,39 @@
|
|
1
|
+
<domain xmlns:qemu='http://libvirt.org/schemas/domain/qemu/1.0' type=''>
|
2
|
+
<name/>
|
3
|
+
<title/>
|
4
|
+
<description/>
|
5
|
+
<uuid/>
|
6
|
+
<memory/>
|
7
|
+
<vcpu>1</vcpu>
|
8
|
+
<cpu mode='host-model'>
|
9
|
+
<model fallback='allow'/>
|
10
|
+
</cpu>
|
11
|
+
<os>
|
12
|
+
<type>hvm</type>
|
13
|
+
<kernel/>
|
14
|
+
<initrd/>
|
15
|
+
<cmdline/>
|
16
|
+
</os>
|
17
|
+
<features>
|
18
|
+
<acpi/>
|
19
|
+
<apic/>
|
20
|
+
<pae/>
|
21
|
+
</features>
|
22
|
+
<clock offset='utc'>
|
23
|
+
<timer name='rtc'/>
|
24
|
+
<timer name='tsc'/>
|
25
|
+
</clock>
|
26
|
+
<devices>
|
27
|
+
<serial type='pty'>
|
28
|
+
<target port='0'/>
|
29
|
+
</serial>
|
30
|
+
<console type='pty'>
|
31
|
+
<target port='0'/>
|
32
|
+
</console>
|
33
|
+
<input bus='ps2' type='mouse'/>
|
34
|
+
<graphics autoport='yes' keymap='en-us' listen='127.0.0.1' port='-1' type='vnc'/>
|
35
|
+
<video>
|
36
|
+
<model heads='1' type='cirrus' vram='16384'/>
|
37
|
+
</video>
|
38
|
+
</devices>
|
39
|
+
</domain>
|
@@ -4,11 +4,11 @@
|
|
4
4
|
<description>Source: /home/test/vagrant-libvirt/Vagrantfile</description>
|
5
5
|
<memory unit='KiB'>2097152</memory>
|
6
6
|
<currentMemory unit='KiB'>2097152</currentMemory>
|
7
|
-
<vcpu placement='static'>
|
7
|
+
<vcpu placement='static'>2</vcpu>
|
8
8
|
<os>
|
9
9
|
<type arch='x86_64' machine='pc-i440fx-6.0'>hvm</type>
|
10
10
|
<loader type='pflash'>/path/to/loader/file</loader>
|
11
|
-
<nvram>/path/to/nvram/
|
11
|
+
<nvram>/path/to/nvram/file1</nvram>
|
12
12
|
<boot dev='hd'/>
|
13
13
|
</os>
|
14
14
|
<features>
|
@@ -33,8 +33,7 @@ describe VagrantPlugins::ProviderLibvirt::Action::StartDomain do
|
|
33
33
|
allow(servers).to receive(:get).and_return(domain)
|
34
34
|
|
35
35
|
allow(logger).to receive(:debug)
|
36
|
-
|
37
|
-
expect(ui).to_not receive(:error)
|
36
|
+
allow(logger).to receive(:info)
|
38
37
|
|
39
38
|
allow(libvirt_domain).to receive(:xml_desc).and_return(domain_xml)
|
40
39
|
|
@@ -43,23 +42,53 @@ describe VagrantPlugins::ProviderLibvirt::Action::StartDomain do
|
|
43
42
|
end
|
44
43
|
|
45
44
|
it 'should execute without changing' do
|
46
|
-
expect(
|
45
|
+
expect(ui).to_not receive(:error)
|
46
|
+
expect(libvirt_client).to_not receive(:define_domain_xml)
|
47
47
|
expect(libvirt_domain).to receive(:autostart=)
|
48
48
|
expect(domain).to receive(:start)
|
49
49
|
|
50
50
|
expect(subject.call(env)).to be_nil
|
51
51
|
end
|
52
52
|
|
53
|
-
context 'when
|
54
|
-
let(:
|
53
|
+
context 'when any setting changed' do
|
54
|
+
let(:vagrantfile_providerconfig) do
|
55
|
+
<<-EOF
|
56
|
+
libvirt.cpus = 2
|
57
|
+
EOF
|
58
|
+
end
|
59
|
+
|
60
|
+
let(:updated_domain_xml) {
|
61
|
+
new_xml = domain_xml.dup
|
62
|
+
new_xml['<vcpu>1</vcpu>'] = '<vcpu>2</vcpu>'
|
63
|
+
new_xml
|
64
|
+
}
|
55
65
|
|
56
|
-
it 'should
|
57
|
-
expect(
|
66
|
+
it 'should update the domain' do
|
67
|
+
expect(ui).to_not receive(:error)
|
58
68
|
expect(libvirt_domain).to receive(:autostart=)
|
69
|
+
expect(connection).to receive(:define_domain).and_return(libvirt_domain)
|
70
|
+
expect(libvirt_domain).to receive(:xml_desc).and_return(domain_xml, updated_domain_xml)
|
59
71
|
expect(domain).to receive(:start)
|
60
72
|
|
61
73
|
expect(subject.call(env)).to be_nil
|
62
74
|
end
|
75
|
+
|
76
|
+
context 'when there is an error during update' do
|
77
|
+
it 'should skip attempting to start' do
|
78
|
+
expect(ui).to receive(:error)
|
79
|
+
expect(connection).to receive(:define_domain).and_raise(::Libvirt::Error)
|
80
|
+
|
81
|
+
expect { subject.call(env) }.to raise_error(VagrantPlugins::ProviderLibvirt::Errors::VagrantLibvirtError)
|
82
|
+
end
|
83
|
+
end
|
84
|
+
|
85
|
+
context 'when there is an interrupt' do
|
86
|
+
it 'should skip attempting to start' do
|
87
|
+
expect(connection).to receive(:define_domain).and_raise(Interrupt)
|
88
|
+
|
89
|
+
expect { subject.call(env) }.to raise_error(Interrupt)
|
90
|
+
end
|
91
|
+
end
|
63
92
|
end
|
64
93
|
|
65
94
|
context 'nvram' do
|
@@ -73,9 +102,10 @@ describe VagrantPlugins::ProviderLibvirt::Action::StartDomain do
|
|
73
102
|
let(:test_file) { 'existing.xml' }
|
74
103
|
let(:updated_test_file) { 'existing_added_nvram.xml' }
|
75
104
|
|
76
|
-
it 'should
|
77
|
-
expect(
|
78
|
-
expect(
|
105
|
+
it 'should add the nvram element' do
|
106
|
+
expect(ui).to_not receive(:error)
|
107
|
+
expect(connection).to receive(:define_domain).with(updated_domain_xml).and_return(libvirt_domain)
|
108
|
+
expect(libvirt_domain).to receive(:xml_desc).and_return(domain_xml, updated_domain_xml)
|
79
109
|
expect(libvirt_domain).to receive(:autostart=)
|
80
110
|
expect(domain).to receive(:start)
|
81
111
|
|
@@ -87,17 +117,16 @@ describe VagrantPlugins::ProviderLibvirt::Action::StartDomain do
|
|
87
117
|
let(:vagrantfile_providerconfig) do
|
88
118
|
<<-EOF
|
89
119
|
libvirt.loader = "/path/to/loader/file"
|
90
|
-
libvirt.nvram = "/path/to/nvram/
|
91
|
-
# change another setting to trigger the undefine/create
|
92
|
-
libvirt.cpus = 4
|
120
|
+
libvirt.nvram = "/path/to/nvram/file1"
|
93
121
|
EOF
|
94
122
|
end
|
95
123
|
let(:test_file) { 'nvram_domain.xml' }
|
96
124
|
let(:updated_test_file) { 'nvram_domain_other_setting.xml' }
|
97
125
|
|
98
|
-
it 'should
|
99
|
-
expect(
|
100
|
-
expect(
|
126
|
+
it 'should keep the XML element' do
|
127
|
+
expect(ui).to_not receive(:error)
|
128
|
+
expect(connection).to receive(:define_domain).with(updated_domain_xml).and_return(libvirt_domain)
|
129
|
+
expect(libvirt_domain).to receive(:xml_desc).and_return(domain_xml, updated_domain_xml)
|
101
130
|
expect(libvirt_domain).to receive(:autostart=)
|
102
131
|
expect(domain).to receive(:start)
|
103
132
|
|
@@ -108,9 +137,10 @@ describe VagrantPlugins::ProviderLibvirt::Action::StartDomain do
|
|
108
137
|
let(:vagrantfile_providerconfig) { }
|
109
138
|
let(:updated_test_file) { 'nvram_domain_removed.xml' }
|
110
139
|
|
111
|
-
it 'should
|
112
|
-
expect(
|
113
|
-
expect(
|
140
|
+
it 'should delete the XML element' do
|
141
|
+
expect(ui).to_not receive(:error)
|
142
|
+
expect(connection).to receive(:define_domain).with(updated_domain_xml).and_return(libvirt_domain)
|
143
|
+
expect(libvirt_domain).to receive(:xml_desc).and_return(domain_xml, updated_domain_xml)
|
114
144
|
expect(libvirt_domain).to receive(:autostart=)
|
115
145
|
expect(domain).to receive(:start)
|
116
146
|
|
@@ -132,9 +162,10 @@ describe VagrantPlugins::ProviderLibvirt::Action::StartDomain do
|
|
132
162
|
end
|
133
163
|
|
134
164
|
it 'should modify the domain tpm_path' do
|
135
|
-
expect(
|
165
|
+
expect(ui).to_not receive(:error)
|
136
166
|
expect(logger).to receive(:debug).with('tpm config changed')
|
137
|
-
expect(
|
167
|
+
expect(connection).to receive(:define_domain).with(updated_domain_xml).and_return(libvirt_domain)
|
168
|
+
expect(libvirt_domain).to receive(:xml_desc).and_return(domain_xml, updated_domain_xml)
|
138
169
|
expect(libvirt_domain).to receive(:autostart=)
|
139
170
|
expect(domain).to receive(:start)
|
140
171
|
|
@@ -153,9 +184,10 @@ describe VagrantPlugins::ProviderLibvirt::Action::StartDomain do
|
|
153
184
|
end
|
154
185
|
|
155
186
|
it 'should modify the domain tpm_path' do
|
156
|
-
expect(
|
187
|
+
expect(ui).to_not receive(:error)
|
157
188
|
expect(logger).to receive(:debug).with('tpm config changed')
|
158
|
-
expect(
|
189
|
+
expect(connection).to receive(:define_domain).with(updated_domain_xml).and_return(libvirt_domain)
|
190
|
+
expect(libvirt_domain).to receive(:xml_desc).and_return(domain_xml, updated_domain_xml)
|
159
191
|
expect(libvirt_domain).to receive(:autostart=)
|
160
192
|
expect(domain).to receive(:start)
|
161
193
|
|
@@ -175,6 +207,7 @@ describe VagrantPlugins::ProviderLibvirt::Action::StartDomain do
|
|
175
207
|
end
|
176
208
|
|
177
209
|
it 'should execute without changing' do
|
210
|
+
expect(ui).to_not receive(:error)
|
178
211
|
expect(libvirt_domain).to receive(:autostart=)
|
179
212
|
expect(domain).to receive(:start)
|
180
213
|
|
@@ -194,6 +227,7 @@ describe VagrantPlugins::ProviderLibvirt::Action::StartDomain do
|
|
194
227
|
end
|
195
228
|
|
196
229
|
it 'should execute without changing' do
|
230
|
+
expect(ui).to_not receive(:error)
|
197
231
|
expect(libvirt_domain).to receive(:autostart=)
|
198
232
|
expect(domain).to receive(:start)
|
199
233
|
|
@@ -213,9 +247,10 @@ describe VagrantPlugins::ProviderLibvirt::Action::StartDomain do
|
|
213
247
|
end
|
214
248
|
|
215
249
|
it 'should modify the domain' do
|
216
|
-
expect(
|
250
|
+
expect(ui).to_not receive(:error)
|
217
251
|
expect(logger).to receive(:debug).with('tpm config changed')
|
218
|
-
expect(
|
252
|
+
expect(connection).to receive(:define_domain).with(updated_domain_xml).and_return(libvirt_domain)
|
253
|
+
expect(libvirt_domain).to receive(:xml_desc).and_return(domain_xml, updated_domain_xml)
|
219
254
|
expect(libvirt_domain).to receive(:autostart=)
|
220
255
|
expect(domain).to receive(:start)
|
221
256
|
|
@@ -235,8 +270,9 @@ describe VagrantPlugins::ProviderLibvirt::Action::StartDomain do
|
|
235
270
|
end
|
236
271
|
|
237
272
|
it 'should not modify the domain' do
|
273
|
+
expect(ui).to_not receive(:error)
|
238
274
|
expect(logger).to_not receive(:debug).with('clock timers config changed')
|
239
|
-
expect(
|
275
|
+
expect(connection).to_not receive(:define_domain)
|
240
276
|
expect(libvirt_domain).to receive(:autostart=)
|
241
277
|
expect(domain).to receive(:start)
|
242
278
|
|
@@ -252,10 +288,13 @@ describe VagrantPlugins::ProviderLibvirt::Action::StartDomain do
|
|
252
288
|
EOF
|
253
289
|
end
|
254
290
|
|
291
|
+
let(:updated_test_file) { 'clock_timer_rtc_tsc.xml' }
|
292
|
+
|
255
293
|
it 'should modify the domain' do
|
256
|
-
expect(
|
294
|
+
expect(ui).to_not receive(:error)
|
257
295
|
expect(logger).to receive(:debug).with('clock timers config changed')
|
258
|
-
expect(
|
296
|
+
expect(connection).to receive(:define_domain).with(match(/<clock offset='utc'>\s*<timer name='rtc'\/>\s*<timer name='tsc'\/>\s*<\/clock>/)).and_return(libvirt_domain)
|
297
|
+
expect(libvirt_domain).to receive(:xml_desc).and_return(domain_xml, updated_domain_xml)
|
259
298
|
expect(libvirt_domain).to receive(:autostart=)
|
260
299
|
expect(domain).to receive(:start)
|
261
300
|
|
@@ -264,10 +303,13 @@ describe VagrantPlugins::ProviderLibvirt::Action::StartDomain do
|
|
264
303
|
end
|
265
304
|
|
266
305
|
context 'timers removed' do
|
306
|
+
let(:updated_test_file) { 'clock_timer_removed.xml' }
|
307
|
+
|
267
308
|
it 'should modify the domain' do
|
268
|
-
expect(
|
309
|
+
expect(ui).to_not receive(:error)
|
269
310
|
expect(logger).to receive(:debug).with('clock timers config changed')
|
270
|
-
expect(
|
311
|
+
expect(connection).to receive(:define_domain).with(match(/<clock offset='utc'>\s*<\/clock>/)).and_return(libvirt_domain)
|
312
|
+
expect(libvirt_domain).to receive(:xml_desc).and_return(domain_xml, updated_domain_xml)
|
271
313
|
expect(libvirt_domain).to receive(:autostart=)
|
272
314
|
expect(domain).to receive(:start)
|
273
315
|
|