vagrant-libvirt 0.10.8 → 0.11.1

Sign up to get free protection for your applications and to get access to all the features.
Files changed (112) 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 -5
  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/prepare_nfs_settings.rb +7 -5
  10. data/lib/vagrant-libvirt/action/resolve_disk_settings.rb +2 -0
  11. data/lib/vagrant-libvirt/action/snapshot_delete.rb +1 -1
  12. data/lib/vagrant-libvirt/action/snapshot_restore.rb +1 -1
  13. data/lib/vagrant-libvirt/action/snapshot_save.rb +1 -2
  14. data/lib/vagrant-libvirt/action/start_domain.rb +149 -62
  15. data/lib/vagrant-libvirt/action/wait_till_up.rb +2 -2
  16. data/lib/vagrant-libvirt/action.rb +18 -13
  17. data/lib/vagrant-libvirt/cap/mount_9p.rb +9 -1
  18. data/lib/vagrant-libvirt/cap/snapshots.rb +1 -1
  19. data/lib/vagrant-libvirt/config.rb +198 -26
  20. data/lib/vagrant-libvirt/driver.rb +94 -55
  21. data/lib/vagrant-libvirt/provider.rb +4 -4
  22. data/lib/vagrant-libvirt/templates/domain.xml.erb +73 -27
  23. data/lib/vagrant-libvirt/templates/public_interface.xml.erb +6 -3
  24. data/lib/vagrant-libvirt/util/network_util.rb +5 -10
  25. data/lib/vagrant-libvirt/version +1 -1
  26. data/locales/en.yml +2 -0
  27. data/spec/acceptance/additional_storage_spec.rb +1 -4
  28. data/spec/acceptance/networking_spec.rb +41 -0
  29. data/spec/acceptance/package_domain_spec.rb +2 -2
  30. data/spec/acceptance/provider_settings_spec.rb +1 -1
  31. data/spec/acceptance/simple_vm_provision_via_shell_spec.rb +1 -1
  32. data/spec/acceptance/snapshots_spec.rb +1 -1
  33. data/spec/acceptance/two_disks_spec.rb +1 -1
  34. data/spec/acceptance/use_qemu_agent_for_connectivity_spec.rb +1 -1
  35. data/spec/spec_helper.rb +31 -8
  36. data/spec/support/acceptance/isolated_environment.rb +1 -1
  37. data/spec/support/environment_helper.rb +1 -1
  38. data/spec/support/libvirt_acceptance_context.rb +15 -1
  39. data/spec/support/{sharedcontext.rb → unit_context.rb} +20 -5
  40. data/spec/unit/action/clean_machine_folder_spec.rb +1 -2
  41. data/spec/unit/action/cleanup_on_failure_spec.rb +1 -2
  42. data/spec/unit/action/create_domain_spec/additional_disks_domain.xml +4 -2
  43. data/spec/unit/action/create_domain_spec/custom_disk_settings.xml +4 -2
  44. data/spec/unit/action/create_domain_spec/default_domain.xml +4 -2
  45. data/spec/unit/action/create_domain_spec/sysinfo.xml +4 -2
  46. data/spec/unit/action/create_domain_spec/sysinfo_only_required.xml +4 -2
  47. data/spec/unit/action/create_domain_spec/two_disk_settings.xml +4 -2
  48. data/spec/unit/action/create_domain_spec.rb +51 -3
  49. data/spec/unit/action/create_domain_volume_spec.rb +2 -4
  50. data/spec/unit/action/destroy_domain_spec/additional_disks_domain.xml +1 -0
  51. data/spec/unit/action/destroy_domain_spec/box_multiple_disks.xml +1 -0
  52. data/spec/unit/action/destroy_domain_spec/box_multiple_disks_and_additional_and_custom_disks.xml +1 -0
  53. data/spec/unit/action/destroy_domain_spec/box_multiple_disks_and_additional_and_custom_disks_no_aliases.xml +1 -0
  54. data/spec/unit/action/destroy_domain_spec/box_multiple_disks_and_additional_disks.xml +1 -0
  55. data/spec/unit/action/destroy_domain_spec/cdrom_domain.xml +1 -0
  56. data/spec/unit/action/destroy_domain_spec.rb +1 -18
  57. data/spec/unit/action/forward_ports_spec.rb +1 -3
  58. data/spec/unit/action/halt_domain_spec.rb +2 -3
  59. data/spec/unit/action/handle_box_image_spec.rb +3 -4
  60. data/spec/unit/action/package_domain_spec.rb +2 -3
  61. data/spec/unit/action/prepare_nfs_settings_spec.rb +25 -9
  62. data/spec/unit/action/remove_libvirt_image_spec.rb +1 -2
  63. data/spec/unit/action/resolve_disk_settings_spec/default_domain.xml +1 -0
  64. data/spec/unit/action/resolve_disk_settings_spec/default_no_aliases.xml +1 -0
  65. data/spec/unit/action/resolve_disk_settings_spec/multi_volume_box.xml +1 -0
  66. data/spec/unit/action/resolve_disk_settings_spec/multi_volume_box_additional_and_custom_no_aliases.xml +1 -0
  67. data/spec/unit/action/resolve_disk_settings_spec/multi_volume_box_additional_storage.xml +1 -0
  68. data/spec/unit/action/resolve_disk_settings_spec.rb +1 -1
  69. data/spec/unit/action/set_boot_order_spec/default.xml +1 -0
  70. data/spec/unit/action/set_boot_order_spec/explicit_boot_order.xml +1 -0
  71. data/spec/unit/action/set_boot_order_spec.rb +1 -3
  72. data/spec/unit/action/set_name_of_domain_spec.rb +3 -1
  73. data/spec/unit/action/shutdown_domain_spec.rb +4 -3
  74. data/spec/unit/action/start_domain_spec/clock_timer_removed.xml +1 -1
  75. data/spec/unit/action/start_domain_spec/clock_timer_rtc.xml +1 -1
  76. data/spec/unit/action/start_domain_spec/clock_timer_rtc_tsc.xml +1 -1
  77. data/spec/unit/action/start_domain_spec/default.xml +1 -1
  78. data/spec/unit/action/start_domain_spec/default_added_tpm_path.xml +1 -1
  79. data/spec/unit/action/start_domain_spec/default_added_tpm_version.xml +1 -1
  80. data/spec/unit/action/start_domain_spec/default_with_different_formatting.xml +1 -1
  81. data/spec/unit/action/start_domain_spec/existing.xml +2 -1
  82. data/spec/unit/action/start_domain_spec/existing_added_nvram.xml +2 -1
  83. data/spec/unit/action/start_domain_spec/existing_reordered.xml +2 -1
  84. data/spec/unit/action/start_domain_spec/nvram_domain.xml +1 -0
  85. data/spec/unit/action/start_domain_spec/nvram_domain_other_setting.xml +2 -1
  86. data/spec/unit/action/start_domain_spec/nvram_domain_removed.xml +2 -1
  87. data/spec/unit/action/start_domain_spec.rb +192 -3
  88. data/spec/unit/action/wait_till_up_spec.rb +3 -5
  89. data/spec/unit/action_spec.rb +403 -10
  90. data/spec/unit/cap/mount_9p_spec.rb +75 -0
  91. data/spec/unit/cap/synced_folder_9p_spec.rb +1 -2
  92. data/spec/unit/cap/synced_folder_virtiofs_spec.rb +1 -2
  93. data/spec/unit/config_spec.rb +365 -25
  94. data/spec/unit/driver_spec.rb +217 -80
  95. data/spec/unit/plugin_spec.rb +6 -3
  96. data/spec/unit/templates/domain_all_settings.xml +26 -4
  97. data/spec/unit/templates/domain_cpu_mode_passthrough.xml +4 -2
  98. data/spec/unit/templates/domain_custom_cpu_model.xml +4 -2
  99. data/spec/unit/templates/domain_defaults.xml +4 -2
  100. data/spec/unit/templates/domain_scsi_bus_storage.xml +4 -2
  101. data/spec/unit/templates/domain_scsi_device_storage.xml +4 -2
  102. data/spec/unit/templates/domain_scsi_multiple_controllers_storage.xml +4 -2
  103. data/spec/unit/templates/domain_spec.rb +11 -3
  104. data/spec/unit/templates/tpm/version_1.2.xml +4 -2
  105. data/spec/unit/templates/tpm/version_2.0.xml +4 -2
  106. data/spec/unit/util/byte_number_spec.rb +1 -1
  107. data/spec/unit/util/network_util_spec/default.xml +16 -0
  108. data/spec/unit/util/network_util_spec/hostdev.xml +6 -0
  109. data/spec/unit/util/network_util_spec/vagrant-libvirt.xml +16 -0
  110. data/spec/unit/util/network_util_spec.rb +59 -0
  111. data/spec/unit/util/resolvers_spec.rb +1 -1
  112. metadata +85 -73
@@ -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>
@@ -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>
@@ -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>
@@ -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>
@@ -1,6 +1,6 @@
1
1
  # frozen_string_literal: true
2
2
 
3
- require 'spec_helper'
3
+ require_relative '../../spec_helper'
4
4
 
5
5
  require 'fog/libvirt/models/compute/volume'
6
6
 
@@ -7,6 +7,7 @@
7
7
  <vcpu placement="static">2</vcpu>
8
8
  <os>
9
9
  <type arch="x86_64" machine="pc-i440fx-6.0">hvm</type>
10
+ <bootmenu enable="yes"/>
10
11
  <boot dev="hd"/>
11
12
  </os>
12
13
  <features>
@@ -8,6 +8,7 @@
8
8
  <vcpu placement="static">2</vcpu>
9
9
  <os>
10
10
  <type arch="x86_64" machine="pc-i440fx-6.0">hvm</type>
11
+ <bootmenu enable="yes"/>
11
12
 
12
13
  </os>
13
14
  <features>
@@ -1,8 +1,6 @@
1
1
  # frozen_string_literal: true
2
2
 
3
- require 'spec_helper'
4
- require 'support/sharedcontext'
5
- require 'support/libvirt_context'
3
+ require_relative '../../spec_helper'
6
4
 
7
5
  require 'vagrant-libvirt/action/set_boot_order'
8
6
 
@@ -1,6 +1,8 @@
1
1
  # frozen_string_literal: true
2
2
 
3
- require 'spec_helper'
3
+ require_relative '../../spec_helper'
4
+
5
+ require 'vagrant-libvirt/action/set_name_of_domain'
4
6
 
5
7
  describe VagrantPlugins::ProviderLibvirt::Action::SetNameOfDomain do
6
8
  before :each do
@@ -1,6 +1,7 @@
1
- require 'spec_helper'
2
- require 'support/sharedcontext'
3
- require 'support/libvirt_context'
1
+ # frozen_string_literal: true
2
+
3
+ require_relative '../../spec_helper'
4
+
4
5
  require 'vagrant-libvirt/action/shutdown_domain'
5
6
 
6
7
  describe VagrantPlugins::ProviderLibvirt::Action::StartShutdownTimer do
@@ -30,7 +30,7 @@
30
30
  <target port='0'/>
31
31
  </console>
32
32
  <input bus='ps2' type='mouse'/>
33
- <graphics autoport='yes' keymap='en-us' listen='127.0.0.1' port='-1' type='vnc'/>
33
+ <graphics autoport='yes' keymap='en-us' listen='127.0.0.1' port='-1' type='vnc' websocket='-1'/>
34
34
  <video>
35
35
  <model heads='1' type='cirrus' vram='16384'/>
36
36
  </video>
@@ -30,7 +30,7 @@
30
30
  <target port='0'/>
31
31
  </console>
32
32
  <input bus='ps2' type='mouse'/>
33
- <graphics autoport='yes' keymap='en-us' listen='127.0.0.1' port='-1' type='vnc'/>
33
+ <graphics autoport='yes' keymap='en-us' listen='127.0.0.1' port='-1' type='vnc' websocket='-1'/>
34
34
  <video>
35
35
  <model heads='1' type='cirrus' vram='16384'/>
36
36
  </video>
@@ -31,7 +31,7 @@
31
31
  <target port='0'/>
32
32
  </console>
33
33
  <input bus='ps2' type='mouse'/>
34
- <graphics autoport='yes' keymap='en-us' listen='127.0.0.1' port='-1' type='vnc'/>
34
+ <graphics autoport='yes' keymap='en-us' listen='127.0.0.1' port='-1' type='vnc' websocket='-1'/>
35
35
  <video>
36
36
  <model heads='1' type='cirrus' vram='16384'/>
37
37
  </video>
@@ -28,7 +28,7 @@
28
28
  <target port='0'/>
29
29
  </console>
30
30
  <input bus='ps2' type='mouse'/>
31
- <graphics autoport='yes' keymap='en-us' listen='127.0.0.1' port='-1' type='vnc'/>
31
+ <graphics autoport='yes' keymap='en-us' listen='127.0.0.1' port='-1' type='vnc' websocket='-1'/>
32
32
  <video>
33
33
  <model heads='1' type='cirrus' vram='16384'/>
34
34
  </video>
@@ -28,7 +28,7 @@
28
28
  <target port='0'/>
29
29
  </console>
30
30
  <input bus='ps2' type='mouse'/>
31
- <graphics autoport='yes' keymap='en-us' listen='127.0.0.1' port='-1' type='vnc'/>
31
+ <graphics autoport='yes' keymap='en-us' listen='127.0.0.1' port='-1' type='vnc' websocket='-1'/>
32
32
  <video>
33
33
  <model heads='1' type='cirrus' vram='16384'/>
34
34
  </video>
@@ -28,7 +28,7 @@
28
28
  <target port='0'/>
29
29
  </console>
30
30
  <input bus='ps2' type='mouse'/>
31
- <graphics autoport='yes' keymap='en-us' listen='127.0.0.1' port='-1' type='vnc'/>
31
+ <graphics autoport='yes' keymap='en-us' listen='127.0.0.1' port='-1' type='vnc' websocket='-1'/>
32
32
  <video>
33
33
  <model heads='1' type='cirrus' vram='16384'/>
34
34
  </video>
@@ -29,7 +29,7 @@
29
29
  <target port='0'/>
30
30
  </console>
31
31
  <input bus='ps2' type='mouse'/>
32
- <graphics autoport='yes' keymap='en-us' listen='127.0.0.1' port='-1' type='vnc'/>
32
+ <graphics autoport='yes' keymap='en-us' listen='127.0.0.1' port='-1' type='vnc' websocket='-1'/>
33
33
  <video>
34
34
  <model heads='1' type='cirrus' vram='16384'/>
35
35
  </video>
@@ -7,6 +7,7 @@
7
7
  <vcpu placement='static'>2</vcpu>
8
8
  <os>
9
9
  <type arch='x86_64' machine='pc-i440fx-6.0'>hvm</type>
10
+ <bootmenu enable='no'/>
10
11
  <boot dev='hd'/>
11
12
  </os>
12
13
  <features>
@@ -47,7 +48,7 @@
47
48
  </console>
48
49
  <input type='mouse' bus='ps2'/>
49
50
  <input type='keyboard' bus='ps2'/>
50
- <graphics type='vnc' port='-1' autoport='yes' listen='127.0.0.1' keymap='en-us'>
51
+ <graphics type='vnc' port='-1' autoport='yes' listen='127.0.0.1' keymap='en-us' websocket='-1'>
51
52
  <listen type='address' address='127.0.0.1'/>
52
53
  </graphics>
53
54
  <audio id='1' type='none'/>
@@ -7,6 +7,7 @@
7
7
  <vcpu placement='static'>2</vcpu>
8
8
  <os>
9
9
  <type arch='x86_64' machine='pc-i440fx-6.0'>hvm</type><loader type='pflash'>/path/to/loader/file</loader><nvram>/path/to/nvram/file</nvram>
10
+ <bootmenu enable='no'/>
10
11
  <boot dev='hd'/>
11
12
  </os>
12
13
  <features>
@@ -47,7 +48,7 @@
47
48
  </console>
48
49
  <input bus='ps2' type='mouse'/>
49
50
  <input bus='ps2' type='keyboard'/>
50
- <graphics autoport='yes' keymap='en-us' listen='127.0.0.1' port='-1' type='vnc'>
51
+ <graphics autoport='yes' keymap='en-us' listen='127.0.0.1' port='-1' type='vnc' websocket='-1'>
51
52
  <listen address='127.0.0.1' type='address'/>
52
53
  </graphics>
53
54
  <audio id='1' type='none'/>
@@ -7,6 +7,7 @@
7
7
  <vcpu placement='static'>2</vcpu>
8
8
  <os>
9
9
  <type arch='x86_64' machine='pc-i440fx-6.0'>hvm</type>
10
+ <bootmenu enable='no'/>
10
11
  <boot dev='hd'/>
11
12
  </os>
12
13
  <features>
@@ -47,7 +48,7 @@
47
48
  </console>
48
49
  <input bus='ps2' type='mouse'/>
49
50
  <input bus='ps2' type='keyboard'/>
50
- <graphics autoport='yes' keymap='en-us' listen='127.0.0.1' port='-1' type='vnc'>
51
+ <graphics autoport='yes' keymap='en-us' listen='127.0.0.1' port='-1' type='vnc' websocket="-1">
51
52
  <listen address='127.0.0.1' type='address'/>
52
53
  </graphics>
53
54
  <audio id='1' type='none'/>
@@ -7,6 +7,7 @@
7
7
  <vcpu placement='static'>2</vcpu>
8
8
  <os>
9
9
  <type arch='x86_64' machine='pc-i440fx-6.0'>hvm</type>
10
+ <bootmenu enable='no'/>
10
11
  <loader type='pflash'>/path/to/loader/file</loader>
11
12
  <nvram>/path/to/nvram/file</nvram>
12
13
  <boot dev='hd'/>
@@ -7,6 +7,7 @@
7
7
  <vcpu placement='static'>2</vcpu>
8
8
  <os>
9
9
  <type arch='x86_64' machine='pc-i440fx-6.0'>hvm</type>
10
+ <bootmenu enable='no'/>
10
11
  <loader type='pflash'>/path/to/loader/file</loader>
11
12
  <nvram>/path/to/nvram/file1</nvram>
12
13
  <boot dev='hd'/>
@@ -49,7 +50,7 @@
49
50
  </console>
50
51
  <input bus='ps2' type='mouse'/>
51
52
  <input bus='ps2' type='keyboard'/>
52
- <graphics autoport='yes' keymap='en-us' listen='127.0.0.1' port='-1' type='vnc'>
53
+ <graphics autoport='yes' keymap='en-us' listen='127.0.0.1' port='-1' type='vnc' websocket='-1'>
53
54
  <listen address='127.0.0.1' type='address'/>
54
55
  </graphics>
55
56
  <audio id='1' type='none'/>
@@ -7,6 +7,7 @@
7
7
  <vcpu placement='static'>2</vcpu>
8
8
  <os>
9
9
  <type arch='x86_64' machine='pc-i440fx-6.0'>hvm</type>
10
+ <bootmenu enable='no'/>
10
11
 
11
12
 
12
13
  <boot dev='hd'/>
@@ -49,7 +50,7 @@
49
50
  </console>
50
51
  <input bus='ps2' type='mouse'/>
51
52
  <input bus='ps2' type='keyboard'/>
52
- <graphics autoport='yes' keymap='en-us' listen='127.0.0.1' port='-1' type='vnc'>
53
+ <graphics autoport='yes' keymap='en-us' listen='127.0.0.1' port='-1' type='vnc' websocket='-1'>
53
54
  <listen address='127.0.0.1' type='address'/>
54
55
  </graphics>
55
56
  <audio id='1' type='none'/>
@@ -1,11 +1,10 @@
1
1
  # frozen_string_literal: true
2
2
 
3
- require 'spec_helper'
4
- require 'support/sharedcontext'
5
- require 'support/libvirt_context'
3
+ require_relative '../../spec_helper'
6
4
 
7
5
  require 'vagrant-libvirt/errors'
8
6
  require 'vagrant-libvirt/action/start_domain'
7
+ require 'vagrant-libvirt/util/unindent'
9
8
 
10
9
  describe VagrantPlugins::ProviderLibvirt::Action::StartDomain do
11
10
  subject { described_class.new(app, env) }
@@ -34,6 +33,7 @@ describe VagrantPlugins::ProviderLibvirt::Action::StartDomain do
34
33
 
35
34
  allow(logger).to receive(:debug)
36
35
  allow(logger).to receive(:info)
36
+ allow(ui).to receive(:info)
37
37
 
38
38
  allow(libvirt_domain).to receive(:xml_desc).and_return(domain_xml)
39
39
 
@@ -162,6 +162,195 @@ describe VagrantPlugins::ProviderLibvirt::Action::StartDomain do
162
162
  end
163
163
  end
164
164
 
165
+ context 'cpu' do
166
+ let(:test_file) { 'existing.xml' }
167
+ let(:updated_domain_xml) {
168
+ new_xml = domain_xml.dup
169
+ new_xml.gsub!(
170
+ /<cpu .*\/>/,
171
+ <<-EOF
172
+ <cpu check='partial' mode='custom'>
173
+ <model fallback='allow'>Haswell</model>
174
+ <feature name='vmx' policy='optional'/>
175
+ <feature name='svm' policy='optional'/>
176
+ </cpu>
177
+ EOF
178
+ )
179
+ new_xml
180
+ }
181
+ let(:vagrantfile_providerconfig) {
182
+ <<-EOF
183
+ libvirt.cpu_mode = 'custom'
184
+ libvirt.cpu_model = 'Haswell'
185
+ libvirt.nested = true
186
+ EOF
187
+ }
188
+
189
+ it 'should set cpu related settings when changed' do
190
+ expect(ui).to_not receive(:warn)
191
+ expect(connection).to receive(:define_domain).and_return(libvirt_domain)
192
+ expect(libvirt_domain).to receive(:xml_desc).and_return(domain_xml, updated_domain_xml)
193
+ expect(libvirt_domain).to receive(:autostart=)
194
+ expect(domain).to receive(:start)
195
+
196
+ expect(subject.call(env)).to be_nil
197
+ end
198
+
199
+ let(:domain_xml_no_cpu) {
200
+ new_xml = domain_xml.dup
201
+ new_xml.gsub!(/<cpu .*\/>/, '')
202
+ new_xml
203
+ }
204
+ let(:updated_domain_xml_new_cpu) {
205
+ new_xml = domain_xml.dup
206
+ new_xml.gsub!(
207
+ /<cpu .*\/>/,
208
+ <<-EOF
209
+ <cpu mode='custom'>
210
+ <model fallback='allow'>Haswell</model>
211
+ <feature name='vmx' policy='optional'/>
212
+ <feature name='svm' policy='optional'/>
213
+ </cpu>
214
+ EOF
215
+ )
216
+ new_xml
217
+ }
218
+
219
+ it 'should add cpu settings if not already present' do
220
+ expect(ui).to_not receive(:warn)
221
+ expect(connection).to receive(:define_domain).and_return(libvirt_domain)
222
+ expect(libvirt_domain).to receive(:xml_desc).and_return(domain_xml_no_cpu, updated_domain_xml_new_cpu)
223
+ expect(libvirt_domain).to receive(:autostart=)
224
+ expect(domain).to receive(:start)
225
+
226
+ expect(subject.call(env)).to be_nil
227
+ end
228
+ end
229
+
230
+ context 'launchSecurity' do
231
+ let(:updated_domain_xml_new_launch_security) {
232
+ new_xml = domain_xml.dup
233
+ new_xml.gsub!(
234
+ /<\/devices>/,
235
+ <<-EOF.unindent.rstrip
236
+ </devices>
237
+ <launchSecurity type='sev'>
238
+ <cbitpos>47</cbitpos>
239
+ <reducedPhysBits>1</reducedPhysBits>
240
+ <policy>0x0003</policy>
241
+ </launchSecurity>
242
+ EOF
243
+ )
244
+ new_xml
245
+ }
246
+
247
+ it 'should create if not already set' do
248
+ machine.provider_config.launchsecurity_data = {:type => 'sev', :cbitpos => 47, :reducedPhysBits => 1, :policy => "0x0003"}
249
+
250
+ expect(ui).to_not receive(:warn)
251
+ expect(connection).to receive(:define_domain).and_return(libvirt_domain)
252
+ expect(libvirt_domain).to receive(:xml_desc).and_return(domain_xml, updated_domain_xml_new_launch_security)
253
+ expect(libvirt_domain).to receive(:autostart=)
254
+ expect(domain).to receive(:start)
255
+
256
+ expect(subject.call(env)).to be_nil
257
+ end
258
+
259
+ context 'already exists' do
260
+ let(:domain_xml_launch_security) { updated_domain_xml_new_launch_security }
261
+ let(:updated_domain_xml_launch_security) {
262
+ new_xml = domain_xml_launch_security.dup
263
+ new_xml.gsub!(/<cbitpos>47/, '<cbitpos>48')
264
+ new_xml.gsub!(/<reducedPhysBits>1/, '<reducedPhysBits>2')
265
+ new_xml.gsub!(/<policy>0x0003/, '<policy>0x0004')
266
+ new_xml
267
+ }
268
+
269
+
270
+ it 'should update all settings' do
271
+ machine.provider_config.launchsecurity_data = {:type => 'sev', :cbitpos => 48, :reducedPhysBits => 2, :policy => "0x0004"}
272
+
273
+ expect(ui).to_not receive(:warn)
274
+ expect(connection).to receive(:define_domain).and_return(libvirt_domain)
275
+ expect(libvirt_domain).to receive(:xml_desc).and_return(domain_xml_launch_security, updated_domain_xml_launch_security)
276
+ expect(libvirt_domain).to receive(:autostart=)
277
+ expect(domain).to receive(:start)
278
+
279
+ expect(subject.call(env)).to be_nil
280
+ end
281
+
282
+ it 'should remove if disabled' do
283
+ machine.provider_config.launchsecurity_data = nil
284
+
285
+ expect(ui).to_not receive(:warn)
286
+ expect(connection).to receive(:define_domain).and_return(libvirt_domain)
287
+ expect(libvirt_domain).to receive(:xml_desc).and_return(domain_xml_launch_security, domain_xml)
288
+ expect(libvirt_domain).to receive(:autostart=)
289
+ expect(domain).to receive(:start)
290
+
291
+ expect(subject.call(env)).to be_nil
292
+ end
293
+
294
+ context 'with controllers' do
295
+ # makes domain_xml contain 2 controllers and memballoon
296
+ # which should mean that launchsecurity element exists, but without
297
+ # iommu set on controllers
298
+ let(:test_file) { 'existing.xml' }
299
+ let(:updated_domain_xml_launch_security_controllers) {
300
+ new_xml = updated_domain_xml_new_launch_security.dup
301
+ new_xml.gsub!(
302
+ /<controller type='pci' index='0' model='pci-root'\/>/,
303
+ "<controller type='pci' index='0' model='pci-root'><driver iommu='on'/></controller>",
304
+ )
305
+ new_xml.gsub!(
306
+ /(<address type='pci' domain='0x0000' bus='0x00' slot='0x01' function='0x2'\/>)/,
307
+ '\1<driver iommu="on"/>',
308
+ )
309
+ # memballoon
310
+ new_xml.gsub!(
311
+ /(<address type='pci' domain='0x0000' bus='0x00' slot='0x04' function='0x0'\/>)/,
312
+ '\1<driver iommu="on"/>',
313
+ )
314
+ new_xml
315
+ }
316
+
317
+ it 'should set driver iommu on all controllers' do
318
+ machine.provider_config.launchsecurity_data = {:type => 'sev', :cbitpos => 47, :reducedPhysBits => 1, :policy => "0x0003"}
319
+
320
+ expect(ui).to_not receive(:warn)
321
+ expect(connection).to receive(:define_domain).and_return(libvirt_domain)
322
+ expect(libvirt_domain).to receive(:xml_desc).and_return(domain_xml_launch_security, updated_domain_xml_launch_security_controllers)
323
+ expect(libvirt_domain).to receive(:autostart=)
324
+ expect(domain).to receive(:start)
325
+
326
+ expect(subject.call(env)).to be_nil
327
+ end
328
+ end
329
+ end
330
+ end
331
+
332
+ context 'graphics' do
333
+ context 'autoport not disabled' do
334
+ let(:test_file) { 'existing.xml' }
335
+ let(:launched_domain_xml) {
336
+ new_xml = domain_xml.dup
337
+ new_xml.gsub!(/graphics type='vnc' port='-1'/m, "graphics type='vnc' port='5900'")
338
+ new_xml
339
+ }
340
+
341
+ it 'should retrieve the port from XML' do
342
+ expect(ui).to_not receive(:warn)
343
+ expect(connection).to_not receive(:define_domain)
344
+ expect(libvirt_domain).to receive(:xml_desc).and_return(domain_xml, launched_domain_xml)
345
+ expect(libvirt_domain).to receive(:autostart=)
346
+ expect(domain).to receive(:start)
347
+ expect(ui).to receive(:info).with(' -- Graphics Port: 5900')
348
+
349
+ expect(subject.call(env)).to be_nil
350
+ end
351
+ end
352
+ end
353
+
165
354
  context 'nvram' do
166
355
  context 'when being added to existing' do
167
356
  let(:vagrantfile_providerconfig) do
@@ -1,12 +1,10 @@
1
1
  # frozen_string_literal: true
2
2
 
3
+ require_relative '../../spec_helper'
4
+
3
5
  require 'vagrant-libvirt/action/wait_till_up'
4
6
  require 'vagrant-libvirt/errors'
5
7
 
6
- require 'spec_helper'
7
- require 'support/sharedcontext'
8
- require 'support/libvirt_context'
9
-
10
8
  describe VagrantPlugins::ProviderLibvirt::Action::WaitTillUp do
11
9
  subject { described_class.new(app, env) }
12
10
 
@@ -74,7 +72,7 @@ describe VagrantPlugins::ProviderLibvirt::Action::WaitTillUp do
74
72
  allow(domain).to receive(:wait_for).and_return(true)
75
73
  allow(env).to receive(:[]).and_call_original
76
74
  allow(env).to receive(:[]).with(:interrupted).and_return(false)
77
- allow(driver).to receive(:get_domain_ipaddress).and_return('192.168.121.2')
75
+ allow(driver).to receive(:get_ipaddress).and_return('192.168.121.2')
78
76
  end
79
77
  it 'should call the next hook' do
80
78
  expect(app).to receive(:call)