vagrant-libvirt 0.6.0 → 0.7.0

Sign up to get free protection for your applications and to get access to all the features.
@@ -1,5 +1,7 @@
1
1
  # frozen_string_literal: true
2
2
 
3
+ require 'fog/libvirt/requests/compute/dhcp_leases'
4
+
3
5
  require 'spec_helper'
4
6
  require 'support/binding_proc'
5
7
  require 'support/sharedcontext'
@@ -8,6 +10,7 @@ require 'vagrant-libvirt/driver'
8
10
 
9
11
  describe VagrantPlugins::ProviderLibvirt::Driver do
10
12
  include_context 'unit'
13
+ include_context 'libvirt'
11
14
 
12
15
  subject { described_class.new(machine) }
13
16
 
@@ -27,6 +30,7 @@ describe VagrantPlugins::ProviderLibvirt::Driver do
27
30
  end
28
31
  EOF
29
32
  end
33
+
30
34
  # need to override the default package iso_env as using a different
31
35
  # name for the test machines above.
32
36
  let(:machine) { iso_env.machine(:test1, :libvirt) }
@@ -36,6 +40,14 @@ describe VagrantPlugins::ProviderLibvirt::Driver do
36
40
  let(:system_connection1) { double("system connection 1") }
37
41
  let(:system_connection2) { double("system connection 2") }
38
42
 
43
+ # make it easier for distros that want to switch the default value for
44
+ # qemu_use_session to true by ensuring it is explicitly false for tests.
45
+ before do
46
+ allow(machine.provider_config).to receive(:qemu_use_session).and_return(false)
47
+ allow(logger).to receive(:info)
48
+ allow(logger).to receive(:debug)
49
+ end
50
+
39
51
  describe '#connection' do
40
52
  it 'should configure a separate connection per machine' do
41
53
  expect(Fog::Compute).to receive(:new).with(
@@ -68,15 +80,15 @@ describe VagrantPlugins::ProviderLibvirt::Driver do
68
80
  # system_uri should be 'qemu+ssh://user@remote1/system'
69
81
  # and not 'qemu:///system'.
70
82
  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)
83
+ expect(Libvirt).to receive(:open_read_only).with('qemu+ssh://user@remote1/system').and_return(system_connection1)
84
+ expect(Libvirt).to receive(:open_read_only).with('qemu+ssh://vms@remote2/system').and_return(system_connection2)
73
85
 
74
86
  expect(machine.provider.driver.system_connection).to eq(system_connection1)
75
87
  expect(machine2.provider.driver.system_connection).to eq(system_connection2)
76
88
  end
77
89
 
78
90
  it 'should configure the connection once' do
79
- expect(Libvirt).to receive(:open).with('qemu:///system').and_return(system_connection1)
91
+ expect(Libvirt).to receive(:open_read_only).with('qemu+ssh://user@remote1/system').and_return(system_connection1)
80
92
 
81
93
  expect(machine.provider.driver.system_connection).to eq(system_connection1)
82
94
  expect(machine.provider.driver.system_connection).to eq(system_connection1)
@@ -84,6 +96,129 @@ describe VagrantPlugins::ProviderLibvirt::Driver do
84
96
  end
85
97
  end
86
98
 
99
+ describe '#get_ipaddress' do
100
+ context 'when domain exists' do
101
+ # not used yet, but this is the form that is returned from addresses
102
+ let(:addresses) { {
103
+ :public => ["192.168.122.111"],
104
+ :private => ["192.168.122.111"],
105
+ } }
106
+
107
+ before do
108
+ allow(subject).to receive(:get_domain).and_return(domain)
109
+ end
110
+
111
+ it 'should retrieve the address via domain fog-libvirt API' do
112
+ # ideally should be able to yield a block to wait_for and check that
113
+ # the 'addresses' function on the domain is called correctly.
114
+ expect(domain).to receive(:wait_for).and_return(nil)
115
+ expect(subject.get_ipaddress(machine)).to eq(nil)
116
+ end
117
+
118
+ context 'when qemu_use_agent is enabled' do
119
+ let(:qemu_agent_interfaces) {
120
+ <<-EOF
121
+ {
122
+ "return": [
123
+ {
124
+ "name": "lo",
125
+ "ip-addresses": [
126
+ {
127
+ "ip-address-type": "ipv4",
128
+ "ip-address": "127.0.0.1",
129
+ "prefix": 8
130
+ }
131
+ ],
132
+ "hardware-address": "00:00:00:00:00:00"
133
+ },
134
+ {
135
+ "name": "eth0",
136
+ "ip-addresses": [
137
+ {
138
+ "ip-address-type": "ipv4",
139
+ "ip-address": "192.168.122.42",
140
+ "prefix": 24
141
+ }
142
+ ],
143
+ "hardware-address": "52:54:00:f8:67:98"
144
+ }
145
+ ]
146
+ }
147
+ EOF
148
+ }
149
+
150
+ before do
151
+ allow(machine.provider_config).to receive(:qemu_use_agent).and_return(true)
152
+ end
153
+
154
+ it 'should retrieve the address via the agent' do
155
+ expect(subject).to receive(:connection).and_return(connection)
156
+ expect(libvirt_client).to receive(:lookup_domain_by_uuid).and_return(libvirt_domain)
157
+ expect(libvirt_domain).to receive(:qemu_agent_command).and_return(qemu_agent_interfaces)
158
+ expect(domain).to receive(:mac).and_return("52:54:00:f8:67:98").exactly(2).times
159
+
160
+ expect(subject.get_ipaddress(machine)).to eq("192.168.122.42")
161
+ end
162
+
163
+ context 'when qemu_use_session is enabled' do
164
+ before do
165
+ allow(machine.provider_config).to receive(:qemu_use_session).and_return(true)
166
+ end
167
+
168
+ it 'should still retrieve the address via the agent' do
169
+ expect(subject).to receive(:connection).and_return(connection)
170
+ expect(libvirt_client).to receive(:lookup_domain_by_uuid).and_return(libvirt_domain)
171
+ expect(libvirt_domain).to receive(:qemu_agent_command).and_return(qemu_agent_interfaces)
172
+ expect(domain).to receive(:mac).and_return("52:54:00:f8:67:98").exactly(2).times
173
+
174
+ expect(subject.get_ipaddress(machine)).to eq("192.168.122.42")
175
+ end
176
+ end
177
+ end
178
+
179
+ context 'when qemu_use_session is enabled' do
180
+ let(:networks) { [instance_double('::Fog::Libvirt::Compute::Real')] }
181
+ let(:dhcp_leases) {
182
+ {
183
+ "iface" =>"virbr0",
184
+ "expirytime" =>1636287162,
185
+ "type" =>0,
186
+ "mac" =>"52:54:00:8b:dc:5f",
187
+ "ipaddr" =>"192.168.122.43",
188
+ "prefix" =>24,
189
+ "hostname" =>"vagrant-default_test",
190
+ "clientid" =>"ff:00:8b:dc:5f:00:01:00:01:29:1a:65:42:52:54:00:8b:dc:5f",
191
+ }
192
+ }
193
+
194
+ before do
195
+ allow(machine.provider_config).to receive(:qemu_use_session).and_return(true)
196
+ end
197
+
198
+ it 'should retreive the address via the system dhcp-leases API' do
199
+ expect(domain).to receive(:mac).and_return("52:54:00:8b:dc:5f")
200
+ expect(subject).to receive(:system_connection).and_return(system_connection1)
201
+ expect(system_connection1).to receive(:list_all_networks).and_return(networks)
202
+ expect(networks[0]).to receive(:dhcp_leases).and_return([dhcp_leases])
203
+
204
+ expect(subject.get_ipaddress(machine)).to eq("192.168.122.43")
205
+ end
206
+
207
+ context 'when qemu_use_agent is enabled' do
208
+ before do
209
+ allow(machine.provider_config).to receive(:qemu_use_agent).and_return(true)
210
+ end
211
+
212
+ it 'should retrieve the address via the agent' do
213
+ expect(subject).to receive(:get_ipaddress_from_qemu_agent).and_return("192.168.122.44")
214
+
215
+ expect(subject.get_ipaddress(machine)).to eq("192.168.122.44")
216
+ end
217
+ end
218
+ end
219
+ end
220
+ end
221
+
87
222
  describe '#state' do
88
223
  let(:domain) { double('domain') }
89
224
 
@@ -81,10 +81,12 @@
81
81
  <readonly/>
82
82
  </disk>
83
83
 
84
- <serial type='pty'>
84
+ <serial type='file'>
85
+ <source path='/var/log/vm_consoles/machine.log'/>
85
86
  <target port='0'/>
86
87
  </serial>
87
- <console type='pty'>
88
+ <console type='file'>
89
+ <source path='/var/log/vm_consoles/machine.log'/>
88
90
  <target port='0'/>
89
91
  </console>
90
92
 
@@ -110,9 +112,13 @@
110
112
 
111
113
  <input type='mouse' bus='ps2'/>
112
114
 
113
- <graphics type='vnc' port='-1' autoport='yes' listen='127.0.0.1' keymap='en-us' />
115
+ <graphics type='vnc' port='-1' autoport='yes' listen='127.0.0.1' keymap='en-us' >
116
+ <gl enable='yes' />
117
+ </graphics>
114
118
  <video>
115
- <model type='cirrus' vram='9216' heads='1'/>
119
+ <model type='cirrus' vram='9216' heads='1'>
120
+ <acceleration accel3d='yes'/>
121
+ </model>
116
122
  </video>
117
123
  <rng model='virtio'>
118
124
  <backend model='random'>/dev/random</backend>
@@ -89,6 +89,7 @@ describe 'templates/domain' do
89
89
  target_port: '4242',
90
90
  source_path: '/tmp/foo')
91
91
  domain.random(model: 'random')
92
+ domain.serial(:type => 'file', :source => {:path => '/var/log/vm_consoles/machine.log'})
92
93
  domain.pci(bus: '0x06', slot: '0x12', function: '0x5')
93
94
  domain.pci(domain: '0x0001', bus: '0x03', slot: '0x00', function: '0x0')
94
95
  domain.usb_controller(model: 'nec-xhci', ports: '4')
@@ -111,6 +112,8 @@ describe 'templates/domain' do
111
112
  domain.shares = '1024'
112
113
  domain.cpuset = '1-4,^3,6'
113
114
  domain.nodeset = '1-4,^3,6'
115
+
116
+ domain.video_accel3d = true
114
117
  end
115
118
  let(:test_file) { 'domain_all_settings.xml' }
116
119
  it 'renders template' do
metadata CHANGED
@@ -1,17 +1,17 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: vagrant-libvirt
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.6.0
4
+ version: 0.7.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Lukas Stanek
8
8
  - Dima Vasilets
9
9
  - Brian Pitts
10
10
  - Darragh Bailey
11
- autorequire:
11
+ autorequire:
12
12
  bindir: bin
13
13
  cert_chain: []
14
- date: 2021-10-08 00:00:00.000000000 Z
14
+ date: 2021-11-09 00:00:00.000000000 Z
15
15
  dependencies:
16
16
  - !ruby/object:Gem::Dependency
17
17
  name: rspec-core
@@ -252,6 +252,7 @@ files:
252
252
  - spec/unit/action/halt_domain_spec.rb
253
253
  - spec/unit/action/handle_box_image_spec.rb
254
254
  - spec/unit/action/package_domain_spec.rb
255
+ - spec/unit/action/prepare_nfs_settings_spec.rb
255
256
  - spec/unit/action/set_name_of_domain_spec.rb
256
257
  - spec/unit/action/shutdown_domain_spec.rb
257
258
  - spec/unit/action/start_domain_spec.rb
@@ -264,7 +265,6 @@ files:
264
265
  - spec/unit/action_spec.rb
265
266
  - spec/unit/config_spec.rb
266
267
  - spec/unit/driver_spec.rb
267
- - spec/unit/provider_spec.rb
268
268
  - spec/unit/templates/domain_all_settings.xml
269
269
  - spec/unit/templates/domain_custom_cpu_model.xml
270
270
  - spec/unit/templates/domain_defaults.xml
@@ -275,8 +275,9 @@ files:
275
275
  homepage: https://github.com/vagrant-libvirt/vagrant-libvirt
276
276
  licenses:
277
277
  - MIT
278
- metadata: {}
279
- post_install_message:
278
+ metadata:
279
+ source_code_uri: https://github.com/vagrant-libvirt/vagrant-libvirt
280
+ post_install_message:
280
281
  rdoc_options: []
281
282
  require_paths:
282
283
  - lib
@@ -291,51 +292,51 @@ required_rubygems_version: !ruby/object:Gem::Requirement
291
292
  - !ruby/object:Gem::Version
292
293
  version: '0'
293
294
  requirements: []
294
- rubygems_version: 3.0.9
295
- signing_key:
295
+ rubygems_version: 3.0.8
296
+ signing_key:
296
297
  specification_version: 4
297
298
  summary: libvirt provider for Vagrant.
298
299
  test_files:
299
- - spec/support/matchers/have_file_content.rb
300
- - spec/support/binding_proc.rb
301
- - spec/support/environment_helper.rb
302
- - spec/support/libvirt_context.rb
303
300
  - spec/support/temporary_dir.rb
301
+ - spec/support/libvirt_context.rb
302
+ - spec/support/binding_proc.rb
304
303
  - spec/support/sharedcontext.rb
305
- - spec/unit/action/create_domain_spec/default_system_storage_pool.xml
306
- - spec/unit/action/create_domain_spec/default_user_storage_pool.xml
304
+ - spec/support/matchers/have_file_content.rb
305
+ - spec/support/environment_helper.rb
306
+ - spec/unit/action_spec.rb
307
+ - spec/unit/templates/domain_all_settings.xml
308
+ - spec/unit/templates/domain_custom_cpu_model.xml
309
+ - spec/unit/templates/domain_defaults.xml
310
+ - spec/unit/templates/domain_spec.rb
311
+ - spec/unit/templates/tpm/version_1.2.xml
312
+ - spec/unit/templates/tpm/version_2.0.xml
307
313
  - spec/unit/action/create_domain_spec/additional_disks_domain.xml
308
314
  - spec/unit/action/create_domain_spec/default_domain.xml
309
- - spec/unit/action/create_domain_volume_spec/one_disk_in_storage.xml
310
- - spec/unit/action/create_domain_volume_spec/three_disks_in_storage_disk_0.xml
315
+ - spec/unit/action/create_domain_spec/default_system_storage_pool.xml
316
+ - spec/unit/action/create_domain_spec/default_user_storage_pool.xml
317
+ - spec/unit/action/create_domain_spec.rb
318
+ - spec/unit/action/wait_till_up_spec.rb
319
+ - spec/unit/action/package_domain_spec.rb
320
+ - spec/unit/action/forward_ports_spec.rb
321
+ - spec/unit/action/destroy_domain_spec.rb
322
+ - spec/unit/action/halt_domain_spec.rb
323
+ - spec/unit/action/start_domain_spec.rb
324
+ - spec/unit/action/shutdown_domain_spec.rb
325
+ - spec/unit/action/clean_machine_folder_spec.rb
326
+ - spec/unit/action/create_domain_volume_spec.rb
327
+ - spec/unit/action/set_name_of_domain_spec.rb
328
+ - spec/unit/action/prepare_nfs_settings_spec.rb
311
329
  - spec/unit/action/create_domain_volume_spec/three_disks_in_storage_disk_1.xml
330
+ - spec/unit/action/create_domain_volume_spec/three_disks_in_storage_disk_0.xml
312
331
  - spec/unit/action/create_domain_volume_spec/three_disks_in_storage_disk_2.xml
332
+ - spec/unit/action/create_domain_volume_spec/one_disk_in_storage.xml
333
+ - spec/unit/action/start_domain_spec/default_added_tpm_path.xml
313
334
  - spec/unit/action/start_domain_spec/clock_timer_rtc.xml
314
335
  - spec/unit/action/start_domain_spec/default.xml
315
- - spec/unit/action/start_domain_spec/default_added_tpm_path.xml
316
- - spec/unit/action/start_domain_spec/default_added_tpm_version.xml
317
336
  - spec/unit/action/start_domain_spec/existing.xml
318
- - spec/unit/action/clean_machine_folder_spec.rb
319
- - spec/unit/action/forward_ports_spec.rb
337
+ - spec/unit/action/start_domain_spec/default_added_tpm_version.xml
320
338
  - spec/unit/action/handle_box_image_spec.rb
321
- - spec/unit/action/set_name_of_domain_spec.rb
322
- - spec/unit/action/wait_till_up_spec.rb
323
- - spec/unit/action/create_domain_volume_spec.rb
324
- - spec/unit/action/start_domain_spec.rb
325
- - spec/unit/action/destroy_domain_spec.rb
326
- - spec/unit/action/halt_domain_spec.rb
327
- - spec/unit/action/shutdown_domain_spec.rb
328
- - spec/unit/action/create_domain_spec.rb
329
- - spec/unit/action/package_domain_spec.rb
330
- - spec/unit/templates/tpm/version_1.2.xml
331
- - spec/unit/templates/tpm/version_2.0.xml
332
- - spec/unit/templates/domain_custom_cpu_model.xml
333
- - spec/unit/templates/domain_defaults.xml
334
- - spec/unit/templates/domain_spec.rb
335
- - spec/unit/templates/domain_all_settings.xml
336
- - spec/unit/util/byte_number_spec.rb
337
- - spec/unit/provider_spec.rb
338
- - spec/unit/action_spec.rb
339
339
  - spec/unit/config_spec.rb
340
+ - spec/unit/util/byte_number_spec.rb
340
341
  - spec/unit/driver_spec.rb
341
342
  - spec/spec_helper.rb
@@ -1,11 +0,0 @@
1
- require 'spec_helper'
2
- require 'support/sharedcontext'
3
-
4
- describe 'VagrantPlugins::ProviderLibvirt::Provider' do
5
- require 'vagrant-libvirt/provider'
6
-
7
- include_context 'unit'
8
-
9
- describe '#ssh_info' do
10
- end
11
- end