vagrant-libvirt 0.0.32 → 0.0.33

Sign up to get free protection for your applications and to get access to all the features.
Files changed (32) hide show
  1. checksums.yaml +4 -4
  2. data/.travis.yml +1 -0
  3. data/Gemfile +4 -0
  4. data/README.md +146 -22
  5. data/lib/vagrant-libvirt/action/create_domain.rb +35 -0
  6. data/lib/vagrant-libvirt/action/create_network_interfaces.rb +1 -0
  7. data/lib/vagrant-libvirt/action/create_networks.rb +2 -0
  8. data/lib/vagrant-libvirt/action/forward_ports.rb +2 -2
  9. data/lib/vagrant-libvirt/action/handle_box_image.rb +3 -1
  10. data/lib/vagrant-libvirt/action/prepare_nfs_settings.rb +9 -9
  11. data/lib/vagrant-libvirt/action/set_name_of_domain.rb +6 -4
  12. data/lib/vagrant-libvirt/action/start_domain.rb +136 -30
  13. data/lib/vagrant-libvirt/action/wait_till_up.rb +22 -14
  14. data/lib/vagrant-libvirt/cap/nic_mac_addresses.rb +7 -1
  15. data/lib/vagrant-libvirt/cap/synced_folder.rb +6 -3
  16. data/lib/vagrant-libvirt/config.rb +109 -0
  17. data/lib/vagrant-libvirt/plugin.rb +3 -0
  18. data/lib/vagrant-libvirt/templates/domain.xml.erb +57 -7
  19. data/lib/vagrant-libvirt/templates/interface.xml.erb +5 -1
  20. data/lib/vagrant-libvirt/templates/private_network.xml.erb +1 -1
  21. data/lib/vagrant-libvirt/templates/tunnel_interface.xml.erb +6 -0
  22. data/lib/vagrant-libvirt/util/network_util.rb +2 -0
  23. data/lib/vagrant-libvirt/version.rb +1 -1
  24. data/locales/en.yml +1 -1
  25. data/spec/spec_helper.rb +1 -0
  26. data/spec/support/libvirt_context.rb +28 -0
  27. data/spec/support/sharedcontext.rb +34 -0
  28. data/spec/{vagrant-libvirt → unit}/action/set_name_of_domain_spec.rb +0 -0
  29. data/spec/unit/action/wait_till_up_spec.rb +128 -0
  30. data/tools/create_box.sh +3 -1
  31. data/vagrant-libvirt.gemspec +4 -4
  32. metadata +21 -15
@@ -10,6 +10,9 @@ if Vagrant::VERSION < '1.5.0'
10
10
  raise 'The Vagrant Libvirt plugin is only compatible with Vagrant 1.5+'
11
11
  end
12
12
 
13
+ # compatibility fix to define constant not available vagrant <1.6
14
+ ::Vagrant::MachineState::NOT_CREATED_ID ||= :not_created
15
+
13
16
  module VagrantPlugins
14
17
  module ProviderLibvirt
15
18
  class Plugin < Vagrant.plugin('2')
@@ -7,11 +7,14 @@
7
7
 
8
8
  <cpu mode='<%= @cpu_mode %>'>
9
9
  <% if @cpu_mode != 'host-passthrough' %>
10
- <model fallback='allow'>qemu64</model>
10
+ <model fallback='<%= @cpu_fallback %>'><%= @cpu_model %></model>
11
11
  <% if @nested %>
12
12
  <feature policy='optional' name='vmx'/>
13
13
  <feature policy='optional' name='svm'/>
14
14
  <% end %>
15
+ <% @cpu_features.each do |cpu_feature| %>
16
+ <feature name='<%= cpu_feature[:name] %>' policy='<%= cpu_feature[:policy] %>'/>
17
+ <% end %>
15
18
  <% end %>
16
19
  </cpu>
17
20
 
@@ -39,14 +42,25 @@
39
42
  <kernel><%= @kernel %></kernel>
40
43
  <initrd><%= @initrd %></initrd>
41
44
  <cmdline><%= @cmd_line %></cmdline>
45
+ <% if @dtb %>
46
+ <dtb><%= @dtb %></dtb>
47
+ <% end %>
42
48
  </os>
43
49
  <features>
44
50
  <acpi/>
45
51
  <apic/>
46
52
  <pae/>
53
+ <% if @kvm_hidden %>
54
+ <kvm>
55
+ <hidden state='on'/>
56
+ </kvm>
57
+ <% end %>
47
58
  </features>
48
59
  <clock offset='utc'/>
49
60
  <devices>
61
+ <% if @emulator_path %>
62
+ <emulator><%= @emulator_path %></emulator>
63
+ <% end %>
50
64
  <% if @domain_volume_path %>
51
65
  <disk type='file' device='disk'>
52
66
  <driver name='qemu' type='qcow2' cache='<%= @domain_volume_cache %>'/>
@@ -86,11 +100,47 @@
86
100
  <input type='<%= input[:type] %>' bus='<%= input[:bus] %>'/>
87
101
  <% end %>
88
102
 
89
- <%# Video device -%>
90
- <graphics type='<%= @graphics_type %>' port='<%= @graphics_port %>' autoport='<%= @graphics_autoport %>' listen='<%= @graphics_ip %>' keymap='<%= @keymap %>' <%= @graphics_passwd%> />
91
- <video>
92
- <model type='<%= @video_type %>' vram='<%= @video_vram %>' heads='1'/>
93
- </video>
94
- <%#End Video -%>
103
+ <% if @graphics_type != 'none' %>
104
+ <%# Video device -%>
105
+ <graphics type='<%= @graphics_type %>' port='<%= @graphics_port %>' autoport='<%= @graphics_autoport %>' listen='<%= @graphics_ip %>' keymap='<%= @keymap %>' <%= @graphics_passwd%> />
106
+ <video>
107
+ <model type='<%= @video_type %>' vram='<%= @video_vram %>' heads='1'/>
108
+ </video>
109
+ <%#End Video -%>
110
+ <% end %>
111
+ <% @pcis.each do |pci| %>
112
+ <hostdev mode='subsystem' type='pci' managed='yes'>
113
+ <source>
114
+ <address domain='0x0000'
115
+ bus='<%= pci[:bus] %>'
116
+ slot='<%= pci[:slot] %>'
117
+ function='<%= pci[:function] %>'/>
118
+ </source>
119
+ </hostdev>
120
+ <% end %>
121
+ <% @usbs.each do |usb| %>
122
+ <hostdev mode='subsystem' type='usb'>
123
+ <source startupPolicy='<%= usb[:startupPolicy] || "mandatory" %>'>
124
+ <% if usb[:vendor] %>
125
+ <vendor id='<%= usb[:vendor] %>'/>
126
+ <% end %>
127
+ <% if usb[:product] %>
128
+ <product id='<%= usb[:product] %>'/>
129
+ <% end %>
130
+ <% if usb[:bus] && usb[:device] %>
131
+ <address bus='<%= usb[:bus] %>' device='<%= usb[:device] %>'/>
132
+ <% end %>
133
+ </source>
134
+ </hostdev>
135
+ <% end %>
136
+
137
+ <% if @tpm_path -%>
138
+ <%# TPM Device -%>
139
+ <tpm model='<%= @tpm_model %>'>
140
+ <backend type='<%= @tpm_type %>'>
141
+ <device path='<%= @tpm_path %>'/>
142
+ </backend>
143
+ </tpm>
144
+ <% end -%>
95
145
  </devices>
96
146
  </domain>
@@ -3,7 +3,11 @@
3
3
  <% if @mac %>
4
4
  <mac address='<%= @mac %>'/>
5
5
  <% end %>
6
- <target dev='vnet<%= @iface_number %>'/>
6
+ <% if @device_name %>
7
+ <target dev='<%= @device_name %>'/>
8
+ <% else %>
9
+ <target dev='vnet<%= @iface_number %>'/>
10
+ <% end %>
7
11
  <alias name='net<%= @iface_number %>'/>
8
12
  <model type='<%=@model_type%>'/>
9
13
  </interface>
@@ -1,4 +1,4 @@
1
- <network ipv6='yes'>
1
+ <network ipv6='<%= @guest_ipv6 %>'>
2
2
  <name><%= @network_name %></name>
3
3
  <bridge name="<%= @network_bridge_name %>" />
4
4
 
@@ -7,5 +7,11 @@
7
7
  <local address='<%=@udp_tunnel_local_ip%>' port='<%=@udp_tunnel_local_port%>' />
8
8
  <% end %>
9
9
  </source>
10
+ <% if @device_name %>
11
+ <target dev='<%= @device_name %>'/>
12
+ <% else %>
13
+ <target dev='tnet<%= @iface_number %>'/>
14
+ <% end %>
15
+ <alias name='net<%= @iface_number %>'/>
10
16
  <model type='<%=@model_type%>'/>
11
17
  </interface>
@@ -12,6 +12,7 @@ module VagrantPlugins
12
12
  management_network_address = env[:machine].provider_config.management_network_address
13
13
  management_network_mode = env[:machine].provider_config.management_network_mode
14
14
  management_network_mac = env[:machine].provider_config.management_network_mac
15
+ management_network_guest_ipv6 = env[:machine].provider_config.management_network_guest_ipv6
15
16
  logger.info "Using #{management_network_name} at #{management_network_address} as the management network #{management_network_mode} is the mode"
16
17
 
17
18
  begin
@@ -36,6 +37,7 @@ module VagrantPlugins
36
37
  netmask: $2,
37
38
  dhcp_enabled: true,
38
39
  forward_mode: management_network_mode,
40
+ guest_ipv6: management_network_guest_ipv6,
39
41
  }
40
42
 
41
43
  unless management_network_mac.nil?
@@ -1,5 +1,5 @@
1
1
  module VagrantPlugins
2
2
  module ProviderLibvirt
3
- VERSION = '0.0.32'
3
+ VERSION = '0.0.33'
4
4
  end
5
5
  end
@@ -53,7 +53,7 @@ en:
53
53
  warnings:
54
54
  ignoring_virtual_size_too_small: |-
55
55
  Ignoring requested virtual disk size of '%{requested}' as it is below
56
- the minimum box image size of '%{box_virtual_size}'.
56
+ the minimum box image size of '%{minimum}'.
57
57
 
58
58
  errors:
59
59
  package_not_supported: No support for package with libvirt. Create box manually.
@@ -1,5 +1,6 @@
1
1
  require 'vagrant-libvirt'
2
2
  require 'support/environment_helper'
3
+ require 'vagrant-spec/unit'
3
4
 
4
5
  RSpec.configure do |spec|
5
6
  end
@@ -0,0 +1,28 @@
1
+ require 'fog/libvirt'
2
+
3
+ shared_context "libvirt" do
4
+ include_context "unit"
5
+
6
+ let(:libvirt_context) { true }
7
+ let(:id) { "dummy-vagrant_dummy" }
8
+ let(:connection) { double("connection") }
9
+ let(:domain) { double("domain") }
10
+
11
+ def connection_result(options={})
12
+ result = options.fetch(:result, nil)
13
+ double("connection_result" => result)
14
+ end
15
+
16
+ before (:each) do
17
+ # we don't want unit tests to ever run commands on the system; so we wire
18
+ # in a double to ensure any unexpected messages raise exceptions
19
+ stub_const("::Fog::Compute", connection)
20
+
21
+ # drivers also call vm_exists? during init;
22
+ allow(connection).to receive(:servers).with(kind_of(String)).
23
+ and_return(connection_result(result: nil))
24
+
25
+ # return some information for domain when needed
26
+ allow(domain).to receive(:mac).and_return("9C:D5:53:F1:5A:E7")
27
+ end
28
+ end
@@ -0,0 +1,34 @@
1
+ require 'spec_helper'
2
+
3
+ shared_context "unit" do
4
+ include_context 'vagrant-unit'
5
+
6
+ let(:test_env) do
7
+ vagrantfile ||= <<-EOF
8
+ Vagrant.configure('2') do |config|
9
+ config.vm.define :test
10
+ end
11
+ EOF
12
+ test_env = isolated_environment
13
+ test_env.vagrantfile vagrantfile
14
+ test_env
15
+ end
16
+ let(:env) { { env: iso_env, machine: machine, ui: ui, root_path: '/rootpath' } }
17
+ let(:conf) { Vagrant::Config::V2::DummyConfig.new() }
18
+ let(:ui) { Vagrant::UI::Basic.new() }
19
+ let(:iso_env) { test_env.create_vagrant_env ui_class: Vagrant::UI::Basic }
20
+ let(:machine) { iso_env.machine(:test, :libvirt) }
21
+ # Mock the communicator to prevent SSH commands for being executed.
22
+ let(:communicator) { double('communicator') }
23
+ # Mock the guest operating system.
24
+ let(:guest) { double('guest') }
25
+ let(:app) { lambda { |env| } }
26
+ let(:plugin) { register_plugin() }
27
+
28
+ before (:each) do
29
+ machine.stub(:guest => guest)
30
+ machine.stub(:communicator => communicator)
31
+ machine.stub(:id => id)
32
+ end
33
+
34
+ end
@@ -0,0 +1,128 @@
1
+ require "vagrant-libvirt/action/wait_till_up"
2
+ require "vagrant-libvirt/errors"
3
+
4
+ require "spec_helper"
5
+ require "support/sharedcontext"
6
+ require "support/libvirt_context"
7
+
8
+ describe VagrantPlugins::ProviderLibvirt::Action::WaitTillUp do
9
+
10
+ subject { described_class.new(app, env) }
11
+
12
+ include_context "vagrant-unit"
13
+ include_context "libvirt"
14
+ include_context "unit"
15
+
16
+ describe "#call" do
17
+ before do
18
+ allow_any_instance_of(VagrantPlugins::ProviderLibvirt::Driver).
19
+ to receive(:get_domain).and_return(domain)
20
+ allow_any_instance_of(VagrantPlugins::ProviderLibvirt::Driver).to receive(:state).
21
+ and_return(:running)
22
+ end
23
+
24
+ context "when machine does not exist" do
25
+ before do
26
+ allow_any_instance_of(VagrantPlugins::ProviderLibvirt::Driver).
27
+ to receive(:get_domain).and_return(nil)
28
+ end
29
+
30
+ it "raises exception" do
31
+ expect(app).to_not receive(:call)
32
+ expect{subject.call(env)}.to raise_error(::VagrantPlugins::ProviderLibvirt::Errors::NoDomainError,
33
+ /No domain found. Domain dummy-vagrant_dummy not found/)
34
+ end
35
+ end
36
+
37
+ context "when machine is booting" do
38
+ context "if interrupted looking for IP" do
39
+ before do
40
+ env[:interrupted] = true
41
+ end
42
+ it "should exit" do
43
+ expect(app).to_not receive(:call)
44
+ expect(ui).to receive(:info).with("Waiting for domain to get an IP address...")
45
+ expect(subject.call(env)).to be_nil
46
+ end
47
+ end
48
+
49
+ context "if interrupted waiting for SSH" do
50
+ before do
51
+ allow(domain).to receive(:wait_for).and_return(true)
52
+ allow(env).to receive(:[]).and_call_original
53
+ allow(env).to receive(:[]).with(:interrupted).and_return(false, true, true)
54
+ allow(env).to receive(:[]).with(:ip_address).and_return("192.168.121.2")
55
+ end
56
+ it "should exit after getting IP" do
57
+ expect(app).to_not receive(:call)
58
+ expect(ui).to receive(:info).with("Waiting for domain to get an IP address...")
59
+ expect(ui).to receive(:info).with("Waiting for SSH to become available...")
60
+ logger = subject.instance_variable_get(:@logger)
61
+ expect(logger).to receive(:debug).with(/Searching for IP for MAC address: .*/)
62
+ expect(logger).to receive(:info).with("Got IP address 192.168.121.2")
63
+ expect(logger).to receive(:info).with(/Time for getting IP: .*/)
64
+ expect(env[:machine].communicate).to_not receive(:ready?)
65
+ expect(subject.call(env)).to be_nil
66
+ end
67
+ end
68
+ end
69
+
70
+ context "when machine boots and ssh available" do
71
+ before do
72
+ allow(domain).to receive(:wait_for).and_return(true)
73
+ allow(env).to receive(:[]).and_call_original
74
+ allow(env).to receive(:[]).with(:interrupted).and_return(false)
75
+ allow(env).to receive(:[]).with(:ip_address).and_return("192.168.121.2")
76
+ end
77
+ it "should call the next hook" do
78
+ expect(app).to receive(:call)
79
+ expect(ui).to receive(:info).with("Waiting for domain to get an IP address...")
80
+ expect(ui).to receive(:info).with("Waiting for SSH to become available...")
81
+ expect(env[:machine].communicate).to receive(:ready?).and_return(true)
82
+ expect(subject.call(env)).to be_nil
83
+ end
84
+ end
85
+ end
86
+
87
+ describe "#recover" do
88
+ before do
89
+ allow_any_instance_of(VagrantPlugins::ProviderLibvirt::Driver).to receive(:get_domain).and_return(machine)
90
+ allow_any_instance_of(VagrantPlugins::ProviderLibvirt::Driver).to receive(:state).
91
+ and_return(:not_created)
92
+ allow(env).to receive(:[]).and_call_original
93
+ end
94
+
95
+ it "should do nothing by default" do
96
+ expect(env).to_not receive(:[]).with(:action_runner) # cleanup
97
+ expect(subject.recover(env)).to be_nil
98
+ end
99
+
100
+ context "with machine coming up" do
101
+ before do
102
+ allow_any_instance_of(VagrantPlugins::ProviderLibvirt::Driver).to receive(:state).
103
+ and_return(:running)
104
+ env[:destroy_on_error] = true
105
+ end
106
+
107
+ context "and user has disabled destroy on failure" do
108
+ before do
109
+ env[:destroy_on_error] = false
110
+ end
111
+
112
+ it "skips terminate on failure" do
113
+ expect(env).to_not receive(:[]).with(:action_runner) # cleanup
114
+ expect(subject.recover(env)).to be_nil
115
+ end
116
+ end
117
+
118
+ context "and using default settings" do
119
+ let(:runner) { double('runner') }
120
+ it "deletes VM on failure" do
121
+ expect(env).to receive(:[]).with(:action_runner).and_return(runner) # cleanup
122
+ expect(runner).to receive(:run)
123
+ expect(subject.recover(env)).to be_nil
124
+ end
125
+ end
126
+ end
127
+ end
128
+ end
@@ -84,7 +84,9 @@ cd "$TMP_DIR"
84
84
  #Using the awk int function here to truncate the virtual image size to an
85
85
  #integer since the fog-libvirt library does not seem to properly handle
86
86
  #floating point.
87
- IMG_SIZE=$(qemu-img info "$TMP_IMG" | awk '/virtual size/{print int($3);}' | tr -d 'G')
87
+ IMG_SIZE=$(qemu-img info "$TMP_IMG" | awk '/virtual size/{print int($3)+1;}' | tr -d 'G')
88
+
89
+ echo "{$IMG_SIZE}"
88
90
 
89
91
  cat > metadata.json <<EOF
90
92
  {
@@ -16,11 +16,11 @@ Gem::Specification.new do |gem|
16
16
  gem.require_paths = ['lib']
17
17
  gem.version = VagrantPlugins::ProviderLibvirt::VERSION
18
18
 
19
- gem.add_development_dependency "rspec-core", "~> 2.12.2"
20
- gem.add_development_dependency "rspec-expectations", "~> 2.12.1"
21
- gem.add_development_dependency "rspec-mocks", "~> 2.12.1"
19
+ gem.add_development_dependency "rspec-core", "~> 2.14.0"
20
+ gem.add_development_dependency "rspec-expectations", "~> 2.14.0"
21
+ gem.add_development_dependency "rspec-mocks", "~> 2.14.0"
22
22
 
23
- gem.add_runtime_dependency 'fog-libvirt', '~> 0.0.1'
23
+ gem.add_runtime_dependency 'fog-libvirt', '0.0.3'
24
24
  gem.add_runtime_dependency 'nokogiri', '~> 1.6.0'
25
25
 
26
26
  gem.add_development_dependency 'rake'
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.0.32
4
+ version: 0.0.33
5
5
  platform: ruby
6
6
  authors:
7
7
  - Lukas Stanek
@@ -10,7 +10,7 @@ authors:
10
10
  autorequire:
11
11
  bindir: bin
12
12
  cert_chain: []
13
- date: 2015-10-06 00:00:00.000000000 Z
13
+ date: 2016-03-29 00:00:00.000000000 Z
14
14
  dependencies:
15
15
  - !ruby/object:Gem::Dependency
16
16
  name: rspec-core
@@ -18,56 +18,56 @@ dependencies:
18
18
  requirements:
19
19
  - - "~>"
20
20
  - !ruby/object:Gem::Version
21
- version: 2.12.2
21
+ version: 2.14.0
22
22
  type: :development
23
23
  prerelease: false
24
24
  version_requirements: !ruby/object:Gem::Requirement
25
25
  requirements:
26
26
  - - "~>"
27
27
  - !ruby/object:Gem::Version
28
- version: 2.12.2
28
+ version: 2.14.0
29
29
  - !ruby/object:Gem::Dependency
30
30
  name: rspec-expectations
31
31
  requirement: !ruby/object:Gem::Requirement
32
32
  requirements:
33
33
  - - "~>"
34
34
  - !ruby/object:Gem::Version
35
- version: 2.12.1
35
+ version: 2.14.0
36
36
  type: :development
37
37
  prerelease: false
38
38
  version_requirements: !ruby/object:Gem::Requirement
39
39
  requirements:
40
40
  - - "~>"
41
41
  - !ruby/object:Gem::Version
42
- version: 2.12.1
42
+ version: 2.14.0
43
43
  - !ruby/object:Gem::Dependency
44
44
  name: rspec-mocks
45
45
  requirement: !ruby/object:Gem::Requirement
46
46
  requirements:
47
47
  - - "~>"
48
48
  - !ruby/object:Gem::Version
49
- version: 2.12.1
49
+ version: 2.14.0
50
50
  type: :development
51
51
  prerelease: false
52
52
  version_requirements: !ruby/object:Gem::Requirement
53
53
  requirements:
54
54
  - - "~>"
55
55
  - !ruby/object:Gem::Version
56
- version: 2.12.1
56
+ version: 2.14.0
57
57
  - !ruby/object:Gem::Dependency
58
58
  name: fog-libvirt
59
59
  requirement: !ruby/object:Gem::Requirement
60
60
  requirements:
61
- - - "~>"
61
+ - - '='
62
62
  - !ruby/object:Gem::Version
63
- version: 0.0.1
63
+ version: 0.0.3
64
64
  type: :runtime
65
65
  prerelease: false
66
66
  version_requirements: !ruby/object:Gem::Requirement
67
67
  requirements:
68
- - - "~>"
68
+ - - '='
69
69
  - !ruby/object:Gem::Version
70
- version: 0.0.1
70
+ version: 0.0.3
71
71
  - !ruby/object:Gem::Dependency
72
72
  name: nokogiri
73
73
  requirement: !ruby/object:Gem::Requirement
@@ -174,7 +174,10 @@ files:
174
174
  - locales/en.yml
175
175
  - spec/spec_helper.rb
176
176
  - spec/support/environment_helper.rb
177
- - spec/vagrant-libvirt/action/set_name_of_domain_spec.rb
177
+ - spec/support/libvirt_context.rb
178
+ - spec/support/sharedcontext.rb
179
+ - spec/unit/action/set_name_of_domain_spec.rb
180
+ - spec/unit/action/wait_till_up_spec.rb
178
181
  - tools/create_box.sh
179
182
  - tools/prepare_redhat_for_box.sh
180
183
  - vagrant-libvirt.gemspec
@@ -198,11 +201,14 @@ required_rubygems_version: !ruby/object:Gem::Requirement
198
201
  version: '0'
199
202
  requirements: []
200
203
  rubyforge_project:
201
- rubygems_version: 2.4.6
204
+ rubygems_version: 2.4.8
202
205
  signing_key:
203
206
  specification_version: 4
204
207
  summary: libvirt provider for Vagrant.
205
208
  test_files:
206
209
  - spec/spec_helper.rb
207
210
  - spec/support/environment_helper.rb
208
- - spec/vagrant-libvirt/action/set_name_of_domain_spec.rb
211
+ - spec/support/libvirt_context.rb
212
+ - spec/support/sharedcontext.rb
213
+ - spec/unit/action/set_name_of_domain_spec.rb
214
+ - spec/unit/action/wait_till_up_spec.rb