vagrant-libvirt 0.5.0 → 0.6.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/README.md +134 -23
- data/lib/vagrant-libvirt/action/clean_machine_folder.rb +4 -0
- data/lib/vagrant-libvirt/action/create_domain.rb +11 -3
- data/lib/vagrant-libvirt/action/create_domain_volume.rb +7 -2
- data/lib/vagrant-libvirt/action/create_network_interfaces.rb +8 -2
- data/lib/vagrant-libvirt/action/create_networks.rb +12 -8
- data/lib/vagrant-libvirt/action/destroy_domain.rb +2 -0
- data/lib/vagrant-libvirt/action/destroy_networks.rb +2 -0
- data/lib/vagrant-libvirt/action/forward_ports.rb +7 -5
- data/lib/vagrant-libvirt/action/halt_domain.rb +4 -34
- data/lib/vagrant-libvirt/action/handle_box_image.rb +18 -13
- data/lib/vagrant-libvirt/action/handle_storage_pool.rb +7 -1
- data/lib/vagrant-libvirt/action/is_created.rb +2 -0
- data/lib/vagrant-libvirt/action/is_running.rb +2 -0
- data/lib/vagrant-libvirt/action/is_suspended.rb +2 -0
- data/lib/vagrant-libvirt/action/message_already_created.rb +2 -0
- data/lib/vagrant-libvirt/action/message_not_created.rb +2 -0
- data/lib/vagrant-libvirt/action/message_not_running.rb +2 -0
- data/lib/vagrant-libvirt/action/message_not_suspended.rb +2 -0
- data/lib/vagrant-libvirt/action/message_will_not_destroy.rb +2 -0
- data/lib/vagrant-libvirt/action/package_domain.rb +133 -68
- data/lib/vagrant-libvirt/action/prepare_nfs_settings.rb +2 -0
- data/lib/vagrant-libvirt/action/prepare_nfs_valid_ids.rb +2 -0
- data/lib/vagrant-libvirt/action/prune_nfs_exports.rb +2 -0
- data/lib/vagrant-libvirt/action/read_mac_addresses.rb +2 -0
- data/lib/vagrant-libvirt/action/remove_libvirt_image.rb +2 -0
- data/lib/vagrant-libvirt/action/remove_stale_volume.rb +2 -0
- data/lib/vagrant-libvirt/action/resume_domain.rb +2 -0
- data/lib/vagrant-libvirt/action/set_boot_order.rb +8 -2
- data/lib/vagrant-libvirt/action/set_name_of_domain.rb +3 -1
- data/lib/vagrant-libvirt/action/share_folders.rb +2 -0
- data/lib/vagrant-libvirt/action/shutdown_domain.rb +49 -0
- data/lib/vagrant-libvirt/action/start_domain.rb +26 -17
- data/lib/vagrant-libvirt/action/suspend_domain.rb +2 -0
- data/lib/vagrant-libvirt/action/wait_till_up.rb +2 -0
- data/lib/vagrant-libvirt/action.rb +34 -4
- data/lib/vagrant-libvirt/cap/mount_9p.rb +2 -0
- data/lib/vagrant-libvirt/cap/mount_virtiofs.rb +2 -0
- data/lib/vagrant-libvirt/cap/nic_mac_addresses.rb +2 -0
- data/lib/vagrant-libvirt/cap/public_address.rb +2 -0
- data/lib/vagrant-libvirt/cap/synced_folder_9p.rb +5 -2
- data/lib/vagrant-libvirt/cap/synced_folder_virtiofs.rb +5 -2
- data/lib/vagrant-libvirt/config.rb +58 -24
- data/lib/vagrant-libvirt/driver.rb +67 -12
- data/lib/vagrant-libvirt/errors.rb +2 -0
- data/lib/vagrant-libvirt/plugin.rb +2 -0
- data/lib/vagrant-libvirt/provider.rb +2 -0
- data/lib/vagrant-libvirt/templates/domain.xml.erb +4 -2
- data/lib/vagrant-libvirt/templates/public_interface.xml.erb +1 -0
- data/lib/vagrant-libvirt/util/byte_number.rb +71 -0
- data/lib/vagrant-libvirt/util/collection.rb +2 -0
- data/lib/vagrant-libvirt/util/erb_template.rb +2 -0
- data/lib/vagrant-libvirt/util/error_codes.rb +2 -0
- data/lib/vagrant-libvirt/util/network_util.rb +3 -0
- data/lib/vagrant-libvirt/util/nfs.rb +2 -0
- data/lib/vagrant-libvirt/util/storage_util.rb +1 -0
- data/lib/vagrant-libvirt/util/timer.rb +2 -0
- data/lib/vagrant-libvirt/util/ui.rb +1 -0
- data/lib/vagrant-libvirt/util.rb +2 -0
- data/lib/vagrant-libvirt/version +1 -1
- data/lib/vagrant-libvirt/version.rb +2 -0
- data/lib/vagrant-libvirt.rb +2 -0
- data/locales/en.yml +2 -0
- data/spec/spec_helper.rb +2 -0
- data/spec/support/binding_proc.rb +2 -0
- data/spec/support/environment_helper.rb +2 -0
- data/spec/support/libvirt_context.rb +2 -0
- data/spec/support/matchers/have_file_content.rb +2 -0
- data/spec/support/sharedcontext.rb +3 -0
- data/spec/support/temporary_dir.rb +12 -0
- data/spec/unit/action/clean_machine_folder_spec.rb +16 -4
- data/spec/unit/action/create_domain_spec/additional_disks_domain.xml +61 -0
- data/spec/unit/action/create_domain_spec/default_domain.xml +55 -0
- data/spec/unit/action/create_domain_spec.rb +68 -32
- data/spec/unit/action/create_domain_volume_spec/one_disk_in_storage.xml +1 -1
- data/spec/unit/action/create_domain_volume_spec/three_disks_in_storage_disk_0.xml +1 -1
- data/spec/unit/action/create_domain_volume_spec/three_disks_in_storage_disk_1.xml +1 -1
- data/spec/unit/action/create_domain_volume_spec/three_disks_in_storage_disk_2.xml +1 -1
- data/spec/unit/action/create_domain_volume_spec.rb +10 -4
- data/spec/unit/action/destroy_domain_spec.rb +8 -2
- data/spec/unit/action/forward_ports_spec.rb +2 -0
- data/spec/unit/action/halt_domain_spec.rb +30 -57
- data/spec/unit/action/handle_box_image_spec.rb +104 -24
- data/spec/unit/action/package_domain_spec.rb +304 -0
- data/spec/unit/action/set_name_of_domain_spec.rb +2 -0
- data/spec/unit/action/shutdown_domain_spec.rb +131 -0
- data/spec/unit/action/start_domain_spec/existing.xml +62 -0
- data/spec/unit/action/start_domain_spec.rb +18 -28
- data/spec/unit/action/wait_till_up_spec.rb +2 -0
- data/spec/unit/action_spec.rb +96 -0
- data/spec/unit/config_spec.rb +56 -3
- data/spec/unit/driver_spec.rb +155 -0
- data/spec/unit/templates/domain_all_settings.xml +4 -0
- data/spec/unit/templates/domain_spec.rb +2 -0
- data/spec/unit/util/byte_number_spec.rb +28 -0
- metadata +59 -38
@@ -0,0 +1,62 @@
|
|
1
|
+
<domain type='qemu'>
|
2
|
+
<name>vagrant-libvirt_default</name>
|
3
|
+
<uuid>881a931b-0110-4d10-81aa-47a1a19f5726</uuid>
|
4
|
+
<description>Source: /home/test/vagrant-libvirt/Vagrantfile</description>
|
5
|
+
<memory unit='KiB'>2097152</memory>
|
6
|
+
<currentMemory unit='KiB'>2097152</currentMemory>
|
7
|
+
<vcpu placement='static'>2</vcpu>
|
8
|
+
<os>
|
9
|
+
<type arch='x86_64' machine='pc-i440fx-6.0'>hvm</type>
|
10
|
+
<boot dev='hd'/>
|
11
|
+
</os>
|
12
|
+
<features>
|
13
|
+
<acpi/>
|
14
|
+
<apic/>
|
15
|
+
<pae/>
|
16
|
+
</features>
|
17
|
+
<cpu mode='host-model' check='partial'/>
|
18
|
+
<clock offset='utc'/>
|
19
|
+
<on_poweroff>destroy</on_poweroff>
|
20
|
+
<on_reboot>restart</on_reboot>
|
21
|
+
<on_crash>destroy</on_crash>
|
22
|
+
<devices>
|
23
|
+
<emulator>/usr/bin/qemu-system-x86_64</emulator>
|
24
|
+
<disk type='file' device='disk'>
|
25
|
+
<driver name='qemu' type='qcow2'/>
|
26
|
+
<source file='/var/lib/libvirt/images/vagrant-libvirt_default.img'/>
|
27
|
+
<target dev='vda' bus='virtio'/>
|
28
|
+
<address type='pci' domain='0x0000' bus='0x00' slot='0x03' function='0x0'/>
|
29
|
+
</disk>
|
30
|
+
<controller type='usb' index='0' model='piix3-uhci'>
|
31
|
+
<address type='pci' domain='0x0000' bus='0x00' slot='0x01' function='0x2'/>
|
32
|
+
</controller>
|
33
|
+
<controller type='pci' index='0' model='pci-root'/>
|
34
|
+
<interface type='network'>
|
35
|
+
<mac address='52:54:00:7d:14:0e'/>
|
36
|
+
<source network='vagrant-libvirt'/>
|
37
|
+
<model type='virtio'/>
|
38
|
+
<address type='pci' domain='0x0000' bus='0x00' slot='0x05' function='0x0'/>
|
39
|
+
</interface>
|
40
|
+
<serial type='pty'>
|
41
|
+
<target type='isa-serial' port='0'>
|
42
|
+
<model name='isa-serial'/>
|
43
|
+
</target>
|
44
|
+
</serial>
|
45
|
+
<console type='pty'>
|
46
|
+
<target type='serial' port='0'/>
|
47
|
+
</console>
|
48
|
+
<input type='mouse' bus='ps2'/>
|
49
|
+
<input type='keyboard' bus='ps2'/>
|
50
|
+
<graphics type='vnc' port='-1' autoport='yes' listen='127.0.0.1' keymap='en-us'>
|
51
|
+
<listen type='address' address='127.0.0.1'/>
|
52
|
+
</graphics>
|
53
|
+
<audio id='1' type='none'/>
|
54
|
+
<video>
|
55
|
+
<model type='cirrus' vram='9216' heads='1' primary='yes'/>
|
56
|
+
<address type='pci' domain='0x0000' bus='0x00' slot='0x02' function='0x0'/>
|
57
|
+
</video>
|
58
|
+
<memballoon model='virtio'>
|
59
|
+
<address type='pci' domain='0x0000' bus='0x00' slot='0x04' function='0x0'/>
|
60
|
+
</memballoon>
|
61
|
+
</devices>
|
62
|
+
</domain>
|
@@ -1,3 +1,5 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
1
3
|
require 'spec_helper'
|
2
4
|
require 'support/sharedcontext'
|
3
5
|
require 'support/libvirt_context'
|
@@ -19,6 +21,8 @@ describe VagrantPlugins::ProviderLibvirt::Action::StartDomain do
|
|
19
21
|
let(:updated_domain_xml) { File.read(File.join(File.dirname(__FILE__), File.basename(__FILE__, '.rb'), updated_test_file)) }
|
20
22
|
|
21
23
|
describe '#call' do
|
24
|
+
let(:test_file) { 'default.xml' }
|
25
|
+
|
22
26
|
before do
|
23
27
|
allow_any_instance_of(VagrantPlugins::ProviderLibvirt::Driver)
|
24
28
|
.to receive(:connection).and_return(connection)
|
@@ -28,23 +32,29 @@ describe VagrantPlugins::ProviderLibvirt::Action::StartDomain do
|
|
28
32
|
allow(connection).to receive(:servers).and_return(servers)
|
29
33
|
allow(servers).to receive(:get).and_return(domain)
|
30
34
|
|
35
|
+
allow(logger).to receive(:debug)
|
31
36
|
expect(logger).to receive(:info)
|
32
37
|
expect(ui).to_not receive(:error)
|
38
|
+
|
39
|
+
allow(libvirt_domain).to receive(:xml_desc).and_return(domain_xml)
|
40
|
+
|
41
|
+
allow(libvirt_domain).to receive(:max_memory).and_return(512*1024)
|
42
|
+
allow(libvirt_domain).to receive(:num_vcpus).and_return(1)
|
33
43
|
end
|
34
44
|
|
35
|
-
|
36
|
-
|
45
|
+
it 'should execute without changing' do
|
46
|
+
allow(libvirt_domain).to receive(:undefine)
|
47
|
+
expect(libvirt_domain).to receive(:autostart=)
|
48
|
+
expect(domain).to receive(:start)
|
37
49
|
|
38
|
-
|
39
|
-
|
50
|
+
expect(subject.call(env)).to be_nil
|
51
|
+
end
|
40
52
|
|
41
|
-
|
42
|
-
|
43
|
-
end
|
53
|
+
context 'when previously running default config' do
|
54
|
+
let(:test_file) { 'existing.xml' }
|
44
55
|
|
45
56
|
it 'should execute without changing' do
|
46
57
|
allow(libvirt_domain).to receive(:undefine)
|
47
|
-
expect(logger).to_not receive(:debug)
|
48
58
|
expect(libvirt_domain).to receive(:autostart=)
|
49
59
|
expect(domain).to receive(:start)
|
50
60
|
|
@@ -53,15 +63,6 @@ describe VagrantPlugins::ProviderLibvirt::Action::StartDomain do
|
|
53
63
|
end
|
54
64
|
|
55
65
|
context 'tpm' do
|
56
|
-
let(:test_file) { 'default.xml' }
|
57
|
-
|
58
|
-
before do
|
59
|
-
allow(libvirt_domain).to receive(:xml_desc).and_return(domain_xml)
|
60
|
-
|
61
|
-
allow(libvirt_domain).to receive(:max_memory).and_return(512*1024)
|
62
|
-
allow(libvirt_domain).to receive(:num_vcpus).and_return(1)
|
63
|
-
end
|
64
|
-
|
65
66
|
context 'passthrough tpm added' do
|
66
67
|
let(:updated_test_file) { 'default_added_tpm_path.xml' }
|
67
68
|
let(:vagrantfile_providerconfig) do
|
@@ -116,7 +117,6 @@ describe VagrantPlugins::ProviderLibvirt::Action::StartDomain do
|
|
116
117
|
end
|
117
118
|
|
118
119
|
it 'should execute without changing' do
|
119
|
-
expect(logger).to_not receive(:debug)
|
120
120
|
expect(libvirt_domain).to receive(:autostart=)
|
121
121
|
expect(domain).to receive(:start)
|
122
122
|
|
@@ -136,7 +136,6 @@ describe VagrantPlugins::ProviderLibvirt::Action::StartDomain do
|
|
136
136
|
end
|
137
137
|
|
138
138
|
it 'should execute without changing' do
|
139
|
-
expect(logger).to_not receive(:debug)
|
140
139
|
expect(libvirt_domain).to receive(:autostart=)
|
141
140
|
expect(domain).to receive(:start)
|
142
141
|
|
@@ -170,13 +169,6 @@ describe VagrantPlugins::ProviderLibvirt::Action::StartDomain do
|
|
170
169
|
context 'clock_timers' do
|
171
170
|
let(:test_file) { 'clock_timer_rtc.xml' }
|
172
171
|
|
173
|
-
before do
|
174
|
-
allow(libvirt_domain).to receive(:xml_desc).and_return(domain_xml)
|
175
|
-
|
176
|
-
allow(libvirt_domain).to receive(:max_memory).and_return(512*1024)
|
177
|
-
allow(libvirt_domain).to receive(:num_vcpus).and_return(1)
|
178
|
-
end
|
179
|
-
|
180
172
|
context 'timers unchanged' do
|
181
173
|
let(:vagrantfile_providerconfig) do
|
182
174
|
<<-EOF
|
@@ -214,8 +206,6 @@ describe VagrantPlugins::ProviderLibvirt::Action::StartDomain do
|
|
214
206
|
end
|
215
207
|
|
216
208
|
context 'timers removed' do
|
217
|
-
let(:updated_test_file) { 'default.xml' }
|
218
|
-
|
219
209
|
it 'should modify the domain' do
|
220
210
|
expect(libvirt_domain).to receive(:undefine)
|
221
211
|
expect(logger).to receive(:debug).with('clock timers config changed')
|
@@ -0,0 +1,96 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
require 'spec_helper'
|
4
|
+
require 'support/sharedcontext'
|
5
|
+
|
6
|
+
require 'vagrant/action/runner'
|
7
|
+
|
8
|
+
require 'vagrant-libvirt/action'
|
9
|
+
|
10
|
+
|
11
|
+
describe VagrantPlugins::ProviderLibvirt::Action do
|
12
|
+
subject { described_class }
|
13
|
+
|
14
|
+
include_context 'libvirt'
|
15
|
+
include_context 'unit'
|
16
|
+
|
17
|
+
let(:libvirt_domain) { double('libvirt_domain') }
|
18
|
+
let(:runner) { Vagrant::Action::Runner.new(env) }
|
19
|
+
let(:state) { double('state') }
|
20
|
+
|
21
|
+
before do
|
22
|
+
allow_any_instance_of(VagrantPlugins::ProviderLibvirt::Driver)
|
23
|
+
.to receive(:connection).and_return(connection)
|
24
|
+
allow(machine).to receive(:id).and_return('test-machine-id')
|
25
|
+
allow(machine).to receive(:state).and_return(state)
|
26
|
+
|
27
|
+
allow(logger).to receive(:info)
|
28
|
+
allow(logger).to receive(:debug)
|
29
|
+
allow(logger).to receive(:error)
|
30
|
+
end
|
31
|
+
|
32
|
+
def allow_action_env_result(action, *responses)
|
33
|
+
results = responses.dup
|
34
|
+
|
35
|
+
allow_any_instance_of(action).to receive(:call) do |cls, env|
|
36
|
+
app = cls.instance_variable_get(:@app)
|
37
|
+
|
38
|
+
env[:result] = results[0]
|
39
|
+
if results.length > 1
|
40
|
+
results.shift
|
41
|
+
end
|
42
|
+
|
43
|
+
app.call(env)
|
44
|
+
end
|
45
|
+
end
|
46
|
+
|
47
|
+
describe '#action_halt' do
|
48
|
+
context 'not created' do
|
49
|
+
before do
|
50
|
+
expect(state).to receive(:id).and_return(:not_created)
|
51
|
+
end
|
52
|
+
|
53
|
+
it 'should execute without error' do
|
54
|
+
expect(ui).to receive(:info).with('Domain is not created. Please run `vagrant up` first.')
|
55
|
+
|
56
|
+
expect { runner.run(subject.action_halt) }.not_to raise_error
|
57
|
+
end
|
58
|
+
end
|
59
|
+
|
60
|
+
context 'running' do
|
61
|
+
before do
|
62
|
+
allow_action_env_result(VagrantPlugins::ProviderLibvirt::Action::IsCreated, true)
|
63
|
+
allow_action_env_result(VagrantPlugins::ProviderLibvirt::Action::IsSuspended, false)
|
64
|
+
allow_action_env_result(VagrantPlugins::ProviderLibvirt::Action::IsRunning, true)
|
65
|
+
end
|
66
|
+
|
67
|
+
context 'when shutdown domain works' do
|
68
|
+
before do
|
69
|
+
allow_action_env_result(VagrantPlugins::ProviderLibvirt::Action::ShutdownDomain, true)
|
70
|
+
allow_action_env_result(Vagrant::Action::Builtin::GracefulHalt, true)
|
71
|
+
allow_action_env_result(VagrantPlugins::ProviderLibvirt::Action::IsRunning, true, false)
|
72
|
+
end
|
73
|
+
|
74
|
+
it 'should skip calling HaltDomain' do
|
75
|
+
expect(ui).to_not receive(:info).with('Domain is not created. Please run `vagrant up` first.')
|
76
|
+
expect_any_instance_of(VagrantPlugins::ProviderLibvirt::Action::HaltDomain).to_not receive(:call)
|
77
|
+
|
78
|
+
expect { runner.run(subject.action_halt) }.not_to raise_error
|
79
|
+
end
|
80
|
+
end
|
81
|
+
|
82
|
+
context 'when shutdown domain fails' do
|
83
|
+
before do
|
84
|
+
allow_action_env_result(VagrantPlugins::ProviderLibvirt::Action::ShutdownDomain, false)
|
85
|
+
allow_action_env_result(Vagrant::Action::Builtin::GracefulHalt, false)
|
86
|
+
end
|
87
|
+
|
88
|
+
it 'should call halt' do
|
89
|
+
expect_any_instance_of(VagrantPlugins::ProviderLibvirt::Action::HaltDomain).to receive(:call)
|
90
|
+
|
91
|
+
expect { runner.run(subject.action_halt) }.not_to raise_error
|
92
|
+
end
|
93
|
+
end
|
94
|
+
end
|
95
|
+
end
|
96
|
+
end
|
data/spec/unit/config_spec.rb
CHANGED
@@ -1,3 +1,5 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
1
3
|
require 'support/binding_proc'
|
2
4
|
|
3
5
|
require 'spec_helper'
|
@@ -190,14 +192,14 @@ describe VagrantPlugins::ProviderLibvirt::Config do
|
|
190
192
|
],
|
191
193
|
[ # when username explicitly set without ssh
|
192
194
|
{:username => 'my_user' },
|
193
|
-
{:uri => 'qemu:///system'},
|
195
|
+
{:uri => 'qemu:///system', :username => 'my_user'},
|
194
196
|
{
|
195
197
|
:env => {'LIBVIRT_DEFAULT_URI' => 'qemu://session'},
|
196
198
|
}
|
197
199
|
],
|
198
200
|
[ # when username explicitly set with host but without ssh
|
199
201
|
{:username => 'my_user', :host => 'remote'},
|
200
|
-
{:uri => 'qemu://remote/system'},
|
202
|
+
{:uri => 'qemu://remote/system', :username => 'my_user'},
|
201
203
|
{
|
202
204
|
:env => {'LIBVIRT_DEFAULT_URI' => 'qemu://session'},
|
203
205
|
}
|
@@ -358,6 +360,10 @@ describe VagrantPlugins::ProviderLibvirt::Config do
|
|
358
360
|
{:connect_via_ssh => true, :host => 'remote', :username => 'myuser'},
|
359
361
|
"ssh 'remote' -l 'myuser' -W %h:%p",
|
360
362
|
],
|
363
|
+
[ # remote contains port
|
364
|
+
{:connect_via_ssh => true, :host => 'remote:2222'},
|
365
|
+
"ssh 'remote' -p 2222 -W %h:%p",
|
366
|
+
],
|
361
367
|
[ # include user and default ssh key exists
|
362
368
|
{:connect_via_ssh => true, :host => 'remote', :username => 'myuser'},
|
363
369
|
"ssh 'remote' -l 'myuser' -i '/home/tests/.ssh/id_rsa' -W %h:%p",
|
@@ -390,7 +396,6 @@ describe VagrantPlugins::ProviderLibvirt::Config do
|
|
390
396
|
[
|
391
397
|
{:uri => 'qemu+ssh://remote/system?keyfile=/some/path/to/keyfile'},
|
392
398
|
"ssh 'remote' -i '/some/path/to/keyfile' -W %h:%p",
|
393
|
-
{:allow_failure => "keyfile not yet inferred from uri"},
|
394
399
|
],
|
395
400
|
|
396
401
|
# provide custom template
|
@@ -430,6 +435,54 @@ describe VagrantPlugins::ProviderLibvirt::Config do
|
|
430
435
|
end
|
431
436
|
end
|
432
437
|
end
|
438
|
+
|
439
|
+
context '@usbctl_dev' do
|
440
|
+
it 'should be empty by default' do
|
441
|
+
subject.finalize!
|
442
|
+
|
443
|
+
expect(subject.usbctl_dev).to eq({})
|
444
|
+
end
|
445
|
+
|
446
|
+
context 'when usb devices added' do
|
447
|
+
it 'should inject a default controller' do
|
448
|
+
subject.usb :vendor => '0x1234', :product => '0xabcd'
|
449
|
+
|
450
|
+
subject.finalize!
|
451
|
+
|
452
|
+
expect(subject.usbctl_dev).to eq({:model => 'qemu-xhci'})
|
453
|
+
end
|
454
|
+
|
455
|
+
context 'when user specified a controller' do
|
456
|
+
it 'should retain the user setting' do
|
457
|
+
subject.usb :vendor => '0x1234', :product => '0xabcd'
|
458
|
+
subject.usb_controller :model => 'pii3-uchi'
|
459
|
+
|
460
|
+
subject.finalize!
|
461
|
+
expect(subject.usbctl_dev).to eq({:model => 'pii3-uchi'})
|
462
|
+
end
|
463
|
+
end
|
464
|
+
end
|
465
|
+
|
466
|
+
context 'when redirdevs entries added' do
|
467
|
+
it 'should inject a default controller' do
|
468
|
+
subject.redirdev :type => 'spicevmc'
|
469
|
+
|
470
|
+
subject.finalize!
|
471
|
+
|
472
|
+
expect(subject.usbctl_dev).to eq({:model => 'qemu-xhci'})
|
473
|
+
end
|
474
|
+
|
475
|
+
context 'when user specified a controller' do
|
476
|
+
it 'should retain the user setting' do
|
477
|
+
subject.redirdev :type => 'spicevmc'
|
478
|
+
subject.usb_controller :model => 'pii3-uchi'
|
479
|
+
|
480
|
+
subject.finalize!
|
481
|
+
expect(subject.usbctl_dev).to eq({:model => 'pii3-uchi'})
|
482
|
+
end
|
483
|
+
end
|
484
|
+
end
|
485
|
+
end
|
433
486
|
end
|
434
487
|
|
435
488
|
def assert_invalid
|
@@ -0,0 +1,155 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
require 'spec_helper'
|
4
|
+
require 'support/binding_proc'
|
5
|
+
require 'support/sharedcontext'
|
6
|
+
|
7
|
+
require 'vagrant-libvirt/driver'
|
8
|
+
|
9
|
+
describe VagrantPlugins::ProviderLibvirt::Driver do
|
10
|
+
include_context 'unit'
|
11
|
+
|
12
|
+
subject { described_class.new(machine) }
|
13
|
+
|
14
|
+
let(:vagrantfile) do
|
15
|
+
<<-EOF
|
16
|
+
Vagrant.configure('2') do |config|
|
17
|
+
config.vm.define :test1 do |node|
|
18
|
+
node.vm.provider :libvirt do |domain|
|
19
|
+
domain.uri = "qemu+ssh://user@remote1/system"
|
20
|
+
end
|
21
|
+
end
|
22
|
+
config.vm.define :test2 do |node|
|
23
|
+
node.vm.provider :libvirt do |domain|
|
24
|
+
domain.uri = "qemu+ssh://vms@remote2/system"
|
25
|
+
end
|
26
|
+
end
|
27
|
+
end
|
28
|
+
EOF
|
29
|
+
end
|
30
|
+
# need to override the default package iso_env as using a different
|
31
|
+
# name for the test machines above.
|
32
|
+
let(:machine) { iso_env.machine(:test1, :libvirt) }
|
33
|
+
let(:machine2) { iso_env.machine(:test2, :libvirt) }
|
34
|
+
let(:connection1) { double("connection 1") }
|
35
|
+
let(:connection2) { double("connection 2") }
|
36
|
+
let(:system_connection1) { double("system connection 1") }
|
37
|
+
let(:system_connection2) { double("system connection 2") }
|
38
|
+
|
39
|
+
describe '#connection' do
|
40
|
+
it 'should configure a separate connection per machine' do
|
41
|
+
expect(Fog::Compute).to receive(:new).with(
|
42
|
+
hash_including({:libvirt_uri => 'qemu+ssh://user@remote1/system'})).and_return(connection1)
|
43
|
+
expect(Fog::Compute).to receive(:new).with(
|
44
|
+
hash_including({:libvirt_uri => 'qemu+ssh://vms@remote2/system'})).and_return(connection2)
|
45
|
+
|
46
|
+
expect(machine.provider.driver.connection).to eq(connection1)
|
47
|
+
expect(machine2.provider.driver.connection).to eq(connection2)
|
48
|
+
end
|
49
|
+
|
50
|
+
it 'should configure the connection once' do
|
51
|
+
expect(Fog::Compute).to receive(:new).once().and_return(connection1)
|
52
|
+
|
53
|
+
expect(machine.provider.driver.connection).to eq(connection1)
|
54
|
+
expect(machine.provider.driver.connection).to eq(connection1)
|
55
|
+
expect(machine.provider.driver.connection).to eq(connection1)
|
56
|
+
end
|
57
|
+
end
|
58
|
+
|
59
|
+
describe '#system_connection' do
|
60
|
+
# note that the urls for the two tests are currently
|
61
|
+
# incorrect here as they should be the following:
|
62
|
+
# qemu+ssh://user@remote1/system
|
63
|
+
# qemu+ssh://vms@remote2/system
|
64
|
+
#
|
65
|
+
# In that the system uri should be resolved based on
|
66
|
+
# the provider uri so that for:
|
67
|
+
# uri => qemu+ssh://user@remote1/session
|
68
|
+
# system_uri should be 'qemu+ssh://user@remote1/system'
|
69
|
+
# and not 'qemu:///system'.
|
70
|
+
it 'should configure a separate connection per machine' do
|
71
|
+
expect(Libvirt).to receive(:open).with('qemu:///system').and_return(system_connection1)
|
72
|
+
expect(Libvirt).to receive(:open).with('qemu:///system').and_return(system_connection2)
|
73
|
+
|
74
|
+
expect(machine.provider.driver.system_connection).to eq(system_connection1)
|
75
|
+
expect(machine2.provider.driver.system_connection).to eq(system_connection2)
|
76
|
+
end
|
77
|
+
|
78
|
+
it 'should configure the connection once' do
|
79
|
+
expect(Libvirt).to receive(:open).with('qemu:///system').and_return(system_connection1)
|
80
|
+
|
81
|
+
expect(machine.provider.driver.system_connection).to eq(system_connection1)
|
82
|
+
expect(machine.provider.driver.system_connection).to eq(system_connection1)
|
83
|
+
expect(machine.provider.driver.system_connection).to eq(system_connection1)
|
84
|
+
end
|
85
|
+
end
|
86
|
+
|
87
|
+
describe '#state' do
|
88
|
+
let(:domain) { double('domain') }
|
89
|
+
|
90
|
+
before do
|
91
|
+
allow(subject).to receive(:get_domain).and_return(domain)
|
92
|
+
end
|
93
|
+
|
94
|
+
[
|
95
|
+
[
|
96
|
+
'not found',
|
97
|
+
:not_created,
|
98
|
+
{
|
99
|
+
:setup => ProcWithBinding.new do
|
100
|
+
expect(subject).to receive(:get_domain).and_return(nil)
|
101
|
+
end,
|
102
|
+
}
|
103
|
+
],
|
104
|
+
[
|
105
|
+
'libvirt error',
|
106
|
+
:not_created,
|
107
|
+
{
|
108
|
+
:setup => ProcWithBinding.new do
|
109
|
+
expect(subject).to receive(:get_domain).and_raise(Libvirt::RetrieveError, 'missing')
|
110
|
+
end,
|
111
|
+
}
|
112
|
+
],
|
113
|
+
[
|
114
|
+
'terminated',
|
115
|
+
:not_created,
|
116
|
+
{
|
117
|
+
:setup => ProcWithBinding.new do
|
118
|
+
expect(domain).to receive(:state).and_return('terminated')
|
119
|
+
end,
|
120
|
+
}
|
121
|
+
],
|
122
|
+
[
|
123
|
+
'no IP returned',
|
124
|
+
:inaccessible,
|
125
|
+
{
|
126
|
+
:setup => ProcWithBinding.new do
|
127
|
+
expect(domain).to receive(:state).and_return('running').twice()
|
128
|
+
expect(subject).to receive(:get_domain_ipaddress).and_raise(Fog::Errors::TimeoutError)
|
129
|
+
end,
|
130
|
+
}
|
131
|
+
],
|
132
|
+
[
|
133
|
+
'running',
|
134
|
+
:running,
|
135
|
+
{
|
136
|
+
:setup => ProcWithBinding.new do
|
137
|
+
expect(domain).to receive(:state).and_return('running').twice()
|
138
|
+
expect(subject).to receive(:get_domain_ipaddress).and_return('192.168.121.2')
|
139
|
+
end,
|
140
|
+
}
|
141
|
+
],
|
142
|
+
].each do |name, expected, options|
|
143
|
+
opts = {}
|
144
|
+
opts.merge!(options) if options
|
145
|
+
|
146
|
+
it "should handle '#{name}' by returning '#{expected}'" do
|
147
|
+
if !opts[:setup].nil?
|
148
|
+
opts[:setup].apply_binding(binding)
|
149
|
+
end
|
150
|
+
|
151
|
+
expect(subject.state(machine)).to eq(expected)
|
152
|
+
end
|
153
|
+
end
|
154
|
+
end
|
155
|
+
end
|
@@ -44,21 +44,25 @@
|
|
44
44
|
<devices>
|
45
45
|
<emulator>/usr/bin/kvm-spice</emulator>
|
46
46
|
<disk type='file' device='disk'>
|
47
|
+
<alias name='ua-box-volume-0'/>
|
47
48
|
<driver name='qemu' type='qcow2' cache='unsafe' io='threads' copy_on_read='on' discard='unmap' detect_zeroes='on'/>
|
48
49
|
<source file='/var/lib/libvirt/images/test.qcow2'/>
|
49
50
|
<target dev='vda' bus='ide'/>
|
50
51
|
</disk>
|
51
52
|
<disk type='file' device='disk'>
|
53
|
+
<alias name='ua-box-volume-1'/>
|
52
54
|
<driver name='qemu' type='qcow2' cache='unsafe' io='threads' copy_on_read='on' discard='unmap' detect_zeroes='on'/>
|
53
55
|
<source file='/var/lib/libvirt/images/test2.qcow2'/>
|
54
56
|
<target dev='vdb' bus='ide'/>
|
55
57
|
</disk>
|
56
58
|
<disk type='file' device='disk'>
|
59
|
+
<alias name='ua-disk-volume-0'/>
|
57
60
|
<driver name='qemu' type='qcow2' cache='default'/>
|
58
61
|
<source file='/var/lib/libvirt/images/test-disk1.qcow2'/>
|
59
62
|
<target dev='vdb' bus='virtio'/>
|
60
63
|
</disk>
|
61
64
|
<disk type='file' device='disk'>
|
65
|
+
<alias name='ua-disk-volume-1'/>
|
62
66
|
<driver name='qemu' type='qcow2' cache='default' io='threads' copy_on_read='on' discard='unmap' detect_zeroes='on'/>
|
63
67
|
<source file='/var/lib/libvirt/images/test-disk2.qcow2'/>
|
64
68
|
<target dev='vdc' bus='virtio'/>
|
@@ -0,0 +1,28 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
require 'spec_helper'
|
4
|
+
|
5
|
+
require 'vagrant-libvirt/util/byte_number'
|
6
|
+
|
7
|
+
|
8
|
+
describe ByteNumber do
|
9
|
+
describe '#ByteNumber to Gigrabyte' do
|
10
|
+
it 'should return bigger size' do
|
11
|
+
expect( ByteNumber.new("10737423360").to_GB).to eq(11)
|
12
|
+
expect( ByteNumber.new("737423360").to_GB).to eq(1)
|
13
|
+
expect( ByteNumber.new("110737423360").to_GB).to eq(104)
|
14
|
+
end
|
15
|
+
end
|
16
|
+
|
17
|
+
describe '#ByteNumber from Gigrabyte' do
|
18
|
+
it 'should convert' do
|
19
|
+
expect( ByteNumber.from_GB(5).to_i).to eq(5368709120)
|
20
|
+
end
|
21
|
+
end
|
22
|
+
|
23
|
+
describe '#ByteNumber pow' do
|
24
|
+
it 'should be work like interger' do
|
25
|
+
expect( ByteNumber.new(5).pow(5).to_i).to eq(5**5)
|
26
|
+
end
|
27
|
+
end
|
28
|
+
end
|