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
data/spec/unit/action_spec.rb
CHANGED
@@ -170,4 +170,92 @@ describe VagrantPlugins::ProviderLibvirt::Action do
|
|
170
170
|
end
|
171
171
|
end
|
172
172
|
end
|
173
|
+
|
174
|
+
describe '#action_snapshot_delete' do
|
175
|
+
context 'when not created' do
|
176
|
+
before do
|
177
|
+
allow_action_env_result(VagrantPlugins::ProviderLibvirt::Action::IsCreated, false)
|
178
|
+
end
|
179
|
+
|
180
|
+
it 'should cause an error' do
|
181
|
+
expect{ machine.action(:snapshot_delete, snapshot_opts: {})}.to raise_error(Vagrant::Errors::VMNotCreatedError)
|
182
|
+
end
|
183
|
+
end
|
184
|
+
|
185
|
+
context 'when created' do
|
186
|
+
before do
|
187
|
+
allow_action_env_result(VagrantPlugins::ProviderLibvirt::Action::IsCreated, true)
|
188
|
+
end
|
189
|
+
|
190
|
+
context 'when running' do
|
191
|
+
before do
|
192
|
+
allow_action_env_result(VagrantPlugins::ProviderLibvirt::Action::IsRunning, true)
|
193
|
+
end
|
194
|
+
|
195
|
+
it 'should call SnapshotDelete' do
|
196
|
+
expect_any_instance_of(VagrantPlugins::ProviderLibvirt::Action::SnapshotDelete).to receive(:call).and_return(0)
|
197
|
+
expect(machine.action(:snapshot_delete, snapshot_opts: {})).to match(hash_including({:action_name => :machine_action_snapshot_delete}))
|
198
|
+
end
|
199
|
+
end
|
200
|
+
end
|
201
|
+
end
|
202
|
+
|
203
|
+
|
204
|
+
describe '#action_snapshot_restore' do
|
205
|
+
context 'when not created' do
|
206
|
+
before do
|
207
|
+
allow_action_env_result(VagrantPlugins::ProviderLibvirt::Action::IsCreated, false)
|
208
|
+
end
|
209
|
+
|
210
|
+
it 'should cause an error' do
|
211
|
+
expect{ machine.action(:snapshot_restore, snapshot_opts: {})}.to raise_error(Vagrant::Errors::VMNotCreatedError)
|
212
|
+
end
|
213
|
+
end
|
214
|
+
|
215
|
+
context 'when created' do
|
216
|
+
before do
|
217
|
+
allow_action_env_result(VagrantPlugins::ProviderLibvirt::Action::IsCreated, true)
|
218
|
+
end
|
219
|
+
|
220
|
+
context 'when running' do
|
221
|
+
before do
|
222
|
+
allow_action_env_result(VagrantPlugins::ProviderLibvirt::Action::IsRunning, true)
|
223
|
+
end
|
224
|
+
|
225
|
+
it 'should call SnapshotRestore' do
|
226
|
+
expect_any_instance_of(VagrantPlugins::ProviderLibvirt::Action::SnapshotRestore).to receive(:call).and_return(0)
|
227
|
+
expect(machine.action(:snapshot_restore, snapshot_opts: {})).to match(hash_including({:action_name => :machine_action_snapshot_restore}))
|
228
|
+
end
|
229
|
+
end
|
230
|
+
end
|
231
|
+
end
|
232
|
+
|
233
|
+
describe '#action_snapshot_save' do
|
234
|
+
context 'when not created' do
|
235
|
+
before do
|
236
|
+
allow_action_env_result(VagrantPlugins::ProviderLibvirt::Action::IsCreated, false)
|
237
|
+
end
|
238
|
+
|
239
|
+
it 'should cause an error' do
|
240
|
+
expect{ machine.action(:snapshot_save, snapshot_opts: {})}.to raise_error(Vagrant::Errors::VMNotCreatedError)
|
241
|
+
end
|
242
|
+
end
|
243
|
+
|
244
|
+
context 'when created' do
|
245
|
+
before do
|
246
|
+
allow_action_env_result(VagrantPlugins::ProviderLibvirt::Action::IsCreated, true)
|
247
|
+
end
|
248
|
+
|
249
|
+
context 'when running' do
|
250
|
+
before do
|
251
|
+
allow_action_env_result(VagrantPlugins::ProviderLibvirt::Action::IsRunning, true)
|
252
|
+
end
|
253
|
+
|
254
|
+
it 'should call SnapshotSave' do
|
255
|
+
expect_any_instance_of(VagrantPlugins::ProviderLibvirt::Action::SnapshotSave).to receive(:call).and_return(0)
|
256
|
+
expect(machine.action(:snapshot_save, snapshot_opts: {})).to match(hash_including({:action_name => :machine_action_snapshot_save}))
|
257
|
+
end
|
258
|
+
end
|
259
|
+
end
|
260
|
+
end
|
173
261
|
end
|
@@ -0,0 +1,120 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
require 'spec_helper'
|
4
|
+
require 'support/sharedcontext'
|
5
|
+
|
6
|
+
require 'vagrant-libvirt/cap/synced_folder_9p'
|
7
|
+
require 'vagrant-libvirt/util/unindent'
|
8
|
+
|
9
|
+
describe VagrantPlugins::SyncedFolder9P::SyncedFolder do
|
10
|
+
include_context 'unit'
|
11
|
+
include_context 'libvirt'
|
12
|
+
|
13
|
+
subject { described_class.new }
|
14
|
+
|
15
|
+
describe '#prepare' do
|
16
|
+
let(:synced_folders) { {
|
17
|
+
"/vagrant" => {
|
18
|
+
:hostpath => '/home/test/default',
|
19
|
+
:disabled=>false,
|
20
|
+
:guestpath=>'/vagrant',
|
21
|
+
:type => :"9p",
|
22
|
+
},
|
23
|
+
} }
|
24
|
+
|
25
|
+
let(:expected_xml) {
|
26
|
+
<<-EOF.unindent
|
27
|
+
<filesystem type="mount" accessmode="passthrough">
|
28
|
+
<driver type="path" wrpolicy="immediate"></driver>
|
29
|
+
<source dir="/home/test/default"></source>
|
30
|
+
<target dir="1ef53e1c9b6a5a0c695c80665331652\"></target>
|
31
|
+
</filesystem>
|
32
|
+
EOF
|
33
|
+
}
|
34
|
+
|
35
|
+
before do
|
36
|
+
allow(libvirt_client).to receive(:lookup_domain_by_uuid).and_return(libvirt_domain)
|
37
|
+
allow(logger).to receive(:debug)
|
38
|
+
end
|
39
|
+
|
40
|
+
it 'should attach device xml' do
|
41
|
+
expect(libvirt_domain).to receive(:attach_device).with(expected_xml, 0)
|
42
|
+
|
43
|
+
subject.prepare(machine, synced_folders, {})
|
44
|
+
end
|
45
|
+
|
46
|
+
context 'multiple folders' do
|
47
|
+
let(:synced_folders) { {
|
48
|
+
"/vagrant" => {
|
49
|
+
:hostpath => '/home/test/default',
|
50
|
+
:disabled=>false,
|
51
|
+
:guestpath=>'/vagrant',
|
52
|
+
:type => :"9p",
|
53
|
+
},
|
54
|
+
"/custom" => {
|
55
|
+
:hostpath => '/home/test/custom',
|
56
|
+
:disabled=>false,
|
57
|
+
:guestpath=>'/custom',
|
58
|
+
:type => :"9p",
|
59
|
+
},
|
60
|
+
} }
|
61
|
+
|
62
|
+
let(:expected_xml) {
|
63
|
+
[ <<-XML1.unindent, <<-XML2.unindent ]
|
64
|
+
<filesystem type="mount" accessmode="passthrough">
|
65
|
+
<driver type="path" wrpolicy="immediate"></driver>
|
66
|
+
<source dir="/home/test/default"></source>
|
67
|
+
<target dir="1ef53e1c9b6a5a0c695c80665331652\"></target>
|
68
|
+
</filesystem>
|
69
|
+
XML1
|
70
|
+
<filesystem type="mount" accessmode="passthrough">
|
71
|
+
<driver type="path" wrpolicy="immediate"></driver>
|
72
|
+
<source dir="/home/test/custom"></source>
|
73
|
+
<target dir=\"a2a1a8b6d98be8f790f3c987e006d13\"></target>
|
74
|
+
</filesystem>
|
75
|
+
XML2
|
76
|
+
}
|
77
|
+
|
78
|
+
it 'should attach all device xml' do
|
79
|
+
expect(libvirt_domain).to receive(:attach_device).with(expected_xml[0], 0)
|
80
|
+
expect(libvirt_domain).to receive(:attach_device).with(expected_xml[1], 0)
|
81
|
+
expect(ui).to receive(:info).with(/Configuring 9p devices for shared folders/).once
|
82
|
+
|
83
|
+
subject.prepare(machine, synced_folders, {})
|
84
|
+
end
|
85
|
+
end
|
86
|
+
end
|
87
|
+
|
88
|
+
describe '#usable?' do
|
89
|
+
context 'with libvirt provider' do
|
90
|
+
before do
|
91
|
+
allow(machine).to receive(:provider_name).and_return(:libvirt)
|
92
|
+
allow(libvirt_client).to receive(:libversion).and_return(8002000)
|
93
|
+
end
|
94
|
+
|
95
|
+
it 'should be' do
|
96
|
+
expect(subject).to be_usable(machine)
|
97
|
+
end
|
98
|
+
|
99
|
+
context 'with version less than 1.2.2' do
|
100
|
+
before do
|
101
|
+
allow(libvirt_client).to receive(:libversion).and_return(1002001)
|
102
|
+
end
|
103
|
+
|
104
|
+
it 'should not be' do
|
105
|
+
expect(subject).to_not be_usable(machine)
|
106
|
+
end
|
107
|
+
end
|
108
|
+
end
|
109
|
+
|
110
|
+
context 'with other provider' do
|
111
|
+
before do
|
112
|
+
allow(machine).to receive(:provider_name).and_return(:virtualbox)
|
113
|
+
end
|
114
|
+
|
115
|
+
it 'should not be' do
|
116
|
+
expect(subject).to_not be_usable(machine)
|
117
|
+
end
|
118
|
+
end
|
119
|
+
end
|
120
|
+
end
|
@@ -0,0 +1,120 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
require 'spec_helper'
|
4
|
+
require 'support/sharedcontext'
|
5
|
+
|
6
|
+
require 'vagrant-libvirt/cap/synced_folder_virtiofs'
|
7
|
+
require 'vagrant-libvirt/util/unindent'
|
8
|
+
|
9
|
+
describe VagrantPlugins::SyncedFolderVirtioFS::SyncedFolder do
|
10
|
+
include_context 'unit'
|
11
|
+
include_context 'libvirt'
|
12
|
+
|
13
|
+
subject { described_class.new }
|
14
|
+
|
15
|
+
describe '#prepare' do
|
16
|
+
let(:synced_folders) { {
|
17
|
+
"/vagrant" => {
|
18
|
+
:hostpath => '/home/test/default',
|
19
|
+
:disabled=>false,
|
20
|
+
:guestpath=>'/vagrant',
|
21
|
+
:type => :virtiofs,
|
22
|
+
},
|
23
|
+
} }
|
24
|
+
|
25
|
+
let(:expected_xml) {
|
26
|
+
<<-EOF.unindent
|
27
|
+
<filesystem type="mount" accessmode="passthrough">
|
28
|
+
<driver type="virtiofs"></driver>
|
29
|
+
<source dir="/home/test/default"></source>
|
30
|
+
<target dir="1ef53e1c9b6a5a0c695c80665331652\"></target>
|
31
|
+
</filesystem>
|
32
|
+
EOF
|
33
|
+
}
|
34
|
+
|
35
|
+
before do
|
36
|
+
allow(libvirt_client).to receive(:lookup_domain_by_uuid).and_return(libvirt_domain)
|
37
|
+
allow(logger).to receive(:debug)
|
38
|
+
end
|
39
|
+
|
40
|
+
it 'should attach device xml' do
|
41
|
+
expect(libvirt_domain).to receive(:attach_device).with(expected_xml, 0)
|
42
|
+
|
43
|
+
subject.prepare(machine, synced_folders, {})
|
44
|
+
end
|
45
|
+
|
46
|
+
context 'multiple folders' do
|
47
|
+
let(:synced_folders) { {
|
48
|
+
"/vagrant" => {
|
49
|
+
:hostpath => '/home/test/default',
|
50
|
+
:disabled=>false,
|
51
|
+
:guestpath=>'/vagrant',
|
52
|
+
:type => :virtiofs,
|
53
|
+
},
|
54
|
+
"/custom" => {
|
55
|
+
:hostpath => '/home/test/custom',
|
56
|
+
:disabled=>false,
|
57
|
+
:guestpath=>'/custom',
|
58
|
+
:type => :virtiofs,
|
59
|
+
},
|
60
|
+
} }
|
61
|
+
|
62
|
+
let(:expected_xml) {
|
63
|
+
[ <<-XML1.unindent, <<-XML2.unindent ]
|
64
|
+
<filesystem type="mount" accessmode="passthrough">
|
65
|
+
<driver type="virtiofs"></driver>
|
66
|
+
<source dir="/home/test/default"></source>
|
67
|
+
<target dir="1ef53e1c9b6a5a0c695c80665331652\"></target>
|
68
|
+
</filesystem>
|
69
|
+
XML1
|
70
|
+
<filesystem type="mount" accessmode="passthrough">
|
71
|
+
<driver type="virtiofs"></driver>
|
72
|
+
<source dir="/home/test/custom"></source>
|
73
|
+
<target dir=\"a2a1a8b6d98be8f790f3c987e006d13\"></target>
|
74
|
+
</filesystem>
|
75
|
+
XML2
|
76
|
+
}
|
77
|
+
|
78
|
+
it 'should attach all device xml' do
|
79
|
+
expect(libvirt_domain).to receive(:attach_device).with(expected_xml[0], 0)
|
80
|
+
expect(libvirt_domain).to receive(:attach_device).with(expected_xml[1], 0)
|
81
|
+
expect(ui).to receive(:info).with(/Configuring virtiofs devices for shared folders/).once
|
82
|
+
|
83
|
+
subject.prepare(machine, synced_folders, {})
|
84
|
+
end
|
85
|
+
end
|
86
|
+
end
|
87
|
+
|
88
|
+
describe '#usable?' do
|
89
|
+
context 'with libvirt provider' do
|
90
|
+
before do
|
91
|
+
allow(machine).to receive(:provider_name).and_return(:libvirt)
|
92
|
+
allow(libvirt_client).to receive(:libversion).and_return(8002000)
|
93
|
+
end
|
94
|
+
|
95
|
+
it 'should be' do
|
96
|
+
expect(subject).to be_usable(machine)
|
97
|
+
end
|
98
|
+
|
99
|
+
context 'with version less than 6.2.0' do
|
100
|
+
before do
|
101
|
+
allow(libvirt_client).to receive(:libversion).and_return(6001000)
|
102
|
+
end
|
103
|
+
|
104
|
+
it 'should not be' do
|
105
|
+
expect(subject).to_not be_usable(machine)
|
106
|
+
end
|
107
|
+
end
|
108
|
+
end
|
109
|
+
|
110
|
+
context 'with other provider' do
|
111
|
+
before do
|
112
|
+
allow(machine).to receive(:provider_name).and_return(:virtualbox)
|
113
|
+
end
|
114
|
+
|
115
|
+
it 'should not be' do
|
116
|
+
expect(subject).to_not be_usable(machine)
|
117
|
+
end
|
118
|
+
end
|
119
|
+
end
|
120
|
+
end
|
data/spec/unit/config_spec.rb
CHANGED
@@ -577,24 +577,28 @@ describe VagrantPlugins::ProviderLibvirt::Config do
|
|
577
577
|
|
578
578
|
def assert_invalid
|
579
579
|
subject.finalize!
|
580
|
-
errors = subject.validate(machine)
|
581
|
-
|
580
|
+
errors = subject.validate(machine).values.first
|
581
|
+
expect(errors).to_not be_empty
|
582
|
+
errors
|
582
583
|
end
|
583
584
|
|
584
585
|
def assert_valid
|
585
586
|
subject.finalize!
|
586
|
-
errors = subject.validate(machine)
|
587
|
-
|
587
|
+
errors = subject.validate(machine).values.first
|
588
|
+
expect(errors).to be_empty
|
588
589
|
end
|
589
590
|
|
590
591
|
describe '#validate' do
|
592
|
+
before do
|
593
|
+
allow(machine).to receive(:provider_config).and_return(subject)
|
594
|
+
allow(machine).to receive(:ui).and_return(ui)
|
595
|
+
end
|
596
|
+
|
591
597
|
it 'is valid with defaults' do
|
592
598
|
assert_valid
|
593
599
|
end
|
594
600
|
|
595
601
|
context 'with disks defined' do
|
596
|
-
before { expect(machine).to receive(:provider_config).and_return(subject).at_least(:once) }
|
597
|
-
|
598
602
|
it 'is valid if relative path used for disk' do
|
599
603
|
subject.storage :file, path: '../path/to/file.qcow2'
|
600
604
|
assert_valid
|
@@ -630,6 +634,53 @@ describe VagrantPlugins::ProviderLibvirt::Config do
|
|
630
634
|
end
|
631
635
|
end
|
632
636
|
|
637
|
+
context 'with public_network defined' do
|
638
|
+
let(:host_devices) { [
|
639
|
+
instance_double(Socket::Ifaddr),
|
640
|
+
instance_double(Socket::Ifaddr),
|
641
|
+
] }
|
642
|
+
before do
|
643
|
+
machine.config.vm.network :public_network, dev: 'eth0', ip: "192.168.2.157"
|
644
|
+
expect(Socket).to receive(:getifaddrs).and_return(host_devices)
|
645
|
+
expect(host_devices[0]).to receive(:name).and_return('eth0')
|
646
|
+
expect(host_devices[1]).to receive(:name).and_return('virbr0')
|
647
|
+
end
|
648
|
+
|
649
|
+
it 'should validate use of existing device' do
|
650
|
+
assert_valid
|
651
|
+
end
|
652
|
+
|
653
|
+
context 'when default device not on host' do
|
654
|
+
before do
|
655
|
+
machine.config.vm.network :public_network, dev: 'eno1', ip: "192.168.2.157"
|
656
|
+
end
|
657
|
+
|
658
|
+
it 'should be invalid' do
|
659
|
+
assert_invalid
|
660
|
+
end
|
661
|
+
end
|
662
|
+
|
663
|
+
context 'when using excluded host device' do
|
664
|
+
before do
|
665
|
+
machine.config.vm.network :public_network, dev: 'virbr0', ip: "192.168.2.157"
|
666
|
+
end
|
667
|
+
|
668
|
+
it 'should be invalid' do
|
669
|
+
assert_invalid
|
670
|
+
end
|
671
|
+
|
672
|
+
context 'when user overrides to allow device' do
|
673
|
+
before do
|
674
|
+
subject.host_device_exclude_prefixes = []
|
675
|
+
end
|
676
|
+
|
677
|
+
it 'should validate' do
|
678
|
+
assert_valid
|
679
|
+
end
|
680
|
+
end
|
681
|
+
end
|
682
|
+
end
|
683
|
+
|
633
684
|
context 'with nvram defined' do
|
634
685
|
before do
|
635
686
|
subject.nvram = '/path/to/some/nvram'
|
@@ -662,6 +713,60 @@ describe VagrantPlugins::ProviderLibvirt::Config do
|
|
662
713
|
assert_valid
|
663
714
|
end
|
664
715
|
end
|
716
|
+
|
717
|
+
context 'with sysinfo defined' do
|
718
|
+
context 'when invalid block name provided' do
|
719
|
+
it 'should be invalid' do
|
720
|
+
subject.sysinfo = {'bad bios': {'vendor': 'some vendor'}}
|
721
|
+
|
722
|
+
errors = assert_invalid
|
723
|
+
expect(errors).to include(match(/invalid sysinfo element 'bad bios';/))
|
724
|
+
end
|
725
|
+
end
|
726
|
+
|
727
|
+
context 'when invalid element name provided' do
|
728
|
+
it 'should be invalid' do
|
729
|
+
subject.sysinfo = {'bios': {'bad vendor': 'some vendor'}}
|
730
|
+
|
731
|
+
errors = assert_invalid
|
732
|
+
expect(errors).to include(match(/'sysinfo.bios' does not support entry name 'bad vendor'/))
|
733
|
+
end
|
734
|
+
end
|
735
|
+
|
736
|
+
context 'when empty element value provided' do
|
737
|
+
it 'should succeed with a warning' do
|
738
|
+
expect(ui).to receive(:warn).with(/Libvirt Provider: sysinfo.bios.vendor is nil or empty/)
|
739
|
+
subject.sysinfo = {'bios': {'vendor': ''}}
|
740
|
+
|
741
|
+
assert_valid
|
742
|
+
end
|
743
|
+
end
|
744
|
+
|
745
|
+
context 'when handling "oem strings"' do
|
746
|
+
it 'should succeed' do
|
747
|
+
subject.sysinfo = {'oem strings': ['string 1']}
|
748
|
+
|
749
|
+
assert_valid
|
750
|
+
end
|
751
|
+
|
752
|
+
context 'when empty entries' do
|
753
|
+
it 'should succeed with a warning' do
|
754
|
+
expect(ui).to receive(:warn).with(/Libvirt Provider: 'sysinfo.oem strings' contains an empty/)
|
755
|
+
subject.sysinfo = {'oem strings': ['']}
|
756
|
+
|
757
|
+
assert_valid
|
758
|
+
end
|
759
|
+
end
|
760
|
+
|
761
|
+
context 'when non string passed' do
|
762
|
+
it 'should be invalid' do
|
763
|
+
subject.sysinfo = {'oem strings': [true]}
|
764
|
+
|
765
|
+
assert_invalid
|
766
|
+
end
|
767
|
+
end
|
768
|
+
end
|
769
|
+
end
|
665
770
|
end
|
666
771
|
|
667
772
|
describe '#merge' do
|
@@ -725,5 +830,27 @@ describe VagrantPlugins::ProviderLibvirt::Config do
|
|
725
830
|
include(name: 'hpet'))
|
726
831
|
end
|
727
832
|
end
|
833
|
+
|
834
|
+
context 'sysinfo' do
|
835
|
+
it 'should merge' do
|
836
|
+
one.sysinfo = {
|
837
|
+
'bios' => {'vendor': 'Some Vendor'},
|
838
|
+
'system' => {'manufacturer': 'some manufacturer'},
|
839
|
+
'oem strings' => ['string 1'],
|
840
|
+
}
|
841
|
+
two.sysinfo = {
|
842
|
+
'bios' => {'vendor': 'Another Vendor'},
|
843
|
+
'system' => {'serial': 'AABBCCDDEE'},
|
844
|
+
'oem strings' => ['string 2'],
|
845
|
+
}
|
846
|
+
|
847
|
+
subject.finalize!
|
848
|
+
expect(subject.sysinfo).to eq(
|
849
|
+
'bios' => {'vendor': 'Another Vendor'},
|
850
|
+
'system' => {'manufacturer': 'some manufacturer', 'serial': 'AABBCCDDEE'},
|
851
|
+
'oem strings' => ['string 1', 'string 2'],
|
852
|
+
)
|
853
|
+
end
|
854
|
+
end
|
728
855
|
end
|
729
856
|
end
|
data/spec/unit/driver_spec.rb
CHANGED
@@ -197,7 +197,7 @@ describe VagrantPlugins::ProviderLibvirt::Driver do
|
|
197
197
|
allow(machine.provider_config).to receive(:qemu_use_session).and_return(true)
|
198
198
|
end
|
199
199
|
|
200
|
-
it 'should
|
200
|
+
it 'should retrieve the address via the system dhcp-leases API' do
|
201
201
|
expect(domain).to receive(:mac).and_return("52:54:00:8b:dc:5f")
|
202
202
|
expect(subject).to receive(:system_connection).and_return(system_connection1)
|
203
203
|
expect(system_connection1).to receive(:list_all_networks).and_return(networks)
|
@@ -0,0 +1,42 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
require 'spec_helper'
|
4
|
+
require 'support/sharedcontext'
|
5
|
+
|
6
|
+
require 'vagrant-libvirt/plugin'
|
7
|
+
|
8
|
+
|
9
|
+
describe VagrantPlugins::ProviderLibvirt::Plugin do
|
10
|
+
subject { described_class.new }
|
11
|
+
|
12
|
+
include_context 'unit'
|
13
|
+
|
14
|
+
describe '#action_hook remove_libvirt_image' do
|
15
|
+
before do
|
16
|
+
# set up some dummy boxes
|
17
|
+
box_path = File.join(env[:env].boxes.directory, 'vagrant-libvirt-VAGRANTSLASH-test', '0.0.1')
|
18
|
+
['libvirt', 'virtualbox'].each do |provider|
|
19
|
+
provider_path = File.join(box_path, provider)
|
20
|
+
FileUtils.mkdir_p(provider_path)
|
21
|
+
metadata = {'provider': provider}
|
22
|
+
File.open(File.join(provider_path, 'metadata.json'), "w") { |f| f.write metadata.to_json }
|
23
|
+
end
|
24
|
+
end
|
25
|
+
|
26
|
+
it 'should call the action hook after box remove' do
|
27
|
+
expect(VagrantPlugins::ProviderLibvirt::Action).to receive(:remove_libvirt_image).and_return(Vagrant::Action::Builder.new)
|
28
|
+
expect {
|
29
|
+
env[:env].action_runner.run(
|
30
|
+
Vagrant::Action.action_box_remove, {
|
31
|
+
box_name: 'vagrant-libvirt/test',
|
32
|
+
box_provider: 'libvirt',
|
33
|
+
box_version: '0.0.1',
|
34
|
+
force_confirm_box_remove: true,
|
35
|
+
box_remove_all_versions: false,
|
36
|
+
ui: ui,
|
37
|
+
}
|
38
|
+
)
|
39
|
+
}.to_not raise_error
|
40
|
+
end
|
41
|
+
end
|
42
|
+
end
|
@@ -23,7 +23,16 @@
|
|
23
23
|
<kernel></kernel>
|
24
24
|
<initrd></initrd>
|
25
25
|
<cmdline></cmdline>
|
26
|
+
<smbios mode='sysinfo'/>
|
26
27
|
</os>
|
28
|
+
<sysinfo type='smbios'>
|
29
|
+
<system>
|
30
|
+
<entry name='serial'>AAAAAAAA</entry>
|
31
|
+
</system>
|
32
|
+
<oemStrings>
|
33
|
+
<entry>AAAAAAAA</entry>
|
34
|
+
</oemStrings>
|
35
|
+
</sysinfo>
|
27
36
|
<features>
|
28
37
|
<acpi/>
|
29
38
|
<apic/>
|
@@ -99,7 +108,7 @@
|
|
99
108
|
</graphics>
|
100
109
|
<video>
|
101
110
|
<model type='cirrus' vram='16384' heads='1'>
|
102
|
-
|
111
|
+
<acceleration accel3d='yes'/>
|
103
112
|
</model>
|
104
113
|
</video>
|
105
114
|
<rng model='virtio'>
|
@@ -123,9 +132,9 @@
|
|
123
132
|
</hostdev>
|
124
133
|
<hostdev mode='subsystem' type='usb'>
|
125
134
|
<source startupPolicy='mandatory'>
|
126
|
-
|
127
|
-
|
128
|
-
|
135
|
+
<vendor id='0x1234'/>
|
136
|
+
<product id='0xabcd'/>
|
137
|
+
<address bus='1' device='2'/>
|
129
138
|
</source>
|
130
139
|
</hostdev>
|
131
140
|
<redirdev bus='usb' type='tcp'>
|
@@ -0,0 +1,44 @@
|
|
1
|
+
<domain type='' xmlns:qemu='http://libvirt.org/schemas/domain/qemu/1.0'>
|
2
|
+
<name></name>
|
3
|
+
<title></title>
|
4
|
+
<description></description>
|
5
|
+
<uuid></uuid>
|
6
|
+
<memory></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
|
+
</os>
|
17
|
+
<features>
|
18
|
+
<acpi/>
|
19
|
+
<apic/>
|
20
|
+
<pae/>
|
21
|
+
</features>
|
22
|
+
<clock offset='utc'>
|
23
|
+
</clock>
|
24
|
+
<devices>
|
25
|
+
<disk type='file' device='disk'>
|
26
|
+
<alias name='ua-box-volume-0'/>
|
27
|
+
<driver name='qemu' type='qcow2' cache='unsafe'/>
|
28
|
+
<source file='/var/lib/libvirt/images/test.qcow2'/>
|
29
|
+
<target dev='vda' bus='scsi'/>
|
30
|
+
</disk>
|
31
|
+
<controller type='scsi' model='virtio-scsi' index='0'/>
|
32
|
+
<serial type='pty'>
|
33
|
+
<target port='0'/>
|
34
|
+
</serial>
|
35
|
+
<console type='pty'>
|
36
|
+
<target port='0'/>
|
37
|
+
</console>
|
38
|
+
<input type='mouse' bus='ps2'/>
|
39
|
+
<graphics type='vnc' port='-1' autoport='yes' listen='127.0.0.1' keymap='en-us'/>
|
40
|
+
<video>
|
41
|
+
<model type='cirrus' vram='16384' heads='1'/>
|
42
|
+
</video>
|
43
|
+
</devices>
|
44
|
+
</domain>
|
@@ -0,0 +1,44 @@
|
|
1
|
+
<domain type='' xmlns:qemu='http://libvirt.org/schemas/domain/qemu/1.0'>
|
2
|
+
<name></name>
|
3
|
+
<title></title>
|
4
|
+
<description></description>
|
5
|
+
<uuid></uuid>
|
6
|
+
<memory></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
|
+
</os>
|
17
|
+
<features>
|
18
|
+
<acpi/>
|
19
|
+
<apic/>
|
20
|
+
<pae/>
|
21
|
+
</features>
|
22
|
+
<clock offset='utc'>
|
23
|
+
</clock>
|
24
|
+
<devices>
|
25
|
+
<disk type='file' device='disk'>
|
26
|
+
<alias name='ua-box-volume-0'/>
|
27
|
+
<driver name='qemu' type='qcow2' cache='unsafe'/>
|
28
|
+
<source file='/var/lib/libvirt/images/test.qcow2'/>
|
29
|
+
<target dev='sda' bus='scsi'/>
|
30
|
+
</disk>
|
31
|
+
<controller type='scsi' model='virtio-scsi' index='0'/>
|
32
|
+
<serial type='pty'>
|
33
|
+
<target port='0'/>
|
34
|
+
</serial>
|
35
|
+
<console type='pty'>
|
36
|
+
<target port='0'/>
|
37
|
+
</console>
|
38
|
+
<input type='mouse' bus='ps2'/>
|
39
|
+
<graphics type='vnc' port='-1' autoport='yes' listen='127.0.0.1' keymap='en-us'/>
|
40
|
+
<video>
|
41
|
+
<model type='cirrus' vram='16384' heads='1'/>
|
42
|
+
</video>
|
43
|
+
</devices>
|
44
|
+
</domain>
|