vagrant-libvirt 0.10.8 → 0.11.2

Sign up to get free protection for your applications and to get access to all the features.
Files changed (115) hide show
  1. checksums.yaml +4 -4
  2. data/README.md +44 -7
  3. data/lib/vagrant-libvirt/action/create_domain.rb +45 -22
  4. data/lib/vagrant-libvirt/action/create_domain_volume.rb +3 -0
  5. data/lib/vagrant-libvirt/action/create_network_interfaces.rb +15 -6
  6. data/lib/vagrant-libvirt/action/create_networks.rb +2 -6
  7. data/lib/vagrant-libvirt/action/destroy_domain.rb +2 -10
  8. data/lib/vagrant-libvirt/action/forward_ports.rb +1 -1
  9. data/lib/vagrant-libvirt/action/is_suspended.rb +2 -2
  10. data/lib/vagrant-libvirt/action/prepare_nfs_settings.rb +7 -5
  11. data/lib/vagrant-libvirt/action/resolve_disk_settings.rb +2 -0
  12. data/lib/vagrant-libvirt/action/resume_domain.rb +3 -1
  13. data/lib/vagrant-libvirt/action/snapshot_delete.rb +1 -1
  14. data/lib/vagrant-libvirt/action/snapshot_restore.rb +1 -1
  15. data/lib/vagrant-libvirt/action/snapshot_save.rb +1 -2
  16. data/lib/vagrant-libvirt/action/start_domain.rb +149 -62
  17. data/lib/vagrant-libvirt/action/wait_till_up.rb +2 -2
  18. data/lib/vagrant-libvirt/action.rb +18 -13
  19. data/lib/vagrant-libvirt/cap/mount_9p.rb +9 -1
  20. data/lib/vagrant-libvirt/cap/snapshots.rb +1 -1
  21. data/lib/vagrant-libvirt/config.rb +198 -26
  22. data/lib/vagrant-libvirt/driver.rb +94 -55
  23. data/lib/vagrant-libvirt/provider.rb +4 -4
  24. data/lib/vagrant-libvirt/templates/domain.xml.erb +73 -27
  25. data/lib/vagrant-libvirt/templates/public_interface.xml.erb +6 -3
  26. data/lib/vagrant-libvirt/util/network_util.rb +5 -10
  27. data/lib/vagrant-libvirt/version +1 -1
  28. data/locales/en.yml +4 -0
  29. data/spec/acceptance/additional_storage_spec.rb +1 -4
  30. data/spec/acceptance/networking_spec.rb +41 -0
  31. data/spec/acceptance/package_domain_spec.rb +2 -2
  32. data/spec/acceptance/provider_settings_spec.rb +1 -1
  33. data/spec/acceptance/simple_vm_provision_via_shell_spec.rb +1 -1
  34. data/spec/acceptance/snapshots_spec.rb +1 -1
  35. data/spec/acceptance/two_disks_spec.rb +1 -1
  36. data/spec/acceptance/use_qemu_agent_for_connectivity_spec.rb +1 -1
  37. data/spec/spec_helper.rb +31 -8
  38. data/spec/support/acceptance/isolated_environment.rb +1 -1
  39. data/spec/support/environment_helper.rb +1 -1
  40. data/spec/support/libvirt_acceptance_context.rb +15 -1
  41. data/spec/support/{sharedcontext.rb → unit_context.rb} +20 -5
  42. data/spec/unit/action/clean_machine_folder_spec.rb +1 -2
  43. data/spec/unit/action/cleanup_on_failure_spec.rb +1 -2
  44. data/spec/unit/action/create_domain_spec/additional_disks_domain.xml +4 -2
  45. data/spec/unit/action/create_domain_spec/custom_disk_settings.xml +4 -2
  46. data/spec/unit/action/create_domain_spec/default_domain.xml +4 -2
  47. data/spec/unit/action/create_domain_spec/sysinfo.xml +4 -2
  48. data/spec/unit/action/create_domain_spec/sysinfo_only_required.xml +4 -2
  49. data/spec/unit/action/create_domain_spec/two_disk_settings.xml +4 -2
  50. data/spec/unit/action/create_domain_spec.rb +51 -3
  51. data/spec/unit/action/create_domain_volume_spec.rb +2 -4
  52. data/spec/unit/action/destroy_domain_spec/additional_disks_domain.xml +1 -0
  53. data/spec/unit/action/destroy_domain_spec/box_multiple_disks.xml +1 -0
  54. data/spec/unit/action/destroy_domain_spec/box_multiple_disks_and_additional_and_custom_disks.xml +1 -0
  55. data/spec/unit/action/destroy_domain_spec/box_multiple_disks_and_additional_and_custom_disks_no_aliases.xml +1 -0
  56. data/spec/unit/action/destroy_domain_spec/box_multiple_disks_and_additional_disks.xml +1 -0
  57. data/spec/unit/action/destroy_domain_spec/cdrom_domain.xml +1 -0
  58. data/spec/unit/action/destroy_domain_spec.rb +1 -18
  59. data/spec/unit/action/forward_ports_spec.rb +1 -3
  60. data/spec/unit/action/halt_domain_spec.rb +2 -3
  61. data/spec/unit/action/handle_box_image_spec.rb +3 -4
  62. data/spec/unit/action/package_domain_spec.rb +2 -3
  63. data/spec/unit/action/prepare_nfs_settings_spec.rb +25 -9
  64. data/spec/unit/action/remove_libvirt_image_spec.rb +1 -2
  65. data/spec/unit/action/resolve_disk_settings_spec/default_domain.xml +1 -0
  66. data/spec/unit/action/resolve_disk_settings_spec/default_no_aliases.xml +1 -0
  67. data/spec/unit/action/resolve_disk_settings_spec/multi_volume_box.xml +1 -0
  68. data/spec/unit/action/resolve_disk_settings_spec/multi_volume_box_additional_and_custom_no_aliases.xml +1 -0
  69. data/spec/unit/action/resolve_disk_settings_spec/multi_volume_box_additional_storage.xml +1 -0
  70. data/spec/unit/action/resolve_disk_settings_spec.rb +1 -1
  71. data/spec/unit/action/resume_domain_spec.rb +66 -0
  72. data/spec/unit/action/set_boot_order_spec/default.xml +1 -0
  73. data/spec/unit/action/set_boot_order_spec/explicit_boot_order.xml +1 -0
  74. data/spec/unit/action/set_boot_order_spec.rb +1 -3
  75. data/spec/unit/action/set_name_of_domain_spec.rb +3 -1
  76. data/spec/unit/action/shutdown_domain_spec.rb +4 -3
  77. data/spec/unit/action/start_domain_spec/clock_timer_removed.xml +1 -1
  78. data/spec/unit/action/start_domain_spec/clock_timer_rtc.xml +1 -1
  79. data/spec/unit/action/start_domain_spec/clock_timer_rtc_tsc.xml +1 -1
  80. data/spec/unit/action/start_domain_spec/default.xml +1 -1
  81. data/spec/unit/action/start_domain_spec/default_added_tpm_path.xml +1 -1
  82. data/spec/unit/action/start_domain_spec/default_added_tpm_version.xml +1 -1
  83. data/spec/unit/action/start_domain_spec/default_with_different_formatting.xml +1 -1
  84. data/spec/unit/action/start_domain_spec/existing.xml +2 -1
  85. data/spec/unit/action/start_domain_spec/existing_added_nvram.xml +2 -1
  86. data/spec/unit/action/start_domain_spec/existing_reordered.xml +2 -1
  87. data/spec/unit/action/start_domain_spec/nvram_domain.xml +1 -0
  88. data/spec/unit/action/start_domain_spec/nvram_domain_other_setting.xml +2 -1
  89. data/spec/unit/action/start_domain_spec/nvram_domain_removed.xml +2 -1
  90. data/spec/unit/action/start_domain_spec.rb +192 -3
  91. data/spec/unit/action/wait_till_up_spec.rb +3 -5
  92. data/spec/unit/action_spec.rb +403 -10
  93. data/spec/unit/cap/mount_9p_spec.rb +75 -0
  94. data/spec/unit/cap/synced_folder_9p_spec.rb +1 -2
  95. data/spec/unit/cap/synced_folder_virtiofs_spec.rb +1 -2
  96. data/spec/unit/config_spec.rb +365 -25
  97. data/spec/unit/driver_spec.rb +217 -80
  98. data/spec/unit/plugin_spec.rb +6 -3
  99. data/spec/unit/templates/domain_all_settings.xml +26 -4
  100. data/spec/unit/templates/domain_cpu_mode_passthrough.xml +4 -2
  101. data/spec/unit/templates/domain_custom_cpu_model.xml +4 -2
  102. data/spec/unit/templates/domain_defaults.xml +4 -2
  103. data/spec/unit/templates/domain_scsi_bus_storage.xml +4 -2
  104. data/spec/unit/templates/domain_scsi_device_storage.xml +4 -2
  105. data/spec/unit/templates/domain_scsi_multiple_controllers_storage.xml +4 -2
  106. data/spec/unit/templates/domain_spec.rb +11 -3
  107. data/spec/unit/templates/tpm/version_1.2.xml +4 -2
  108. data/spec/unit/templates/tpm/version_2.0.xml +4 -2
  109. data/spec/unit/util/byte_number_spec.rb +1 -1
  110. data/spec/unit/util/network_util_spec/default.xml +16 -0
  111. data/spec/unit/util/network_util_spec/hostdev.xml +6 -0
  112. data/spec/unit/util/network_util_spec/vagrant-libvirt.xml +16 -0
  113. data/spec/unit/util/network_util_spec.rb +59 -0
  114. data/spec/unit/util/resolvers_spec.rb +1 -1
  115. metadata +87 -73
@@ -1,10 +1,9 @@
1
1
  # frozen_string_literal: true
2
2
 
3
- require 'fog/libvirt/requests/compute/dhcp_leases'
3
+ require_relative '../spec_helper'
4
+ require_relative '../support/binding_proc'
4
5
 
5
- require 'spec_helper'
6
- require 'support/binding_proc'
7
- require 'support/sharedcontext'
6
+ require 'fog/libvirt/requests/compute/dhcp_leases'
8
7
 
9
8
  require 'vagrant-libvirt/driver'
10
9
 
@@ -14,87 +13,94 @@ describe VagrantPlugins::ProviderLibvirt::Driver do
14
13
 
15
14
  subject { described_class.new(machine) }
16
15
 
17
- let(:vagrantfile) do
18
- <<-EOF
19
- Vagrant.configure('2') do |config|
20
- config.vm.define :test1 do |node|
21
- node.vm.provider :libvirt do |domain|
22
- domain.uri = "qemu+ssh://user@remote1/system"
23
- end
24
- end
25
- config.vm.define :test2 do |node|
26
- node.vm.provider :libvirt do |domain|
27
- domain.uri = "qemu+ssh://vms@remote2/system"
28
- end
29
- end
30
- end
31
- EOF
32
- end
33
-
34
- # need to override the default package iso_env as using a different
35
- # name for the test machines above.
36
- let(:machine) { iso_env.machine(:test1, :libvirt) }
37
- let(:machine2) { iso_env.machine(:test2, :libvirt) }
38
- let(:connection1) { double("connection 1") }
39
- let(:connection2) { double("connection 2") }
40
- let(:system_connection1) { double("system connection 1") }
41
- let(:system_connection2) { double("system connection 2") }
42
-
43
16
  # make it easier for distros that want to switch the default value for
44
17
  # qemu_use_session to true by ensuring it is explicitly false for tests.
45
18
  before do
46
19
  allow(machine.provider_config).to receive(:qemu_use_session).and_return(false)
47
20
  allow(logger).to receive(:info)
48
21
  allow(logger).to receive(:debug)
49
- allow(machine.provider).to receive('driver').and_call_original
50
- allow(machine2.provider).to receive('driver').and_call_original
51
22
  end
52
23
 
53
- describe '#connection' do
54
- it 'should configure a separate connection per machine' do
55
- expect(Fog::Compute).to receive(:new).with(
56
- hash_including({:libvirt_uri => 'qemu+ssh://user@remote1/system'})).and_return(connection1)
57
- expect(Fog::Compute).to receive(:new).with(
58
- hash_including({:libvirt_uri => 'qemu+ssh://vms@remote2/system'})).and_return(connection2)
24
+ describe 'connections' do
25
+ let(:vagrantfile) do
26
+ <<-EOF
27
+ Vagrant.configure('2') do |config|
28
+ config.vm.define :test1 do |node|
29
+ node.vm.provider :libvirt do |domain|
30
+ domain.uri = "qemu+ssh://user@remote1/system"
31
+ end
32
+ end
33
+ config.vm.define :test2 do |node|
34
+ node.vm.provider :libvirt do |domain|
35
+ domain.uri = "qemu+ssh://vms@remote2/system"
36
+ end
37
+ end
38
+ end
39
+ EOF
40
+ end
59
41
 
60
- expect(machine.provider.driver.connection).to eq(connection1)
61
- expect(machine2.provider.driver.connection).to eq(connection2)
42
+ # need to override the default package iso_env as using a different
43
+ # name for the test machines above.
44
+ let(:machine) { iso_env.machine(:test1, :libvirt) }
45
+ let(:machine2) { iso_env.machine(:test2, :libvirt) }
46
+ let(:connection1) { double("connection 1") }
47
+ let(:connection2) { double("connection 2") }
48
+ let(:system_connection1) { double("system connection 1") }
49
+ let(:system_connection2) { double("system connection 2") }
50
+
51
+ # make it easier for distros that want to switch the default value for
52
+ # qemu_use_session to true by ensuring it is explicitly false for tests.
53
+ before do
54
+ allow(machine.provider).to receive('driver').and_call_original
55
+ allow(machine2.provider).to receive('driver').and_call_original
62
56
  end
63
57
 
64
- it 'should configure the connection once' do
65
- expect(Fog::Compute).to receive(:new).once().and_return(connection1)
58
+ describe '#connection' do
59
+ it 'should configure a separate connection per machine' do
60
+ expect(Fog::Compute).to receive(:new).with(
61
+ hash_including({:libvirt_uri => 'qemu+ssh://user@remote1/system'})).and_return(connection1)
62
+ expect(Fog::Compute).to receive(:new).with(
63
+ hash_including({:libvirt_uri => 'qemu+ssh://vms@remote2/system'})).and_return(connection2)
66
64
 
67
- expect(machine.provider.driver.connection).to eq(connection1)
68
- expect(machine.provider.driver.connection).to eq(connection1)
69
- expect(machine.provider.driver.connection).to eq(connection1)
70
- end
71
- end
65
+ expect(machine.provider.driver.connection).to eq(connection1)
66
+ expect(machine2.provider.driver.connection).to eq(connection2)
67
+ end
72
68
 
73
- describe '#system_connection' do
74
- # note that the urls for the two tests are currently
75
- # incorrect here as they should be the following:
76
- # qemu+ssh://user@remote1/system
77
- # qemu+ssh://vms@remote2/system
78
- #
79
- # In that the system uri should be resolved based on
80
- # the provider uri so that for:
81
- # uri => qemu+ssh://user@remote1/session
82
- # system_uri should be 'qemu+ssh://user@remote1/system'
83
- # and not 'qemu:///system'.
84
- it 'should configure a separate connection per machine' do
85
- expect(Libvirt).to receive(:open_read_only).with('qemu+ssh://user@remote1/system').and_return(system_connection1)
86
- expect(Libvirt).to receive(:open_read_only).with('qemu+ssh://vms@remote2/system').and_return(system_connection2)
87
-
88
- expect(machine.provider.driver.system_connection).to eq(system_connection1)
89
- expect(machine2.provider.driver.system_connection).to eq(system_connection2)
69
+ it 'should configure the connection once' do
70
+ expect(Fog::Compute).to receive(:new).once().and_return(connection1)
71
+
72
+ expect(machine.provider.driver.connection).to eq(connection1)
73
+ expect(machine.provider.driver.connection).to eq(connection1)
74
+ expect(machine.provider.driver.connection).to eq(connection1)
75
+ end
90
76
  end
91
77
 
92
- it 'should configure the connection once' do
93
- expect(Libvirt).to receive(:open_read_only).with('qemu+ssh://user@remote1/system').and_return(system_connection1)
78
+ describe '#system_connection' do
79
+ # note that the urls for the two tests are currently
80
+ # incorrect here as they should be the following:
81
+ # qemu+ssh://user@remote1/system
82
+ # qemu+ssh://vms@remote2/system
83
+ #
84
+ # In that the system uri should be resolved based on
85
+ # the provider uri so that for:
86
+ # uri => qemu+ssh://user@remote1/session
87
+ # system_uri should be 'qemu+ssh://user@remote1/system'
88
+ # and not 'qemu:///system'.
89
+ it 'should configure a separate connection per machine' do
90
+ expect(Libvirt).to receive(:open_read_only).with('qemu+ssh://user@remote1/system').and_return(system_connection1)
91
+ expect(Libvirt).to receive(:open_read_only).with('qemu+ssh://vms@remote2/system').and_return(system_connection2)
92
+
93
+ expect(machine.provider.driver.system_connection).to eq(system_connection1)
94
+ expect(machine2.provider.driver.system_connection).to eq(system_connection2)
95
+ end
96
+
97
+ it 'should configure the connection once' do
98
+ expect(Libvirt).to receive(:open_read_only).with('qemu+ssh://user@remote1/system').and_return(system_connection1)
94
99
 
95
- expect(machine.provider.driver.system_connection).to eq(system_connection1)
96
- expect(machine.provider.driver.system_connection).to eq(system_connection1)
97
- expect(machine.provider.driver.system_connection).to eq(system_connection1)
100
+ expect(machine.provider.driver.system_connection).to eq(system_connection1)
101
+ expect(machine.provider.driver.system_connection).to eq(system_connection1)
102
+ expect(machine.provider.driver.system_connection).to eq(system_connection1)
103
+ end
98
104
  end
99
105
  end
100
106
 
@@ -114,7 +120,7 @@ describe VagrantPlugins::ProviderLibvirt::Driver do
114
120
  # ideally should be able to yield a block to wait_for and check that
115
121
  # the 'addresses' function on the domain is called correctly.
116
122
  expect(domain).to receive(:wait_for).and_return(nil)
117
- expect(subject.get_ipaddress(machine)).to eq(nil)
123
+ expect(subject.get_ipaddress).to eq(nil)
118
124
  end
119
125
 
120
126
  context 'when qemu_use_agent is enabled' do
@@ -159,7 +165,7 @@ describe VagrantPlugins::ProviderLibvirt::Driver do
159
165
  expect(libvirt_domain).to receive(:qemu_agent_command).and_return(qemu_agent_interfaces)
160
166
  expect(domain).to receive(:mac).and_return("52:54:00:f8:67:98").exactly(2).times
161
167
 
162
- expect(subject.get_ipaddress(machine)).to eq("192.168.122.42")
168
+ expect(subject.get_ipaddress).to eq("192.168.122.42")
163
169
  end
164
170
 
165
171
  context 'when qemu_use_session is enabled' do
@@ -173,13 +179,14 @@ describe VagrantPlugins::ProviderLibvirt::Driver do
173
179
  expect(libvirt_domain).to receive(:qemu_agent_command).and_return(qemu_agent_interfaces)
174
180
  expect(domain).to receive(:mac).and_return("52:54:00:f8:67:98").exactly(2).times
175
181
 
176
- expect(subject.get_ipaddress(machine)).to eq("192.168.122.42")
182
+ expect(subject.get_ipaddress).to eq("192.168.122.42")
177
183
  end
178
184
  end
179
185
  end
180
186
 
181
187
  context 'when qemu_use_session is enabled' do
182
- let(:networks) { [instance_double(::Fog::Libvirt::Compute::Real)] }
188
+ let(:system_connection) { double("system connection") }
189
+ let(:networks) { [instance_double(::Libvirt::Network)] }
183
190
  let(:dhcp_leases) {
184
191
  {
185
192
  "iface" =>"virbr0",
@@ -199,11 +206,10 @@ describe VagrantPlugins::ProviderLibvirt::Driver do
199
206
 
200
207
  it 'should retrieve the address via the system dhcp-leases API' do
201
208
  expect(domain).to receive(:mac).and_return("52:54:00:8b:dc:5f")
202
- expect(subject).to receive(:system_connection).and_return(system_connection1)
203
- expect(system_connection1).to receive(:list_all_networks).and_return(networks)
209
+ expect(subject).to receive(:list_all_networks).and_return(networks)
204
210
  expect(networks[0]).to receive(:dhcp_leases).and_return([dhcp_leases])
205
211
 
206
- expect(subject.get_ipaddress(machine)).to eq("192.168.122.43")
212
+ expect(subject.get_ipaddress).to eq("192.168.122.43")
207
213
  end
208
214
 
209
215
  context 'when qemu_use_agent is enabled' do
@@ -214,13 +220,144 @@ describe VagrantPlugins::ProviderLibvirt::Driver do
214
220
  it 'should retrieve the address via the agent' do
215
221
  expect(subject).to receive(:get_ipaddress_from_qemu_agent).and_return("192.168.122.44")
216
222
 
217
- expect(subject.get_ipaddress(machine)).to eq("192.168.122.44")
223
+ expect(subject.get_ipaddress).to eq("192.168.122.44")
218
224
  end
219
225
  end
220
226
  end
221
227
  end
222
228
  end
223
229
 
230
+
231
+ describe '#list_all_networks' do
232
+ let(:vagrantfile_providerconfig) do
233
+ <<-EOF
234
+ libvirt.uri = "qemu:///system"
235
+ EOF
236
+ end
237
+
238
+ let(:libvirt_networks) { [
239
+ instance_double(::Libvirt::Network),
240
+ instance_double(::Libvirt::Network),
241
+ instance_double(::Libvirt::Network),
242
+ ] }
243
+
244
+ before do
245
+ allow(subject).to receive(:connection).and_return(connection)
246
+ allow(connection).to receive(:client).and_return(libvirt_client)
247
+ expect(libvirt_client).to receive(:list_all_networks).and_return(libvirt_networks)
248
+ end
249
+
250
+ it 'should list networks' do
251
+ expect(libvirt_networks[0]).to receive(:bridge_name).and_return('')
252
+ expect(libvirt_networks[1]).to receive(:bridge_name).and_return('virbr0')
253
+ expect(libvirt_networks[2]).to receive(:bridge_name).and_return('virbr1')
254
+
255
+ expect(subject.list_all_networks).to eq(libvirt_networks)
256
+ end
257
+
258
+ it 'should skip networks missing bridge_name' do
259
+ expect(libvirt_networks[0]).to receive(:bridge_name).and_return('')
260
+ expect(libvirt_networks[1]).to receive(:bridge_name).and_raise(Libvirt::Error)
261
+ expect(libvirt_networks[1]).to receive(:name).and_return('bad_network')
262
+ expect(libvirt_networks[2]).to receive(:bridge_name).and_return('virbr1')
263
+
264
+ expect(subject.list_all_networks).to eq([libvirt_networks[0], libvirt_networks[2]])
265
+ end
266
+ end
267
+
268
+ describe '#host_devices' do
269
+ let(:vagrantfile_providerconfig) do
270
+ <<-EOF
271
+ libvirt.uri = "qemu:///system"
272
+ EOF
273
+ end
274
+
275
+ let(:ip_link_show) {
276
+ JSON.dump(
277
+ [
278
+ # trimmed element details of what would be returned by 'ip -j link show'
279
+ { "ifindex": 1, "ifname": "lo", "group": "default", "link_type": "loopback"},
280
+ { "ifindex": 2, "ifname": "eth0", "group": "default", "link_type": "ether"},
281
+ { "ifindex": 3, "ifname": "eth1", "group": "default", "link_type": "ether"},
282
+ { "ifindex": 4, "ifname": "virbr0", "group": "default", "link_type": "ether"},
283
+ ]
284
+ )
285
+ }
286
+
287
+ let(:libvirt_interfaces) { [
288
+ instance_double(Libvirt::Interface),
289
+ instance_double(Libvirt::Interface),
290
+ ] }
291
+ let(:libvirt_networks) { [
292
+ instance_double(Libvirt::Network),
293
+ instance_double(Libvirt::Network),
294
+ ] }
295
+
296
+ before do
297
+ allow(subject).to receive(:connection).and_return(connection)
298
+
299
+ allow(Vagrant::Util::Subprocess).to receive(:execute) do |*arr|
300
+ expect(arr[0]).to eq('ip')
301
+ end.and_return(Vagrant::Util::Subprocess::Result.new(exit_code=0, stdout=ip_link_show, stderr=''))
302
+
303
+ expect(libvirt_client).to receive(:list_all_interfaces).and_return(libvirt_interfaces)
304
+ expect(subject).to receive(:list_all_networks).and_return(libvirt_networks)
305
+ expect(libvirt_interfaces[0]).to receive(:name).and_return('eth0')
306
+ expect(libvirt_interfaces[1]).to receive(:name).and_return('virbr0')
307
+ expect(libvirt_networks[0]).to receive(:bridge_name).and_return('')
308
+ expect(libvirt_networks[1]).to receive(:bridge_name).and_return('virbr0')
309
+ end
310
+
311
+ it 'should query system and libvirt' do
312
+ expect(subject.host_devices).to eq(['lo', 'eth0', 'eth1', 'virbr0'])
313
+ end
314
+
315
+ it 'should handle empty string' do
316
+ expect(machine.provider_config).to receive(:proxy_command).and_return('').twice
317
+
318
+ expect(subject.host_devices).to eq(['lo', 'eth0', 'eth1', 'virbr0'])
319
+ end
320
+
321
+ it 'should cache the result' do
322
+ expect(machine.provider_config).to receive(:proxy_command).and_return(nil).once
323
+
324
+ expect(subject.host_devices).to eq(['lo', 'eth0', 'eth1', 'virbr0'])
325
+ expect(subject.host_devices).to eq(['lo', 'eth0', 'eth1', 'virbr0'])
326
+ end
327
+
328
+ context 'when libvirt is remote' do
329
+ let(:vagrantfile_providerconfig) do
330
+ <<-EOF
331
+ libvirt.uri = "qemu+ssh://remote-server/system"
332
+ EOF
333
+ end
334
+
335
+ before do
336
+ allow(machine.provider_config).to receive(:proxy_command).and_return('ssh remote-server -W %h:%p')
337
+ end
338
+
339
+ it 'should use ssh for ip link' do
340
+ expect(Vagrant::Util::Subprocess).to receive(:execute) do |*arr|
341
+ expect(arr[0..3]).to eq(['ssh', 'remote-server', 'ip', '-j'])
342
+ end.and_return(Vagrant::Util::Subprocess::Result.new(exit_code=0, stdout=ip_link_show, stderr=''))
343
+
344
+ expect(subject.host_devices).to eq(['lo', 'eth0', 'eth1', 'virbr0'])
345
+ end
346
+
347
+ it 'should construct the ssh command with all options when needed' do
348
+ machine.provider_config.port = 2022
349
+ machine.provider_config.username = 'remote-user'
350
+ machine.provider_config.id_ssh_key_file = 'my-key-file'
351
+
352
+ expect(Vagrant::Util::Subprocess).to receive(:execute) do |*arr|
353
+ expect(arr[0..9]).to eq(['ssh', 'remote-server', '-p', '2022', '-l', 'remote-user', '-i', 'my-key-file', 'ip', '-j'])
354
+ end.and_return(Vagrant::Util::Subprocess::Result.new(exit_code=0, stdout=ip_link_show, stderr=''))
355
+
356
+ expect(subject.host_devices).to eq(['lo', 'eth0', 'eth1', 'virbr0'])
357
+ end
358
+ end
359
+ end
360
+
224
361
  describe '#state' do
225
362
  let(:domain) { double('domain') }
226
363
 
@@ -271,7 +408,7 @@ describe VagrantPlugins::ProviderLibvirt::Driver do
271
408
  {
272
409
  :setup => ProcWithBinding.new do
273
410
  expect(domain).to receive(:state).and_return('running').at_least(:once)
274
- expect(subject).to receive(:get_domain_ipaddress).and_raise(Fog::Errors::TimeoutError)
411
+ expect(subject).to receive(:get_ipaddress).and_raise(Fog::Errors::TimeoutError)
275
412
  end,
276
413
  }
277
414
  ],
@@ -281,7 +418,7 @@ describe VagrantPlugins::ProviderLibvirt::Driver do
281
418
  {
282
419
  :setup => ProcWithBinding.new do
283
420
  expect(domain).to receive(:state).and_return('running').at_least(:once)
284
- expect(subject).to receive(:get_domain_ipaddress).and_return('192.168.121.2')
421
+ expect(subject).to receive(:get_ipaddress).and_return('192.168.121.2')
285
422
  end,
286
423
  }
287
424
  ],
@@ -294,7 +431,7 @@ describe VagrantPlugins::ProviderLibvirt::Driver do
294
431
  opts[:setup].apply_binding(binding)
295
432
  end
296
433
 
297
- expect(subject.state(machine)).to eq(expected)
434
+ expect(subject.state).to eq(expected)
298
435
  end
299
436
  end
300
437
  end
@@ -1,10 +1,11 @@
1
1
  # frozen_string_literal: true
2
2
 
3
- require 'spec_helper'
4
- require 'support/sharedcontext'
3
+ require_relative '../spec_helper'
5
4
 
6
5
  require 'vagrant-libvirt'
7
6
  require 'vagrant-libvirt/plugin'
7
+ require 'vagrant-libvirt/action'
8
+ require 'vagrant-libvirt/action/remove_libvirt_image'
8
9
 
9
10
 
10
11
  describe VagrantPlugins::ProviderLibvirt::Plugin do
@@ -25,7 +26,9 @@ describe VagrantPlugins::ProviderLibvirt::Plugin do
25
26
  end
26
27
 
27
28
  it 'should call the action hook after box remove' do
28
- expect(VagrantPlugins::ProviderLibvirt::Action).to receive(:remove_libvirt_image).and_return(Vagrant::Action::Builder.new)
29
+ expect_any_instance_of(VagrantPlugins::ProviderLibvirt::Action::RemoveLibvirtImage).to receive(:call) do |cls, env|
30
+ cls.instance_variable_get(:@app).call(env)
31
+ end
29
32
  expect {
30
33
  env[:env].action_runner.run(
31
34
  Vagrant::Action.action_box_remove, {
@@ -13,7 +13,12 @@
13
13
  <numatune>
14
14
  <memory nodeset='1-4,^3,6'/>
15
15
  </numatune>
16
+ <memtune>
17
+ <hard_limit unit='KiB'>250000</hard_limit>
18
+ <soft_limit unit='KiB'>200000</soft_limit>
19
+ </memtune>
16
20
  <cputune>
21
+ <vcpupin vcpu="0" cpuset="0" />
17
22
  <shares>1024</shares>
18
23
  </cputune>
19
24
  <os>
@@ -53,24 +58,35 @@
53
58
  <driver name='qemu' type='qcow2' cache='unsafe' io='threads' copy_on_read='on' discard='unmap' detect_zeroes='on'/>
54
59
  <source file='/var/lib/libvirt/images/test.qcow2'/>
55
60
  <target dev='vda' bus='ide'/>
61
+ <address type='virtio-mmio'/>
56
62
  </disk>
57
63
  <disk type='file' device='disk'>
58
64
  <alias name='ua-box-volume-1'/>
59
65
  <driver name='qemu' type='qcow2' cache='unsafe' io='threads' copy_on_read='on' discard='unmap' detect_zeroes='on'/>
60
66
  <source file='/var/lib/libvirt/images/test2.qcow2'/>
61
67
  <target dev='vdb' bus='ide'/>
68
+ <address type='virtio-mmio'/>
62
69
  </disk>
63
70
  <disk type='file' device='disk'>
64
71
  <alias name='ua-disk-volume-0'/>
65
72
  <driver name='qemu' type='qcow2' cache='default'/>
66
73
  <source file='/var/lib/libvirt/images/test-disk1.qcow2'/>
67
74
  <target dev='vdc' bus='virtio'/>
75
+ <address type='virtio-mmio'/>
68
76
  </disk>
69
77
  <disk type='file' device='disk'>
70
78
  <alias name='ua-disk-volume-1'/>
71
79
  <driver name='qemu' type='qcow2' cache='default' io='threads' copy_on_read='on' discard='unmap' detect_zeroes='on'/>
72
80
  <source file='/var/lib/libvirt/images/test-disk2.qcow2'/>
73
81
  <target dev='vdd' bus='virtio'/>
82
+ <address type='virtio-mmio'/>
83
+ </disk>
84
+ <disk type='file' device='disk'>
85
+ <alias name='ua-disk-volume-2'/>
86
+ <driver name='qemu' type='qcow2' cache='default'/>
87
+ <source file='/var/lib/libvirt/images/test-disk3.qcow2'/>
88
+ <target dev='vde' bus='virtio'/>
89
+ <address type='pci'/>
74
90
  </disk>
75
91
  <disk type='file' device='cdrom'>
76
92
  <driver name='qemu' type='raw' />
@@ -84,6 +100,10 @@
84
100
  <target dev='hdb' bus='ide'/>
85
101
  <readonly/>
86
102
  </disk>
103
+ <disk type='file' device='floppy'>
104
+ <source file=''/>
105
+ <target dev='fda' bus='fdc'/>
106
+ </disk>
87
107
  <serial type='file'>
88
108
  <source path='/var/log/vm_consoles/machine.log'/>
89
109
  <target port='0'/>
@@ -102,12 +122,13 @@
102
122
  <source path='/tmp/foo'/>
103
123
  <target type='guestfwd' address='192.0.2.42' port='4242'/>
104
124
  </channel>
105
- <input type='mouse' bus='ps2'/>
106
- <graphics type='vnc' port='-1' autoport='yes' listen='127.0.0.1' keymap='en-us'>
125
+ <input type='mouse' bus='ps2'>
126
+ </input>
127
+ <graphics type='vnc' port='-1' autoport='yes' websocket='-1' listen='127.0.0.1' keymap='en-us'>
107
128
  <gl enable='yes'/>
108
129
  </graphics>
109
130
  <video>
110
- <model type='cirrus' vram='16384' heads='1'>
131
+ <model type='virtio' vram='16384' heads='1'>
111
132
  <acceleration accel3d='yes'/>
112
133
  </model>
113
134
  </video>
@@ -149,7 +170,8 @@
149
170
  <device path='/dev/tpm0'/>
150
171
  </backend>
151
172
  </tpm>
152
- <controller type='usb' model='nec-xhci' ports="4" />
173
+ <controller type='usb' model='nec-xhci' ports="4" >
174
+ </controller>
153
175
  </devices>
154
176
  <qemu:commandline>
155
177
  <qemu:arg value='-device'/>
@@ -12,6 +12,7 @@
12
12
  </cpu>
13
13
  <os>
14
14
  <type>hvm</type>
15
+ <bootmenu enable='no'/>
15
16
  <kernel></kernel>
16
17
  <initrd></initrd>
17
18
  <cmdline></cmdline>
@@ -30,8 +31,9 @@
30
31
  <console type='pty'>
31
32
  <target port='0'/>
32
33
  </console>
33
- <input type='mouse' bus='ps2'/>
34
- <graphics type='vnc' port='-1' autoport='yes' listen='127.0.0.1' keymap='en-us'/>
34
+ <input type='mouse' bus='ps2'>
35
+ </input>
36
+ <graphics type='vnc' port='-1' autoport='yes' websocket='-1' listen='127.0.0.1' keymap='en-us'/>
35
37
  <video>
36
38
  <model type='cirrus' vram='16384' heads='1'/>
37
39
  </video>
@@ -10,6 +10,7 @@
10
10
  </cpu>
11
11
  <os>
12
12
  <type>hvm</type>
13
+ <bootmenu enable='no'/>
13
14
  <kernel></kernel>
14
15
  <initrd></initrd>
15
16
  <cmdline></cmdline>
@@ -28,8 +29,9 @@
28
29
  <console type='pty'>
29
30
  <target port='0'/>
30
31
  </console>
31
- <input type='mouse' bus='ps2'/>
32
- <graphics type='vnc' port='-1' autoport='yes' listen='127.0.0.1' keymap='en-us'/>
32
+ <input type='mouse' bus='ps2'>
33
+ </input>
34
+ <graphics type='vnc' port='-1' autoport='yes' websocket='-1' listen='127.0.0.1' keymap='en-us'/>
33
35
  <video>
34
36
  <model type='cirrus' vram='16384' heads='1'/>
35
37
  </video>
@@ -10,6 +10,7 @@
10
10
  </cpu>
11
11
  <os>
12
12
  <type>hvm</type>
13
+ <bootmenu enable='no'/>
13
14
  <kernel></kernel>
14
15
  <initrd></initrd>
15
16
  <cmdline></cmdline>
@@ -28,8 +29,9 @@
28
29
  <console type='pty'>
29
30
  <target port='0'/>
30
31
  </console>
31
- <input type='mouse' bus='ps2'/>
32
- <graphics type='vnc' port='-1' autoport='yes' listen='127.0.0.1' keymap='en-us'/>
32
+ <input type='mouse' bus='ps2'>
33
+ </input>
34
+ <graphics type='vnc' port='-1' autoport='yes' websocket='-1' listen='127.0.0.1' keymap='en-us'/>
33
35
  <video>
34
36
  <model type='cirrus' vram='16384' heads='1'/>
35
37
  </video>
@@ -10,6 +10,7 @@
10
10
  </cpu>
11
11
  <os>
12
12
  <type>hvm</type>
13
+ <bootmenu enable='no'/>
13
14
  <kernel></kernel>
14
15
  <initrd></initrd>
15
16
  <cmdline></cmdline>
@@ -35,8 +36,9 @@
35
36
  <console type='pty'>
36
37
  <target port='0'/>
37
38
  </console>
38
- <input type='mouse' bus='ps2'/>
39
- <graphics type='vnc' port='-1' autoport='yes' listen='127.0.0.1' keymap='en-us'/>
39
+ <input type='mouse' bus='ps2'>
40
+ </input>
41
+ <graphics type='vnc' port='-1' autoport='yes' websocket='-1' listen='127.0.0.1' keymap='en-us'/>
40
42
  <video>
41
43
  <model type='cirrus' vram='16384' heads='1'/>
42
44
  </video>
@@ -10,6 +10,7 @@
10
10
  </cpu>
11
11
  <os>
12
12
  <type>hvm</type>
13
+ <bootmenu enable='no'/>
13
14
  <kernel></kernel>
14
15
  <initrd></initrd>
15
16
  <cmdline></cmdline>
@@ -35,8 +36,9 @@
35
36
  <console type='pty'>
36
37
  <target port='0'/>
37
38
  </console>
38
- <input type='mouse' bus='ps2'/>
39
- <graphics type='vnc' port='-1' autoport='yes' listen='127.0.0.1' keymap='en-us'/>
39
+ <input type='mouse' bus='ps2'>
40
+ </input>
41
+ <graphics type='vnc' port='-1' autoport='yes' websocket='-1' listen='127.0.0.1' keymap='en-us'/>
40
42
  <video>
41
43
  <model type='cirrus' vram='16384' heads='1'/>
42
44
  </video>
@@ -10,6 +10,7 @@
10
10
  </cpu>
11
11
  <os>
12
12
  <type>hvm</type>
13
+ <bootmenu enable='no'/>
13
14
  <kernel></kernel>
14
15
  <initrd></initrd>
15
16
  <cmdline></cmdline>
@@ -121,8 +122,9 @@
121
122
  <console type='pty'>
122
123
  <target port='0'/>
123
124
  </console>
124
- <input type='mouse' bus='ps2'/>
125
- <graphics type='vnc' port='-1' autoport='yes' listen='127.0.0.1' keymap='en-us'/>
125
+ <input type='mouse' bus='ps2'>
126
+ </input>
127
+ <graphics type='vnc' port='-1' autoport='yes' websocket='-1' listen='127.0.0.1' keymap='en-us'/>
126
128
  <video>
127
129
  <model type='cirrus' vram='16384' heads='1'/>
128
130
  </video>