vagrant-libvirt 0.8.2 → 0.10.1

Sign up to get free protection for your applications and to get access to all the features.
Files changed (88) hide show
  1. checksums.yaml +4 -4
  2. data/README.md +51 -2079
  3. data/lib/vagrant-libvirt/action/create_domain.rb +57 -94
  4. data/lib/vagrant-libvirt/action/create_network_interfaces.rb +1 -1
  5. data/lib/vagrant-libvirt/action/create_networks.rb +3 -3
  6. data/lib/vagrant-libvirt/action/destroy_domain.rb +21 -5
  7. data/lib/vagrant-libvirt/action/destroy_networks.rb +2 -2
  8. data/lib/vagrant-libvirt/action/handle_box_image.rb +3 -1
  9. data/lib/vagrant-libvirt/action/package_domain.rb +1 -5
  10. data/lib/vagrant-libvirt/action/remove_libvirt_image.rb +3 -1
  11. data/lib/vagrant-libvirt/action/resolve_disk_settings.rb +181 -0
  12. data/lib/vagrant-libvirt/action/snapshot_delete.rb +26 -0
  13. data/lib/vagrant-libvirt/action/snapshot_restore.rb +22 -0
  14. data/lib/vagrant-libvirt/action/snapshot_save.rb +27 -0
  15. data/lib/vagrant-libvirt/action/start_domain.rb +80 -11
  16. data/lib/vagrant-libvirt/action.rb +53 -1
  17. data/lib/vagrant-libvirt/cap/snapshots.rb +12 -0
  18. data/lib/vagrant-libvirt/cap/synced_folder_9p.rb +4 -4
  19. data/lib/vagrant-libvirt/cap/synced_folder_virtiofs.rb +4 -4
  20. data/lib/vagrant-libvirt/config.rb +104 -6
  21. data/lib/vagrant-libvirt/driver.rb +108 -46
  22. data/lib/vagrant-libvirt/errors.rb +23 -3
  23. data/lib/vagrant-libvirt/plugin.rb +7 -3
  24. data/lib/vagrant-libvirt/provider.rb +1 -1
  25. data/lib/vagrant-libvirt/templates/domain.xml.erb +32 -6
  26. data/lib/vagrant-libvirt/util/byte_number.rb +0 -1
  27. data/lib/vagrant-libvirt/util/compat.rb +23 -0
  28. data/lib/vagrant-libvirt/util/domain_flags.rb +15 -0
  29. data/lib/vagrant-libvirt/util/unindent.rb +7 -0
  30. data/lib/vagrant-libvirt/util.rb +1 -0
  31. data/lib/vagrant-libvirt/version +1 -1
  32. data/locales/en.yml +28 -4
  33. data/spec/acceptance/additional_storage_spec.rb +32 -0
  34. data/spec/acceptance/package_domain_spec.rb +90 -0
  35. data/spec/acceptance/provider_settings_spec.rb +54 -0
  36. data/spec/acceptance/simple_vm_provision_via_shell_spec.rb +31 -0
  37. data/spec/acceptance/snapshots_spec.rb +41 -0
  38. data/spec/acceptance/support-skeletons/package_complex/Vagrantfile.testbox +14 -0
  39. data/spec/acceptance/support-skeletons/package_complex/scripts/sysprep.sh +32 -0
  40. data/spec/acceptance/support-skeletons/package_simple/Vagrantfile.testbox +10 -0
  41. data/spec/acceptance/two_disks_spec.rb +29 -0
  42. data/spec/acceptance/use_qemu_agent_for_connectivity_spec.rb +35 -0
  43. data/spec/spec_helper.rb +3 -0
  44. data/spec/support/acceptance/configuration.rb +21 -0
  45. data/spec/support/acceptance/context.rb +70 -0
  46. data/spec/support/acceptance/isolated_environment.rb +41 -0
  47. data/spec/support/libvirt_acceptance_context.rb +64 -0
  48. data/spec/support/libvirt_context.rb +4 -0
  49. data/spec/support/sharedcontext.rb +1 -0
  50. data/spec/unit/action/cleanup_on_failure_spec.rb +0 -2
  51. data/spec/unit/action/create_domain_spec/sysinfo.xml +66 -0
  52. data/spec/unit/action/create_domain_spec/sysinfo_only_required.xml +49 -0
  53. data/spec/unit/action/create_domain_spec.rb +188 -140
  54. data/spec/unit/action/create_domain_volume_spec.rb +0 -3
  55. data/spec/unit/action/destroy_domain_spec.rb +43 -10
  56. data/spec/unit/action/forward_ports_spec.rb +0 -1
  57. data/spec/unit/action/handle_box_image_spec.rb +31 -14
  58. data/spec/unit/action/package_domain_spec.rb +0 -5
  59. data/spec/unit/action/remove_libvirt_image_spec.rb +43 -0
  60. data/spec/unit/action/resolve_disk_settings_spec/default_domain.xml +43 -0
  61. data/spec/unit/action/resolve_disk_settings_spec/default_no_aliases.xml +42 -0
  62. data/spec/unit/action/{create_domain_spec → resolve_disk_settings_spec}/default_system_storage_pool.xml +0 -0
  63. data/spec/unit/action/resolve_disk_settings_spec/multi_volume_box.xml +55 -0
  64. data/spec/unit/action/resolve_disk_settings_spec/multi_volume_box_additional_and_custom_no_aliases.xml +67 -0
  65. data/spec/unit/action/resolve_disk_settings_spec/multi_volume_box_additional_storage.xml +67 -0
  66. data/spec/unit/action/resolve_disk_settings_spec.rb +385 -0
  67. data/spec/unit/action/start_domain_spec/clock_timer_removed.xml +38 -0
  68. data/spec/unit/action/start_domain_spec/clock_timer_rtc_tsc.xml +39 -0
  69. data/spec/unit/action/start_domain_spec/existing_added_nvram.xml +62 -0
  70. data/spec/unit/action/start_domain_spec/nvram_domain.xml +64 -0
  71. data/spec/unit/action/start_domain_spec/nvram_domain_other_setting.xml +64 -0
  72. data/spec/unit/action/start_domain_spec/nvram_domain_removed.xml +64 -0
  73. data/spec/unit/action/start_domain_spec.rb +122 -22
  74. data/spec/unit/action/wait_till_up_spec.rb +0 -2
  75. data/spec/unit/action_spec.rb +88 -3
  76. data/spec/unit/cap/synced_folder_9p_spec.rb +120 -0
  77. data/spec/unit/cap/synced_folder_virtiofs_spec.rb +120 -0
  78. data/spec/unit/config_spec.rb +153 -6
  79. data/spec/unit/driver_spec.rb +3 -1
  80. data/spec/unit/plugin_spec.rb +42 -0
  81. data/spec/unit/templates/domain_all_settings.xml +15 -6
  82. data/spec/unit/templates/domain_scsi_bus_storage.xml +44 -0
  83. data/spec/unit/templates/domain_scsi_device_storage.xml +44 -0
  84. data/spec/unit/templates/domain_scsi_multiple_controllers_storage.xml +130 -0
  85. data/spec/unit/templates/domain_spec.rb +105 -21
  86. data/spec/unit/util/byte_number_spec.rb +1 -1
  87. metadata +169 -79
  88. data/spec/unit/provider_spec.rb +0 -11
@@ -21,15 +21,9 @@ describe VagrantPlugins::ProviderLibvirt::Action::CreateDomain do
21
21
  let(:domain_volume) { instance_double(::Fog::Libvirt::Compute::Volume) }
22
22
 
23
23
  let(:domain_xml) { File.read(File.join(File.dirname(__FILE__), File.basename(__FILE__, '.rb'), domain_xml_file)) }
24
- let(:storage_pool_xml) { File.read(File.join(File.dirname(__FILE__), File.basename(__FILE__, '.rb'), storage_pool_xml_file)) }
25
- let(:libvirt_storage_pool) { double('storage_pool') }
26
24
 
27
25
  describe '#call' do
28
26
  before do
29
- allow_any_instance_of(VagrantPlugins::ProviderLibvirt::Driver)
30
- .to receive(:connection).and_return(connection)
31
- allow(connection).to receive(:client).and_return(libvirt_client)
32
-
33
27
  allow(connection).to receive(:servers).and_return(servers)
34
28
  allow(connection).to receive(:volumes).and_return(volumes)
35
29
  allow(volumes).to receive(:all).and_return([domain_volume])
@@ -43,15 +37,17 @@ describe VagrantPlugins::ProviderLibvirt::Action::CreateDomain do
43
37
 
44
38
  env[:domain_name] = "vagrant-test_default"
45
39
 
46
- env[:box_volumes] = []
47
- env[:box_volumes].push({
40
+ env[:domain_volumes] = []
41
+ env[:domain_volumes].push({
42
+ :device=>'vda',
43
+ :bus=>'virtio',
44
+ :cache=>'default',
45
+ :absolute_path=>'/var/lib/libvirt/images/vagrant-test_default.img',
48
46
  :path=>"/test/box.img",
49
- :name=>"test_vagrant_box_image_1.1.1_0.img",
47
+ :name=>'test_vagrant_box_image_1.1.1_0.img',
50
48
  :virtual_size=> ByteNumber.new(5),
49
+ :pool=>'default',
51
50
  })
52
- # should be ignored for system session and used for user session
53
- allow(Process).to receive(:uid).and_return(9999)
54
- allow(Process).to receive(:gid).and_return(9999)
55
51
  end
56
52
 
57
53
  context 'connection => qemu:///system' do
@@ -61,123 +57,181 @@ describe VagrantPlugins::ProviderLibvirt::Action::CreateDomain do
61
57
  allow(machine.provider_config).to receive(:qemu_use_session).and_return(false)
62
58
  end
63
59
 
64
- context 'default pool' do
65
- it 'should execute correctly' do
66
- expect(servers).to receive(:create).with(xml: domain_xml).and_return(machine)
67
- expect(volumes).to_not receive(:create) # additional disks only
60
+ it 'should execute correctly' do
61
+ expect(servers).to receive(:create).with(xml: domain_xml).and_return(machine)
62
+ expect(volumes).to_not receive(:create) # additional disks only
68
63
 
69
- expect(subject.call(env)).to be_nil
64
+ expect(subject.call(env)).to be_nil
65
+ end
66
+
67
+ context 'additional disks' do
68
+ let(:disks) do
69
+ [
70
+ :device => 'vdb',
71
+ :cache => 'default',
72
+ :bus => 'virtio',
73
+ :type => 'qcow2',
74
+ :absolute_path => '/var/lib/libvirt/images/vagrant-test_default-vdb.qcow2',
75
+ :virtual_size => ByteNumber.new(20*1024*1024*1024),
76
+ :pool => 'default',
77
+ ]
70
78
  end
71
79
 
72
- context 'with no box' do
73
- let(:storage_pool_xml_file) { 'default_system_storage_pool.xml' }
74
- let(:vagrantfile) do
75
- <<-EOF
76
- Vagrant.configure('2') do |config|
77
- config.vm.define :test
78
- end
79
- EOF
80
- end
80
+ before do
81
+ env[:disks] = disks
82
+ end
81
83
 
82
- it 'should query for the storage pool path' do
83
- expect(libvirt_client).to receive(:lookup_storage_pool_by_name).and_return(libvirt_storage_pool)
84
- expect(libvirt_storage_pool).to receive(:xml_desc).and_return(storage_pool_xml)
85
- expect(servers).to receive(:create).and_return(machine)
84
+ context 'volume create failed' do
85
+ it 'should raise an exception' do
86
+ expect(volumes).to receive(:create).and_raise(Libvirt::Error)
86
87
 
87
- expect(subject.call(env)).to be_nil
88
+ expect{ subject.call(env) }.to raise_error(VagrantPlugins::ProviderLibvirt::Errors::FogCreateDomainVolumeError)
88
89
  end
89
90
  end
90
91
 
91
- context 'additional disks' do
92
- let(:vagrantfile_providerconfig) do
93
- <<-EOF
94
- libvirt.storage :file, :size => '20G'
95
- EOF
96
- end
92
+ context 'volume create succeeded' do
93
+ let(:domain_xml_file) { 'additional_disks_domain.xml' }
97
94
 
98
- context 'volume create failed' do
99
- it 'should raise an exception' do
100
- expect(volumes).to receive(:create).and_raise(Libvirt::Error)
95
+ it 'should complete' do
96
+ expect(volumes).to receive(:create).with(
97
+ hash_including(
98
+ :path => "/var/lib/libvirt/images/vagrant-test_default-vdb.qcow2",
99
+ :owner => 0,
100
+ :group => 0,
101
+ :pool_name => "default",
102
+ )
103
+ )
104
+ expect(servers).to receive(:create).with(xml: domain_xml).and_return(machine)
101
105
 
102
- expect{ subject.call(env) }.to raise_error(VagrantPlugins::ProviderLibvirt::Errors::FogCreateDomainVolumeError)
103
- end
106
+ expect(subject.call(env)).to be_nil
104
107
  end
108
+ end
109
+ end
105
110
 
106
- context 'volume create succeeded' do
107
- let(:domain_xml_file) { 'additional_disks_domain.xml' }
108
-
109
- it 'should complete' do
110
- expect(volumes).to receive(:create).with(
111
- hash_including(
112
- :path => "/var/lib/libvirt/images/vagrant-test_default-vdb.qcow2",
113
- :owner => 0,
114
- :group => 0,
115
- :pool_name => "default",
116
- )
117
- )
118
- expect(servers).to receive(:create).with(xml: domain_xml).and_return(machine)
111
+ context 'with custom disk device setting' do
112
+ let(:domain_xml_file) { 'custom_disk_settings.xml' }
119
113
 
120
- expect(subject.call(env)).to be_nil
121
- end
122
- end
114
+ before do
115
+ env[:domain_volumes][0][:device] = 'sda'
123
116
  end
124
117
 
125
- context 'with custom disk device setting' do
126
- let(:domain_xml_file) { 'custom_disk_settings.xml' }
127
- let(:vagrantfile_providerconfig) {
128
- <<-EOF
129
- libvirt.disk_device = 'sda'
130
- EOF
131
- }
118
+ it 'should set the domain device' do
119
+ expect(ui).to receive(:info).with(/ -- Image\(sda\):.*/)
120
+ expect(servers).to receive(:create).with(xml: domain_xml).and_return(machine)
132
121
 
133
- it 'should set the domain device' do
134
- expect(ui).to receive(:info).with(/ -- Image\(sda\):.*/)
135
- expect(servers).to receive(:create).with(xml: domain_xml).and_return(machine)
122
+ expect(subject.call(env)).to be_nil
123
+ end
124
+ end
136
125
 
137
- expect(subject.call(env)).to be_nil
138
- end
126
+ context 'with two domain disks' do
127
+ let(:domain_xml_file) { 'two_disk_settings.xml' }
128
+ let(:domain_volume_2) { double('domain_volume 2') }
129
+
130
+ before do
131
+ expect(volumes).to receive(:all).with(name: 'vagrant-test_default.img').and_return([domain_volume])
132
+ expect(volumes).to receive(:all).with(name: 'vagrant-test_default_1.img').and_return([domain_volume_2])
133
+ expect(domain_volume_2).to receive(:pool_name).and_return('default')
134
+
135
+ env[:domain_volumes].push({
136
+ :device=>'vdb',
137
+ :bus=>'virtio',
138
+ :cache=>'default',
139
+ :absolute_path=>'/var/lib/libvirt/images/vagrant-test_default_1.img',
140
+ :path=>"/test/box_1.img",
141
+ :name=>"test_vagrant_box_image_1.1.1_1.img",
142
+ :virtual_size=> ByteNumber.new(5),
143
+ :pool=>'default',
144
+ })
139
145
  end
140
146
 
141
- context 'with two domain disks' do
142
- let(:domain_xml_file) { 'two_disk_settings.xml' }
143
- let(:domain_volume_2) { double('domain_volume 2') }
147
+ it 'should list multiple device entries' do
148
+ expect(ui).to receive(:info).with(/ -- Image\(vda\):.*/)
149
+ expect(ui).to receive(:info).with(/ -- Image\(vdb\):.*/)
150
+ expect(servers).to receive(:create).with(xml: domain_xml).and_return(machine)
144
151
 
145
- before do
146
- expect(volumes).to receive(:all).and_return([domain_volume])
147
- expect(volumes).to receive(:all).and_return([domain_volume_2])
148
- expect(domain_volume_2).to receive(:pool_name).and_return('default')
149
- expect(domain_volume_2).to receive(:path).and_return('/var/lib/libvirt/images/vagrant-test_default_1.img')
152
+ expect(subject.call(env)).to be_nil
153
+ end
154
+ end
150
155
 
151
- env[:box_volumes].push({
152
- :path=>"/test/box_1.img",
153
- :name=>"test_vagrant_box_image_1.1.1_1.img",
154
- :virtual_size=> ByteNumber.new(5),
155
- })
156
- end
156
+ context 'with disk controller model virtio-scsi' do
157
+ before do
158
+ allow(machine.provider_config).to receive(:disk_controller_model).and_return('virtio-scsi')
159
+ expect(volumes).to receive(:all).with(name: 'vagrant-test_default.img').and_return([domain_volume])
157
160
 
158
- it 'should correctly assign device entries' do
159
- expect(ui).to receive(:info).with(/ -- Image\(vda\):.*/)
160
- expect(ui).to receive(:info).with(/ -- Image\(vdb\):.*/)
161
- expect(servers).to receive(:create).with(xml: domain_xml).and_return(machine)
161
+ env[:domain_volumes][0][:bus] = 'scsi'
162
+ end
162
163
 
163
- expect(subject.call(env)).to be_nil
164
- end
164
+ it 'should add a virtio-scsi disk controller' do
165
+ expect(ui).to receive(:info).with(/ -- Image\(vda\):.*/)
166
+ expect(servers).to receive(:create) do |args|
167
+ expect(args[:xml]).to match(/<controller type='scsi' model='virtio-scsi' index='0'\/>/)
168
+ end.and_return(machine)
169
+
170
+ expect(subject.call(env)).to be_nil
165
171
  end
166
172
  end
167
173
 
168
- context 'no default pool' do
169
- let(:vagrantfile) do
174
+ context 'sysinfo' do
175
+ let(:domain_xml_file) { 'sysinfo.xml' }
176
+ let(:vagrantfile_providerconfig) do
170
177
  <<-EOF
171
- Vagrant.configure('2') do |config|
172
- config.vm.define :test
173
- end
178
+ libvirt.sysinfo = {
179
+ 'bios': {
180
+ 'vendor': 'Test Vendor',
181
+ 'version': '',
182
+ },
183
+ 'system': {
184
+ 'manufacturer': 'Test Manufacturer',
185
+ 'version': '0.1.0',
186
+ 'serial': '',
187
+ },
188
+ 'base board': {
189
+ 'manufacturer': 'Test Manufacturer',
190
+ 'version': '',
191
+ },
192
+ 'chassis': {
193
+ 'manufacturer': 'Test Manufacturer',
194
+ 'serial': 'AABBCCDDEE',
195
+ 'asset': '',
196
+ },
197
+ 'oem strings': [
198
+ 'app1: string1',
199
+ 'app1: string2',
200
+ 'app2: string1',
201
+ 'app2: string2',
202
+ '',
203
+ '',
204
+ ],
205
+ }
174
206
  EOF
175
207
  end
176
208
 
177
- it 'should raise an exception' do
178
- expect(libvirt_client).to receive(:lookup_storage_pool_by_name).and_return(nil)
209
+ it 'should populate sysinfo as expected' do
210
+ expect(servers).to receive(:create).with(xml: domain_xml).and_return(machine)
211
+
212
+ expect(subject.call(env)).to be_nil
213
+ end
179
214
 
180
- expect{ subject.call(env) }.to raise_error(VagrantPlugins::ProviderLibvirt::Errors::NoStoragePool)
215
+ context 'with block of empty entries' do
216
+ let(:domain_xml_file) { 'sysinfo_only_required.xml' }
217
+ let(:vagrantfile_providerconfig) do
218
+ <<-EOF
219
+ libvirt.sysinfo = {
220
+ 'bios': {
221
+ 'vendor': 'Test Vendor',
222
+ },
223
+ 'system': {
224
+ 'serial': '',
225
+ },
226
+ }
227
+ EOF
228
+ end
229
+
230
+ it 'should skip outputting the surrounding tags' do
231
+ expect(servers).to receive(:create).with(xml: domain_xml).and_return(machine)
232
+
233
+ expect(subject.call(env)).to be_nil
234
+ end
181
235
  end
182
236
  end
183
237
  end
@@ -187,57 +241,51 @@ describe VagrantPlugins::ProviderLibvirt::Action::CreateDomain do
187
241
  allow(machine.provider_config).to receive(:qemu_use_session).and_return(true)
188
242
  end
189
243
 
190
- context 'default pool' do
191
- it 'should execute correctly' do
192
- expect(servers).to receive(:create).and_return(machine)
244
+ it 'should execute correctly' do
245
+ expect(servers).to receive(:create).and_return(machine)
193
246
 
194
- expect(subject.call(env)).to be_nil
247
+ expect(subject.call(env)).to be_nil
248
+ end
249
+
250
+ context 'additional disks' do
251
+ let(:vagrantfile_providerconfig) do
252
+ <<-EOF
253
+ libvirt.qemu_use_session = true
254
+ EOF
195
255
  end
196
256
 
197
- context 'with no box' do
198
- let(:storage_pool_xml_file) { 'default_user_storage_pool.xml' }
199
- let(:vagrantfile) do
200
- <<-EOF
201
- Vagrant.configure('2') do |config|
202
- config.vm.define :test
203
- config.vm.provider :libvirt do |libvirt|
204
- #{vagrantfile_providerconfig}
205
- end
206
- end
207
- EOF
208
- end
257
+ let(:disks) do
258
+ [
259
+ :device => 'vdb',
260
+ :cache => 'default',
261
+ :bus => 'virtio',
262
+ :type => 'qcow2',
263
+ :absolute_path => '/var/lib/libvirt/images/vagrant-test_default-vdb.qcow2',
264
+ :virtual_size => ByteNumber.new(20*1024*1024*1024),
265
+ :pool => 'default',
266
+ ]
267
+ end
209
268
 
210
- it 'should query for the storage pool path' do
211
- expect(libvirt_client).to receive(:lookup_storage_pool_by_name).and_return(libvirt_storage_pool)
212
- expect(libvirt_storage_pool).to receive(:xml_desc).and_return(storage_pool_xml)
213
- expect(servers).to receive(:create).and_return(machine)
269
+ before do
270
+ expect(Process).to receive(:uid).and_return(9999).at_least(:once)
271
+ expect(Process).to receive(:gid).and_return(9999).at_least(:once)
214
272
 
215
- expect(subject.call(env)).to be_nil
216
- end
273
+ env[:disks] = disks
217
274
  end
218
275
 
219
- context 'additional disks' do
220
- let(:vagrantfile_providerconfig) do
221
- <<-EOF
222
- libvirt.qemu_use_session = true
223
- libvirt.storage :file, :size => '20G'
224
- EOF
225
- end
226
-
227
- context 'volume create succeeded' do
228
- it 'should complete' do
229
- expect(volumes).to receive(:create).with(
230
- hash_including(
231
- :path => "/var/lib/libvirt/images/vagrant-test_default-vdb.qcow2",
232
- :owner => 9999,
233
- :group => 9999,
234
- :pool_name => "default",
235
- )
276
+ context 'volume create succeeded' do
277
+ it 'should complete' do
278
+ expect(volumes).to receive(:create).with(
279
+ hash_including(
280
+ :path => "/var/lib/libvirt/images/vagrant-test_default-vdb.qcow2",
281
+ :owner => 9999,
282
+ :group => 9999,
283
+ :pool_name => "default",
236
284
  )
237
- expect(servers).to receive(:create).and_return(machine)
285
+ )
286
+ expect(servers).to receive(:create).and_return(machine)
238
287
 
239
- expect(subject.call(env)).to be_nil
240
- end
288
+ expect(subject.call(env)).to be_nil
241
289
  end
242
290
  end
243
291
  end
@@ -26,9 +26,6 @@ describe VagrantPlugins::ProviderLibvirt::Action::CreateDomainVolume do
26
26
 
27
27
  describe '#call' do
28
28
  before do
29
- allow_any_instance_of(VagrantPlugins::ProviderLibvirt::Driver)
30
- .to receive(:connection).and_return(connection)
31
- allow(connection).to receive(:client).and_return(libvirt_client)
32
29
  allow(connection).to receive(:volumes).and_return(volumes)
33
30
  allow(volumes).to receive(:all).and_return(all)
34
31
  allow(all).to receive(:first).and_return(box_volume)
@@ -19,10 +19,14 @@ describe VagrantPlugins::ProviderLibvirt::Action::DestroyDomain do
19
19
 
20
20
  let(:domain_xml) { File.read(File.join(File.dirname(__FILE__), File.basename(__FILE__, '.rb'), domain_xml_file)) }
21
21
 
22
+ let(:destroy_method) { double('destroy_method') }
23
+
22
24
  before do
23
25
  allow(machine.provider).to receive('driver').and_return(driver)
24
26
  allow(driver).to receive(:connection).and_return(connection)
25
27
  allow(logger).to receive(:info)
28
+ allow(domain).to receive(:method).with(:destroy).and_return(destroy_method)
29
+ allow(destroy_method).to receive(:parameters).and_return([[:opt, :options, :flags]])
26
30
  end
27
31
 
28
32
  describe '#call' do
@@ -49,7 +53,7 @@ describe VagrantPlugins::ProviderLibvirt::Action::DestroyDomain do
49
53
 
50
54
  context 'when box only has one root disk' do
51
55
  it 'calls fog to destroy volumes' do
52
- expect(domain).to receive(:destroy).with(destroy_volumes: true)
56
+ expect(domain).to receive(:destroy).with(destroy_volumes: true, flags: 0)
53
57
  expect(subject.call(env)).to be_nil
54
58
  end
55
59
 
@@ -69,7 +73,7 @@ describe VagrantPlugins::ProviderLibvirt::Action::DestroyDomain do
69
73
  end
70
74
 
71
75
  it 'destroys disks individually' do
72
- expect(domain).to receive(:destroy).with(destroy_volumes: false)
76
+ expect(domain).to receive(:destroy).with(destroy_volumes: false, flags: 0)
73
77
  expect(extra_disk).to receive(:destroy) # extra disk remove
74
78
  expect(root_disk).to receive(:destroy) # root disk remove
75
79
  expect(subject.call(env)).to be_nil
@@ -81,7 +85,7 @@ describe VagrantPlugins::ProviderLibvirt::Action::DestroyDomain do
81
85
  let(:domain_xml_file) { 'box_multiple_disks.xml' }
82
86
 
83
87
  it 'calls fog to destroy volumes' do
84
- expect(domain).to receive(:destroy).with(destroy_volumes: true)
88
+ expect(domain).to receive(:destroy).with(destroy_volumes: true, flags: 0)
85
89
  expect(subject.call(env)).to be_nil
86
90
  end
87
91
 
@@ -111,7 +115,7 @@ describe VagrantPlugins::ProviderLibvirt::Action::DestroyDomain do
111
115
  expect(disk).to receive(:name).and_return(name).at_least(:once)
112
116
  expect(disk).to receive(:destroy)
113
117
  end
114
- expect(domain).to receive(:destroy).with(destroy_volumes: false)
118
+ expect(domain).to receive(:destroy).with(destroy_volumes: false, flags: 0)
115
119
  expect(subject.call(env)).to be_nil
116
120
  end
117
121
 
@@ -133,7 +137,7 @@ describe VagrantPlugins::ProviderLibvirt::Action::DestroyDomain do
133
137
  next if disk == domain_disks.last.first
134
138
  expect(disk).to receive(:destroy)
135
139
  end
136
- expect(domain).to receive(:destroy).with(destroy_volumes: false)
140
+ expect(domain).to receive(:destroy).with(destroy_volumes: false, flags: 0)
137
141
  expect(subject.call(env)).to be_nil
138
142
  end
139
143
 
@@ -141,7 +145,7 @@ describe VagrantPlugins::ProviderLibvirt::Action::DestroyDomain do
141
145
  let(:domain_xml_file) { 'box_multiple_disks_and_additional_and_custom_disks_no_aliases.xml' }
142
146
 
143
147
  it 'only destroys expected disks' do
144
- expect(ui).to receive(:warn).with(/Destroying machine that was originally created without device aliases.*/)
148
+ expect(ui).to receive(:warn).with(/Machine that was originally created without device aliases.*/)
145
149
  expect(ui).to receive(:warn).with(/Unexpected number of volumes detected/)
146
150
  expect(ui).to receive(:warn).with(/box metadata not available to get volume list during destroy, assuming inferred list/)
147
151
  domain_disks.each do |disk, name|
@@ -150,7 +154,7 @@ describe VagrantPlugins::ProviderLibvirt::Action::DestroyDomain do
150
154
  next if domain_disks.last.first == disk
151
155
  expect(disk).to receive(:destroy)
152
156
  end
153
- expect(domain).to receive(:destroy).with(destroy_volumes: false)
157
+ expect(domain).to receive(:destroy).with(destroy_volumes: false, flags: 0)
154
158
  expect(subject.call(env)).to be_nil
155
159
  end
156
160
 
@@ -168,7 +172,7 @@ describe VagrantPlugins::ProviderLibvirt::Action::DestroyDomain do
168
172
  end
169
173
 
170
174
  it 'only destroys expected disks' do
171
- expect(ui).to receive(:warn).with(/Destroying machine that was originally created without device aliases.*/)
175
+ expect(ui).to receive(:warn).with(/Machine that was originally created without device aliases.*/)
172
176
  expect(ui).to receive(:warn).with(/Unexpected number of volumes detected/)
173
177
  domain_disks.each do |disk, name|
174
178
  expect(disk).to receive(:name).and_return(name).at_least(:once)
@@ -176,7 +180,7 @@ describe VagrantPlugins::ProviderLibvirt::Action::DestroyDomain do
176
180
  next if domain_disks.last.first == disk
177
181
  expect(disk).to receive(:destroy)
178
182
  end
179
- expect(domain).to receive(:destroy).with(destroy_volumes: false)
183
+ expect(domain).to receive(:destroy).with(destroy_volumes: false, flags: 0)
180
184
  expect(subject.call(env)).to be_nil
181
185
  end
182
186
  end
@@ -185,6 +189,35 @@ describe VagrantPlugins::ProviderLibvirt::Action::DestroyDomain do
185
189
  end
186
190
  end
187
191
 
192
+ context 'when has nvram' do
193
+ let(:vagrantfile) do
194
+ <<-EOF
195
+ Vagrant.configure('2') do |config|
196
+ config.vm.define :test
197
+ config.vm.provider :libvirt do |libvirt|
198
+ libvirt.nvram = "test"
199
+ end
200
+ end
201
+ EOF
202
+ end
203
+
204
+ it 'sets destroy flags to keep nvram' do
205
+ expect(domain).to receive(:destroy).with(destroy_volumes: true, flags: VagrantPlugins::ProviderLibvirt::Util::DomainFlags::VIR_DOMAIN_UNDEFINE_KEEP_NVRAM)
206
+ expect(subject.call(env)).to be_nil
207
+ end
208
+
209
+ context 'when fog does not support destroy with flags' do
210
+ before do
211
+ expect(destroy_method).to receive(:parameters).and_return([[:opt, :options]])
212
+ end
213
+
214
+ it 'skips setting additional destroy flags' do
215
+ expect(domain).to receive(:destroy).with(destroy_volumes: true)
216
+ expect(subject.call(env)).to be_nil
217
+ end
218
+ end
219
+ end
220
+
188
221
  context 'when has CDROMs attached' do
189
222
  let(:vagrantfile_providerconfig) do
190
223
  <<-EOF
@@ -197,7 +230,7 @@ describe VagrantPlugins::ProviderLibvirt::Action::DestroyDomain do
197
230
  expect(domain).to receive(:volumes).and_return([root_disk, nil])
198
231
  expect(libvirt_domain).to receive(:xml_desc).and_return(domain_xml)
199
232
 
200
- expect(domain).to_not receive(:destroy).with(destroy_volumes: true)
233
+ expect(domain).to_not receive(:destroy).with(destroy_volumes: true, flags: 0)
201
234
  expect(root_disk).to receive(:destroy) # root disk remove
202
235
  expect(subject.call(env)).to be_nil
203
236
  end
@@ -195,7 +195,6 @@ describe VagrantPlugins::ProviderLibvirt::Action::ClearForwardedPorts do
195
195
  end
196
196
  end
197
197
  it 'should terminate each of the processes' do
198
- expect(logger).to receive(:info).with(no_args) # don't know how to test translations from vagrant
199
198
  expect(subject).to receive(:ssh_pid?).with("10001").and_return(true)
200
199
  expect(subject).to receive(:ssh_pid?).with("10002").and_return(true)
201
200
  expect(logger).to receive(:debug).with(/Killing pid/).twice()