vagrant-libvirt 0.11.2 → 0.12.0

Sign up to get free protection for your applications and to get access to all the features.
Files changed (33) hide show
  1. checksums.yaml +4 -4
  2. data/lib/vagrant-libvirt/action/create_domain.rb +15 -1
  3. data/lib/vagrant-libvirt/action/create_domain_volume.rb +1 -0
  4. data/lib/vagrant-libvirt/action/create_network_interfaces.rb +7 -3
  5. data/lib/vagrant-libvirt/action/create_networks.rb +1 -1
  6. data/lib/vagrant-libvirt/action/destroy_domain_confirm.rb +22 -0
  7. data/lib/vagrant-libvirt/action/forward_ports.rb +1 -1
  8. data/lib/vagrant-libvirt/action/handle_box_image.rb +6 -3
  9. data/lib/vagrant-libvirt/action/start_domain.rb +38 -9
  10. data/lib/vagrant-libvirt/action.rb +0 -2
  11. data/lib/vagrant-libvirt/config.rb +75 -28
  12. data/lib/vagrant-libvirt/templates/domain.xml.erb +25 -14
  13. data/lib/vagrant-libvirt/templates/public_interface.xml.erb +22 -17
  14. data/lib/vagrant-libvirt/util/network_util.rb +25 -22
  15. data/lib/vagrant-libvirt/version +1 -1
  16. data/spec/support/libvirt_acceptance_context.rb +1 -1
  17. data/spec/support/matchers/have_file_content.rb +1 -1
  18. data/spec/support/unit_context.rb +0 -3
  19. data/spec/unit/action/clean_machine_folder_spec.rb +3 -3
  20. data/spec/unit/action/create_domain_volume_spec/one_disk_in_storage.xml +1 -0
  21. data/spec/unit/action/create_domain_volume_spec/three_disks_in_storage_disk_0.xml +1 -0
  22. data/spec/unit/action/create_domain_volume_spec/three_disks_in_storage_disk_1.xml +1 -0
  23. data/spec/unit/action/create_domain_volume_spec/three_disks_in_storage_disk_2.xml +1 -0
  24. data/spec/unit/action/create_network_interfaces.rb +305 -0
  25. data/spec/unit/action/handle_box_image_spec.rb +9 -2
  26. data/spec/unit/action/start_domain_spec.rb +42 -0
  27. data/spec/unit/action_spec.rb +62 -1
  28. data/spec/unit/cap/mount_9p_spec.rb +4 -0
  29. data/spec/unit/config_spec.rb +39 -10
  30. data/spec/unit/driver_spec.rb +29 -18
  31. data/spec/unit/templates/domain_all_settings.xml +2 -2
  32. data/spec/unit/templates/domain_spec.rb +2 -1
  33. metadata +5 -2
@@ -58,7 +58,7 @@ describe VagrantPlugins::ProviderLibvirt::Action do
58
58
  end
59
59
 
60
60
  def receive_and_call_next(&block)
61
- return receive(:call) { |cls, env| call_next(cls, env, &block) }
61
+ return receive(:call) { |cls, env| call_next(cls, env, &block) }.exactly(1).times
62
62
  end
63
63
 
64
64
  def call_next(cls, env)
@@ -332,6 +332,25 @@ describe VagrantPlugins::ProviderLibvirt::Action do
332
332
  end
333
333
  end
334
334
  end
335
+
336
+ context 'running' do
337
+ before do
338
+ allow_action_env_result(VagrantPlugins::ProviderLibvirt::Action::IsCreated, true)
339
+ allow_action_env_result(VagrantPlugins::ProviderLibvirt::Action::IsRunning, true)
340
+ allow_action_env_result(VagrantPlugins::ProviderLibvirt::Action::IsSuspended, false)
341
+ end
342
+
343
+ it 'should call provision' do
344
+ expect_any_instance_of(Vagrant::Action::Builtin::BoxCheckOutdated).to receive_and_call_next
345
+ expect_any_instance_of(VagrantPlugins::ProviderLibvirt::Action::Provision).to receive_and_call_next
346
+ # ideally following two actions should not be scheduled if the machine is already running
347
+ expect_any_instance_of(VagrantPlugins::ProviderLibvirt::Action::ResolveDiskSettings).to receive_and_call_next
348
+ expect_any_instance_of(VagrantPlugins::ProviderLibvirt::Action::CreateNetworks).to receive_and_call_next
349
+ expect_any_instance_of(VagrantPlugins::ProviderLibvirt::Action::SetupComplete).to receive_and_call_next
350
+
351
+ expect(runner.run(subject.action_up)).to match(hash_including({:machine => machine}))
352
+ end
353
+ end
335
354
  end
336
355
 
337
356
  describe '#action_halt' do
@@ -389,6 +408,48 @@ describe VagrantPlugins::ProviderLibvirt::Action do
389
408
  end
390
409
  end
391
410
 
411
+ describe '#action_reload' do
412
+ context 'when not created' do
413
+ before do
414
+ allow_action_env_result(VagrantPlugins::ProviderLibvirt::Action::IsCreated, false)
415
+ end
416
+
417
+ it 'should report not created' do
418
+ expect(ui).to receive(:info).with('Domain is not created. Please run `vagrant up` first.')
419
+
420
+ expect(runner.run(subject.action_reload)).to match(hash_including({:machine => machine}))
421
+ end
422
+ end
423
+
424
+ context 'when halted' do
425
+ before do
426
+ allow_action_env_result(VagrantPlugins::ProviderLibvirt::Action::IsCreated, true)
427
+ allow_action_env_result(VagrantPlugins::ProviderLibvirt::Action::IsSuspended, false)
428
+ allow_action_env_result(VagrantPlugins::ProviderLibvirt::Action::IsRunning, false)
429
+ end
430
+
431
+ it 'should call reload' do
432
+ expect_any_instance_of(VagrantPlugins::ProviderLibvirt::Action::Provision).to receive_and_call_next
433
+ expect(subject).to receive(:action_halt).and_return(Vagrant::Action::Builder.new)
434
+ expect_any_instance_of(VagrantPlugins::ProviderLibvirt::Action::ResolveDiskSettings).to receive_and_call_next
435
+
436
+ # start action
437
+ expect_any_instance_of(VagrantPlugins::ProviderLibvirt::Action::PrepareNFSValidIds).to receive_and_call_next
438
+ expect_any_instance_of(VagrantPlugins::ProviderLibvirt::Action::SyncedFolderCleanup).to receive_and_call_next
439
+ expect_any_instance_of(Vagrant::Action::Builtin::SyncedFolders).to receive_and_call_next
440
+ expect_any_instance_of(VagrantPlugins::ProviderLibvirt::Action::PrepareNFSSettings).to receive_and_call_next
441
+ expect_any_instance_of(VagrantPlugins::ProviderLibvirt::Action::ShareFolders).to receive_and_call_next
442
+ expect_any_instance_of(VagrantPlugins::ProviderLibvirt::Action::SetBootOrder).to receive_and_call_next
443
+ expect_any_instance_of(VagrantPlugins::ProviderLibvirt::Action::StartDomain).to receive_and_call_next
444
+ expect_any_instance_of(VagrantPlugins::ProviderLibvirt::Action::WaitTillUp).to receive_and_call_next
445
+ expect_any_instance_of(Vagrant::Action::Builtin::WaitForCommunicator).to receive_and_call_next
446
+ expect_any_instance_of(VagrantPlugins::ProviderLibvirt::Action::ForwardPorts).to receive_and_call_next
447
+
448
+ expect(runner.run(subject.action_reload)).to match(hash_including({:machine => machine}))
449
+ end
450
+ end
451
+ end
452
+
392
453
  describe '#action_suspend' do
393
454
  context 'not created' do
394
455
  before do
@@ -15,6 +15,9 @@ describe 'VagrantPlugins::ProviderLibvirt::Cap::Mount9P' do
15
15
  end
16
16
 
17
17
  let(:options) { {} }
18
+ # Mock the guest operating system.
19
+ let(:guest) { double('guest') }
20
+
18
21
  describe '#mount_9p_shared_folder' do
19
22
  let(:synced_folders) { {
20
23
  "/vagrant" => {
@@ -26,6 +29,7 @@ describe 'VagrantPlugins::ProviderLibvirt::Cap::Mount9P' do
26
29
  } }
27
30
 
28
31
  before do
32
+ allow(machine).to receive(:guest).and_return(guest)
29
33
  allow(guest).to receive(:capability).and_return('/home/vagrant/vagant')
30
34
  allow(communicator).to receive(:sudo).with('mkdir -p /home/vagrant/vagant')
31
35
  end
@@ -86,7 +86,7 @@ describe VagrantPlugins::ProviderLibvirt::Config do
86
86
  ],
87
87
  [ # connect explicit to unix socket
88
88
  {:uri => "qemu+unix:///system"},
89
- {:uri => "qemu+unix:///system", :connect_via_ssh => false, :host => nil, :username => nil},
89
+ {:uri => "qemu+unix:///system", :connect_via_ssh => false, :host => "", :username => nil},
90
90
  ],
91
91
  [ # via libssh2 should enable ssh as well
92
92
  {:uri => "qemu+libssh2://user@remote/system?known_hosts=/home/user/.ssh/known_hosts"},
@@ -139,7 +139,7 @@ describe VagrantPlugins::ProviderLibvirt::Config do
139
139
  ],
140
140
  [ # with session and using ssh infer connect by ssh and ignore host as not provided
141
141
  {},
142
- {:uri => "qemu+ssh:///session", :qemu_use_session => true, :connect_via_ssh => true, :host => nil},
142
+ {:uri => "qemu+ssh:///session", :qemu_use_session => true, :connect_via_ssh => true, :host => ""},
143
143
  {
144
144
  :env => {'LIBVIRT_DEFAULT_URI' => "qemu+ssh:///session"},
145
145
  }
@@ -768,8 +768,13 @@ describe VagrantPlugins::ProviderLibvirt::Config do
768
768
 
769
769
  context 'with mac defined' do
770
770
  let (:vm) { double('vm') }
771
+ let(:box) { instance_double(::Vagrant::Box) }
772
+
771
773
  before do
772
774
  machine.config.instance_variable_get("@keys")[:vm] = vm
775
+ allow(vm).to receive(:box).and_return(box)
776
+
777
+ allow(vm).to receive(:synced_folders).and_return({})
773
778
  end
774
779
 
775
780
  it 'is valid with valid mac' do
@@ -781,7 +786,7 @@ describe VagrantPlugins::ProviderLibvirt::Config do
781
786
  network = [:public, { mac: 'aabbccddeeff' }]
782
787
  expect(vm).to receive(:networks).and_return([network])
783
788
  assert_valid
784
- expect(network[1][:mac]).to eql('aa:bb:cc:dd:ee:ff')
789
+ expect(network[1][:mac]).to eql('aabbccddeeff')
785
790
  end
786
791
 
787
792
  it 'should be invalid if MAC not formatted correctly' do
@@ -798,8 +803,9 @@ describe VagrantPlugins::ProviderLibvirt::Config do
798
803
  'virbr0',
799
804
  ] }
800
805
  let(:driver) { instance_double(::VagrantPlugins::ProviderLibvirt::Driver) }
806
+ let(:device_name) { 'eth0' }
801
807
  before do
802
- machine.config.vm.network :public_network, dev: 'eth0', ip: "192.168.2.157"
808
+ machine.config.vm.network :public_network, dev: device_name, ip: "192.168.2.157"
803
809
  allow(machine.provider).to receive(:driver).and_return(driver)
804
810
  expect(driver).to receive(:host_devices).and_return(host_devices).at_least(:once).times
805
811
  end
@@ -809,9 +815,7 @@ describe VagrantPlugins::ProviderLibvirt::Config do
809
815
  end
810
816
 
811
817
  context 'when default device not on host' do
812
- before do
813
- machine.config.vm.network :public_network, dev: 'eno1', ip: "192.168.2.157"
814
- end
818
+ let(:device_name) { 'eno1' }
815
819
 
816
820
  it 'should be invalid' do
817
821
  assert_invalid
@@ -819,9 +823,7 @@ describe VagrantPlugins::ProviderLibvirt::Config do
819
823
  end
820
824
 
821
825
  context 'when using excluded host device' do
822
- before do
823
- machine.config.vm.network :public_network, dev: 'virbr0', ip: "192.168.2.157"
824
- end
826
+ let(:device_name) { 'virbr0' }
825
827
 
826
828
  it 'should be invalid' do
827
829
  assert_invalid
@@ -837,6 +839,27 @@ describe VagrantPlugins::ProviderLibvirt::Config do
837
839
  end
838
840
  end
839
841
  end
842
+
843
+ context 'when setting iface_name' do
844
+ let(:iface_name) { 'myvnet1' }
845
+
846
+ before do
847
+ machine.config.vm.network :public_network, libvirt__iface_name: iface_name, ip: "192.168.2.157"
848
+ end
849
+
850
+ it 'should valididate' do
851
+ assert_valid
852
+ end
853
+
854
+ context 'when set to reserved value' do
855
+ let(:iface_name) { 'vnet1' }
856
+
857
+ it 'should be invalid' do
858
+ errors = assert_invalid
859
+ expect(errors).to include(match(/network configuration for machine test with setting :libvirt__iface_name => '#{iface_name}' starts/))
860
+ end
861
+ end
862
+ end
840
863
  end
841
864
 
842
865
  context 'with nvram defined' do
@@ -996,10 +1019,16 @@ describe VagrantPlugins::ProviderLibvirt::Config do
996
1019
  EOF
997
1020
  end
998
1021
  let(:driver) { instance_double(::VagrantPlugins::ProviderLibvirt::Driver) }
1022
+ let(:host_devices) { [
1023
+ 'lo',
1024
+ 'eth0',
1025
+ 'virbr0',
1026
+ ] }
999
1027
 
1000
1028
  before do
1001
1029
  allow(machine.provider).to receive(:driver).and_return(driver)
1002
1030
  allow(driver).to receive_message_chain('connection.client.libversion').and_return(6_002_000)
1031
+ allow(driver).to receive(:host_devices).and_return(host_devices)
1003
1032
  end
1004
1033
 
1005
1034
  context 'when type is 9p' do
@@ -42,40 +42,51 @@ describe VagrantPlugins::ProviderLibvirt::Driver do
42
42
  # need to override the default package iso_env as using a different
43
43
  # name for the test machines above.
44
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") }
45
+ let(:connection) { double("connection 1") }
46
+ let(:system_connection) { double("system connection 1") }
50
47
 
51
48
  # make it easier for distros that want to switch the default value for
52
49
  # qemu_use_session to true by ensuring it is explicitly false for tests.
53
50
  before do
54
51
  allow(machine.provider).to receive('driver').and_call_original
55
- allow(machine2.provider).to receive('driver').and_call_original
56
52
  end
57
53
 
58
54
  describe '#connection' do
55
+ let(:machine2) { iso_env.machine(:test2, :libvirt) }
56
+ let(:connection2) { double("connection 2") }
57
+
58
+ before do
59
+ allow(machine2.provider).to receive('driver').and_call_original
60
+ end
61
+
59
62
  it 'should configure a separate connection per machine' do
60
63
  expect(Fog::Compute).to receive(:new).with(
61
- hash_including({:libvirt_uri => 'qemu+ssh://user@remote1/system'})).and_return(connection1)
64
+ hash_including({:libvirt_uri => 'qemu+ssh://user@remote1/system'})).and_return(connection)
62
65
  expect(Fog::Compute).to receive(:new).with(
63
66
  hash_including({:libvirt_uri => 'qemu+ssh://vms@remote2/system'})).and_return(connection2)
64
67
 
65
- expect(machine.provider.driver.connection).to eq(connection1)
68
+ expect(machine.provider.driver.connection).to eq(connection)
66
69
  expect(machine2.provider.driver.connection).to eq(connection2)
67
70
  end
68
71
 
69
72
  it 'should configure the connection once' do
70
- expect(Fog::Compute).to receive(:new).once().and_return(connection1)
73
+ expect(Fog::Compute).to receive(:new).once().and_return(connection)
71
74
 
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
+ expect(machine.provider.driver.connection).to eq(connection)
76
+ expect(machine.provider.driver.connection).to eq(connection)
77
+ expect(machine.provider.driver.connection).to eq(connection)
75
78
  end
76
79
  end
77
80
 
78
81
  describe '#system_connection' do
82
+ let(:machine2) { iso_env.machine(:test2, :libvirt) }
83
+ let(:connection2) { double("connection 2") }
84
+ let(:system_connection2) { double("system connection 2") }
85
+
86
+ before do
87
+ allow(machine2.provider).to receive('driver').and_call_original
88
+ end
89
+
79
90
  # note that the urls for the two tests are currently
80
91
  # incorrect here as they should be the following:
81
92
  # qemu+ssh://user@remote1/system
@@ -87,19 +98,19 @@ describe VagrantPlugins::ProviderLibvirt::Driver do
87
98
  # system_uri should be 'qemu+ssh://user@remote1/system'
88
99
  # and not 'qemu:///system'.
89
100
  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)
101
+ expect(Libvirt).to receive(:open_read_only).with('qemu+ssh://user@remote1/system').and_return(system_connection)
91
102
  expect(Libvirt).to receive(:open_read_only).with('qemu+ssh://vms@remote2/system').and_return(system_connection2)
92
103
 
93
- expect(machine.provider.driver.system_connection).to eq(system_connection1)
104
+ expect(machine.provider.driver.system_connection).to eq(system_connection)
94
105
  expect(machine2.provider.driver.system_connection).to eq(system_connection2)
95
106
  end
96
107
 
97
108
  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)
109
+ expect(Libvirt).to receive(:open_read_only).with('qemu+ssh://user@remote1/system').and_return(system_connection)
99
110
 
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)
111
+ expect(machine.provider.driver.system_connection).to eq(system_connection)
112
+ expect(machine.provider.driver.system_connection).to eq(system_connection)
113
+ expect(machine.provider.driver.system_connection).to eq(system_connection)
103
114
  end
104
115
  end
105
116
  end
@@ -47,7 +47,7 @@
47
47
  <spinlocks state='on' retries='4096' />
48
48
  </hyperv>
49
49
  </features>
50
- <clock offset='variable'>
50
+ <clock offset='variable' basis='localtime' adjustment='-31536000'>
51
51
  <timer name='t1'/>
52
52
  <timer name='t2' track='b' tickpolicy='c' frequency='d' mode='e' present='yes'/>
53
53
  </clock>
@@ -105,7 +105,7 @@
105
105
  <target dev='fda' bus='fdc'/>
106
106
  </disk>
107
107
  <serial type='file'>
108
- <source path='/var/log/vm_consoles/machine.log'/>
108
+ <source path='/var/log/vm_consoles/machine.log' append='on'/>
109
109
  <target port='0'/>
110
110
  </serial>
111
111
  <console type='file'>
@@ -62,7 +62,8 @@ describe 'templates/domain' do
62
62
  domain.cpu_mode = 'custom'
63
63
  domain.cpu_feature(name: 'AAA', policy: 'required')
64
64
  domain.hyperv_feature(name: 'BBB', state: 'on')
65
- domain.clock_offset = 'variable'
65
+ domain.clock_adjustment = -(365 * 24 * 60 * 60)
66
+ domain.clock_basis = 'localtime'
66
67
  domain.clock_timer(name: 't1')
67
68
  domain.clock_timer(name: 't2', track: 'b', tickpolicy: 'c', frequency: 'd', mode: 'e', present: 'yes')
68
69
  domain.hyperv_feature(name: 'spinlocks', state: 'on', retries: '4096')
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: vagrant-libvirt
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.11.2
4
+ version: 0.12.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Lukas Stanek
@@ -11,7 +11,7 @@ authors:
11
11
  autorequire:
12
12
  bindir: bin
13
13
  cert_chain: []
14
- date: 2022-12-04 00:00:00.000000000 Z
14
+ date: 2023-04-22 00:00:00.000000000 Z
15
15
  dependencies:
16
16
  - !ruby/object:Gem::Dependency
17
17
  name: fog-libvirt
@@ -174,6 +174,7 @@ files:
174
174
  - lib/vagrant-libvirt/action/create_network_interfaces.rb
175
175
  - lib/vagrant-libvirt/action/create_networks.rb
176
176
  - lib/vagrant-libvirt/action/destroy_domain.rb
177
+ - lib/vagrant-libvirt/action/destroy_domain_confirm.rb
177
178
  - lib/vagrant-libvirt/action/destroy_networks.rb
178
179
  - lib/vagrant-libvirt/action/forward_ports.rb
179
180
  - lib/vagrant-libvirt/action/halt_domain.rb
@@ -277,6 +278,7 @@ files:
277
278
  - spec/unit/action/create_domain_volume_spec/three_disks_in_storage_disk_0.xml
278
279
  - spec/unit/action/create_domain_volume_spec/three_disks_in_storage_disk_1.xml
279
280
  - spec/unit/action/create_domain_volume_spec/three_disks_in_storage_disk_2.xml
281
+ - spec/unit/action/create_network_interfaces.rb
280
282
  - spec/unit/action/destroy_domain_spec.rb
281
283
  - spec/unit/action/destroy_domain_spec/additional_disks_domain.xml
282
284
  - spec/unit/action/destroy_domain_spec/box_multiple_disks.xml
@@ -403,6 +405,7 @@ test_files:
403
405
  - spec/unit/action/create_domain_volume_spec/three_disks_in_storage_disk_1.xml
404
406
  - spec/unit/action/create_domain_volume_spec/three_disks_in_storage_disk_2.xml
405
407
  - spec/unit/action/create_domain_volume_spec.rb
408
+ - spec/unit/action/create_network_interfaces.rb
406
409
  - spec/unit/action/destroy_domain_spec/additional_disks_domain.xml
407
410
  - spec/unit/action/destroy_domain_spec/box_multiple_disks.xml
408
411
  - spec/unit/action/destroy_domain_spec/box_multiple_disks_and_additional_and_custom_disks.xml