vagrant-libvirt 0.6.3 → 0.8.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- checksums.yaml +4 -4
- data/README.md +65 -13
- data/lib/vagrant-libvirt/action/cleanup_on_failure.rb +76 -0
- data/lib/vagrant-libvirt/action/create_domain.rb +56 -10
- data/lib/vagrant-libvirt/action/create_network_interfaces.rb +5 -1
- data/lib/vagrant-libvirt/action/create_networks.rb +24 -0
- data/lib/vagrant-libvirt/action/destroy_domain.rb +106 -21
- data/lib/vagrant-libvirt/action/destroy_networks.rb +1 -1
- data/lib/vagrant-libvirt/action/forward_ports.rb +12 -11
- data/lib/vagrant-libvirt/action/prepare_nfs_settings.rb +1 -1
- data/lib/vagrant-libvirt/action/start_domain.rb +36 -0
- data/lib/vagrant-libvirt/action/wait_till_up.rb +6 -32
- data/lib/vagrant-libvirt/action.rb +72 -83
- data/lib/vagrant-libvirt/config.rb +85 -30
- data/lib/vagrant-libvirt/driver.rb +11 -9
- data/lib/vagrant-libvirt/errors.rb +12 -0
- data/lib/vagrant-libvirt/templates/domain.xml.erb +228 -218
- data/lib/vagrant-libvirt/templates/private_network.xml.erb +4 -1
- data/lib/vagrant-libvirt/util/network_util.rb +15 -3
- data/lib/vagrant-libvirt/util/nfs.rb +2 -0
- data/lib/vagrant-libvirt/util/resolvers.rb +80 -0
- data/lib/vagrant-libvirt/version +1 -1
- data/locales/en.yml +17 -0
- data/spec/spec_helper.rb +36 -23
- data/spec/support/libvirt_context.rb +7 -4
- data/spec/support/sharedcontext.rb +1 -1
- data/spec/unit/action/cleanup_on_failure_spec.rb +131 -0
- data/spec/unit/action/create_domain_spec/additional_disks_domain.xml +6 -18
- data/spec/unit/action/create_domain_spec/custom_disk_settings.xml +43 -0
- data/spec/unit/action/create_domain_spec/default_domain.xml +6 -18
- data/spec/unit/action/create_domain_spec/two_disk_settings.xml +49 -0
- data/spec/unit/action/create_domain_spec.rb +51 -7
- data/spec/unit/action/create_domain_volume_spec.rb +5 -3
- data/spec/unit/action/destroy_domain_spec/additional_disks_domain.xml +47 -0
- data/spec/unit/action/destroy_domain_spec/box_multiple_disks.xml +55 -0
- data/spec/unit/action/destroy_domain_spec/box_multiple_disks_and_additional_and_custom_disks.xml +72 -0
- data/spec/unit/action/destroy_domain_spec/box_multiple_disks_and_additional_and_custom_disks_no_aliases.xml +67 -0
- data/spec/unit/action/destroy_domain_spec/box_multiple_disks_and_additional_disks.xml +67 -0
- data/spec/unit/action/destroy_domain_spec/cdrom_domain.xml +48 -0
- data/spec/unit/action/destroy_domain_spec.rb +134 -30
- data/spec/unit/action/forward_ports_spec.rb +10 -2
- data/spec/unit/action/prepare_nfs_settings_spec.rb +59 -0
- data/spec/unit/action/shutdown_domain_spec.rb +1 -1
- data/spec/unit/action/start_domain_spec/clock_timer_rtc.xml +6 -18
- data/spec/unit/action/start_domain_spec/default.xml +6 -18
- data/spec/unit/action/start_domain_spec/default_added_tpm_path.xml +6 -18
- data/spec/unit/action/start_domain_spec/default_added_tpm_version.xml +6 -18
- data/spec/unit/action/start_domain_spec/existing.xml +1 -1
- data/spec/unit/action/wait_till_up_spec.rb +4 -43
- data/spec/unit/action_spec.rb +2 -0
- data/spec/unit/config_spec.rb +133 -26
- data/spec/unit/driver_spec.rb +154 -10
- data/spec/unit/templates/domain_all_settings.xml +56 -77
- data/spec/unit/templates/domain_cpu_mode_passthrough.xml +39 -0
- data/spec/unit/templates/domain_custom_cpu_model.xml +6 -18
- data/spec/unit/templates/domain_defaults.xml +6 -18
- data/spec/unit/templates/domain_spec.rb +39 -13
- data/spec/unit/templates/tpm/version_1.2.xml +6 -18
- data/spec/unit/templates/tpm/version_2.0.xml +6 -18
- data/spec/unit/util/resolvers_spec.rb +116 -0
- metadata +40 -41
@@ -0,0 +1,80 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
require 'log4r'
|
4
|
+
|
5
|
+
require 'vagrant-libvirt/errors'
|
6
|
+
|
7
|
+
module VagrantPlugins
|
8
|
+
module ProviderLibvirt
|
9
|
+
module Util
|
10
|
+
class DiskDeviceResolver
|
11
|
+
attr_reader :existing
|
12
|
+
|
13
|
+
def initialize(prefix='vd')
|
14
|
+
@default_prefix = prefix
|
15
|
+
|
16
|
+
@device_indicies = Hash.new
|
17
|
+
@existing = Hash.new
|
18
|
+
end
|
19
|
+
|
20
|
+
def resolve!(disks, options={})
|
21
|
+
# check for duplicate device entries and raise an exception if one found
|
22
|
+
# with enough details that the user should be able to determine what
|
23
|
+
# to do to resolve.
|
24
|
+
disks.select { |x| !x[:device].nil? }.each do |x|
|
25
|
+
if @existing.has_key?(x[:device])
|
26
|
+
raise Errors::DuplicateDiskDevice, new_disk: x, existing_disk: @existing[x[:device]]
|
27
|
+
end
|
28
|
+
|
29
|
+
@existing[x[:device]] = x
|
30
|
+
end
|
31
|
+
|
32
|
+
disks.each_index do |index|
|
33
|
+
dev = disks[index][:device]
|
34
|
+
if dev.nil?
|
35
|
+
prefix = options.fetch(:prefix, @default_prefix)
|
36
|
+
dev = next_device(prefix=prefix)
|
37
|
+
if dev.nil?
|
38
|
+
raise Errors::NoDiskDeviceAvailable, prefix: prefix
|
39
|
+
end
|
40
|
+
|
41
|
+
disks[index][:device] = dev
|
42
|
+
@existing[dev] = disks[index]
|
43
|
+
end
|
44
|
+
end
|
45
|
+
end
|
46
|
+
|
47
|
+
def resolve(disks)
|
48
|
+
new_disks = []
|
49
|
+
disks.each do |disk|
|
50
|
+
new_disks.push disk.dup
|
51
|
+
end
|
52
|
+
|
53
|
+
resolve!(new_disks)
|
54
|
+
|
55
|
+
new_disks
|
56
|
+
end
|
57
|
+
|
58
|
+
private
|
59
|
+
|
60
|
+
def next_device(prefix)
|
61
|
+
curr = device_index(prefix)
|
62
|
+
while curr <= 'z'.ord
|
63
|
+
dev = prefix + curr.chr
|
64
|
+
if !@existing[dev].nil?
|
65
|
+
curr += 1
|
66
|
+
next
|
67
|
+
else
|
68
|
+
@device_indicies[prefix] = curr
|
69
|
+
return dev
|
70
|
+
end
|
71
|
+
end
|
72
|
+
end
|
73
|
+
|
74
|
+
def device_index(prefix)
|
75
|
+
@device_indicies[prefix] ||= 'a'.ord
|
76
|
+
end
|
77
|
+
end
|
78
|
+
end
|
79
|
+
end
|
80
|
+
end
|
data/lib/vagrant-libvirt/version
CHANGED
@@ -1 +1 @@
|
|
1
|
-
0.
|
1
|
+
0.8.1
|
data/locales/en.yml
CHANGED
@@ -58,16 +58,31 @@ en:
|
|
58
58
|
remove_stale_volume: |-
|
59
59
|
Remove stale volume...
|
60
60
|
|
61
|
+
destroy:
|
62
|
+
obsolete_method: |
|
63
|
+
Destroying machine that was originally created without device aliases (pre 0.6.0), using fallback approach.
|
64
|
+
unexpected_volumes: |
|
65
|
+
Unexpected number of volumes detected, possibly additional volumes attached outside of vagrant-libvirt.
|
66
|
+
Attempting to handle this correctly, however may experience unexpected behaviour in the domain destroy.
|
67
|
+
expected_removal_mismatch: |
|
68
|
+
mismatch of volumes associated with box to number removed, may be stray box volumes left
|
69
|
+
box_metadata_unavailable: |
|
70
|
+
box metadata not available to get volume list during destroy, assuming inferred list
|
71
|
+
|
61
72
|
warnings:
|
62
73
|
ignoring_virtual_size_too_small: |-
|
63
74
|
Ignoring requested virtual disk size of '%{requested}' as it is below
|
64
75
|
the minimum box image size of '%{minimum}'.
|
65
76
|
forwarding_udp: |-
|
66
77
|
Forwarding UDP ports is not supported. Ignoring.
|
78
|
+
creating_domain_console_access_disabled: |-
|
79
|
+
Serial console is being redirected, access via virsh will be disabled.
|
67
80
|
|
68
81
|
errors:
|
69
82
|
call_chain_error: Invalid action chain, must ensure that '%{require_action}' is called prior to calling '%{current_action}'
|
70
83
|
package_not_supported: No support for package with Libvirt. Create box manually.
|
84
|
+
duplicate_disk_device: Disk with details '%{new_disk}' duplicates :device attribute of disk '%{existing_disk}'
|
85
|
+
no_disk_device_available: All available devices allocated under '%{prefix}x', try a different type
|
71
86
|
fog_error: |-
|
72
87
|
There was an error talking to Libvirt. The error message is shown
|
73
88
|
below:
|
@@ -166,6 +181,8 @@ en:
|
|
166
181
|
management_network_required: |-
|
167
182
|
Management network can't be disabled when VM use box.
|
168
183
|
Please fix your configuration and run vagrant again.
|
184
|
+
serial_cannot_create_path_error: |-
|
185
|
+
Error creating path for serial port output log: %{path}
|
169
186
|
|
170
187
|
states:
|
171
188
|
paused: |-
|
data/spec/spec_helper.rb
CHANGED
@@ -1,36 +1,45 @@
|
|
1
1
|
# frozen_string_literal: true
|
2
2
|
|
3
|
-
|
4
|
-
|
5
|
-
|
6
|
-
|
7
|
-
|
8
|
-
|
9
|
-
|
10
|
-
|
11
|
-
|
3
|
+
# make simplecov optional
|
4
|
+
begin
|
5
|
+
require 'simplecov'
|
6
|
+
require 'simplecov-lcov'
|
7
|
+
|
8
|
+
# patch simplecov configuration
|
9
|
+
if ! SimpleCov::Configuration.method_defined? :branch_coverage?
|
10
|
+
module SimpleCov
|
11
|
+
module Configuration
|
12
|
+
def branch_coverage?
|
13
|
+
return false
|
14
|
+
end
|
12
15
|
end
|
13
16
|
end
|
14
17
|
end
|
15
|
-
end
|
16
18
|
|
17
|
-
SimpleCov::Formatter::LcovFormatter.config do |config|
|
18
|
-
|
19
|
-
|
20
|
-
end
|
19
|
+
SimpleCov::Formatter::LcovFormatter.config do |config|
|
20
|
+
config.report_with_single_file = true
|
21
|
+
config.single_report_path = 'coverage/lcov.info'
|
22
|
+
end
|
21
23
|
|
22
|
-
SimpleCov.formatters = SimpleCov::Formatter::MultiFormatter.new(
|
23
|
-
|
24
|
-
|
25
|
-
|
26
|
-
|
27
|
-
)
|
28
|
-
SimpleCov.start do
|
29
|
-
|
24
|
+
SimpleCov.formatters = SimpleCov::Formatter::MultiFormatter.new(
|
25
|
+
[
|
26
|
+
SimpleCov::Formatter::HTMLFormatter,
|
27
|
+
SimpleCov::Formatter::LcovFormatter,
|
28
|
+
]
|
29
|
+
)
|
30
|
+
SimpleCov.start do
|
31
|
+
add_filter 'spec/'
|
32
|
+
end
|
33
|
+
rescue LoadError
|
34
|
+
TRUTHY_VALUES = %w(t true yes y 1).freeze
|
35
|
+
require_simplecov = ENV.fetch('VAGRANT_LIBVIRT_REQUIRE_SIMPLECOV', 'false').to_s.downcase
|
36
|
+
if TRUTHY_VALUES.include?(require_simplecov)
|
37
|
+
raise
|
38
|
+
end
|
30
39
|
end
|
31
40
|
|
41
|
+
|
32
42
|
require 'vagrant-libvirt'
|
33
|
-
require 'support/environment_helper'
|
34
43
|
require 'vagrant-spec/unit'
|
35
44
|
|
36
45
|
Dir[File.dirname(__FILE__) + '/support/**/*.rb'].each { |f| require f }
|
@@ -42,4 +51,8 @@ RSpec.configure do |config|
|
|
42
51
|
config.before(:suite) do
|
43
52
|
ENV.delete('LIBVIRT_DEFAULT_URI')
|
44
53
|
end
|
54
|
+
|
55
|
+
config.mock_with :rspec do |mocks|
|
56
|
+
mocks.verify_partial_doubles = true
|
57
|
+
end
|
45
58
|
end
|
@@ -1,6 +1,8 @@
|
|
1
1
|
# frozen_string_literal: true
|
2
2
|
|
3
3
|
require 'fog/libvirt'
|
4
|
+
require 'fog/libvirt/models/compute/server'
|
5
|
+
require 'libvirt'
|
4
6
|
|
5
7
|
shared_context 'libvirt' do
|
6
8
|
include_context 'unit'
|
@@ -8,7 +10,9 @@ shared_context 'libvirt' do
|
|
8
10
|
let(:libvirt_context) { true }
|
9
11
|
let(:id) { 'dummy-vagrant_dummy' }
|
10
12
|
let(:connection) { double('connection') }
|
11
|
-
let(:domain) {
|
13
|
+
let(:domain) { instance_double(::Fog::Libvirt::Compute::Server) }
|
14
|
+
let(:libvirt_client) { instance_double(::Libvirt::Connect) }
|
15
|
+
let(:libvirt_domain) { instance_double(::Libvirt::Domain) }
|
12
16
|
let(:logger) { double('logger') }
|
13
17
|
|
14
18
|
def connection_result(options = {})
|
@@ -22,11 +26,10 @@ shared_context 'libvirt' do
|
|
22
26
|
stub_const('::Fog::Compute', connection)
|
23
27
|
|
24
28
|
# drivers also call vm_exists? during init;
|
25
|
-
allow(connection).to receive(:servers)
|
29
|
+
allow(connection).to receive(:servers)
|
26
30
|
.and_return(connection_result(result: nil))
|
27
31
|
|
28
|
-
|
29
|
-
allow(domain).to receive(:mac).and_return('9C:D5:53:F1:5A:E7')
|
32
|
+
allow(connection).to receive(:client).and_return(libvirt_client)
|
30
33
|
|
31
34
|
allow(machine).to receive(:id).and_return(id)
|
32
35
|
allow(Log4r::Logger).to receive(:new).and_return(logger)
|
@@ -0,0 +1,131 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
require 'spec_helper'
|
4
|
+
require 'support/sharedcontext'
|
5
|
+
|
6
|
+
require 'vagrant/action/runner'
|
7
|
+
|
8
|
+
require 'vagrant-libvirt/action'
|
9
|
+
require 'vagrant-libvirt/action/cleanup_on_failure'
|
10
|
+
|
11
|
+
|
12
|
+
describe VagrantPlugins::ProviderLibvirt::Action::CleanupOnFailure do
|
13
|
+
subject { described_class }
|
14
|
+
let(:callable_error) do
|
15
|
+
Class.new do
|
16
|
+
def initialize(app, env)
|
17
|
+
end
|
18
|
+
|
19
|
+
def self.name
|
20
|
+
"TestAction"
|
21
|
+
end
|
22
|
+
|
23
|
+
def call(env)
|
24
|
+
raise Exception, "some action failed"
|
25
|
+
end
|
26
|
+
end
|
27
|
+
end
|
28
|
+
|
29
|
+
include_context 'libvirt'
|
30
|
+
include_context 'unit'
|
31
|
+
|
32
|
+
let(:libvirt_domain) { double('libvirt_domain') }
|
33
|
+
let(:runner) { Vagrant::Action::Runner.new(env) }
|
34
|
+
let(:state) { double('state') }
|
35
|
+
|
36
|
+
before do
|
37
|
+
allow_any_instance_of(VagrantPlugins::ProviderLibvirt::Driver)
|
38
|
+
.to receive(:connection).and_return(connection)
|
39
|
+
allow(machine).to receive(:id).and_return('test-machine-id')
|
40
|
+
allow(machine).to receive(:state).and_return(state)
|
41
|
+
|
42
|
+
allow(logger).to receive(:info)
|
43
|
+
allow(logger).to receive(:debug)
|
44
|
+
allow(logger).to receive(:error)
|
45
|
+
|
46
|
+
allow(runner).to receive(:run).and_call_original
|
47
|
+
env[:action_runner] = runner
|
48
|
+
env[:destroy_on_error] = true
|
49
|
+
end
|
50
|
+
|
51
|
+
describe '#recover' do
|
52
|
+
let(:action_chain) do
|
53
|
+
Vagrant::Action::Builder.new.tap do |b|
|
54
|
+
b.use subject
|
55
|
+
b.use callable_error
|
56
|
+
end
|
57
|
+
end
|
58
|
+
|
59
|
+
context 'not created' do
|
60
|
+
before do
|
61
|
+
expect(state).to receive(:id).and_return(:not_created)
|
62
|
+
end
|
63
|
+
|
64
|
+
it 'should return early' do
|
65
|
+
expect(logger).to_not receive(:info).with('VM completed provider setup, no need to teardown')
|
66
|
+
|
67
|
+
expect { runner.run(action_chain) }.to raise_error(Exception, "some action failed")
|
68
|
+
end
|
69
|
+
end
|
70
|
+
|
71
|
+
context 'running' do
|
72
|
+
before do
|
73
|
+
allow(state).to receive(:id).and_return(:running)
|
74
|
+
end
|
75
|
+
|
76
|
+
it 'should destroy' do
|
77
|
+
expect(VagrantPlugins::ProviderLibvirt::Action).to_not receive(:action_halt)
|
78
|
+
expect(VagrantPlugins::ProviderLibvirt::Action).to receive(:action_destroy).and_return(Vagrant::Action::Builder.new)
|
79
|
+
expect(logger).to_not receive(:info).with('VM completed provider setup, no need to teardown')
|
80
|
+
|
81
|
+
expect { runner.run(action_chain) }.to raise_error(Exception, "some action failed")
|
82
|
+
end
|
83
|
+
|
84
|
+
context 'halt on error enabled' do
|
85
|
+
before do
|
86
|
+
env[:halt_on_error] = true
|
87
|
+
end
|
88
|
+
|
89
|
+
it 'should halt' do
|
90
|
+
expect(VagrantPlugins::ProviderLibvirt::Action).to receive(:action_halt).and_return(Vagrant::Action::Builder.new)
|
91
|
+
expect(VagrantPlugins::ProviderLibvirt::Action).to_not receive(:action_destroy)
|
92
|
+
expect(logger).to_not receive(:info).with('VM completed provider setup, no need to teardown')
|
93
|
+
|
94
|
+
expect { runner.run(action_chain) }.to raise_error(Exception, "some action failed")
|
95
|
+
end
|
96
|
+
end
|
97
|
+
|
98
|
+
context 'destroy on error disabled' do
|
99
|
+
before do
|
100
|
+
env[:destroy_on_error] = false
|
101
|
+
end
|
102
|
+
|
103
|
+
it 'should not destroy' do
|
104
|
+
expect(VagrantPlugins::ProviderLibvirt::Action).to_not receive(:action_halt)
|
105
|
+
expect(VagrantPlugins::ProviderLibvirt::Action).to_not receive(:action_destroy)
|
106
|
+
expect(logger).to_not receive(:info).with('VM completed provider setup, no need to teardown')
|
107
|
+
|
108
|
+
expect { runner.run(action_chain) }.to raise_error(Exception, "some action failed")
|
109
|
+
end
|
110
|
+
end
|
111
|
+
|
112
|
+
context 'completed setup' do
|
113
|
+
let(:action_chain) do
|
114
|
+
Vagrant::Action::Builder.new.tap do |b|
|
115
|
+
b.use subject
|
116
|
+
b.use VagrantPlugins::ProviderLibvirt::Action::SetupComplete
|
117
|
+
b.use callable_error
|
118
|
+
end
|
119
|
+
end
|
120
|
+
|
121
|
+
it 'should not perform halt or destroy' do
|
122
|
+
expect(VagrantPlugins::ProviderLibvirt::Action).to_not receive(:action_halt)
|
123
|
+
expect(VagrantPlugins::ProviderLibvirt::Action).to_not receive(:action_destroy)
|
124
|
+
expect(logger).to receive(:debug).with('VM provider setup was completed, no need to halt/destroy')
|
125
|
+
|
126
|
+
expect { runner.run(action_chain) }.to raise_error(Exception, "some action failed")
|
127
|
+
end
|
128
|
+
end
|
129
|
+
end
|
130
|
+
end
|
131
|
+
end
|
@@ -5,15 +5,11 @@
|
|
5
5
|
<uuid></uuid>
|
6
6
|
<memory>524288</memory>
|
7
7
|
<vcpu>1</vcpu>
|
8
|
-
|
9
|
-
|
10
8
|
<cpu mode='host-model'>
|
11
|
-
|
9
|
+
<model fallback='allow'></model>
|
12
10
|
</cpu>
|
13
|
-
|
14
|
-
|
15
11
|
<os>
|
16
|
-
|
12
|
+
<type>hvm</type>
|
17
13
|
<kernel></kernel>
|
18
14
|
<initrd></initrd>
|
19
15
|
<cmdline></cmdline>
|
@@ -38,24 +34,16 @@
|
|
38
34
|
<source file='/var/lib/libvirt/images/vagrant-test_default-vdb.qcow2'/>
|
39
35
|
<target dev='vdb' bus='virtio'/>
|
40
36
|
</disk>
|
41
|
-
|
42
|
-
|
43
37
|
<serial type='pty'>
|
44
38
|
<target port='0'/>
|
45
39
|
</serial>
|
46
40
|
<console type='pty'>
|
47
41
|
<target port='0'/>
|
48
42
|
</console>
|
49
|
-
|
50
|
-
|
51
43
|
<input type='mouse' bus='ps2'/>
|
52
|
-
|
53
|
-
|
54
|
-
<
|
55
|
-
|
56
|
-
</video>
|
57
|
-
|
58
|
-
|
44
|
+
<graphics type='vnc' port='-1' autoport='yes' listen='127.0.0.1' keymap='en-us'/>
|
45
|
+
<video>
|
46
|
+
<model type='cirrus' vram='16384' heads='1'/>
|
47
|
+
</video>
|
59
48
|
</devices>
|
60
|
-
|
61
49
|
</domain>
|
@@ -0,0 +1,43 @@
|
|
1
|
+
<domain type='kvm' xmlns:qemu='http://libvirt.org/schemas/domain/qemu/1.0'>
|
2
|
+
<name>vagrant-test_default</name>
|
3
|
+
<title></title>
|
4
|
+
<description>Source: /rootpath/Vagrantfile</description>
|
5
|
+
<uuid></uuid>
|
6
|
+
<memory>524288</memory>
|
7
|
+
<vcpu>1</vcpu>
|
8
|
+
<cpu mode='host-model'>
|
9
|
+
<model fallback='allow'></model>
|
10
|
+
</cpu>
|
11
|
+
<os>
|
12
|
+
<type>hvm</type>
|
13
|
+
<kernel></kernel>
|
14
|
+
<initrd></initrd>
|
15
|
+
<cmdline></cmdline>
|
16
|
+
</os>
|
17
|
+
<features>
|
18
|
+
<acpi/>
|
19
|
+
<apic/>
|
20
|
+
<pae/>
|
21
|
+
</features>
|
22
|
+
<clock offset='utc'>
|
23
|
+
</clock>
|
24
|
+
<devices>
|
25
|
+
<disk type='file' device='disk'>
|
26
|
+
<alias name='ua-box-volume-0'/>
|
27
|
+
<driver name='qemu' type='qcow2' cache='default'/>
|
28
|
+
<source file='/var/lib/libvirt/images/vagrant-test_default.img'/>
|
29
|
+
<target dev='sda' bus='virtio'/>
|
30
|
+
</disk>
|
31
|
+
<serial type='pty'>
|
32
|
+
<target port='0'/>
|
33
|
+
</serial>
|
34
|
+
<console type='pty'>
|
35
|
+
<target port='0'/>
|
36
|
+
</console>
|
37
|
+
<input type='mouse' bus='ps2'/>
|
38
|
+
<graphics type='vnc' port='-1' autoport='yes' listen='127.0.0.1' keymap='en-us'/>
|
39
|
+
<video>
|
40
|
+
<model type='cirrus' vram='16384' heads='1'/>
|
41
|
+
</video>
|
42
|
+
</devices>
|
43
|
+
</domain>
|
@@ -5,15 +5,11 @@
|
|
5
5
|
<uuid></uuid>
|
6
6
|
<memory>524288</memory>
|
7
7
|
<vcpu>1</vcpu>
|
8
|
-
|
9
|
-
|
10
8
|
<cpu mode='host-model'>
|
11
|
-
|
9
|
+
<model fallback='allow'></model>
|
12
10
|
</cpu>
|
13
|
-
|
14
|
-
|
15
11
|
<os>
|
16
|
-
|
12
|
+
<type>hvm</type>
|
17
13
|
<kernel></kernel>
|
18
14
|
<initrd></initrd>
|
19
15
|
<cmdline></cmdline>
|
@@ -32,24 +28,16 @@
|
|
32
28
|
<source file='/var/lib/libvirt/images/vagrant-test_default.img'/>
|
33
29
|
<target dev='vda' bus='virtio'/>
|
34
30
|
</disk>
|
35
|
-
|
36
|
-
|
37
31
|
<serial type='pty'>
|
38
32
|
<target port='0'/>
|
39
33
|
</serial>
|
40
34
|
<console type='pty'>
|
41
35
|
<target port='0'/>
|
42
36
|
</console>
|
43
|
-
|
44
|
-
|
45
37
|
<input type='mouse' bus='ps2'/>
|
46
|
-
|
47
|
-
|
48
|
-
<
|
49
|
-
|
50
|
-
</video>
|
51
|
-
|
52
|
-
|
38
|
+
<graphics type='vnc' port='-1' autoport='yes' listen='127.0.0.1' keymap='en-us'/>
|
39
|
+
<video>
|
40
|
+
<model type='cirrus' vram='16384' heads='1'/>
|
41
|
+
</video>
|
53
42
|
</devices>
|
54
|
-
|
55
43
|
</domain>
|
@@ -0,0 +1,49 @@
|
|
1
|
+
<domain type='kvm' xmlns:qemu='http://libvirt.org/schemas/domain/qemu/1.0'>
|
2
|
+
<name>vagrant-test_default</name>
|
3
|
+
<title></title>
|
4
|
+
<description>Source: /rootpath/Vagrantfile</description>
|
5
|
+
<uuid></uuid>
|
6
|
+
<memory>524288</memory>
|
7
|
+
<vcpu>1</vcpu>
|
8
|
+
<cpu mode='host-model'>
|
9
|
+
<model fallback='allow'></model>
|
10
|
+
</cpu>
|
11
|
+
<os>
|
12
|
+
<type>hvm</type>
|
13
|
+
<kernel></kernel>
|
14
|
+
<initrd></initrd>
|
15
|
+
<cmdline></cmdline>
|
16
|
+
</os>
|
17
|
+
<features>
|
18
|
+
<acpi/>
|
19
|
+
<apic/>
|
20
|
+
<pae/>
|
21
|
+
</features>
|
22
|
+
<clock offset='utc'>
|
23
|
+
</clock>
|
24
|
+
<devices>
|
25
|
+
<disk type='file' device='disk'>
|
26
|
+
<alias name='ua-box-volume-0'/>
|
27
|
+
<driver name='qemu' type='qcow2' cache='default'/>
|
28
|
+
<source file='/var/lib/libvirt/images/vagrant-test_default.img'/>
|
29
|
+
<target dev='vda' bus='virtio'/>
|
30
|
+
</disk>
|
31
|
+
<disk type='file' device='disk'>
|
32
|
+
<alias name='ua-box-volume-1'/>
|
33
|
+
<driver name='qemu' type='qcow2' cache='default'/>
|
34
|
+
<source file='/var/lib/libvirt/images/vagrant-test_default_1.img'/>
|
35
|
+
<target dev='vdb' bus='virtio'/>
|
36
|
+
</disk>
|
37
|
+
<serial type='pty'>
|
38
|
+
<target port='0'/>
|
39
|
+
</serial>
|
40
|
+
<console type='pty'>
|
41
|
+
<target port='0'/>
|
42
|
+
</console>
|
43
|
+
<input type='mouse' bus='ps2'/>
|
44
|
+
<graphics type='vnc' port='-1' autoport='yes' listen='127.0.0.1' keymap='en-us'/>
|
45
|
+
<video>
|
46
|
+
<model type='cirrus' vram='16384' heads='1'/>
|
47
|
+
</video>
|
48
|
+
</devices>
|
49
|
+
</domain>
|
@@ -4,6 +4,8 @@ require 'spec_helper'
|
|
4
4
|
require 'support/sharedcontext'
|
5
5
|
require 'support/libvirt_context'
|
6
6
|
|
7
|
+
require 'fog/libvirt/models/compute/volume'
|
8
|
+
|
7
9
|
require 'vagrant-libvirt/errors'
|
8
10
|
require 'vagrant-libvirt/util/byte_number'
|
9
11
|
require 'vagrant-libvirt/action/create_domain'
|
@@ -14,10 +16,9 @@ describe VagrantPlugins::ProviderLibvirt::Action::CreateDomain do
|
|
14
16
|
include_context 'unit'
|
15
17
|
include_context 'libvirt'
|
16
18
|
|
17
|
-
let(:libvirt_client) { double('libvirt_client') }
|
18
19
|
let(:servers) { double('servers') }
|
19
20
|
let(:volumes) { double('volumes') }
|
20
|
-
let(:domain_volume) {
|
21
|
+
let(:domain_volume) { instance_double(::Fog::Libvirt::Compute::Volume) }
|
21
22
|
|
22
23
|
let(:domain_xml) { File.read(File.join(File.dirname(__FILE__), File.basename(__FILE__, '.rb'), domain_xml_file)) }
|
23
24
|
let(:storage_pool_xml) { File.read(File.join(File.dirname(__FILE__), File.basename(__FILE__, '.rb'), storage_pool_xml_file)) }
|
@@ -33,7 +34,6 @@ describe VagrantPlugins::ProviderLibvirt::Action::CreateDomain do
|
|
33
34
|
allow(connection).to receive(:volumes).and_return(volumes)
|
34
35
|
allow(volumes).to receive(:all).and_return([domain_volume])
|
35
36
|
allow(domain_volume).to receive(:pool_name).and_return('default')
|
36
|
-
allow(domain_volume).to receive(:[]).with('name').and_return('vagrant-test_default.img')
|
37
37
|
allow(domain_volume).to receive(:path).and_return('/var/lib/libvirt/images/vagrant-test_default.img')
|
38
38
|
allow(machine).to receive_message_chain("box.name") { 'vagrant-libvirt/test' }
|
39
39
|
|
@@ -57,6 +57,10 @@ describe VagrantPlugins::ProviderLibvirt::Action::CreateDomain do
|
|
57
57
|
context 'connection => qemu:///system' do
|
58
58
|
let(:domain_xml_file) { 'default_domain.xml' }
|
59
59
|
|
60
|
+
before do
|
61
|
+
allow(machine.provider_config).to receive(:qemu_use_session).and_return(false)
|
62
|
+
end
|
63
|
+
|
60
64
|
context 'default pool' do
|
61
65
|
it 'should execute correctly' do
|
62
66
|
expect(servers).to receive(:create).with(xml: domain_xml).and_return(machine)
|
@@ -117,6 +121,48 @@ describe VagrantPlugins::ProviderLibvirt::Action::CreateDomain do
|
|
117
121
|
end
|
118
122
|
end
|
119
123
|
end
|
124
|
+
|
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
|
+
}
|
132
|
+
|
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)
|
136
|
+
|
137
|
+
expect(subject.call(env)).to be_nil
|
138
|
+
end
|
139
|
+
end
|
140
|
+
|
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') }
|
144
|
+
|
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')
|
150
|
+
|
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
|
157
|
+
|
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)
|
162
|
+
|
163
|
+
expect(subject.call(env)).to be_nil
|
164
|
+
end
|
165
|
+
end
|
120
166
|
end
|
121
167
|
|
122
168
|
context 'no default pool' do
|
@@ -137,10 +183,8 @@ describe VagrantPlugins::ProviderLibvirt::Action::CreateDomain do
|
|
137
183
|
end
|
138
184
|
|
139
185
|
context 'connection => qemu:///session' do
|
140
|
-
|
141
|
-
|
142
|
-
libvirt.qemu_use_session = true
|
143
|
-
EOF
|
186
|
+
before do
|
187
|
+
allow(machine.provider_config).to receive(:qemu_use_session).and_return(true)
|
144
188
|
end
|
145
189
|
|
146
190
|
context 'default pool' do
|